mirror of
git://git.gnupg.org/gnupg.git
synced 2025-02-24 20:11:06 +01:00
2003-08-18 Timo Schulz <twoaday@freakmail.de>
* encode.c (encode_sesskey): Checked the code and removed the warning since all compatibility checks with PGP succeeded. * mainproc.c (symkey_decrypt_sesskey): Better check for the algorithm and check the return values of some functions.
This commit is contained in:
parent
4eb5165019
commit
73b5da4c7d
@ -1,3 +1,10 @@
|
||||
2003-08-18 Timo Schulz <twoaday@freakmail.de>
|
||||
|
||||
* encode.c (encode_sesskey): Checked the code and removed
|
||||
the warning since all compatibility checks with PGP succeeded.
|
||||
* mainproc.c (symkey_decrypt_sesskey): Better check for the
|
||||
algorithm and check the return values of some functions.
|
||||
|
||||
2003-08-07 Werner Koch <wk@gnupg.org>
|
||||
|
||||
* pkglue.c (pk_sign): Fix last change.
|
||||
|
35
g10/encode.c
35
g10/encode.c
@ -78,33 +78,36 @@ encode_store( const char *filename )
|
||||
}
|
||||
|
||||
static void
|
||||
encode_sesskey( DEK *dek, DEK **ret_dek, byte *enckey )
|
||||
encode_sesskey (DEK * dek, DEK ** ret_dek, byte * enckey)
|
||||
{
|
||||
#warning This functions needs a review.
|
||||
CIPHER_HANDLE hd;
|
||||
DEK *c;
|
||||
DEK * c;
|
||||
byte buf[33];
|
||||
|
||||
assert ( dek->keylen < 32 );
|
||||
assert (dek->keylen < 32);
|
||||
|
||||
c = xcalloc (1, sizeof *c );
|
||||
c = xcalloc (1, sizeof *c);
|
||||
c->keylen = dek->keylen;
|
||||
c->algo = dek->algo;
|
||||
make_session_key( c );
|
||||
/*log_hexdump( "thekey", c->key, c->keylen );*/
|
||||
make_session_key (c);
|
||||
/*log_hexdump ("thekey", c->key, c->keylen);*/
|
||||
|
||||
/* the encrypted session key is prefixed with a one-octet algorithm id */
|
||||
buf[0] = c->algo;
|
||||
memcpy( buf + 1, c->key, c->keylen );
|
||||
memcpy (buf + 1, c->key, c->keylen);
|
||||
|
||||
/* due to the fact that we use only checked values, consider each
|
||||
failure as fatal. */
|
||||
if (gcry_cipher_open (&hd, dek->algo, GCRY_CIPHER_MODE_CFB, 1))
|
||||
BUG();
|
||||
if (gcry_cipher_setkey (hd, dek->key, dek->keylen))
|
||||
BUG();
|
||||
gcry_cipher_setiv (hd, NULL, 0);
|
||||
gcry_cipher_encrypt (hd, buf, c->keylen + 1, NULL, 0);
|
||||
gcry_cipher_close (hd);
|
||||
|
||||
gcry_cipher_open (&hd, dek->algo, GCRY_CIPHER_MODE_CFB, 1 );
|
||||
gcry_cipher_setkey( hd, dek->key, dek->keylen );
|
||||
gcry_cipher_setiv( hd, NULL, 0 );
|
||||
gcry_cipher_encrypt( hd, buf, c->keylen + 1, NULL, 0 );
|
||||
gcry_cipher_close( hd );
|
||||
|
||||
memcpy( enckey, buf, c->keylen + 1 );
|
||||
wipememory( buf, sizeof buf ); /* burn key */
|
||||
memcpy (enckey, buf, c->keylen + 1);
|
||||
wipememory (buf, sizeof buf); /* burn key */
|
||||
*ret_dek = c;
|
||||
}
|
||||
|
||||
|
@ -239,25 +239,30 @@ add_signature( CTX c, PACKET *pkt )
|
||||
}
|
||||
|
||||
static void
|
||||
symkey_decrypt_sesskey( DEK *dek, byte *sesskey, size_t slen )
|
||||
symkey_decrypt_sesskey (DEK * dek, byte *sesskey, size_t slen)
|
||||
{
|
||||
CIPHER_HANDLE hd;
|
||||
int n;
|
||||
|
||||
if ( slen < 17 || slen > 33 ) {
|
||||
if (slen < 17 || slen > 33)
|
||||
{
|
||||
log_error ( _("weird size for an encrypted session key (%d)\n"),
|
||||
(int)slen);
|
||||
return;
|
||||
}
|
||||
gcry_cipher_open ( &hd, dek->algo, GCRY_CIPHER_MODE_CFB, 1 );
|
||||
gcry_cipher_setkey( hd, dek->key, dek->keylen );
|
||||
gcry_cipher_setiv( hd, NULL, 0 );
|
||||
gcry_cipher_decrypt( hd, sesskey, slen, NULL, 0);
|
||||
gcry_cipher_close( hd );
|
||||
/* we checked the DEK values before, so consider all errors as fatal */
|
||||
if (gcry_cipher_open (&hd, dek->algo, GCRY_CIPHER_MODE_CFB, 1))
|
||||
BUG();
|
||||
if (gcry_cipher_setkey (hd, dek->key, dek->keylen))
|
||||
BUG();
|
||||
gcry_cipher_setiv (hd, NULL, 0);
|
||||
gcry_cipher_decrypt (hd, sesskey, slen, NULL, 0);
|
||||
gcry_cipher_close (hd);
|
||||
/* check first byte (the cipher algo) */
|
||||
if ( sesskey[0] > 10 ) {
|
||||
log_error ( _("invalid symkey algorithm detected (%d)\n"),
|
||||
sesskey[0] );
|
||||
if (openpgp_cipher_test_algo (sesskey[0]))
|
||||
{
|
||||
log_error (_("invalid symkey algorithm detected (%d)\n"),
|
||||
sesskey[0]);
|
||||
return;
|
||||
}
|
||||
n = gcry_cipher_get_algo_keylen (sesskey[0]);
|
||||
@ -265,10 +270,10 @@ symkey_decrypt_sesskey( DEK *dek, byte *sesskey, size_t slen )
|
||||
BUG ();
|
||||
/* now we replace the dek components with the real session key
|
||||
to decrypt the contents of the sequencing packet. */
|
||||
dek->keylen = gcry_cipher_get_algo_keylen (sesskey[0]);
|
||||
dek->keylen = n;
|
||||
dek->algo = sesskey[0];
|
||||
memcpy (dek->key, sesskey + 1, dek->keylen);
|
||||
/*log_hexdump( "thekey", dek->key, dek->keylen );*/
|
||||
/*log_hexdump ("thekey", dek->key, dek->keylen);*/
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
x
Reference in New Issue
Block a user