From bf244e9aebc38f2308602e5dbda03273c6e194ed Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Mon, 28 Jul 2003 18:31:28 +0000 Subject: [PATCH] * parse-packet.c (parse_key): Allow to parse the gnu-divert-to-s2k mode. --- g10/ChangeLog | 5 +++++ g10/keyid.c | 2 ++ g10/parse-packet.c | 24 ++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/g10/ChangeLog b/g10/ChangeLog index 7de4dc6a8..f5a54e18c 100644 --- a/g10/ChangeLog +++ b/g10/ChangeLog @@ -1,3 +1,8 @@ +2003-07-28 Werner Koch + + * parse-packet.c (parse_key): Allow to parse the gnu-divert-to-s2k + mode. + 2003-07-27 David Shaw * packet.h, sig-check.c (signature_check2, do_check, diff --git a/g10/keyid.c b/g10/keyid.c index 43e531e3e..767a5ac92 100644 --- a/g10/keyid.c +++ b/g10/keyid.c @@ -60,6 +60,8 @@ do_fingerprint_md( PKT_public_key *pk ) int npkey = pubkey_get_npkey( pk->pubkey_algo ); md = md_open( pk->version < 4 ? DIGEST_ALGO_RMD160 : DIGEST_ALGO_SHA1, 0); + md_start_debug (md,"keyid"); +#warning fffff n = pk->version < 4 ? 8 : 6; for(i=0; i < npkey; i++ ) { nb[i] = mpi_get_nbits(pk->pkey[i]); diff --git a/g10/parse-packet.c b/g10/parse-packet.c index f966eb31e..f2ace1322 100644 --- a/g10/parse-packet.c +++ b/g10/parse-packet.c @@ -1559,6 +1559,7 @@ parse_key( IOBUF inp, int pkttype, unsigned long pktlen, if( pkttype == PKT_SECRET_KEY || pkttype == PKT_SECRET_SUBKEY ) { PKT_secret_key *sk = pkt->pkt.secret_key; byte temp[16]; + size_t snlen = 0; if( !npkey ) { sk->skey[0] = mpi_set_opaque( NULL, @@ -1631,6 +1632,8 @@ parse_key( IOBUF inp, int pkttype, unsigned long pktlen, break; case 1001: if( list_mode ) printf( "\tgnu-dummy S2K" ); break; + case 1002: if (list_mode) printf("\tgnu-divert-to-card S2K"); + break; default: if( list_mode ) printf( "\tunknown %sS2K %d\n", @@ -1666,6 +1669,19 @@ parse_key( IOBUF inp, int pkttype, unsigned long pktlen, printf("\tprotect count: %lu\n", (ulong)sk->protect.s2k.count); } + else if( sk->protect.s2k.mode == 1002 ) { + /* Read the serial number. */ + if (pktlen < 1) { + rc = G10ERR_INVALID_PACKET; + goto leave; + } + snlen = iobuf_get (inp); + pktlen--; + if (pktlen < snlen || snlen == -1) { + rc = G10ERR_INVALID_PACKET; + goto leave; + } + } } /* Note that a sk->protect.algo > 110 is illegal, but I'm not erroring on it here as otherwise there would be no @@ -1695,6 +1711,8 @@ parse_key( IOBUF inp, int pkttype, unsigned long pktlen, } if( sk->protect.s2k.mode == 1001 ) sk->protect.ivlen = 0; + else if( sk->protect.s2k.mode == 1002 ) + sk->protect.ivlen = snlen < 16? snlen : 16; if( pktlen < sk->protect.ivlen ) { rc = G10ERR_INVALID_PACKET; @@ -1703,7 +1721,8 @@ parse_key( IOBUF inp, int pkttype, unsigned long pktlen, for(i=0; i < sk->protect.ivlen && pktlen; i++, pktlen-- ) temp[i] = iobuf_get_noeof(inp); if( list_mode ) { - printf( "\tprotect IV: "); + printf( sk->protect.s2k.mode == 1002? "\tserial-number: " + : "\tprotect IV: "); for(i=0; i < sk->protect.ivlen; i++ ) printf(" %02x", temp[i] ); putchar('\n'); @@ -1716,7 +1735,8 @@ parse_key( IOBUF inp, int pkttype, unsigned long pktlen, * If the user is so careless, not to protect his secret key, * we can assume, that he operates an open system :=(. * So we put the key into secure memory when we unprotect it. */ - if( sk->protect.s2k.mode == 1001 ) { + if( sk->protect.s2k.mode == 1001 + || sk->protect.s2k.mode == 1002 ) { /* better set some dummy stuff here */ sk->skey[npkey] = mpi_set_opaque(NULL, m_strdup("dummydata"), 10); pktlen = 0;