From: Timo Schulz Date: Sun, 3 Nov 2002 12:30:04 +0000 (+0000) Subject: Bug fix for the OpenPGP secret key order. X-Git-Tag: gnutls_0_5_11~14 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d3b3fe228981b9f3efe677ae27aa91c3f5d4e22c;p=thirdparty%2Fgnutls.git Bug fix for the OpenPGP secret key order. --- diff --git a/libextra/gnutls_openpgp.c b/libextra/gnutls_openpgp.c index 9a1ffc646d..aee63a83e4 100644 --- a/libextra/gnutls_openpgp.c +++ b/libextra/gnutls_openpgp.c @@ -453,29 +453,23 @@ _gnutls_openpgp_key2gnutls_key( gnutls_private_key *pkey, uint8 buf[512]; int rc = 0; - if( !pkey || raw_key->size <= 0 ) { - printf( "%s:%d: failed.\n", __FILE__, __LINE__ ); + if( !pkey || raw_key->size <= 0 ) return GNUTLS_E_INVALID_REQUEST; - } out = cdk_stream_tmp( ); - if( !out ) { - printf( "%s:%d: failed.\n", __FILE__, __LINE__ ); + if( !out ) return GNUTLS_E_INTERNAL_ERROR; - } cdk_stream_write( out, raw_key->data, raw_key->size ); cdk_stream_seek( out, 0 ); cdk_keydb_get_keyblock( out, &snode ); if( !snode ) { - printf( "%s:%d: failed.\n", __FILE__, __LINE__ ); rc = GNUTLS_E_INTERNAL_ERROR; goto leave; } pkt = cdk_kbnode_find_packet( snode, CDK_PKT_SECRET_KEY ); if( !pkt ) { - printf( "%s:%d: failed.\n", __FILE__, __LINE__ ); rc = GNUTLS_E_INTERNAL_ERROR; goto leave; } @@ -487,7 +481,6 @@ _gnutls_openpgp_key2gnutls_key( gnutls_private_key *pkey, cdk_pk_get_mpi( sk->pk, i, buf, &nbytes, NULL ); rc = _gnutls_mpi_scan_pgp( &pkey->params[i], buf, &nbytes ); if( rc ) { - printf( "%s:%d: failed.\n", __FILE__, __LINE__ ); rc = GNUTLS_E_MPI_SCAN_FAILED; release_mpi_array( pkey->params, i-1 ); goto leave; @@ -496,27 +489,23 @@ _gnutls_openpgp_key2gnutls_key( gnutls_private_key *pkey, pkey->params_size += cdk_pk_get_nskey( pke_algo ); for( j = 0; j < cdk_pk_get_nskey( pke_algo ); j++, i++ ) { nbytes = sizeof buf-1; - cdk_sk_get_mpi( sk, i, buf, &nbytes, NULL ); + cdk_sk_get_mpi( sk, j, buf, &nbytes, NULL ); rc = _gnutls_mpi_scan_pgp( &pkey->params[i], buf, &nbytes ); if ( rc ) { - printf( "%s:%d: failed.\n", __FILE__, __LINE__ ); rc = GNUTLS_E_MPI_SCAN_FAILED; release_mpi_array( pkey->params, i-1 ); goto leave; } } - if( is_ELG(pke_algo) ) { - printf( "%s:%d: failed.\n", __FILE__, __LINE__ ); + if( is_ELG(pke_algo) ) return GNUTLS_E_UNWANTED_ALGORITHM; - } else if( is_DSA(pke_algo) ) pkey->pk_algorithm = GNUTLS_PK_DSA; else if( is_RSA(pke_algo) ) pkey->pk_algorithm = GNUTLS_PK_RSA; rc = gnutls_set_datum( &pkey->raw, raw_key->data, raw_key->size ); if( rc < 0 ) { - printf( "%s:%d: failed.\n", __FILE__, __LINE__ ); release_mpi_array( pkey->params, i ); rc = GNUTLS_E_MEMORY_ERROR; } diff --git a/tests/openpgp_test.c b/tests/openpgp_test.c index 83a8cc1ab0..b61a6a7348 100644 --- a/tests/openpgp_test.c +++ b/tests/openpgp_test.c @@ -45,6 +45,7 @@ main( int argc, char ** argv ) gnutls_datum dat, xml, pk; gnutls_openpgp_name uid; gnutls_private_key * pkey; + gnutls_cert * cert; unsigned char fpr[20], keyid[8]; char *s, *t; size_t fprlen = 0; @@ -90,7 +91,17 @@ main( int argc, char ** argv ) assert( rc == 0 ); for( i = 0; i < 8; i++ ) printf( "%02X", keyid[i] ); - printf( "\n" ); + printf( "\n\n" ); + + printf( "Check MPIs\n" ); + cert = ctx->cert_list[0]; + printf( "number of certs %d\n", *ctx->cert_list_length ); + assert( *ctx->cert_list_length == 1 ); + printf( "number of items %d\n", cert->params_size ); + for( i = 0; i < cert->params_size; i++ ) { + nbits = gcry_mpi_get_nbits( cert->params[i] ); + printf( "mpi %d %d bits\n", i, nbits ); + } printf( "\nCheck key\n" ); rc = gnutls_openpgp_verify_key( NULL, &ctx->keyring, &dat, 1 ); @@ -102,8 +113,9 @@ main( int argc, char ** argv ) assert( pkey->params_size ); nbits = gcry_mpi_get_nbits( pkey->params[0] ); rc = pkey->pk_algorithm; - printf ("pk-algorithm %s %d bits\n", get_pkalgo( rc ), nbits ); - for( i = 1; i < pkey->params_size; i++ ) { + printf( "pk-algorithm %s %d bits\n", get_pkalgo( rc ), nbits ); + printf( "number of items %d\n", pkey->params_size ); + for( i = 0; i < pkey->params_size; i++ ) { nbits = gcry_mpi_get_nbits( pkey->params[i] ); printf( "mpi %d %d bits\n", i, nbits ); }