]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
Bug fix for the OpenPGP secret key order.
authorTimo Schulz <twoaday@gnutls.org>
Sun, 3 Nov 2002 12:30:04 +0000 (12:30 +0000)
committerTimo Schulz <twoaday@gnutls.org>
Sun, 3 Nov 2002 12:30:04 +0000 (12:30 +0000)
libextra/gnutls_openpgp.c
tests/openpgp_test.c

index 9a1ffc646d1206b2d4567e240d37116ac673dee1..aee63a83e4ea1ed3f3cb602cf79a05b80eda5929 100644 (file)
@@ -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;
     }
index 83a8cc1ab0d031eb8ad376b7dd416893d41203a8..b61a6a7348284c37475f8fabab19409a38629b94 100644 (file)
@@ -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 );
     }