Changeset View
Changeset View
Standalone View
Standalone View
b/agent/genkey.c
/* genkey.c - Generate a keypair | /* genkey.c - Generate a keypair | ||||
* Copyright (C) 2002, 2003, 2004, 2007, 2010 Free Software Foundation, Inc. | * Copyright (C) 2002, 2003, 2004, 2007, 2010 Free Software Foundation, Inc. | ||||
* Copyright (C) 2015 g10 Code GmbH. | |||||
* | * | ||||
* This file is part of GnuPG. | * This file is part of GnuPG. | ||||
* | * | ||||
Context not available. | |||||
/* Check whether the passphrase PW is suitable. Returns 0 if the | /* Check whether the passphrase PW is suitable. Returns 0 if the | ||||
passphrase is suitable and true if it is not and the user should be | passphrase is suitable and true if it is not and the user should be | ||||
asked to provide a different one. If SILENT is set, no message are | asked to provide a different one. If FAILED_CONSTRAINT is set, a | ||||
displayed. */ | message describing the problem is returned in | ||||
*FAILED_CONSTRAINT. */ | |||||
int | int | ||||
check_passphrase_constraints (ctrl_t ctrl, const char *pw, int silent) | check_passphrase_constraints (ctrl_t ctrl, const char *pw, | ||||
char **failed_constraint) | |||||
{ | { | ||||
gpg_error_t err = 0; | gpg_error_t err = 0; | ||||
unsigned int minlen = opt.min_passphrase_len; | unsigned int minlen = opt.min_passphrase_len; | ||||
Context not available. | |||||
"Please confirm that you do not want to " | "Please confirm that you do not want to " | ||||
"have any protection on your key.")); | "have any protection on your key.")); | ||||
if (silent) | err = 1; | ||||
return gpg_error (GPG_ERR_INV_PASSPHRASE); | if (failed_constraint) | ||||
{ | |||||
if (opt.enforce_passphrase_constraints) | |||||
*failed_constraint = xstrdup (desc); | |||||
else | |||||
err = take_this_one_anyway2 (ctrl, desc, | |||||
_("Yes, protection is not needed")); | |||||
} | |||||
err = take_this_one_anyway2 (ctrl, desc, | |||||
_("Yes, protection is not needed")); | |||||
goto leave; | goto leave; | ||||
} | } | ||||
Context not available. | |||||
in in silent mode which returns immediately. */ | in in silent mode which returns immediately. */ | ||||
if (utf8_charcount (pw) < minlen ) | if (utf8_charcount (pw) < minlen ) | ||||
{ | { | ||||
if (silent) | if (!failed_constraint) | ||||
{ | { | ||||
err = gpg_error (GPG_ERR_INV_PASSPHRASE); | err = gpg_error (GPG_ERR_INV_PASSPHRASE); | ||||
goto leave; | goto leave; | ||||
Context not available. | |||||
if (nonalpha_count (pw) < minnonalpha ) | if (nonalpha_count (pw) < minnonalpha ) | ||||
{ | { | ||||
if (silent) | if (!failed_constraint) | ||||
{ | { | ||||
err = gpg_error (GPG_ERR_INV_PASSPHRASE); | err = gpg_error (GPG_ERR_INV_PASSPHRASE); | ||||
goto leave; | goto leave; | ||||
Context not available. | |||||
if (*pw && opt.check_passphrase_pattern && | if (*pw && opt.check_passphrase_pattern && | ||||
check_passphrase_pattern (ctrl, pw)) | check_passphrase_pattern (ctrl, pw)) | ||||
{ | { | ||||
if (silent) | if (!failed_constraint) | ||||
{ | { | ||||
err = gpg_error (GPG_ERR_INV_PASSPHRASE); | err = gpg_error (GPG_ERR_INV_PASSPHRASE); | ||||
goto leave; | goto leave; | ||||
Context not available. | |||||
} | } | ||||
} | } | ||||
if (msg1 || msg2 || msg3) | if (failed_constraint && (msg1 || msg2 || msg3)) | ||||
{ | { | ||||
char *msg; | char *msg; | ||||
size_t n; | size_t n; | ||||
Context not available. | |||||
if (n > 3 && !strcmp (msg + n - 3, "%0A")) | if (n > 3 && !strcmp (msg + n - 3, "%0A")) | ||||
msg[n-3] = 0; | msg[n-3] = 0; | ||||
/* Show error messages. */ | err = 1; | ||||
err = take_this_one_anyway (ctrl, msg); | if (opt.enforce_passphrase_constraints) | ||||
xfree (msg); | *failed_constraint = msg; | ||||
else | |||||
{ | |||||
err = take_this_one_anyway (ctrl, msg); | |||||
xfree (msg); | |||||
} | |||||
} | } | ||||
leave: | leave: | ||||
Context not available. | |||||
gpg_error_t err; | gpg_error_t err; | ||||
const char *text1 = prompt; | const char *text1 = prompt; | ||||
const char *text2 = _("Please re-enter this passphrase"); | const char *text2 = _("Please re-enter this passphrase"); | ||||
const char *initial_errtext = NULL; | char *initial_errtext = NULL; | ||||
int initial_errtext_do_free = 0; | |||||
struct pin_entry_info_s *pi, *pi2; | struct pin_entry_info_s *pi, *pi2; | ||||
*r_passphrase = NULL; | *r_passphrase = NULL; | ||||
Context not available. | |||||
next_try: | next_try: | ||||
err = agent_askpin (ctrl, text1, NULL, initial_errtext, pi, NULL, 0); | err = agent_askpin (ctrl, text1, NULL, initial_errtext, pi, NULL, 0); | ||||
if (initial_errtext_do_free) | |||||
{ | |||||
xfree (initial_errtext); | |||||
initial_errtext_do_free = 0; | |||||
} | |||||
initial_errtext = NULL; | initial_errtext = NULL; | ||||
if (!err) | if (!err) | ||||
{ | { | ||||
if (check_passphrase_constraints (ctrl, pi->pin, 0)) | if (check_passphrase_constraints (ctrl, pi->pin, &initial_errtext)) | ||||
{ | { | ||||
initial_errtext_do_free = 1; | |||||
pi->failed_tries = 0; | pi->failed_tries = 0; | ||||
pi2->failed_tries = 0; | pi2->failed_tries = 0; | ||||
goto next_try; | goto next_try; | ||||
Context not available. |