[OpenPGP:SDK svn] r488 - openpgpsdk/trunk/tests

Subversion ben at links.org
Mon Aug 20 16:42:50 BST 2007


Author: rachel
Date: 2007-08-20 16:42:50 +0100 (Mon, 20 Aug 2007)
New Revision: 488

Modified:
   openpgpsdk/trunk/tests/test_crypto.c
   openpgpsdk/trunk/tests/test_packet_types.c
   openpgpsdk/trunk/tests/test_rsa_decrypt.c
   openpgpsdk/trunk/tests/test_rsa_encrypt.c
   openpgpsdk/trunk/tests/tests.c
   openpgpsdk/trunk/tests/tests.h
Log:
Finally managed to get GPG to produce SE IP packets (secret: don't use --openpgp)
Minor refactoring.


Modified: openpgpsdk/trunk/tests/test_crypto.c
===================================================================
--- openpgpsdk/trunk/tests/test_crypto.c	2007-08-20 10:24:17 UTC (rev 487)
+++ openpgpsdk/trunk/tests/test_crypto.c	2007-08-20 15:42:50 UTC (rev 488)
@@ -11,11 +11,11 @@
 #include "openpgpsdk/crypto.h"
 #include "openpgpsdk/readerwriter.h"
 #include "../src/advanced/parse_local.h"
-#include <openssl/aes.h>
 #include <openssl/cast.h>
+#include <openssl/aes.h>
 #include <openssl/sha.h>
 */
-
+ 
 #include "tests.h"
 
 /*
@@ -94,7 +94,7 @@
     return 0;
     }
 
-static void test_cfb_aes()
+static void test_cfb_aes256()
     {
     // Used for trying low-level OpenSSL tests
 
@@ -112,39 +112,34 @@
     crypt.set_key(&crypt, key);
     ops_encrypt_init(&crypt);
 
-    // Why does aes encrypt/decrypt work??
-    //    crypt=&crypt_aes;
-
     unsigned char *in=ops_mallocz(crypt.blocksize);
     unsigned char *out=ops_mallocz(crypt.blocksize);
     unsigned char *out2=ops_mallocz(crypt.blocksize);
 
     snprintf((char *)in,crypt.blocksize,"hello");
-	/*
+
     printf("\n");
     printf("in:\t0x%.2x 0x%.2x 0x%.2x 0x%.2x   0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", 
            in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
     printf("in:\t%c    %c    %c    %c      %c    %c    %c    %c\n", 
            in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
-	*/
 
     crypt.block_encrypt(&crypt, out, in);
-    //    AES_ecb_encrypt(in,out,crypt.data,AES_ENCRYPT);
-	/*
+    //        AES_ecb_encrypt(in,out,crypt.data,AES_ENCRYPT);
+
     printf("out:\t0x%.2x 0x%.2x 0x%.2x 0x%.2x   0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", 
            out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]);
     printf("out:\t%c    %c    %c    %c      %c    %c    %c    %c\n", 
            out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]);
-	*/
 
+
     crypt.block_decrypt(&crypt, out2, out);
-    //    AES_ecb_encrypt(out,out2,crypt.data,AES_DECRYPT);
-	/*
+    //        AES_ecb_encrypt(out,out2,crypt.data,AES_DECRYPT);
     printf("out2:\t0x%.2x 0x%.2x 0x%.2x 0x%.2x   0x%.2x 0x%.2x 0x%.2x 0x%.2x\n", 
            out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]);
     printf("out2:\t%c    %c    %c    %c      %c    %c    %c    %c\n", 
            out2[0], out2[1], out2[2], out2[3], out2[4], out2[5], out2[6], out2[7]);
-	*/
+
     CU_ASSERT(memcmp((char *)in, (char *)out2, strlen((char *)in))==0);
 
     }
@@ -278,7 +273,7 @@
 
     // add tests to suite
     
-    if (NULL == CU_add_test(suite, "Test CFB AES", test_cfb_aes))
+    if (NULL == CU_add_test(suite, "Test CFB AES 256", test_cfb_aes256))
 	    return NULL;
 
     if (NULL == CU_add_test(suite, "Test CFB CAST", test_cfb_cast))

Modified: openpgpsdk/trunk/tests/test_packet_types.c
===================================================================
--- openpgpsdk/trunk/tests/test_packet_types.c	2007-08-20 10:24:17 UTC (rev 487)
+++ openpgpsdk/trunk/tests/test_packet_types.c	2007-08-20 15:42:50 UTC (rev 488)
@@ -20,7 +20,7 @@
 static unsigned char* encrypted_pk_sk=NULL;
 static size_t sz_encrypted_pk_sk=0;
 
-static void suite_cleanup();
+static void local_cleanup();
 
 /* 
  * Packet Types initialisation.
@@ -207,7 +207,7 @@
     CU_ASSERT(strncmp((char *)literal_data,in,MAXBUF)==0);
 
     // cleanup
-    suite_cleanup();
+    local_cleanup();
     ops_teardown_memory_read(pinfo,mem);
     free (in);
     }
@@ -254,7 +254,7 @@
     CU_ASSERT(memcmp(literal_data,in,MAXBUF)==0);
 
     // cleanup
-    suite_cleanup();
+    local_cleanup();
     ops_teardown_memory_read(pinfo,mem);
     free (in);
     }
@@ -303,7 +303,7 @@
         CU_ASSERT(memcmp(mdc_data, hashed, OPS_SHA1_HASH_SIZE)==0);
 
 	// clean up
-    suite_cleanup();
+    local_cleanup();
     ops_teardown_memory_read(pinfo,mem);
 	}
 
@@ -368,11 +368,45 @@
     CU_ASSERT(memcmp(literal_data,ldt_text, strlen(ldt_text))==0);
 
     // cleanup
-    suite_cleanup();
+    local_cleanup();
     ops_teardown_memory_read(pinfo,mem);
     ops_memory_free(mem_ldt);
     }
 
+static void test_ops_pk_session_key()
+    {
+    ops_pk_session_key_t *encrypted_pk_session_key;
+    ops_create_info_t *cinfo;
+    ops_parse_info_t *pinfo;
+    ops_memory_t *mem;
+    int rtn=0;
+
+    // setup for write
+    ops_setup_memory_write(&cinfo,&mem,MAXBUF);
+
+    // write
+    const ops_key_data_t *pub_key=ops_keyring_find_key_by_userid(&pub_keyring, alpha_user_id);
+    assert(pub_key);
+
+    encrypted_pk_session_key=ops_create_pk_session_key(pub_key);
+    ops_write_pk_session_key(cinfo,encrypted_pk_session_key);
+
+    // setup for read
+    ops_setup_memory_read(&pinfo,mem,callback_encrypted_pk_session_key);
+
+    // read
+    rtn=ops_parse(pinfo);
+    CU_ASSERT(rtn==1);
+
+    // test
+    CU_ASSERT(memcmp(encrypted_pk_session_key, encrypted_pk_sk, sz_encrypted_pk_sk)==0);
+
+    // cleanup
+    local_cleanup();
+    ops_teardown_memory_read(pinfo,mem);
+    }
+
+#ifdef XXX
 static void test_ops_encrypted_pk_sk()
     {
     ops_pk_session_key_t *encrypted_pk_session_key;
@@ -402,9 +436,10 @@
     CU_ASSERT(memcmp(encrypted_pk_session_key, encrypted_pk_sk, sz_encrypted_pk_sk)==0);
 
     // cleanup
-    suite_cleanup();
+    local_cleanup();
     ops_teardown_memory_read(pinfo,mem);
     }
+#endif
 
 CU_pSuite suite_packet_types()
 {
@@ -428,13 +463,13 @@
     if (NULL == CU_add_test(suite, "Tag 20: Sym. Encrypted Integrity Protected Data packet", test_ops_se_ip))
 	    return NULL;
 
-    if (NULL == CU_add_test(suite, "Tag 1: PK Encrypted Session Key packet", test_ops_encrypted_pk_sk))
+    if (NULL == CU_add_test(suite, "Tag 1: PK Encrypted Session Key packet", test_ops_pk_session_key))
 	    return NULL;
 
     return suite;
 }
 
-static void suite_cleanup()
+static void local_cleanup()
     {
     if (literal_data)
         {

Modified: openpgpsdk/trunk/tests/test_rsa_decrypt.c
===================================================================
--- openpgpsdk/trunk/tests/test_rsa_decrypt.c	2007-08-20 10:24:17 UTC (rev 487)
+++ openpgpsdk/trunk/tests/test_rsa_decrypt.c	2007-08-20 15:42:50 UTC (rev 488)
@@ -17,14 +17,11 @@
 #include "../src/advanced/parse_local.h"
 #include "../src/advanced/keyring_local.h"
 
-//static char secring[MAXBUF+1];
-//static char dir[MAXBUF+1];
-//static char keydetails[MAXBUF+1];
-static ops_keyring_t keyring;
-static char *filename_rsa_noarmour_nopassphrase="rsa_noarmour_nopassphrase.txt";
-static char *filename_rsa_armour_nopassphrase="rsa_armour_nopassphrase.txt";
-static char *filename_rsa_noarmour_passphrase="rsa_noarmour_passphrase.txt";
-static char *filename_rsa_armour_passphrase="rsa_armour_passphrase.txt";
+//static ops_keyring_t keyring;
+static char *filename_rsa_noarmour_nopassphrase="dec_rsa_noarmour_nopassphrase.txt";
+static char *filename_rsa_armour_nopassphrase="dec_rsa_armour_nopassphrase.txt";
+static char *filename_rsa_noarmour_passphrase="dec_rsa_noarmour_passphrase.txt";
+static char *filename_rsa_armour_passphrase="dec_rsa_armour_passphrase.txt";
 static char *nopassphrase="";
 static char *passphrase="hello";
 static char *current_passphrase=NULL;
@@ -54,9 +51,9 @@
     {
     ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content;
     static ops_boolean_t skipping;
-    static const ops_key_data_t *decrypter;
-    const ops_key_data_t *keydata=NULL;
-    const ops_secret_key_t *secret;
+    //    static const ops_key_data_t *decrypter;
+    //    const ops_key_data_t *keydata=NULL;
+    //    const ops_secret_key_t *secret;
 
     OPS_USED(cbinfo);
 
@@ -82,66 +79,25 @@
 	break;
 
     case OPS_PTAG_CT_PK_SESSION_KEY:
-		//	printf ("OPS_PTAG_CT_PK_SESSION_KEY\n");
-	if(decrypter)
-	    break;
+        return callback_pk_session_key(content_,cbinfo);
+        break;
 
-	decrypter=ops_keyring_find_key_by_id(&keyring,
-					     content->pk_session_key.key_id);
-	if(!decrypter)
-	    break;
-	break;
-
     case OPS_PARSER_CMD_GET_SECRET_KEY:
-	keydata=ops_keyring_find_key_by_id(&keyring,content->get_secret_key.pk_session_key->key_id);
-	if (!keydata || !ops_key_is_secret(keydata))
-	    return 0;
+        return callback_cmd_get_secret_key(content_,cbinfo);
+        break;
 
-	//	ops_set_secret_key(content,keydata);
-
-	// Do we need the passphrase and not have it? If so, get it
-	ops_parser_content_t pc;
-	char *passphrase;
-	memset(&pc,'\0',sizeof pc);
-	passphrase=NULL;
-	pc.content.secret_key_passphrase.passphrase=&passphrase;
-	pc.content.secret_key_passphrase.secret_key=&(keydata->key.skey);
-
-	/* Ugh. Need to duplicate this macro here to get the passphrase 
-	   Duplication to be removed when the callback gets moved to main code.
-	   Can we make this inline code rather than a macro?
-	*/
-#define CB(cbinfo,t,pc)	do { (pc)->tag=(t); if((cbinfo)->cb(pc,(cbinfo)) == OPS_RELEASE_MEMORY) ops_parser_content_free(pc); } while(0)
-	CB(cbinfo,OPS_PARSER_CMD_GET_SK_PASSPHRASE,&pc);
-	
-	/* now get the key from the data */
-	secret=ops_get_secret_key_from_data(keydata);
-	while(!secret)
-	    {
-	    /* then it must be encrypted */
-	    secret=ops_decrypt_secret_key_from_data(keydata,passphrase);
-	    free(passphrase);
-	    }
-
-	*content->get_secret_key.secret_key=secret;
-	
-	break;
-
     case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
-	/*
-	  Doing this so the test can be automated.
-	  Will move this into separate stacked callback later
-	*/
-	*(content->secret_key_passphrase.passphrase)=ops_malloc_passphrase(current_passphrase);
-	return OPS_KEEP_MEMORY;
-	break;
+        return callback_cmd_get_secret_key_passphrase(content_,cbinfo);
+        break;
 
     case OPS_PTAG_CT_LITERAL_DATA_BODY:
+        /*
 	text=ops_mallocz(content->literal_data_body.length+1);
 	memcpy(text,content->literal_data_body.data,content->literal_data_body.length);
+        */
+        return callback_literal_data(content_,cbinfo);
 		break;
 
-    case OPS_PARSER_PTAG:
     case OPS_PTAG_CT_ARMOUR_HEADER:
     case OPS_PTAG_CT_ARMOUR_TRAILER:
     case OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY:
@@ -149,15 +105,19 @@
     case OPS_PTAG_CT_LITERAL_DATA_HEADER:
     case OPS_PTAG_CT_SE_IP_DATA_BODY:
     case OPS_PTAG_CT_SE_IP_DATA_HEADER:
+    case OPS_PTAG_CT_SE_DATA_BODY:
+    case OPS_PTAG_CT_SE_DATA_HEADER:
+
 	// Ignore these packets 
 	// They're handled in ops_parse_one_packet()
 	// and nothing else needs to be done
 	break;
 
     default:
-	fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag,
-		content_->tag);
-	assert(0);
+        return callback_general(content_,cbinfo);
+        //	fprintf(stderr,"Unexpected packet tag=%d (0x%x)\n",content_->tag,
+        //		content_->tag);
+        //	assert(0);
 	}
 
     return OPS_RELEASE_MEMORY;
@@ -170,15 +130,7 @@
 
 int init_suite_rsa_decrypt(void)
     {
-#ifdef XXX
-    int fd=0;
     char cmd[MAXBUF+1];
-    char *rsa_nopass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Alpha\nName-Comment: RSA, no passphrase\nName-Email: alpha at test.com\nKey-Length: 1024\n";
-    char *rsa_pass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Bravo\nName-Comment: RSA, passphrase\nName-Email: bravo at test.com\nPassphrase: hello\nKey-Length: 1024\n";
-    
-    // Create temp directory
-    if (!mktmpdir())
-	return 1;
 
     // Create RSA test files
 
@@ -187,6 +139,47 @@
     create_testfile(filename_rsa_noarmour_passphrase);
     create_testfile(filename_rsa_armour_passphrase);
 
+    // Restrict list of algorithms used
+   
+    //    snprintf(cmd,MAXBUF,"gpg --homedir=%s --default-preference-list \"CAST5\"", dir);
+    //    if (system(cmd))
+    //        return -1;
+
+    // Now encrypt the test files with GPG
+    // Note:: To make it do SE_IP packets, do NOT use --openpgp and DO use --force-mdc
+    snprintf(cmd,MAXBUF,"gpg --homedir=%s --cipher-algo \"CAST5\" --force-mdc --compress-level 0 --quiet --encrypt --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase);
+    if (system(cmd))
+        {
+        return 1;
+        }
+
+    snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --encrypt --personal-cipher-preferences='CAST5' --armor --homedir=%s --recipient Alpha %s/%s", dir, dir, filename_rsa_armour_nopassphrase);
+    if (system(cmd))
+        {
+        return 1;
+        }
+    
+    snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --encrypt --s2k-cipher-algo CAST5 --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_noarmour_passphrase);
+    if (system(cmd))
+        {
+        return 1;
+        }
+
+    snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --encrypt --s2k-cipher-algo CAST5 --armor --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_armour_passphrase);
+    if (system(cmd))
+        {
+        return 1;
+        }
+
+#ifdef XXX
+    int fd=0;
+    char *rsa_nopass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Alpha\nName-Comment: RSA, no passphrase\nName-Email: alpha at test.com\nKey-Length: 1024\n";
+    char *rsa_pass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Bravo\nName-Comment: RSA, passphrase\nName-Email: bravo at test.com\nPassphrase: hello\nKey-Length: 1024\n";
+    
+    // Create temp directory
+    if (!mktmpdir())
+	return 1;
+
     /*
      * Create a RSA keypair with no passphrase
      */
@@ -202,23 +195,9 @@
     write(fd,rsa_nopass,strlen(rsa_nopass));
     close(fd);
 
-    snprintf(cmd,MAXBUF,"gpg --quiet --gen-key --expert --homedir=%s --batch %s",dir,keydetails);
+    snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --gen-key --expert --homedir=%s --batch %s",dir,keydetails);
     system(cmd);
 
-    // Now encrypt the test file with GPG
-    snprintf(cmd,MAXBUF,"gpg --quiet --encrypt --homedir=%s --recipient Alpha %s/%s", dir, dir, filename_rsa_noarmour_nopassphrase);
-    if (system(cmd))
-	{
-	return 1;
-	}
-
-    // Now encrypt and ascii-armour the test file with GPG
-    snprintf(cmd,MAXBUF,"gpg --quiet --encrypt --armor --homedir=%s --recipient Alpha %s/%s", dir, dir, filename_rsa_armour_nopassphrase);
-    if (system(cmd))
-	{
-	return 1;
-	}
-    
     /*
      * Create a RSA keypair with passphrase
      */
@@ -233,23 +212,10 @@
     write(fd,rsa_pass,strlen(rsa_pass));
     close(fd);
 
-    snprintf(cmd,MAXBUF,"gpg --quiet --gen-key --expert --homedir=%s --batch %s",dir,keydetails);
+    snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --gen-key --expert --homedir=%s --batch %s",dir,keydetails);
     system(cmd);
 
-    // Now encrypt the test file with GPG
-    snprintf(cmd,MAXBUF,"gpg --quiet --encrypt --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_noarmour_passphrase);
-    if (system(cmd))
-	{
-	return 1;
-	}
 
-    // Now encrypt and ascii-armour the test file with GPG
-    snprintf(cmd,MAXBUF,"gpg --quiet --encrypt --armor --homedir=%s --recipient Bravo %s/%s", dir, dir, filename_rsa_armour_passphrase);
-    if (system(cmd))
-	{
-	return 1;
-	}
-
     // Initialise OPS 
     ops_init();
 
@@ -298,10 +264,10 @@
     snprintf(encfile,MAXBUF,"%s/%s.%s",dir,filename,suffix);
     fd=open(encfile,O_RDONLY);
     if(fd < 0)
-	{
-	perror(encfile);
-	exit(2);
-	}
+        {
+        perror(encfile);
+        exit(2);
+        }
     
     // Set decryption reader and handling options
 
@@ -312,7 +278,7 @@
     // Set up armour/passphrase options
 
     if (has_armour)
-	ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false);
+        ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false);
     current_passphrase=has_passphrase ? passphrase : nopassphrase;
     
     // Do the decryption

Modified: openpgpsdk/trunk/tests/test_rsa_encrypt.c
===================================================================
--- openpgpsdk/trunk/tests/test_rsa_encrypt.c	2007-08-20 10:24:17 UTC (rev 487)
+++ openpgpsdk/trunk/tests/test_rsa_encrypt.c	2007-08-20 15:42:50 UTC (rev 488)
@@ -11,15 +11,15 @@
 
 #include "tests.h"
 
-static char *filename_rsa_noarmour_singlekey="rsa_noarmour_singlekey.txt";
-static char *filename_rsa_armour_singlekey="rsa_armour_singlekey.txt";
+static char *filename_rsa_noarmour_singlekey="enc_rsa_noarmour_singlekey.txt";
+static char *filename_rsa_armour_singlekey="enc_rsa_armour_singlekey.txt";
 
 static ops_parse_cb_return_t
 callback_ops_decrypt(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo)
     {
     ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content;
     static ops_boolean_t skipping;
-    static const ops_key_data_t *decrypter;
+    //    static const ops_key_data_t *decrypter;
     //    const ops_key_data_t *keydata=NULL;
     //    const ops_secret_key_t *secret;
 
@@ -47,16 +47,8 @@
 	break;
 
     case OPS_PTAG_CT_PK_SESSION_KEY:
-		//	printf ("OPS_PTAG_CT_PK_SESSION_KEY\n");
-	if(decrypter)
-	    break;
+        return callback_pk_session_key(content_,cbinfo);
 
-	decrypter=ops_keyring_find_key_by_id(&sec_keyring,
-					     content->pk_session_key.key_id);
-	if(!decrypter)
-	    break;
-	break;
-
     case OPS_PARSER_CMD_GET_SECRET_KEY:
         return callback_cmd_get_secret_key(content_,cbinfo);
 

Modified: openpgpsdk/trunk/tests/tests.c
===================================================================
--- openpgpsdk/trunk/tests/tests.c	2007-08-20 10:24:17 UTC (rev 487)
+++ openpgpsdk/trunk/tests/tests.c	2007-08-20 15:42:50 UTC (rev 488)
@@ -25,7 +25,10 @@
 unsigned char* literal_data=NULL;
 size_t sz_literal_data=0;
 char *alpha_user_id="Alpha (RSA, no passphrase) <alpha at test.com>";
+char *bravo_user_id="Bravo (RSA, passphrase) <bravo at test.com>";
 
+const ops_key_data_t *decrypter=NULL;
+
 void setup_test_keys()
     {
     char keydetails[MAXBUF+1];
@@ -34,6 +37,8 @@
     char cmd[MAXBUF+1];
 
     char *rsa_nopass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Alpha\nName-Comment: RSA, no passphrase\nName-Email: alpha at test.com\nKey-Length: 1024\n";
+    char *rsa_pass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Bravo\nName-Comment: RSA, passphrase\nName-Email: bravo at test.com\nPassphrase: hello\nKey-Length: 1024\n";
+
     // Create temp directory
     if (!mktmpdir())
         return;
@@ -46,17 +51,37 @@
 
     if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0)
         {
-        fprintf(stderr,"Can't create key details\n");
+        fprintf(stderr,"Can't create Alpha key details\n");
         return;
         }
 
     write(fd,rsa_nopass,strlen(rsa_nopass));
     close(fd);
 
-    snprintf(cmd,MAXBUF,"gpg --quiet --gen-key --expert --homedir=%s --batch %s",dir,keydetails);
+    snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --gen-key --expert --homedir=%s --batch %s",dir,keydetails);
     system(cmd);
+
+    /*
+     * Create a RSA keypair with passphrase
+     */
+
+    snprintf(keydetails,MAXBUF,"%s/%s",dir,"keydetails.bravo");
+
+    if ((fd=open(keydetails,O_WRONLY | O_CREAT | O_EXCL, 0600))<0)
+        {
+        fprintf(stderr,"Can't create Bravo key details\n");
+        return;
+        }
+
+    write(fd,rsa_pass,strlen(rsa_pass));
+    close(fd);
+
+    snprintf(cmd,MAXBUF,"gpg --openpgp --quiet --gen-key --expert --homedir=%s --batch %s",dir,keydetails);
+    system(cmd);
     
-    // read keyrings
+    /*
+     * read keyrings
+     */
 
     snprintf(keyring_name,MAXBUF,"%s/pubring.gpg", dir);
     ops_keyring_read(&pub_keyring,keyring_name);
@@ -109,15 +134,13 @@
         return CU_get_error();
         }
 
-    /*
-    if (NULL == suite_rsa_decrypt()) 
+    if (NULL == suite_rsa_encrypt()) 
         {
         CU_cleanup_registry();
         return CU_get_error();
         }
-    */
 
-    if (NULL == suite_rsa_encrypt()) 
+    if (NULL == suite_rsa_decrypt()) 
         {
         CU_cleanup_registry();
         return CU_get_error();
@@ -230,9 +253,6 @@
     ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content;
     const ops_key_data_t *keydata=NULL;
     const ops_secret_key_t *secret;
-    /*
-    static const ops_key_data_t *decrypt_key;
-    */
 
     OPS_USED(cbinfo);
 
@@ -251,7 +271,6 @@
         memset(&pc,'\0',sizeof pc);
         passphrase=NULL;
         pc.content.secret_key_passphrase.passphrase=&passphrase;
-        //        pc.content.secret_key_passphrase.secret_key=&(keydata->key.skey);
         pc.content.secret_key_passphrase.secret_key=ops_get_secret_key_from_data(keydata);
 
         /* Ugh. Need to duplicate this macro here to get the passphrase 
@@ -299,7 +318,6 @@
     case OPS_PARSER_CMD_GET_SK_PASSPHRASE:
         /*
           Doing this so the test can be automated.
-          Will move this into separate stacked callback later
         */
         *(content->secret_key_passphrase.passphrase)=ops_malloc_passphrase(no_passphrase);
         return OPS_KEEP_MEMORY;
@@ -341,6 +359,36 @@
     return OPS_RELEASE_MEMORY;
     }
  
+ops_parse_cb_return_t
+callback_pk_session_key(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo)
+    {
+    ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content;
+    
+    OPS_USED(cbinfo);
+
+    //    ops_print_packet(content_);
+    
+    // Read data from packet into static buffer
+    switch(content_->tag)
+        {
+    case OPS_PTAG_CT_PK_SESSION_KEY:
+		//	printf ("OPS_PTAG_CT_PK_SESSION_KEY\n");
+        if(decrypter)
+            break;
+
+        decrypter=ops_keyring_find_key_by_id(&sec_keyring,
+                                             content->pk_session_key.key_id);
+        if(!decrypter)
+            break;
+        break;
+
+    default:
+        return callback_general(content_,cbinfo);
+        }
+
+    return OPS_RELEASE_MEMORY;
+    }
+
 void reset_vars()
     {
     if (literal_data)
@@ -349,6 +397,11 @@
         literal_data=NULL;
         sz_literal_data=0;
         }
+    if (decrypter)
+        {
+        //        free (decrypter);
+        decrypter=NULL;
+        }
     }
 
 int file_compare(char* file1, char* file2)

Modified: openpgpsdk/trunk/tests/tests.h
===================================================================
--- openpgpsdk/trunk/tests/tests.h	2007-08-20 10:24:17 UTC (rev 487)
+++ openpgpsdk/trunk/tests/tests.h	2007-08-20 15:42:50 UTC (rev 488)
@@ -28,6 +28,8 @@
 callback_cmd_get_secret_key_passphrase(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo);
 ops_parse_cb_return_t
 callback_literal_data(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo);
+ops_parse_cb_return_t
+callback_pk_session_key(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo);
 
 void reset_vars();
 int file_compare(char* file1, char* file2);
@@ -37,5 +39,7 @@
 unsigned char* literal_data;
 size_t sz_literal_data;
 char* alpha_user_id;
+char* bravo_user_id;
+const ops_key_data_t *decrypter;
 #endif
 



More information about the OpenPGPsdk-svn mailing list