Changeset 507
- Timestamp:
- 09/20/07 11:03:06
- Files:
-
- openpgpsdk/trunk/tests/test_rsa_encrypt.c (modified) (10 diffs)
- openpgpsdk/trunk/tests/test_rsa_verify.c (modified) (1 diff)
- openpgpsdk/trunk/tests/tests.c (modified) (5 diffs)
- openpgpsdk/trunk/tests/tests.h (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/tests/test_rsa_encrypt.c
r506 r507 12 12 #include "tests.h" 13 13 14 static char *filename_rsa_noarmour_singlekey="enc_rsa_noarmour_singlekey.txt"; 14 static char *filename_rsa_noarmour_nopassphrase_singlekey="enc_rsa_noarmour_np_singlekey.txt"; 15 static char *filename_rsa_noarmour_passphrase_singlekey="enc_rsa_noarmour_pp_singlekey.txt"; 15 16 static char *filename_rsa_armour_singlekey="enc_rsa_armour_singlekey.txt"; 16 17 … … 93 94 // Create RSA test files 94 95 95 create_testfile(filename_rsa_noarmour_singlekey); 96 create_testfile(filename_rsa_noarmour_nopassphrase_singlekey); 97 create_testfile(filename_rsa_noarmour_passphrase_singlekey); 96 98 create_testfile(filename_rsa_armour_singlekey); 97 99 /* … … 149 151 } 150 152 151 static void test_rsa_encrypt(const int has_armour, const ops_key_data_t * key, const char *filename)153 static void test_rsa_encrypt(const int has_armour, const ops_key_data_t *pub_key, const char *filename) 152 154 { 153 155 ops_memory_t *mem_ldt; … … 234 236 // Create and write encrypted PK session key 235 237 236 char *user_id="Alpha (RSA, no passphrase) <alpha@test.com>";237 const ops_key_data_t *pub_key=ops_keyring_find_key_by_userid(&pub_keyring, user_id);238 // char *user_id="Alpha (RSA, no passphrase) <alpha@test.com>"; 239 // const ops_key_data_t *pub_key=ops_keyring_find_key_by_userid(&pub_keyring, user_id); 238 240 // ops_print_public_key_verbose(pub_key); 239 241 … … 247 249 iv=ops_mallocz(encrypt.blocksize); 248 250 encrypt.set_iv(&encrypt, iv); 249 key=ops_mallocz(encrypt.keysize);251 //key=ops_mallocz(encrypt.keysize); 250 252 encrypt.set_key(&encrypt, &encrypted_pk_session_key->key[0]); 251 253 ops_encrypt_init(&encrypt); … … 272 274 // File contents should match - check with GPG 273 275 276 char pp[MAXBUF]; 277 if (pub_key==alpha_pub_keydata) 278 pp[0]='\0'; 279 else if (pub_key==bravo_pub_keydata) 280 snprintf(pp,MAXBUF," --passphrase %s ", bravo_passphrase); 274 281 snprintf(decrypted_file,MAXBUF,"%s/decrypted_%s",dir,filename); 275 snprintf(cmd,MAXBUF,"gpg --decrypt --output=%s --quiet --homedir %s %s ",decrypted_file, dir, encrypted_file);282 snprintf(cmd,MAXBUF,"gpg --decrypt --output=%s --quiet --homedir %s %s %s",decrypted_file, dir, pp, encrypted_file); 276 283 // printf("cmd: %s\n", cmd); 277 284 rtn=system(cmd); … … 280 287 } 281 288 282 void test_rsa_encrypt_noarmour_ singlekey(void)289 void test_rsa_encrypt_noarmour_nopassphrase_singlekey(void) 283 290 { 284 291 int armour=0; 285 char *user_id="Alpha (RSA, no passphrase) <alpha@test.com>"; 286 assert(pub_keyring.nkeys); 287 const ops_key_data_t *pub_key=ops_keyring_find_key_by_userid(&pub_keyring, user_id); 288 assert(pub_key); 289 test_rsa_encrypt(armour,pub_key,filename_rsa_noarmour_singlekey); 292 test_rsa_encrypt(armour,alpha_pub_keydata,filename_rsa_noarmour_nopassphrase_singlekey); 293 } 294 295 void test_rsa_encrypt_noarmour_passphrase_singlekey(void) 296 { 297 int armour=0; 298 test_rsa_encrypt(armour,bravo_pub_keydata,filename_rsa_noarmour_passphrase_singlekey); 290 299 } 291 300 … … 300 309 } 301 310 302 void test_rsa_encrypt_noarmour_passphrase(void)303 {304 int armour=0;305 int passphrase=1;306 test_rsa_encrypt(armour,passphrase,filename_rsa_noarmour_passphrase);307 }308 309 311 void test_rsa_encrypt_armour_passphrase(void) 310 312 { … … 325 327 // add tests to suite 326 328 327 if (NULL == CU_add_test(suite, "Unarmoured, single key", test_rsa_encrypt_noarmour_singlekey)) 329 if (NULL == CU_add_test(suite, "Unarmoured, single key, no passphrase", test_rsa_encrypt_noarmour_nopassphrase_singlekey)) 330 return NULL; 331 332 if (NULL == CU_add_test(suite, "Unarmoured, single key, passphrase", test_rsa_encrypt_noarmour_passphrase_singlekey)) 328 333 return NULL; 329 334 … … 332 337 return NULL; 333 338 334 if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_encrypt_noarmour_passphrase))335 return NULL;336 337 339 if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_encrypt_armour_passphrase)) 338 340 return NULL; openpgpsdk/trunk/tests/test_rsa_verify.c
r504 r507 139 139 { return 1; } 140 140 141 snprintf(cmd,MAXBUF,"gpg --homedir=%s --quiet --compress-level 0 --sign --local-user %s --passphrase hello%s/%s",142 dir, bravo_name, dir, filename_rsa_noarmour_passphrase);143 if (system(cmd)) 144 { return 1; } 145 146 snprintf(cmd,MAXBUF,"gpg --homedir=%s --quiet --compress-level 0 --sign --armour --local-user %s --passphrase hello%s/%s",147 dir, bravo_name, dir, filename_rsa_armour_passphrase);141 snprintf(cmd,MAXBUF,"gpg --homedir=%s --quiet --compress-level 0 --sign --local-user %s --passphrase %s %s/%s", 142 dir, bravo_name, bravo_passphrase, dir, filename_rsa_noarmour_passphrase); 143 if (system(cmd)) 144 { return 1; } 145 146 snprintf(cmd,MAXBUF,"gpg --homedir=%s --quiet --compress-level 0 --sign --armour --local-user %s --passphrase %s %s/%s", 147 dir, bravo_name, bravo_passphrase, dir, filename_rsa_armour_passphrase); 148 148 if (system(cmd)) 149 149 { return 1; } openpgpsdk/trunk/tests/tests.c
r506 r507 19 19 unsigned char* literal_data=NULL; 20 20 size_t sz_literal_data=0; 21 21 22 char *alpha_user_id="Alpha (RSA, no passphrase) <alpha@test.com>"; 22 char *bravo_user_id="Bravo (RSA, passphrase) <bravo@test.com>";23 23 char *alpha_name="Alpha"; 24 char *bravo_name="Bravo";25 24 const ops_public_key_t *alpha_pkey; 26 25 const ops_secret_key_t *alpha_skey; 26 const ops_key_data_t *alpha_pub_keydata; 27 const ops_key_data_t *alpha_sec_keydata; 28 char* alpha_passphrase=""; 29 30 char *bravo_user_id="Bravo (RSA, passphrase) <bravo@test.com>"; 31 char *bravo_name="Bravo"; 27 32 const ops_public_key_t *bravo_pkey; 28 33 const ops_secret_key_t *bravo_skey; 34 const ops_key_data_t *bravo_pub_keydata; 35 const ops_key_data_t *bravo_sec_keydata; 29 36 char* bravo_passphrase="hello"; 37 30 38 const ops_key_data_t *decrypter=NULL; 31 39 32 40 void setup_test_keys() 33 41 { 34 const ops_key_data_t* alpha_keydata;35 const ops_key_data_t* bravo_keydata;36 42 char keydetails[MAXBUF+1]; 37 43 char keyring_name[MAXBUF+1]; … … 98 104 assert(pub_keyring.nkeys); 99 105 100 alpha_keydata=ops_keyring_find_key_by_userid(&sec_keyring, alpha_user_id); 101 bravo_keydata=ops_keyring_find_key_by_userid(&sec_keyring, bravo_user_id); 102 assert(alpha_keydata); 103 assert(bravo_keydata); 104 105 alpha_pkey=ops_get_public_key_from_data(alpha_keydata); 106 alpha_skey=ops_get_secret_key_from_data(alpha_keydata); 107 bravo_pkey=ops_get_public_key_from_data(bravo_keydata); 108 bravo_skey=ops_decrypt_secret_key_from_data(bravo_keydata,bravo_passphrase); 106 alpha_pub_keydata=ops_keyring_find_key_by_userid(&pub_keyring, alpha_user_id); 107 bravo_pub_keydata=ops_keyring_find_key_by_userid(&pub_keyring, bravo_user_id); 108 assert(alpha_pub_keydata); 109 assert(bravo_pub_keydata); 110 111 alpha_sec_keydata=ops_keyring_find_key_by_userid(&sec_keyring, alpha_user_id); 112 bravo_sec_keydata=ops_keyring_find_key_by_userid(&sec_keyring, bravo_user_id); 113 assert(alpha_sec_keydata); 114 assert(bravo_sec_keydata); 115 116 alpha_pkey=ops_get_public_key_from_data(alpha_pub_keydata); 117 alpha_skey=ops_get_secret_key_from_data(alpha_sec_keydata); 118 bravo_pkey=ops_get_public_key_from_data(bravo_pub_keydata); 119 bravo_skey=ops_decrypt_secret_key_from_data(bravo_sec_keydata,bravo_passphrase); 109 120 110 121 assert(alpha_pkey); … … 295 306 296 307 // Do we need the passphrase and not have it? If so, get it 297 ops_parser_content_t pc; 298 char *passphrase; 299 memset(&pc,'\0',sizeof pc); 308 char *passphrase=NULL; 300 309 passphrase=NULL; 301 pc.content.secret_key_passphrase.passphrase=&passphrase; 302 pc.content.secret_key_passphrase.secret_key=ops_get_secret_key_from_data(keydata); 303 304 /* Ugh. Need to duplicate this macro here to get the passphrase 305 Duplication to be removed when the callback gets moved to main code. 306 Can we make this inline code rather than a macro? 307 */ 308 #define CB(cbinfo,t,pc) do { (pc)->tag=(t); if((cbinfo)->cb(pc,(cbinfo)) == OPS_RELEASE_MEMORY) ops_parser_content_free(pc); } while(0) 309 CB(cbinfo,OPS_PARSER_CMD_GET_SK_PASSPHRASE,&pc); 310 310 311 /* 312 * Hard-coded to allow automated test 313 */ 314 if (keydata==alpha_sec_keydata) 315 passphrase=alpha_passphrase; 316 else if (keydata==bravo_sec_keydata) 317 passphrase=bravo_passphrase; 318 else 319 assert(0); 320 311 321 /* now get the key from the data */ 312 322 secret=ops_get_secret_key_from_data(keydata); … … 315 325 /* then it must be encrypted */ 316 326 secret=ops_decrypt_secret_key_from_data(keydata,passphrase); 317 free(passphrase);318 327 } 319 328 … … 332 341 { 333 342 ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 334 /*335 static const ops_key_data_t *decrypt_key;336 const ops_key_data_t *keydata=NULL;337 const ops_secret_key_t *secret;338 */339 343 340 344 OPS_USED(cbinfo); openpgpsdk/trunk/tests/tests.h
r505 r507 54 54 unsigned char* literal_data; 55 55 size_t sz_literal_data; 56 57 // "Alpha" is the user who has NO passphrase on his key 56 58 char* alpha_user_id; 57 char* bravo_user_id;58 59 char* alpha_name; 60 const ops_key_data_t *alpha_pub_keydata; 61 const ops_key_data_t *alpha_sec_keydata; 62 const ops_public_key_t *alpha_pkey; 63 const ops_secret_key_t *alpha_skey; 64 char* alpha_passphrase; 65 66 // "Bravo" is the user who has a passphrase on his key 59 67 char* bravo_name; 60 68 char* bravo_passphrase; 61 const ops_public_key_t *alpha_pkey; 62 const ops_secret_key_t *alpha_skey; 69 char* bravo_user_id; 70 const ops_key_data_t *bravo_pub_keydata; 71 const ops_key_data_t *bravo_sec_keydata; 63 72 const ops_public_key_t *bravo_pkey; 64 73 const ops_secret_key_t *bravo_skey; 65 const ops_key_data_t *decrypter;74 //const ops_key_data_t *decrypter; 66 75 #endif 67 76
