mirror of
git://git.gnupg.org/gnupg.git
synced 2025-01-18 14:17:03 +01:00
gpg: Use a more descriptive prompt for symmetric decryption.
* g10/keydb.h (GETPASSWORD_FLAG_SYMDECRYPT): New. (passphrase_to_dek_ext): Remove this obsolete prototype. * g10/passphrase.c (passphrase_get): Add arg flags. Use new flag value. (passphrase_to_dek): Add arg flags and pass it on. * g10/mainproc.c (proc_symkey_enc): Use new flag. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
50ea1b67e8
commit
03f83bcda5
@ -404,7 +404,7 @@ setup_symkey (STRING2KEY **symkey_s2k, DEK **symkey_dek)
|
|||||||
(*symkey_s2k)->hash_algo = s2kdigest;
|
(*symkey_s2k)->hash_algo = s2kdigest;
|
||||||
|
|
||||||
*symkey_dek = passphrase_to_dek (defcipher,
|
*symkey_dek = passphrase_to_dek (defcipher,
|
||||||
*symkey_s2k, 1, 0, NULL, &canceled);
|
*symkey_s2k, 1, 0, NULL, 0, &canceled);
|
||||||
if (!*symkey_dek || !(*symkey_dek)->keylen)
|
if (!*symkey_dek || !(*symkey_dek)->keylen)
|
||||||
{
|
{
|
||||||
xfree(*symkey_dek);
|
xfree(*symkey_dek);
|
||||||
|
@ -584,13 +584,14 @@ check_secret_key (PKT_public_key *pk, int n)
|
|||||||
*/
|
*/
|
||||||
DEK *
|
DEK *
|
||||||
passphrase_to_dek (int cipher_algo, STRING2KEY *s2k, int create, int nocache,
|
passphrase_to_dek (int cipher_algo, STRING2KEY *s2k, int create, int nocache,
|
||||||
const char *tmp, int *canceled)
|
const char *tmp, unsigned int flags, int *canceled)
|
||||||
{
|
{
|
||||||
(void)cipher_algo;
|
(void)cipher_algo;
|
||||||
(void)s2k;
|
(void)s2k;
|
||||||
(void)create;
|
(void)create;
|
||||||
(void)nocache;
|
(void)nocache;
|
||||||
(void)tmp;
|
(void)tmp;
|
||||||
|
(void)flags;
|
||||||
|
|
||||||
if (canceled)
|
if (canceled)
|
||||||
*canceled = 0;
|
*canceled = 0;
|
||||||
|
13
g10/keydb.h
13
g10/keydb.h
@ -277,20 +277,21 @@ gpg_error_t build_sk_list (ctrl_t ctrl, strlist_t locusr,
|
|||||||
SK_LIST *ret_sk_list, unsigned use);
|
SK_LIST *ret_sk_list, unsigned use);
|
||||||
|
|
||||||
/*-- passphrase.h --*/
|
/*-- passphrase.h --*/
|
||||||
|
|
||||||
|
/* Flags for passphrase_to_dek */
|
||||||
|
#define GETPASSWORD_FLAG_SYMDECRYPT 1
|
||||||
|
|
||||||
|
|
||||||
unsigned char encode_s2k_iterations (int iterations);
|
unsigned char encode_s2k_iterations (int iterations);
|
||||||
int have_static_passphrase(void);
|
int have_static_passphrase(void);
|
||||||
const char *get_static_passphrase (void);
|
const char *get_static_passphrase (void);
|
||||||
void set_passphrase_from_string(const char *pass);
|
void set_passphrase_from_string(const char *pass);
|
||||||
void read_passphrase_from_fd( int fd );
|
void read_passphrase_from_fd( int fd );
|
||||||
void passphrase_clear_cache (const char *cacheid);
|
void passphrase_clear_cache (const char *cacheid);
|
||||||
DEK *passphrase_to_dek_ext(u32 *keyid, int pubkey_algo,
|
|
||||||
int cipher_algo, STRING2KEY *s2k, int mode,
|
|
||||||
const char *tryagain_text,
|
|
||||||
const char *custdesc, const char *custprompt,
|
|
||||||
int *canceled);
|
|
||||||
DEK *passphrase_to_dek (int cipher_algo, STRING2KEY *s2k,
|
DEK *passphrase_to_dek (int cipher_algo, STRING2KEY *s2k,
|
||||||
int create, int nocache,
|
int create, int nocache,
|
||||||
const char *tryagain_text, int *canceled);
|
const char *tryagain_text, unsigned int flags,
|
||||||
|
int *canceled);
|
||||||
void set_next_passphrase( const char *s );
|
void set_next_passphrase( const char *s );
|
||||||
char *get_last_passphrase(void);
|
char *get_last_passphrase(void);
|
||||||
void next_to_last_passphrase(void);
|
void next_to_last_passphrase(void);
|
||||||
|
@ -420,7 +420,8 @@ proc_symkey_enc (CTX c, PACKET *pkt)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
c->dek = passphrase_to_dek (algo, &enc->s2k, 0, 0, NULL, NULL);
|
c->dek = passphrase_to_dek (algo, &enc->s2k, 0, 0, NULL,
|
||||||
|
GETPASSWORD_FLAG_SYMDECRYPT, NULL);
|
||||||
if (c->dek)
|
if (c->dek)
|
||||||
{
|
{
|
||||||
c->dek->symmetric = 1;
|
c->dek->symmetric = 1;
|
||||||
@ -709,7 +710,8 @@ proc_encrypted (CTX c, PACKET *pkt)
|
|||||||
log_info (_("assuming %s encrypted data\n"), "IDEA");
|
log_info (_("assuming %s encrypted data\n"), "IDEA");
|
||||||
}
|
}
|
||||||
|
|
||||||
c->dek = passphrase_to_dek (algo, s2k, 0, 0, NULL, &canceled);
|
c->dek = passphrase_to_dek (algo, s2k, 0, 0, NULL,
|
||||||
|
GETPASSWORD_FLAG_SYMDECRYPT, &canceled);
|
||||||
if (c->dek)
|
if (c->dek)
|
||||||
c->dek->algo_info_printed = 1;
|
c->dek->algo_info_printed = 1;
|
||||||
else if (canceled)
|
else if (canceled)
|
||||||
|
@ -221,15 +221,18 @@ read_passphrase_from_fd( int fd )
|
|||||||
* operation. If CACHEID is not NULL, it will be used as the cacheID
|
* operation. If CACHEID is not NULL, it will be used as the cacheID
|
||||||
* for the gpg-agent; if is NULL and a key fingerprint can be
|
* for the gpg-agent; if is NULL and a key fingerprint can be
|
||||||
* computed, this will be used as the cacheid.
|
* computed, this will be used as the cacheid.
|
||||||
|
*
|
||||||
|
* For FLAGS see passphrase_to_dek;
|
||||||
*/
|
*/
|
||||||
static char *
|
static char *
|
||||||
passphrase_get (int newsymkey, int nocache, const char *cacheid, int repeat,
|
passphrase_get (int newsymkey, int nocache, const char *cacheid, int repeat,
|
||||||
const char *tryagain_text, int *canceled)
|
const char *tryagain_text, unsigned int flags, int *canceled)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
char *pw = NULL;
|
char *pw = NULL;
|
||||||
char *orig_codeset;
|
char *orig_codeset;
|
||||||
const char *my_cacheid;
|
const char *my_cacheid;
|
||||||
|
const char *desc;
|
||||||
|
|
||||||
if (canceled)
|
if (canceled)
|
||||||
*canceled = 0;
|
*canceled = 0;
|
||||||
@ -244,6 +247,11 @@ passphrase_get (int newsymkey, int nocache, const char *cacheid, int repeat,
|
|||||||
if (tryagain_text)
|
if (tryagain_text)
|
||||||
tryagain_text = _(tryagain_text);
|
tryagain_text = _(tryagain_text);
|
||||||
|
|
||||||
|
if ((flags & GETPASSWORD_FLAG_SYMDECRYPT))
|
||||||
|
desc = _("Please enter the passphrase for decryption.");
|
||||||
|
else
|
||||||
|
desc = _("Enter passphrase\n");
|
||||||
|
|
||||||
/* Here we have:
|
/* Here we have:
|
||||||
* REPEAT is set in create mode and if opt.passphrase_repeat is set.
|
* REPEAT is set in create mode and if opt.passphrase_repeat is set.
|
||||||
* (Thus it is not a clean indication that we want a new passphrase).
|
* (Thus it is not a clean indication that we want a new passphrase).
|
||||||
@ -255,7 +263,7 @@ passphrase_get (int newsymkey, int nocache, const char *cacheid, int repeat,
|
|||||||
* for a full state analysis and thus this new parameter.
|
* for a full state analysis and thus this new parameter.
|
||||||
*/
|
*/
|
||||||
rc = agent_get_passphrase (my_cacheid, tryagain_text, NULL,
|
rc = agent_get_passphrase (my_cacheid, tryagain_text, NULL,
|
||||||
_("Enter passphrase\n"),
|
desc,
|
||||||
newsymkey, repeat, nocache, &pw);
|
newsymkey, repeat, nocache, &pw);
|
||||||
|
|
||||||
i18n_switchback (orig_codeset);
|
i18n_switchback (orig_codeset);
|
||||||
@ -314,11 +322,16 @@ passphrase_clear_cache (const char *cacheid)
|
|||||||
* CANCELED is not NULL, sets it to true.
|
* CANCELED is not NULL, sets it to true.
|
||||||
*
|
*
|
||||||
* If CREATE is true a new passphrase sll be created. If NOCACHE is
|
* If CREATE is true a new passphrase sll be created. If NOCACHE is
|
||||||
* true the symmetric key caching will not be used. */
|
* true the symmetric key caching will not be used.
|
||||||
|
*
|
||||||
|
* FLAG bits are:
|
||||||
|
* GETPASSWORD_FLAG_SYMDECRYPT := for symmetric decryption
|
||||||
|
*/
|
||||||
DEK *
|
DEK *
|
||||||
passphrase_to_dek (int cipher_algo, STRING2KEY *s2k,
|
passphrase_to_dek (int cipher_algo, STRING2KEY *s2k,
|
||||||
int create, int nocache,
|
int create, int nocache,
|
||||||
const char *tryagain_text, int *canceled)
|
const char *tryagain_text, unsigned int flags,
|
||||||
|
int *canceled)
|
||||||
{
|
{
|
||||||
char *pw = NULL;
|
char *pw = NULL;
|
||||||
DEK *dek;
|
DEK *dek;
|
||||||
@ -405,7 +418,7 @@ passphrase_to_dek (int cipher_algo, STRING2KEY *s2k,
|
|||||||
/* Divert to the gpg-agent. */
|
/* Divert to the gpg-agent. */
|
||||||
pw = passphrase_get (create, create && nocache, s2k_cacheid,
|
pw = passphrase_get (create, create && nocache, s2k_cacheid,
|
||||||
create? opt.passphrase_repeat : 0,
|
create? opt.passphrase_repeat : 0,
|
||||||
tryagain_text, canceled);
|
tryagain_text, flags, canceled);
|
||||||
if (*canceled)
|
if (*canceled)
|
||||||
{
|
{
|
||||||
xfree (pw);
|
xfree (pw);
|
||||||
|
@ -1463,7 +1463,7 @@ sign_symencrypt_file (ctrl_t ctrl, const char *fname, strlist_t locusr)
|
|||||||
if (!opt.quiet || !opt.batch)
|
if (!opt.quiet || !opt.batch)
|
||||||
log_info (_("%s encryption will be used\n"),
|
log_info (_("%s encryption will be used\n"),
|
||||||
openpgp_cipher_algo_name (algo) );
|
openpgp_cipher_algo_name (algo) );
|
||||||
cfx.dek = passphrase_to_dek (algo, s2k, 1, 1, NULL, &canceled);
|
cfx.dek = passphrase_to_dek (algo, s2k, 1, 1, NULL, 0, &canceled);
|
||||||
|
|
||||||
if (!cfx.dek || !cfx.dek->keylen) {
|
if (!cfx.dek || !cfx.dek->keylen) {
|
||||||
rc = gpg_error (canceled?GPG_ERR_CANCELED:GPG_ERR_BAD_PASSPHRASE);
|
rc = gpg_error (canceled?GPG_ERR_CANCELED:GPG_ERR_BAD_PASSPHRASE);
|
||||||
|
@ -341,13 +341,14 @@ check_secret_key (PKT_public_key *pk, int n)
|
|||||||
*/
|
*/
|
||||||
DEK *
|
DEK *
|
||||||
passphrase_to_dek (int cipher_algo, STRING2KEY *s2k, int create, int nocache,
|
passphrase_to_dek (int cipher_algo, STRING2KEY *s2k, int create, int nocache,
|
||||||
const char *tmp, int *canceled)
|
const char *tmp, unsigned int flags, int *canceled)
|
||||||
{
|
{
|
||||||
(void)cipher_algo;
|
(void)cipher_algo;
|
||||||
(void)s2k;
|
(void)s2k;
|
||||||
(void)create;
|
(void)create;
|
||||||
(void)nocache;
|
(void)nocache;
|
||||||
(void)tmp;
|
(void)tmp;
|
||||||
|
(void)flags;
|
||||||
|
|
||||||
if (canceled)
|
if (canceled)
|
||||||
*canceled = 0;
|
*canceled = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user