Changeset 523
- Timestamp:
- 12/10/07 15:43:20
- Files:
-
- openpgpsdk/trunk/tests/test_common.c (modified) (8 diffs)
- openpgpsdk/trunk/tests/test_rsa_signature.c (modified) (6 diffs)
- openpgpsdk/trunk/tests/test_rsa_verify.c (modified) (12 diffs)
- openpgpsdk/trunk/tests/tests.c (modified) (1 diff)
- openpgpsdk/trunk/tests/tests.h (modified) (2 diffs)
- openpgpsdk/trunk/tests/tests_gpg.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/tests/test_common.c
r521 r523 16 16 17 17 char dir[MAXBUF+1]; 18 char gpgcmd[MAXBUF+1]; 18 19 ops_keyring_t pub_keyring; 19 20 ops_keyring_t sec_keyring; … … 39 40 const ops_key_data_t *decrypter=NULL; 40 41 41 void setup_test_keys() 42 static void setup_test_keys(); 43 44 void setup() 45 { 46 // Create temp directory 47 if (!mktmpdir()) 48 return; 49 50 assert(strlen(dir)); 51 snprintf(gpgcmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s",dir); 52 53 setup_test_keys(); 54 } 55 56 static void setup_test_keys() 42 57 { 43 58 char keydetails[MAXBUF+1]; … … 49 64 char *rsa_pass="Key-Type: RSA\nKey-Usage: encrypt, sign\nName-Real: Bravo\nName-Comment: RSA, passphrase\nName-Email: bravo@test.com\nPassphrase: hello\nKey-Length: 1024\n"; 50 65 51 // Create temp directory52 if (!mktmpdir())53 return;54 55 66 /* 56 67 * Create a RSA keypair with no passphrase … … 72 83 close(fd); 73 84 74 snprintf(cmd,MAXBUF," gpg --quiet --no-tty --openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails);85 snprintf(cmd,MAXBUF,"%s --openpgp --gen-key --s2k-cipher-algo \"AES\" --expert --batch %s",gpgcmd,keydetails); 75 86 system(cmd); 76 87 … … 94 105 close(fd); 95 106 96 snprintf(cmd,MAXBUF," gpg --quiet --no-tty --openpgp --quiet --gen-key --s2k-cipher-algo \"AES\" --expert --homedir=%s --batch %s",dir,keydetails);107 snprintf(cmd,MAXBUF,"%s --openpgp --gen-key --s2k-cipher-algo \"AES\" --expert --batch %s",gpgcmd,keydetails); 97 108 system(cmd); 98 109 … … 249 260 callback_general(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 250 261 { 262 int debug=0; 263 251 264 ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 252 265 … … 262 275 263 276 case OPS_PARSER_PACKET_END: 264 // nothing to do 277 // print raw packet 278 279 if (debug) 280 { 281 unsigned i=0; 282 fprintf(stderr,"***\n***Raw Packet:\n"); 283 for (i=0; i<content_->content.packet.length; i++) 284 { 285 fprintf(stderr,"0x%02x ", content_->content.packet.raw[i]); 286 if (!((i+1) % 16)) 287 fprintf(stderr,"\n"); 288 else if (!((i+1) % 8)) 289 fprintf(stderr," "); 290 } 291 fprintf(stderr,"\n"); 292 } 265 293 break; 266 294 … … 428 456 429 457 ops_parse_cb_return_t 458 callback_verify(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 459 { 460 /* 461 int debug=0; 462 463 if (debug) 464 { ops_print_packet(content_); } 465 */ 466 switch(content_->tag) 467 { 468 case OPS_PTAG_RAW_SS: 469 case OPS_PTAG_SS_CREATION_TIME: 470 case OPS_PTAG_SS_ISSUER_KEY_ID: 471 // \todo should free memory? 472 return OPS_KEEP_MEMORY; 473 474 case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 475 case OPS_PTAG_CT_ARMOUR_HEADER: 476 case OPS_PTAG_CT_ARMOUR_TRAILER: 477 break; 478 479 case OPS_PTAG_CT_SIGNATURE: 480 case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER: 481 case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY: 482 case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER: 483 case OPS_PTAG_CT_SIGNATURE_HEADER: 484 case OPS_PTAG_CT_SIGNATURE_FOOTER: 485 case OPS_PTAG_CT_LITERAL_DATA_HEADER: 486 case OPS_PTAG_CT_LITERAL_DATA_BODY: 487 return callback_data_signature(content_, cbinfo); 488 489 default: 490 return callback_general(content_,cbinfo); 491 } 492 493 return OPS_RELEASE_MEMORY; 494 } 495 496 ops_parse_cb_return_t 430 497 callback_pk_session_key(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 431 498 { openpgpsdk/trunk/tests/test_rsa_signature.c
r521 r523 25 25 static char *filename_rsa_armour_passphrase="ops_rsa_signed_armour_passphrase.txt"; 26 26 27 static ops_parse_cb_return_t28 callback_verify(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo);29 30 27 /* Signature suite initialization. 31 28 * Create temporary directory. … … 79 76 int rtn=0; 80 77 ops_create_info_t *cinfo=NULL; 78 unsigned char buf[MAXBUF]; 81 79 82 80 // open file to sign … … 123 121 for (;;) 124 122 { 125 unsigned char buf[MAXBUF];126 123 int n=0; 127 124 … … 140 137 ops_keyid(keyid,&skey->public_key); 141 138 ops_signature_add_issuer_key_id(sig,keyid); 139 142 140 ops_signature_hashed_subpackets_end(sig); 143 141 ops_write_signature(sig,(ops_public_key_t *)&skey->public_key,(ops_secret_key_t *)skey,cinfo); … … 145 143 close(fd_out); 146 144 147 // Check 148 149 if (!do_gpgtest) 150 { 151 int fd=0; 152 ops_parse_info_t *pinfo=NULL; 153 validate_data_cb_arg_t validate_arg; 154 ops_validate_result_t result; 155 int rtn=0; 156 157 if (debug) 158 { 159 fprintf(stderr,"\n***\n*** Starting to parse for validation\n***\n"); 160 } 161 145 /* 146 * Validate output 147 */ 148 149 // Check with OPS 150 151 { 152 int fd=0; 153 ops_parse_info_t *pinfo=NULL; 154 validate_data_cb_arg_t validate_arg; 155 ops_validate_result_t result; 156 int rtn=0; 157 158 if (debug) 159 { 160 fprintf(stderr,"\n***\n*** Starting to parse for validation\n***\n"); 161 } 162 162 163 // open signed file 163 164 #ifdef WIN32 164 fd=open(signed_file,O_RDONLY | O_BINARY);165 fd=open(signed_file,O_RDONLY | O_BINARY); 165 166 #else 166 fd=open(signed_file,O_RDONLY);167 fd=open(signed_file,O_RDONLY); 167 168 #endif 168 if(fd < 0)169 {170 perror(signed_file);171 exit(2);172 }173 174 // Set verification reader and handling options175 176 pinfo=ops_parse_info_new();177 178 memset(&validate_arg,'\0',sizeof validate_arg);179 validate_arg.result=&result;180 validate_arg.keyring=&pub_keyring;181 validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo);182 183 ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED);184 ops_parse_cb_set(pinfo,callback_verify,&validate_arg);185 ops_reader_set_fd(pinfo,fd);186 pinfo->rinfo.accumulate=ops_true;187 188 // Set up armour/passphrase options189 190 if (has_armour)191 ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false);192 // current_passphrase=has_passphrase ? passphrase : nopassphrase;193 194 // Do the verification195 196 rtn=ops_parse(pinfo);197 ops_print_errors(ops_parse_info_get_errors(pinfo));198 CU_ASSERT(rtn==1);199 200 // Tidy up201 if (has_armour)202 ops_reader_pop_dearmour(pinfo);203 204 ops_parse_info_delete(pinfo);205 206 close(fd);207 }208 else 209 {210 // Check signature with GPG211 212 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --verify --quiet --homedir %s %s", dir, signed_file);213 rtn=system(cmd);214 CU_ASSERT(rtn==0);215 }169 if(fd < 0) 170 { 171 perror(signed_file); 172 exit(2); 173 } 174 175 // Set verification reader and handling options 176 177 pinfo=ops_parse_info_new(); 178 179 memset(&validate_arg,'\0',sizeof validate_arg); 180 validate_arg.result=&result; 181 validate_arg.keyring=&pub_keyring; 182 validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo); 183 184 ops_parse_options(pinfo,OPS_PTAG_SS_ALL,OPS_PARSE_PARSED); 185 ops_parse_cb_set(pinfo,callback_verify,&validate_arg); 186 ops_reader_set_fd(pinfo,fd); 187 pinfo->rinfo.accumulate=ops_true; 188 189 // Set up armour/passphrase options 190 191 if (has_armour) 192 ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 193 // current_passphrase=has_passphrase ? passphrase : nopassphrase; 194 195 // Do the verification 196 197 rtn=ops_parse(pinfo); 198 ops_print_errors(ops_parse_info_get_errors(pinfo)); 199 CU_ASSERT(rtn==1); 200 201 // Tidy up 202 if (has_armour) 203 ops_reader_pop_dearmour(pinfo); 204 205 ops_parse_info_delete(pinfo); 206 207 close(fd); 208 } 209 210 // Check signature with GPG 211 { 212 213 snprintf(cmd,MAXBUF,"%s --verify %s", gpgcmd, signed_file); 214 rtn=system(cmd); 215 CU_ASSERT(rtn==0); 216 } 216 217 } 217 218 … … 309 310 } 310 311 311 static ops_parse_cb_return_t312 callback_verify(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo)313 {314 int debug=0;315 316 if (debug)317 { ops_print_packet(content_); }318 319 switch(content_->tag)320 {321 case OPS_PTAG_RAW_SS:322 case OPS_PTAG_SS_CREATION_TIME:323 case OPS_PTAG_SS_ISSUER_KEY_ID:324 // \todo should free memory?325 return OPS_KEEP_MEMORY;326 327 case OPS_PTAG_CT_ONE_PASS_SIGNATURE:328 case OPS_PTAG_CT_ARMOUR_HEADER:329 case OPS_PTAG_CT_ARMOUR_TRAILER:330 break;331 332 case OPS_PTAG_CT_SIGNATURE:333 case OPS_PTAG_CT_SIGNED_CLEARTEXT_HEADER:334 case OPS_PTAG_CT_SIGNED_CLEARTEXT_BODY:335 case OPS_PTAG_CT_SIGNED_CLEARTEXT_TRAILER:336 case OPS_PTAG_CT_SIGNATURE_HEADER:337 case OPS_PTAG_CT_SIGNATURE_FOOTER:338 case OPS_PTAG_CT_LITERAL_DATA_HEADER:339 case OPS_PTAG_CT_LITERAL_DATA_BODY:340 return callback_data_signature(content_, cbinfo);341 342 default:343 return callback_general(content_,cbinfo);344 }345 346 return OPS_RELEASE_MEMORY;347 }348 349 312 // EOF openpgpsdk/trunk/tests/test_rsa_verify.c
r521 r523 16 16 #include "tests.h" 17 17 18 static int do_gpgtest=0; 19 18 20 #ifndef ATTRIBUTE_UNUSED 19 21 … … 31 33 static char *filename_rsa_armour_passphrase="gpg_signed_armour_passphrase.txt"; 32 34 33 static ops_parse_cb_return_t 34 callback(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo) 35 { 36 // ops_parser_content_union_t* content=(ops_parser_content_union_t *)&content_->content; 37 38 // ops_print_packet(content_); 39 40 switch(content_->tag) 41 { 42 /* 43 case OPS_PTAG_CT_LITERAL_DATA_HEADER: 44 break; 45 46 case OPS_PTAG_CT_LITERAL_DATA_BODY: 47 return callback_literal_data(content_,cbinfo); 48 break; 49 */ 50 51 case OPS_PTAG_CT_ONE_PASS_SIGNATURE: 52 break; 53 54 case OPS_PTAG_CT_SIGNATURE: 55 case OPS_PTAG_CT_SIGNATURE_HEADER: 56 case OPS_PTAG_CT_SIGNATURE_FOOTER: 57 case OPS_PTAG_CT_LITERAL_DATA_HEADER: 58 case OPS_PTAG_CT_LITERAL_DATA_BODY: 59 return callback_data_signature(content_, cbinfo); 60 61 /* 62 case OPS_PTAG_CT_UNARMOURED_TEXT: 63 printf("OPS_PTAG_CT_UNARMOURED_TEXT\n"); 64 if(!skipping) 65 { 66 puts("Skipping..."); 67 skipping=ops_true; 68 } 69 fwrite(content->unarmoured_text.data,1, 70 content->unarmoured_text.length,stdout); 71 break; 72 73 case OPS_PTAG_CT_PK_SESSION_KEY: 74 return callback_pk_session_key(content_,cbinfo); 75 76 case OPS_PARSER_CMD_GET_SECRET_KEY: 77 return callback_cmd_get_secret_key(content_,cbinfo); 78 79 case OPS_PARSER_CMD_GET_SK_PASSPHRASE: 80 return callback_cmd_get_secret_key_passphrase(content_,cbinfo); 81 82 case OPS_PTAG_CT_LITERAL_DATA_BODY: 83 return callback_literal_data(content_,cbinfo); 84 // text=ops_mallocz(content->literal_data_body.length+1); 85 // memcpy(text,content->literal_data_body.data,content->literal_data_body.length); 86 // break; 87 88 case OPS_PARSER_PTAG: 89 case OPS_PTAG_CT_ARMOUR_HEADER: 90 case OPS_PTAG_CT_ARMOUR_TRAILER: 91 case OPS_PTAG_CT_ENCRYPTED_PK_SESSION_KEY: 92 case OPS_PTAG_CT_COMPRESSED: 93 case OPS_PTAG_CT_SE_IP_DATA_BODY: 94 case OPS_PTAG_CT_SE_IP_DATA_HEADER: 95 // Ignore these packets 96 // They're handled in ops_parse_one_packet() 97 // and nothing else needs to be done 98 break; 99 */ 100 101 default: 102 return callback_general(content_,cbinfo); 103 } 104 105 return OPS_RELEASE_MEMORY; 106 } 35 static char *filename_rsa_clearsign_armour_nopassphrase="gpg_clearsigned_armour_nopassphrase.txt"; 107 36 108 37 /* Signature verification suite initialization. … … 114 43 char cmd[MAXBUF+1]; 115 44 116 // Create test files 45 do_gpgtest=0; 46 47 // Create SIGNED test files 117 48 118 49 create_testfile(filename_rsa_noarmour_nopassphrase); … … 123 54 // Now sign the test files with GPG 124 55 125 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --openpgp --compress-level 0 --sign --local-user %s %s/%s", 126 dir, alpha_name, dir, filename_rsa_noarmour_nopassphrase); 127 if (system(cmd)) 128 { return 1; } 129 130 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --compress-level 0 --sign --armour --local-user %s %s/%s", 131 dir, alpha_name, dir, filename_rsa_armour_nopassphrase); 132 if (system(cmd)) 133 { return 1; } 134 135 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --compress-level 0 --sign --local-user %s --passphrase %s %s/%s", 136 dir, bravo_name, bravo_passphrase, dir, filename_rsa_noarmour_passphrase); 137 if (system(cmd)) 138 { return 1; } 139 140 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --compress-level 0 --sign --armour --local-user %s --passphrase %s %s/%s", 141 dir, bravo_name, bravo_passphrase, dir, filename_rsa_armour_passphrase); 56 snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --sign --local-user %s %s/%s", 57 gpgcmd, alpha_name, dir, filename_rsa_noarmour_nopassphrase); 58 if (system(cmd)) 59 { return 1; } 60 61 snprintf(cmd,MAXBUF,"%s --compress-level 0 --sign --local-user %s --armor %s/%s", 62 gpgcmd, alpha_name, dir, filename_rsa_armour_nopassphrase); 63 if (system(cmd)) 64 { return 1; } 65 66 snprintf(cmd,MAXBUF,"%s --compress-level 0 --sign --local-user %s --passphrase %s %s/%s", 67 gpgcmd, bravo_name, bravo_passphrase, dir, filename_rsa_noarmour_passphrase); 68 if (system(cmd)) 69 { return 1; } 70 71 snprintf(cmd,MAXBUF,"%s --compress-level 0 --sign --local-user %s --passphrase %s --armor %s/%s", 72 gpgcmd, bravo_name, bravo_passphrase, dir, filename_rsa_armour_passphrase); 73 if (system(cmd)) 74 { return 1; } 75 76 /* 77 * Create CLEARSIGNED test files 78 */ 79 80 create_testfile(filename_rsa_clearsign_armour_nopassphrase); 81 82 // and sign them 83 84 snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign --local-user %s --armor %s/%s", 85 gpgcmd, alpha_name, dir, filename_rsa_clearsign_armour_nopassphrase); 142 86 if (system(cmd)) 143 87 { return 1; } … … 147 91 } 148 92 93 int init_suite_rsa_verify_gpgtest(void) 94 { 95 init_suite_rsa_verify(); 96 97 do_gpgtest=1; 98 99 return 0; 100 } 101 149 102 int clean_suite_rsa_verify(void) 150 103 { … … 159 112 { 160 113 char signedfile[MAXBUF+1]; 161 // char testtext[MAXBUF+1];162 114 char *suffix= has_armour ? "asc" : "gpg"; 163 115 int fd=0; … … 168 120 169 121 // open signed file 170 snprintf(signedfile,MAXBUF,"%s/%s%s%s.%s",dir, 122 snprintf(signedfile,MAXBUF,"%s/%s%s%s.%s", 123 dir, filename, 124 protocol==NULL ? "" : "_", 171 125 protocol==NULL ? "" : protocol, 172 protocol==NULL ? "" : "_", 173 filename,suffix); 126 suffix); 174 127 #ifdef WIN32 175 128 fd=open(signedfile,O_RDONLY | O_BINARY); … … 192 145 validate_arg.rarg=ops_reader_get_arg_from_pinfo(pinfo); 193 146 194 ops_parse_cb_set(pinfo,callback ,&validate_arg);147 ops_parse_cb_set(pinfo,callback_verify,&validate_arg); 195 148 ops_reader_set_fd(pinfo,fd); 196 149 pinfo->rinfo.accumulate=ops_true; … … 225 178 void test_rsa_verify_noarmour_nopassphrase(void) 226 179 { 180 // int clearsign=0; 227 181 int armour=0; 228 182 int passphrase=0; … … 233 187 } 234 188 189 void test_rsa_verify_clearsign_armour_nopassphrase(void) 190 { 191 // int clearsign=1; 192 int armour=1; 193 int passphrase=0; 194 assert(pub_keyring.nkeys); 195 196 test_rsa_verify(armour,passphrase,filename_rsa_clearsign_armour_nopassphrase,NULL); 197 } 198 235 199 #ifdef TBD 236 200 void test_rsa_encrypt_armour_singlekey(void) … … 268 232 // add tests to suite 269 233 234 if (NULL == CU_add_test(suite, "Clearsigned, armoured, no passphrase", test_rsa_verify_clearsign_armour_nopassphrase)) 235 return NULL; 236 270 237 if (NULL == CU_add_test(suite, "Unarmoured, no passphrase", test_rsa_verify_noarmour_nopassphrase)) 271 238 return NULL; … … 278 245 } 279 246 247 CU_pSuite suite_rsa_verify_GPGtest() 248 { 249 CU_pSuite suite = NULL; 250 251 suite = CU_add_suite("RSA Verification Suite (GPG interop)", init_suite_rsa_verify_gpgtest, clean_suite_rsa_verify); 252 if (!suite) 253 return NULL; 254 255 // add tests to suite 256 257 if (NULL == CU_add_test(suite, "Clearsigned, armoured, no passphrase", test_rsa_verify_clearsign_armour_nopassphrase)) 258 return NULL; 259 260 if (NULL == CU_add_test(suite, "Unarmoured, no passphrase", test_rsa_verify_noarmour_nopassphrase)) 261 return NULL; 262 263 /* 264 if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_verify_noarmour_passphrase)) 265 return NULL; 266 */ 267 return suite; 268 } 269 270 // EOF openpgpsdk/trunk/tests/tests.c
r517 r523 19 19 20 20 mem_literal_data=ops_memory_new(); 21 setup _test_keys();21 setup(); 22 22 23 23 if (CUE_SUCCESS != CU_initialize_registry()) openpgpsdk/trunk/tests/tests.h
r521 r523 38 38 // utility functions 39 39 40 void setup_test_keys(); 40 extern char gpgcmd[]; 41 void setup(); 41 42 void cleanup(); 42 43 … … 60 61 ops_parse_cb_return_t 61 62 callback_data_signature(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 63 ops_parse_cb_return_t 64 callback_verify(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo); 65 62 66 63 67 void reset_vars(); openpgpsdk/trunk/tests/tests_gpg.c
r521 r523 19 19 20 20 mem_literal_data=ops_memory_new(); 21 setup _test_keys();21 setup(); 22 22 23 23 if (CUE_SUCCESS != CU_initialize_registry()) … … 36 36 } 37 37 38 #ifdef TODO 39 40 if (NULL == suite_rsa_decrypt_GPGtest()) 38 if (NULL == suite_rsa_verify_GPGtest()) 41 39 { 42 40 CU_cleanup_registry(); … … 44 42 } 45 43 46 if (NULL == suite_rsa_verify_GPGtest()) 44 #ifdef TODO 45 46 if (NULL == suite_rsa_decrypt_GPGtest()) 47 47 { 48 48 CU_cleanup_registry();
