1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-06-04 22:57:47 +02:00

* findkey.c (agent_key_from_file): Extra paranoid wipe.

* protect.c (agent_unprotect): Ditto.
(merge_lists): Ditto. Add arg RESULTLEN.
* pkdecrypt.c (agent_pkdecrypt): Don't show the secret key even in
debug mode.

* protect.c: Add DSA and Elgamal description.
This commit is contained in:
Werner Koch 2004-02-03 16:24:37 +00:00
parent 5bda9a8e74
commit 31de2267ec
5 changed files with 40 additions and 18 deletions

View File

@ -1,3 +1,13 @@
2004-02-03 Werner Koch <wk@gnupg.org>
* findkey.c (agent_key_from_file): Extra paranoid wipe.
* protect.c (agent_unprotect): Ditto.
(merge_lists): Ditto. Add arg RESULTLEN.
* pkdecrypt.c (agent_pkdecrypt): Don't show the secret key even in
debug mode.
* protect.c: Add DSA and Elgamal description.
2004-01-29 Werner Koch <wk@gnupg.org> 2004-01-29 Werner Koch <wk@gnupg.org>
* agent.h (server_control_s): Add connection_fd field. * agent.h (server_control_s): Add connection_fd field.

View File

@ -154,7 +154,7 @@ unprotect (CTRL ctrl,
sprintf (hexgrip+2*i, "%02X", grip[i]); sprintf (hexgrip+2*i, "%02X", grip[i]);
hexgrip[40] = 0; hexgrip[40] = 0;
/* first try to get it from the cache - if there is none or we can't /* First try to get it from the cache - if there is none or we can't
unprotect it, we fall back to ask the user */ unprotect it, we fall back to ask the user */
if (!ignore_cache) if (!ignore_cache)
{ {
@ -329,9 +329,9 @@ agent_key_from_file (CTRL ctrl,
return rc; return rc;
} }
/* Arggg FIXME: does scan support secure memory? */ buflen = gcry_sexp_canon_len (buf, 0, NULL, NULL);
rc = gcry_sexp_sscan (&s_skey, &erroff, rc = gcry_sexp_sscan (&s_skey, &erroff, buf, buflen);
buf, gcry_sexp_canon_len (buf, 0, NULL, NULL)); wipememory (buf, buflen);
xfree (buf); xfree (buf);
if (rc) if (rc)
{ {

View File

@ -93,12 +93,12 @@ agent_pkdecrypt (CTRL ctrl, const char *ciphertext, size_t ciphertextlen,
putc (0, outfp); putc (0, outfp);
} }
else else
{ /* no smartcard, but a private key */ { /* No smartcard, but a private key */
if (DBG_CRYPTO) /* if (DBG_CRYPTO ) */
{ /* { */
log_debug ("skey: "); /* log_debug ("skey: "); */
gcry_sexp_dump (s_skey); /* gcry_sexp_dump (s_skey); */
} /* } */
rc = gcry_pk_decrypt (&s_plain, s_cipher, s_skey); rc = gcry_pk_decrypt (&s_plain, s_cipher, s_skey);
if (rc) if (rc)

View File

@ -46,6 +46,8 @@ static struct {
int prot_from, prot_to; int prot_from, prot_to;
} protect_info[] = { } protect_info[] = {
{ "rsa", "nedpqu", 2, 5 }, { "rsa", "nedpqu", 2, 5 },
{ "dsa", "pqgyx", 4, 4 },
{ "elg", "pgyx", 3, 3 },
{ NULL } { NULL }
}; };
@ -432,13 +434,13 @@ do_decryption (const unsigned char *protected, size_t protectedlen,
xfree (outbuf); xfree (outbuf);
return rc; return rc;
} }
/* do a quick check first */ /* Do a quick check first. */
if (*outbuf != '(' && outbuf[1] != '(') if (*outbuf != '(' && outbuf[1] != '(')
{ {
xfree (outbuf); xfree (outbuf);
return gpg_error (GPG_ERR_BAD_PASSPHRASE); return gpg_error (GPG_ERR_BAD_PASSPHRASE);
} }
/* check that we have a consistent S-Exp */ /* Check that we have a consistent S-Exp. */
reallen = gcry_sexp_canon_len (outbuf, protectedlen, NULL, NULL); reallen = gcry_sexp_canon_len (outbuf, protectedlen, NULL, NULL);
if (!reallen || (reallen + blklen < protectedlen) ) if (!reallen || (reallen + blklen < protectedlen) )
{ {
@ -458,7 +460,8 @@ static int
merge_lists (const unsigned char *protectedkey, merge_lists (const unsigned char *protectedkey,
size_t replacepos, size_t replacepos,
const unsigned char *cleartext, const unsigned char *cleartext,
unsigned char *sha1hash, unsigned char **result) unsigned char *sha1hash,
unsigned char **result, size_t *resultlen)
{ {
size_t n, newlistlen; size_t n, newlistlen;
unsigned char *newlist, *p; unsigned char *newlist, *p;
@ -559,13 +562,16 @@ merge_lists (const unsigned char *protectedkey,
/* ready */ /* ready */
*result = newlist; *result = newlist;
*resultlen = newlistlen;
return 0; return 0;
failure: failure:
wipememory (newlist, newlistlen);
xfree (newlist); xfree (newlist);
return rc; return rc;
invalid_sexp: invalid_sexp:
wipememory (newlist, newlistlen);
xfree (newlist); xfree (newlist);
return gpg_error (GPG_ERR_INV_SEXP); return gpg_error (GPG_ERR_INV_SEXP);
} }
@ -589,6 +595,7 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase,
const unsigned char *prot_begin; const unsigned char *prot_begin;
unsigned char *cleartext; unsigned char *cleartext;
unsigned char *final; unsigned char *final;
size_t finallen;
s = protectedkey; s = protectedkey;
if (*s != '(') if (*s != '(')
@ -612,7 +619,7 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase,
if (!protect_info[infidx].algo) if (!protect_info[infidx].algo)
return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM); return gpg_error (GPG_ERR_UNSUPPORTED_ALGORITHM);
/* now find the list with the protected information. Here is an /* Now find the list with the protected information. Here is an
example for such a list: example for such a list:
(protected openpgp-s2k3-sha1-aes-cbc (protected openpgp-s2k3-sha1-aes-cbc
((sha1 <salt> <count>) <Initialization_Vector>) ((sha1 <salt> <count>) <Initialization_Vector>)
@ -669,7 +676,7 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase,
s++; /* skip list end */ s++; /* skip list end */
n = snext (&s); n = snext (&s);
if (n != 16) /* Wrong blocksize for IV (we support ony aes-128) */ if (n != 16) /* Wrong blocksize for IV (we support only aes-128). */
return gpg_error (GPG_ERR_CORRUPTED_PROTECTION); return gpg_error (GPG_ERR_CORRUPTED_PROTECTION);
iv = s; iv = s;
s += n; s += n;
@ -688,7 +695,11 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase,
return rc; return rc;
rc = merge_lists (protectedkey, prot_begin-protectedkey, cleartext, rc = merge_lists (protectedkey, prot_begin-protectedkey, cleartext,
sha1hash, &final); sha1hash, &final, &finallen);
/* Albeit cleartext has been allocated in secure memory and thus
xfree will wipe it out, we do an extra wipe just in case
somethings goes badly wrong. */
wipememory (cleartext, prot_begin-protectedkey);
xfree (cleartext); xfree (cleartext);
if (rc) if (rc)
return rc; return rc;
@ -698,6 +709,7 @@ agent_unprotect (const unsigned char *protectedkey, const char *passphrase,
rc = gpg_error (GPG_ERR_CORRUPTED_PROTECTION); rc = gpg_error (GPG_ERR_CORRUPTED_PROTECTION);
if (rc) if (rc)
{ {
wipememory (final, finallen);
xfree (final); xfree (final);
return rc; return rc;
} }
@ -954,7 +966,7 @@ agent_get_shadow_info (const unsigned char *shadowkey,
depth--; depth--;
s++; s++;
} }
/* found the shadowed list, s points to the protocol */ /* Found the shadowed list, S points to the protocol */
n = snext (&s); n = snext (&s);
if (!n) if (!n)
return gpg_error (GPG_ERR_INV_SEXP); return gpg_error (GPG_ERR_INV_SEXP);

View File

@ -1,5 +1,5 @@
/* query.c - fork of the pinentry to query stuff from the user /* query.c - fork of the pinentry to query stuff from the user
* Copyright (C) 2001, 2002 Free Software Foundation, Inc. * Copyright (C) 2001, 2002, 2004 Free Software Foundation, Inc.
* *
* This file is part of GnuPG. * This file is part of GnuPG.
* *