Changeset 689
- Timestamp:
- 08/02/09 15:02:37
- Files:
-
- openpgpsdk/trunk/src/lib/create.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_keys.c (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/src/lib/create.c
r686 r689 205 205 206 206 default: 207 fprintf(stderr, "Unknown algorithm %d\n", key->algorithm); 207 208 assert(0); 208 209 break; openpgpsdk/trunk/tests/test_rsa_keys.c
r688 r689 47 47 { 48 48 ops_keydata_t* keydata=ops_keydata_new(); 49 CU_ASSERT(ops_rsa_generate_keypair(1024, 65537,keydata)==ops_true);49 CU_ASSERT(ops_rsa_generate_keypair(1024, 65537, keydata)); 50 50 ops_keydata_free(keydata); 51 51 } … … 58 58 ops_keydata_t* keydata=NULL; 59 59 60 keydata=ops_rsa_create_selfsigned_keypair(1024, 17,&uid);60 keydata=ops_rsa_create_selfsigned_keypair(1024, 17, &uid); 61 61 62 62 CU_ASSERT(keydata != NULL); … … 66 66 67 67 static ops_parse_cb_return_t 68 cb_get_passphrase(const ops_parser_content_t *content_,ops_parse_cb_info_t *cbinfo __attribute__((unused))) 68 cb_get_passphrase(const ops_parser_content_t *content_, 69 ops_parse_cb_info_t *cbinfo __attribute__((unused))) 69 70 { 70 71 const ops_parser_content_union_t *content=&content_->content; … … 78 79 Doing this so the test can be automated. 79 80 */ 80 *(content->secret_key_passphrase.passphrase)=ops_malloc_passphrase("hello"); 81 *(content->secret_key_passphrase.passphrase) 82 =ops_malloc_passphrase("hello"); 81 83 return OPS_KEEP_MEMORY; 82 84 break; … … 99 101 const ops_public_key_t* pub_key=NULL; 100 102 const ops_secret_key_t* sec_key=NULL; 101 const char* pp="hello"; 102 const unsigned char *passphrase=(unsigned char *)pp; 103 const size_t pplen=strlen(pp); 103 static const unsigned char pp[]="hello"; 104 104 char filename[MAXBUF+1]; 105 105 int fd=0; … … 117 117 uid.user_id=(unsigned char *) userid; 118 118 119 keydata=ops_rsa_create_selfsigned_keypair(1024, 65537,&uid);119 keydata=ops_rsa_create_selfsigned_keypair(1024, 65537, &uid); 120 120 CU_ASSERT(keydata != NULL); 121 121 pub_key=ops_get_public_key_from_data(keydata); … … 127 127 */ 128 128 129 snprintf(filename,MAXBUF,"%s/%s.%s",dir,"ops_transferable_public_key",suffix); 130 fd=ops_setup_file_write(&cinfo, filename,overwrite); 131 ops_write_transferable_public_key(keydata,armoured,cinfo); 132 ops_teardown_file_write(cinfo,fd); 129 snprintf(filename, MAXBUF, "%s/%s.%s", dir, "ops_transferable_public_key", 130 suffix); 131 fd=ops_setup_file_write(&cinfo, filename, overwrite); 132 ops_write_transferable_public_key(keydata, armoured, cinfo); 133 ops_teardown_file_write(cinfo, fd); 133 134 134 135 /* … … 143 144 result=ops_mallocz(sizeof(*result)); 144 145 145 CU_ASSERT(ops_validate_all_signatures(result, &pub_keyring, NULL)==ops_true); 146 CU_ASSERT(result->valid_count==1); 147 148 CU_ASSERT(memcmp(result->valid_sigs[0].signer_id,keyid,OPS_KEY_ID_SIZE)==0); 149 CU_ASSERT(result->invalid_count==0); 150 CU_ASSERT(result->unknown_signer_count==0); 146 CU_ASSERT(ops_validate_all_signatures(result, &pub_keyring, NULL)); 147 CU_ASSERT(result->valid_count == 1); 148 149 CU_ASSERT(memcmp(result->valid_sigs[0].signer_id, keyid, OPS_KEY_ID_SIZE) 150 == 0); 151 CU_ASSERT(result->invalid_count == 0); 152 CU_ASSERT(result->unknown_signer_count == 0); 151 153 152 154 ops_validate_result_free(result); … … 154 156 // Validate public key with GPG 155 157 156 snprintf(cmd, sizeof cmd, "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, gpgcmd); 158 snprintf(cmd, sizeof cmd, 159 "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, 160 gpgcmd); 157 161 rtn=run(cmd); 158 162 CU_ASSERT(rtn==0); … … 164 168 result=ops_mallocz(sizeof(*result)); 165 169 166 snprintf(filename,MAXBUF,"%s/%s.%s",dir,"ops_transferable_secret_key",suffix); 167 fd=ops_setup_file_write(&cinfo, filename,overwrite); 168 ops_write_transferable_secret_key(keydata,passphrase,pplen,armoured,cinfo); 169 ops_teardown_file_write(cinfo,fd); 170 snprintf(filename, MAXBUF, "%s/%s.%s", dir, "ops_transferable_secret_key", 171 suffix); 172 fd=ops_setup_file_write(&cinfo, filename, overwrite); 173 ops_write_transferable_secret_key(keydata, pp, sizeof pp-1, armoured, 174 cinfo); 175 ops_teardown_file_write(cinfo, fd); 170 176 171 177 // generate keyring from this file … … 176 182 result=ops_mallocz(sizeof(*result)); 177 183 178 CU_ASSERT(ops_validate_all_signatures(result, &sec_keyring, cb_get_passphrase)==ops_true); 179 CU_ASSERT(result->valid_count==1); 180 CU_ASSERT(result->invalid_count==0); 181 CU_ASSERT(result->unknown_signer_count==0); 184 CU_ASSERT(ops_validate_all_signatures(result, &sec_keyring, 185 cb_get_passphrase)); 186 CU_ASSERT(result->valid_count == 1); 187 CU_ASSERT(result->invalid_count == 0); 188 CU_ASSERT(result->unknown_signer_count == 0); 182 189 183 190 ops_validate_result_free(result); 184 191 185 192 // validate with GPG 186 snprintf(cmd, sizeof cmd, "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, gpgcmd); 193 snprintf(cmd, sizeof cmd, 194 "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, 195 gpgcmd); 187 196 rtn=run(cmd); 188 197 CU_ASSERT(rtn==0); … … 201 210 ops_keyring_t keyring; 202 211 char filename[MAXBUF+1]; 203 snprintf(filename,MAXBUF,"%s/%s", dir, "pubring.gpg"); 212 213 snprintf(filename, MAXBUF, "%s/%s", dir, "pubring.gpg"); 204 214 205 215 memset(&keyring, '\0', sizeof keyring); … … 249 259 250 260 // Keyring 1 251 keydata=ops_rsa_create_selfsigned_keypair(1024, 65537,&uid1);261 keydata=ops_rsa_create_selfsigned_keypair(1024, 65537, &uid1); 252 262 CU_ASSERT(keydata != NULL); 253 snprintf(filename, MAXBUF,"%s/%s",dir,"transferable_public_key_1");254 fd=ops_setup_file_write(&cinfo, filename, overwrite);255 ops_write_transferable_public_key(keydata, OPS_ARMOURED,cinfo);256 ops_teardown_file_write(cinfo, fd);263 snprintf(filename, MAXBUF, "%s/%s", dir, "transferable_public_key_1"); 264 fd=ops_setup_file_write(&cinfo, filename, overwrite); 265 ops_write_transferable_public_key(keydata, OPS_ARMOURED, cinfo); 266 ops_teardown_file_write(cinfo, fd); 257 267 ops_keyring_read_from_file(&keyring1, OPS_ARMOURED, filename); 258 268 259 269 // Keyring 2 260 keydata=ops_rsa_create_selfsigned_keypair(1024, 65537,&uid2);270 keydata=ops_rsa_create_selfsigned_keypair(1024, 65537, &uid2); 261 271 CU_ASSERT(keydata != NULL); 262 snprintf(filename, MAXBUF,"%s/%s",dir,"transferable_public_key_2");263 fd=ops_setup_file_write(&cinfo, filename, overwrite);264 ops_write_transferable_public_key(keydata, OPS_ARMOURED,cinfo);265 ops_teardown_file_write(cinfo, fd);272 snprintf(filename, MAXBUF, "%s/%s", dir, "transferable_public_key_2"); 273 fd=ops_setup_file_write(&cinfo, filename, overwrite); 274 ops_write_transferable_public_key(keydata, OPS_ARMOURED, cinfo); 275 ops_teardown_file_write(cinfo, fd); 266 276 ops_keyring_read_from_file(&keyring2, OPS_ARMOURED, filename); 267 277 … … 277 287 snprintf(filename,MAXBUF,"%s/%s",dir,"transferable_public_key_3_bad"); 278 288 fd=ops_setup_file_write(&cinfo, filename, overwrite); 279 ops_write_transferable_public_key(keydata, OPS_ARMOURED,cinfo);280 ops_teardown_file_write(cinfo, fd);289 ops_write_transferable_public_key(keydata, OPS_ARMOURED, cinfo); 290 ops_teardown_file_write(cinfo, fd); 281 291 ops_keyring_read_from_file(&keyring3, OPS_ARMOURED, filename); 282 292 … … 289 299 assert(keydata1); 290 300 291 CU_ASSERT( ops_validate_key_signatures(result, keydata1, &keyring2, NULL)==ops_false);301 CU_ASSERT(!ops_validate_key_signatures(result, keydata1, &keyring2, NULL)); 292 302 293 303 CU_ASSERT(result->valid_count==0); … … 307 317 assert(keydata3); 308 318 309 CU_ASSERT( ops_validate_key_signatures(result, keydata3, &keyring3, NULL)==ops_false);310 311 CU_ASSERT(result->valid_count ==0);312 CU_ASSERT(result->invalid_count ==1);313 CU_ASSERT(result->unknown_signer_count ==0);319 CU_ASSERT(!ops_validate_key_signatures(result, keydata3, &keyring3, NULL)); 320 321 CU_ASSERT(result->valid_count == 0); 322 CU_ASSERT(result->invalid_count == 1); 323 CU_ASSERT(result->unknown_signer_count == 0); 314 324 ops_validate_result_free(result); 315 325 316 326 // validate with GPG - should fail 317 snprintf(cmd, sizeof cmd, "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, gpgcmd); 327 snprintf(cmd, sizeof cmd, 328 "cat %s | %s --import --no-allow-non-selfsigned-uid", filename, 329 gpgcmd); 318 330 rtn=run(cmd); 319 331 CU_ASSERT(rtn!=0); … … 351 363 352 364 // add suite 353 suite=CU_add_suite("RSA Keys Suite", init_suite_rsa_keys, clean_suite_rsa_keys); 365 suite=CU_add_suite("RSA Keys Suite", init_suite_rsa_keys, 366 clean_suite_rsa_keys); 354 367 if (!suite) 355 368 return NULL; … … 357 370 // add tests to suite 358 371 359 if (NULL == CU_add_test(suite, "Generate key pair", test_rsa_keys_generate_keypair)) 360 return NULL; 361 362 if (NULL == CU_add_test(suite, "Self-sign key pair", test_rsa_keys_selfsign_keypair)) 363 return NULL; 364 365 if (NULL == CU_add_test(suite, "Verify self-signed key pair", test_rsa_keys_verify_keypair)) 366 return NULL; 367 368 if (NULL == CU_add_test(suite, "Verify self-signed key pair (armoured)", test_rsa_keys_verify_armoured_keypair)) 369 return NULL; 370 371 if (NULL == CU_add_test(suite, "Verify self-signed key pair fails", test_rsa_keys_verify_keypair_fail)) 372 return NULL; 373 374 if (NULL == CU_add_test(suite, "Read keyring from file", test_rsa_keys_read_from_file)) 372 if (NULL == CU_add_test(suite, "Generate key pair", 373 test_rsa_keys_generate_keypair)) 374 return NULL; 375 376 if (NULL == CU_add_test(suite, "Self-sign key pair", 377 test_rsa_keys_selfsign_keypair)) 378 return NULL; 379 380 if (NULL == CU_add_test(suite, "Verify self-signed key pair", 381 test_rsa_keys_verify_keypair)) 382 return NULL; 383 384 if (NULL == CU_add_test(suite, "Verify self-signed key pair (armoured)", 385 test_rsa_keys_verify_armoured_keypair)) 386 return NULL; 387 388 if (NULL == CU_add_test(suite, "Verify self-signed key pair fails", 389 test_rsa_keys_verify_keypair_fail)) 390 return NULL; 391 392 if (NULL == CU_add_test(suite, "Read keyring from file", 393 test_rsa_keys_read_from_file)) 375 394 return NULL; 376 395
