Changeset 518
- Timestamp:
- 10/18/07 13:36:34
- Files:
-
- openpgpsdk/trunk/src/advanced/adv_packet-parse.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_decrypt.c (modified) (10 diffs)
- openpgpsdk/trunk/tests/test_rsa_encrypt.c (modified) (8 diffs)
- openpgpsdk/trunk/tests/test_rsa_signature.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/src/advanced/adv_packet-parse.c
r517 r518 920 920 break; 921 921 922 case 0: 923 // nothing to free 924 break; 925 922 926 default: 923 927 assert(0); openpgpsdk/trunk/tests/test_rsa_decrypt.c
r517 r518 258 258 } 259 259 260 void test_rsa_decrypt_noarmour_nopassphrase(void)260 static void test_rsa_decrypt_noarmour_nopassphrase(void) 261 261 { 262 262 int armour=0; … … 265 265 } 266 266 267 #ifndef OPENSSL_NO_IDEA 268 void test_rsa_decrypt_noarmour_nopassphrase_idea(void) 269 { 270 int armour=0; 271 int passphrase=0; 272 test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"IDEA"); 273 } 274 #endif 275 276 void test_rsa_decrypt_noarmour_nopassphrase_3des(void) 277 { 267 static void test_rsa_decrypt_noarmour_nopassphrase_3des(void) 268 { 269 CU_FAIL("3DES decryption not yet unimplemented"); 270 271 /* 278 272 int armour=0; 279 273 int passphrase=0; 280 274 test_rsa_decrypt(armour,passphrase,filename_rsa_noarmour_nopassphrase,"3DES"); 281 } 282 283 void test_rsa_decrypt_noarmour_nopassphrase_cast5(void) 275 */ 276 } 277 278 static void test_rsa_decrypt_noarmour_nopassphrase_cast5(void) 284 279 { 285 280 int armour=0; … … 289 284 290 285 #ifdef TODO 291 void test_rsa_decrypt_armour_nopassphrase_cast5(void)286 static void test_rsa_decrypt_armour_nopassphrase_cast5(void) 292 287 { 293 288 int armour=1; … … 297 292 #endif 298 293 299 void test_rsa_decrypt_noarmour_nopassphrase_aes128(void)294 static void test_rsa_decrypt_noarmour_nopassphrase_aes128(void) 300 295 { 301 296 int armour=0; … … 304 299 } 305 300 306 void test_rsa_decrypt_noarmour_nopassphrase_aes256(void)301 static void test_rsa_decrypt_noarmour_nopassphrase_aes256(void) 307 302 { 308 303 int armour=0; … … 313 308 // 314 309 315 void test_rsa_decrypt_armour_nopassphrase(void) 310 #ifdef TODO 311 static void test_rsa_decrypt_armour_nopassphrase(void) 316 312 { 317 313 int armour=1; … … 320 316 } 321 317 322 void test_rsa_decrypt_noarmour_passphrase(void)318 static void test_rsa_decrypt_noarmour_passphrase(void) 323 319 { 324 320 int armour=0; … … 327 323 } 328 324 329 void test_rsa_decrypt_armour_passphrase(void)325 static void test_rsa_decrypt_armour_passphrase(void) 330 326 { 331 327 int armour=1; … … 333 329 test_rsa_decrypt(armour,passphrase,filename_rsa_armour_passphrase,NULL); 334 330 } 331 #endif 332 333 static void test_todo(void) 334 { 335 CU_FAIL("Test TODO: IDEA"); 336 CU_FAIL("Test TODO: Armoured decryption (with&without passphrase)"); 337 CU_FAIL("Test TODO: Decryption with multiple keys in same keyring"); 338 CU_FAIL("Test TODO: Decryption with multiple keys where some are not in my keyring"); 339 CU_FAIL("Test TODO: Decryption with multiple keys where my key is (a) first key in list; (b) last key in list; (c) in the middle of the list"); 340 } 335 341 336 342 CU_pSuite suite_rsa_decrypt() … … 356 362 return NULL; 357 363 358 #ifndef OPENSSL_NO_IDEA359 /* \todo360 if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (IDEA)", test_rsa_decrypt_noarmour_nopassphrase_idea))361 return NULL;362 */363 #endif364 365 #ifdef TODO366 if (NULL == CU_add_test(suite, "Armoured, no passphrase (CAST5)", test_rsa_decrypt_armour_nopassphrase_cast5))367 return NULL;368 369 364 if (NULL == CU_add_test(suite, "Unarmoured, no passphrase (3DES)", test_rsa_decrypt_noarmour_nopassphrase_3des)) 370 365 return NULL; 371 366 372 if (NULL == CU_add_test(suite, "Armoured, no passphrase", test_rsa_decrypt_armour_nopassphrase)) 373 return NULL; 374 375 if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_decrypt_noarmour_passphrase)) 376 return NULL; 377 378 if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_decrypt_armour_passphrase)) 379 return NULL; 380 #endif 367 if (NULL == CU_add_test(suite, "Tests to be implemented", test_todo)) 368 return NULL; 369 381 370 return suite; 382 371 } openpgpsdk/trunk/tests/test_rsa_encrypt.c
r517 r518 13 13 14 14 static int do_gpgtest=0; 15 16 static char *filename_rsa_noarmour_nopassphrase_singlekey_old="enc_rsa_noarmour_np_singlekey_old.txt";17 static char *filename_rsa_noarmour_passphrase_singlekey_old="enc_rsa_noarmour_pp_singlekey_old.txt";18 15 19 16 static char *filename_rsa_noarmour_nopassphrase_singlekey="enc_rsa_noarmour_np_singlekey.txt"; … … 95 92 create_testfile(filename_rsa_noarmour_nopassphrase_singlekey); 96 93 create_testfile(filename_rsa_noarmour_passphrase_singlekey); 97 create_testfile(filename_rsa_noarmour_nopassphrase_singlekey_old);98 create_testfile(filename_rsa_noarmour_passphrase_singlekey_old);99 94 create_testfile(filename_rsa_armour_singlekey); 100 95 /* … … 166 161 167 162 return rtn; 168 }169 170 static void old_test_rsa_encrypt(const int has_armour, const ops_key_data_t *pub_key, const char *filename)171 {172 char* testtext=NULL;173 ops_memory_t *mem_ldt;174 ops_create_info_t *cinfo_ldt;175 176 char cmd[MAXBUF+1];177 char myfile[MAXBUF+1];178 char encrypted_file[MAXBUF+1];179 char decrypted_file[MAXBUF+1];180 char *suffix= has_armour ? "asc" : "gpg";181 int fd_in=0;182 int fd_out=0;183 int rtn=0;184 ops_create_info_t *cinfo;185 ops_pk_session_key_t* encrypted_pk_session_key;186 ops_crypt_t encrypt;187 unsigned char *iv=NULL;188 189 /*190 * Read from test file and write plaintext to memory191 * in set of Literal Data packets192 * \todo optimise using stacked writers193 */194 195 // open file to encrypt196 snprintf(myfile,MAXBUF,"%s/%s",dir,filename);197 #ifdef WIN32198 fd_in=open(myfile,O_RDONLY | O_BINARY);199 #else200 fd_in=open(myfile,O_RDONLY);201 #endif202 if(fd_in < 0)203 {204 perror(myfile);205 exit(2);206 }207 208 snprintf(encrypted_file,MAXBUF,"%s/%s.%s",dir,filename,suffix);209 #ifdef WIN32210 fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600);211 #else212 fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL, 0600);213 #endif214 if(fd_out < 0)215 {216 perror(encrypted_file);217 exit(2);218 }219 220 // write plaintext to memory221 222 for (;;)223 {224 unsigned char buf[MAXBUF];225 int n=0;226 227 n=read(fd_in,buf,sizeof(buf));228 if (!n)229 break;230 assert(n>=0);231 232 // create a simple literal data packet as the encrypted payload233 ops_setup_memory_write(&cinfo_ldt,&mem_ldt,n);234 ops_write_literal_data((unsigned char *)buf, n,235 OPS_LDT_BINARY, cinfo_ldt);236 }237 close(fd_in);238 239 /*240 * Encrypt and write to file241 */242 243 // Set encryption writer and handling options244 245 cinfo=ops_create_info_new();246 ops_writer_set_fd(cinfo,fd_out);247 248 // Create and write encrypted PK session key249 250 encrypted_pk_session_key=ops_create_pk_session_key(pub_key);251 ops_write_pk_session_key(cinfo,encrypted_pk_session_key);252 253 ops_crypt_any(&encrypt, encrypted_pk_session_key->symmetric_algorithm);254 iv=ops_mallocz(encrypt.blocksize);255 encrypt.set_iv(&encrypt, iv);256 encrypt.set_key(&encrypt, &encrypted_pk_session_key->key[0]);257 ops_encrypt_init(&encrypt);258 259 /*260 * write out encrypted packets261 */262 263 ops_write_se_ip_pktset( ops_memory_get_data(mem_ldt),264 ops_memory_get_length(mem_ldt),265 &encrypt, cinfo);266 close(fd_out);267 268 /*269 * Test results270 */271 272 if (!do_gpgtest)273 {274 // File contents should match - checking with OPS275 276 testtext=create_testtext(filename);277 CU_ASSERT(test_rsa_decrypt(encrypted_file,testtext)==1);278 }279 280 else281 {282 // File contents should match - check with GPG283 284 char pp[MAXBUF];285 if (pub_key==alpha_pub_keydata)286 pp[0]='\0';287 else if (pub_key==bravo_pub_keydata)288 snprintf(pp,MAXBUF," --passphrase %s ", bravo_passphrase);289 snprintf(decrypted_file,MAXBUF,"%s/decrypted_%s",dir,filename);290 snprintf(cmd,MAXBUF,"gpg --decrypt --output=%s --quiet --homedir %s %s %s",decrypted_file, dir, pp, encrypted_file);291 // printf("cmd: %s\n", cmd);292 rtn=system(cmd);293 CU_ASSERT(rtn==0);294 CU_ASSERT(file_compare(myfile,decrypted_file)==0);295 }296 163 } 297 164 … … 415 282 } 416 283 417 void old_test_rsa_encrypt_noarmour_nopassphrase_singlekey(void) 418 { 419 int armour=0; 420 old_test_rsa_encrypt(armour,alpha_pub_keydata,filename_rsa_noarmour_nopassphrase_singlekey_old); 421 } 422 423 void old_test_rsa_encrypt_noarmour_passphrase_singlekey(void) 424 { 425 int armour=0; 426 old_test_rsa_encrypt(armour,bravo_pub_keydata,filename_rsa_noarmour_passphrase_singlekey_old); 427 } 428 429 void test_rsa_encrypt_noarmour_nopassphrase_singlekey(void) 284 static void test_rsa_encrypt_noarmour_nopassphrase_singlekey(void) 430 285 { 431 286 int armour=0; … … 433 288 } 434 289 435 void test_rsa_encrypt_noarmour_passphrase_singlekey(void)290 static void test_rsa_encrypt_noarmour_passphrase_singlekey(void) 436 291 { 437 292 int armour=0; … … 439 294 } 440 295 296 static void test_rsa_encrypt_armour_nopassphrase_singlekey(void) 297 { 298 CU_FAIL("Test TODO: Encrypt with armour/no passphrase/single-key"); 441 299 #ifdef TBD 442 void test_rsa_encrypt_armour_singlekey(void)443 {444 300 int armour=1; 445 301 char *user_id="Alpha (RSA, no passphrase) <alpha@test.com>"; … … 447 303 assert(pub_key); 448 304 test_rsa_encrypt(armour,pub_key,filename_rsa_armour_singlekey); 449 } 450 451 void test_rsa_encrypt_armour_passphrase(void) 452 { 305 #endif 306 } 307 308 static void test_rsa_encrypt_armour_passphrase_singlekey(void) 309 { 310 CU_FAIL("Test TODO: Encrypt with armour/passphrase/single-key"); 311 #ifdef TBD 453 312 int armour=1; 454 313 int passphrase=1; 455 314 test_rsa_encrypt(armour,passphrase,filename_rsa_armour_passphrase); 456 } 457 #endif /*TBD*/ 315 #endif 316 } 317 318 static void test_todo(void) 319 { 320 CU_FAIL("Test TODO: Encrypt to multiple keys in same keyring"); 321 CU_FAIL("Test TODO: Encrypt to multiple keys where my keys is (a) first key in list; (b) last key in list; (c) in the middle of the list"); 322 CU_FAIL("Test TODO: Encrypt to users with different preferences"); 323 } 458 324 459 325 int add_tests(CU_pSuite suite) … … 467 333 return 0; 468 334 469 #ifdef OLD 470 if (NULL == CU_add_test(suite, "Unarmoured, single key, no passphrase (OLD)", old_test_rsa_encrypt_noarmour_nopassphrase_singlekey)) 471 return 0; 472 473 if (NULL == CU_add_test(suite, "Unarmoured, single key, passphrase (OLD)", old_test_rsa_encrypt_noarmour_passphrase_singlekey)) 474 return 0; 475 #endif 476 477 #ifdef TBD 478 if (NULL == CU_add_test(suite, "Armoured, single key", test_rsa_encrypt_armour_singlekey)) 479 return 0; 480 481 if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_encrypt_armour_passphrase)) 482 return 0; 483 #endif /*TBD*/ 484 335 if (NULL == CU_add_test(suite, "Armoured, single key, no passphrase", test_rsa_encrypt_armour_nopassphrase_singlekey)) 336 return 0; 337 338 if (NULL == CU_add_test(suite, "Armoured, single key, passphrase", test_rsa_encrypt_armour_passphrase_singlekey)) 339 return 0; 340 341 if (NULL == CU_add_test(suite, "Tests to be implemented", test_todo)) 342 return 0; 343 485 344 return 1; 486 345 } openpgpsdk/trunk/tests/test_rsa_signature.c
r517 r518 186 186 CU_ASSERT(rtn==1); 187 187 188 // Tidy up 189 if (has_armour) 190 ops_reader_pop_dearmour(pinfo); 191 192 ops_public_key_free(&validate_arg.pkey); 193 if (validate_arg.subkey.version) 194 ops_public_key_free(&validate_arg.subkey); 195 ops_user_id_free(&validate_arg.user_id); 196 ops_user_attribute_free(&validate_arg.user_attribute); 197 ops_parse_info_delete(pinfo); 198 199 close(fd); 188 200 } 189 201 else
