summaryrefslogtreecommitdiffstats
path: root/g10/seckey-cert.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2002-08-16 09:13:13 +0200
committerWerner Koch <wk@gnupg.org>2002-08-16 09:13:13 +0200
commit0996f7d4dfc81b69814063c8ca829be4ac793d55 (patch)
tree18343e52d3a460fa9015e157fef6885d7bccb992 /g10/seckey-cert.c
parent* hkp.c (parse_hkp_index): Properly handle really large keys (5 digit key (diff)
downloadgnupg2-0996f7d4dfc81b69814063c8ca829be4ac793d55.tar.xz
gnupg2-0996f7d4dfc81b69814063c8ca829be4ac793d55.zip
* seckey-cert.c: Workaround to allow decryption of v3 keys created
with a bug in the mpi_get_secure_buffer.
Diffstat (limited to '')
-rw-r--r--g10/seckey-cert.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/g10/seckey-cert.c b/g10/seckey-cert.c
index 01f4c7b2f..2eadc9dd3 100644
--- a/g10/seckey-cert.c
+++ b/g10/seckey-cert.c
@@ -158,6 +158,32 @@ do_check( PKT_secret_key *sk, const char *tryagain_text )
csum += checksum_mpi( sk->skey[i] );
m_free( buffer );
}
+ if( csum != sk->csum ) {
+ /* Due to a fix of a bug in mpi_get_secure_buffer we
+ might encounter seceret keys which are not correctly
+ encrypted. We fix this by a second try, this time
+ with a reversed bug fix (the memmove below). */
+ byte *p;
+
+ copy_secret_key( sk, save_sk );
+ cipher_setiv( cipher_hd, sk->protect.iv, sk->protect.ivlen );
+ csum = 0;
+ for(i=pubkey_get_npkey (sk->pubkey_algo);
+ i < pubkey_get_nskey (sk->pubkey_algo); i++ ) {
+ buffer = mpi_get_secure_buffer (sk->skey[i], &nbytes,NULL);
+ for (p=buffer; !*p && nbytes; p++, --nbytes )
+ ;
+ if (p != buffer)
+ memmove (buffer, p, nbytes);
+ cipher_sync (cipher_hd);
+ assert (mpi_is_protected(sk->skey[i]));
+ cipher_decrypt (cipher_hd, buffer, buffer, nbytes);
+ mpi_set_buffer (sk->skey[i], buffer, nbytes, 0);
+ mpi_clear_protect_flag (sk->skey[i]);
+ csum += checksum_mpi (sk->skey[i]);
+ m_free (buffer);
+ }
+ }
if( opt.emulate_bugs & EMUBUG_GPGCHKSUM ) {
csum = sk->csum;
}