Changeset 525
- Timestamp:
- 12/10/07 17:51:16
- Files:
-
- openpgpsdk/trunk/tests/Makefile.template (modified) (1 diff)
- openpgpsdk/trunk/tests/test_common.c (modified) (1 diff)
- openpgpsdk/trunk/tests/test_rsa_encrypt.c (modified) (7 diffs)
- openpgpsdk/trunk/tests/test_rsa_signature.c (modified) (13 diffs)
- openpgpsdk/trunk/tests/test_rsa_verify.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
openpgpsdk/trunk/tests/Makefile.template
r521 r525 21 21 TESTOBJ= $(TESTSRC:.c=.o) 22 22 23 GPGTESTSRC= tests_gpg.c 24 GPGTESTOBJ= $(GPGTESTSRC:.c=.o) 25 26 all: Makefile $(CUNIT_LIB) .depend tests tests_gpg 23 all: Makefile $(CUNIT_LIB) .depend tests 27 24 28 25 tests: $(CUNIT_LIB) $(TESTOBJ) $(COMMONTESTOBJ) $(LIBDEPS) 29 26 $(CC) $(LDFLAGS) -o tests $(TESTOBJ) $(COMMONTESTOBJ) $(LIBS) 30 31 tests_gpg: $(CUNIT_LIB) $(GPGTESTOBJ) $(COMMONTESTOBJ) $(LIBDEPS)32 $(CC) $(LDFLAGS) -o tests_gpg $(GPGTESTOBJ) $(COMMONTESTOBJ) $(LIBS)33 27 34 28 $(CUNIT_LIB): openpgpsdk/trunk/tests/test_common.c
r523 r525 49 49 50 50 assert(strlen(dir)); 51 snprintf(gpgcmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s ",dir);51 snprintf(gpgcmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --openpgp",dir); 52 52 53 53 setup_test_keys(); openpgpsdk/trunk/tests/test_rsa_encrypt.c
r521 r525 11 11 12 12 #include "tests.h" 13 14 static int do_gpgtest=0;15 13 16 14 static char *filename_rsa_noarmour_nopassphrase_singlekey="enc_rsa_noarmour_np_singlekey.txt"; … … 86 84 int init_suite_rsa_encrypt(void) 87 85 { 88 do_gpgtest=0;89 90 86 // Create RSA test files 91 87 … … 99 95 100 96 // Return success 101 return 0;102 }103 104 int init_suite_rsa_encrypt_gpgtest(void)105 {106 init_suite_rsa_encrypt();107 108 do_gpgtest=1;109 110 97 return 0; 111 98 } … … 170 157 char decrypted_file[MAXBUF+1]; 171 158 char *suffix= has_armour ? "asc" : "gpg"; 172 char *gpgtest = do_gpgtest ? "gpgtest_" : "";159 // char *gpgtest = do_gpgtest ? "gpgtest_" : ""; 173 160 int fd_in=0; 174 161 int fd_out=0; … … 197 184 } 198 185 199 snprintf(encrypted_file,MAXBUF,"%s/%s %s.%s",dir,gpgtest,filename,suffix);186 snprintf(encrypted_file,MAXBUF,"%s/%s.%s",dir,filename,suffix); 200 187 #ifdef WIN32 201 188 fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600); … … 258 245 */ 259 246 260 if (do_gpgtest) 261 { 262 // File contents should match - check with GPG 247 // File contents should match - check with GPG 263 248 264 if (pub_key==alpha_pub_keydata) 265 pp[0]='\0'; 266 else if (pub_key==bravo_pub_keydata) 267 snprintf(pp,MAXBUF," --passphrase %s ", bravo_passphrase); 268 snprintf(decrypted_file,MAXBUF,"%s/decrypted_%s",dir,filename); 269 snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --decrypt --output=%s --homedir %s %s %s",decrypted_file, dir, pp, encrypted_file); 270 // printf("cmd: %s\n", cmd); 271 rtn=system(cmd); 272 CU_ASSERT(rtn==0); 273 CU_ASSERT(file_compare(myfile,decrypted_file)==0); 274 } 275 else 276 { 277 // File contents should match - checking with OPS 249 if (pub_key==alpha_pub_keydata) 250 pp[0]='\0'; 251 else if (pub_key==bravo_pub_keydata) 252 snprintf(pp,MAXBUF," --passphrase %s ", bravo_passphrase); 253 snprintf(decrypted_file,MAXBUF,"%s/decrypted_%s",dir,filename); 254 snprintf(cmd,MAXBUF,"%s --decrypt --output=%s %s %s",gpgcmd, decrypted_file, pp, encrypted_file); 255 // printf("cmd: %s\n", cmd); 256 rtn=system(cmd); 257 CU_ASSERT(rtn==0); 258 CU_ASSERT(file_compare(myfile,decrypted_file)==0); 259 260 // File contents should match - checking with OPS 278 261 279 testtext=create_testtext(filename); 280 test_rsa_decrypt(encrypted_file,testtext); 281 } 262 testtext=create_testtext(filename); 263 test_rsa_decrypt(encrypted_file,testtext); 282 264 } 283 265 … … 359 341 } 360 342 361 CU_pSuite suite_rsa_encrypt_GPGtest()362 {363 CU_pSuite suite = NULL;364 365 suite = CU_add_suite("RSA Encryption Suite (GPG interoperability)", init_suite_rsa_encrypt_gpgtest, clean_suite_rsa_encrypt);366 367 if (!suite)368 return NULL;369 370 if (!add_tests(suite))371 return NULL;372 373 return suite;374 }375 376 343 // EOF openpgpsdk/trunk/tests/test_rsa_signature.c
r523 r525 18 18 19 19 static int debug=0; 20 static int do_gpgtest=0;21 20 22 21 static char *filename_rsa_noarmour_nopassphrase="ops_rsa_signed_noarmour_nopassphrase.txt"; … … 24 23 static char *filename_rsa_armour_nopassphrase="ops_rsa_signed_armour_nopassphrase.txt"; 25 24 static char *filename_rsa_armour_passphrase="ops_rsa_signed_armour_passphrase.txt"; 25 static char *filename_rsa_clearsign_nopassphrase="ops_rsa_signed_clearsign_nopassphrase.txt"; 26 static char *filename_rsa_clearsign_passphrase="ops_rsa_signed_clearsign_passphrase.txt"; 26 27 27 28 /* Signature suite initialization. … … 32 33 int init_suite_rsa_signature(void) 33 34 { 34 do_gpgtest=0;35 36 35 // Create test files 37 36 … … 40 39 create_testfile(filename_rsa_armour_nopassphrase); 41 40 create_testfile(filename_rsa_armour_passphrase); 41 create_testfile(filename_rsa_clearsign_nopassphrase); 42 create_testfile(filename_rsa_clearsign_passphrase); 42 43 43 44 // Return success … … 45 46 } 46 47 47 int init_suite_rsa_signature_gpgtest(void)48 { 49 init_suite_rsa_signature();50 51 do_gpgtest=1;48 int clean_suite_rsa_signature(void) 49 { 50 ops_finish(); 51 52 reset_vars(); 52 53 53 54 return 0; 54 55 } 55 56 56 int clean_suite_rsa_signature(void) 57 { 58 ops_finish(); 59 60 reset_vars(); 61 62 return 0; 63 } 64 65 static void test_rsa_signature(const int has_armour, const char *filename, const ops_secret_key_t *skey, ops_hash_algorithm_t hash_alg) 57 static void test_rsa_signature_clearsign(const char *filename, const ops_secret_key_t *skey, ops_hash_algorithm_t hash_alg) 66 58 { 67 59 unsigned char keyid[OPS_KEY_ID_SIZE]; … … 71 63 char myfile[MAXBUF+1]; 72 64 char signed_file[MAXBUF+1]; 73 char *suffix= has_armour ? "asc" : "gpg"; 65 // char *suffix= has_armour ? "asc" : "gpg"; 66 char *suffix= "asc"; 74 67 int fd_in=0; 75 68 int fd_out=0; … … 106 99 // OPS code armours signatures by default 107 100 108 assert(has_armour);101 // assert(has_armour); 109 102 110 103 // set up signature … … 189 182 // Set up armour/passphrase options 190 183 191 if (has_armour)184 // if (has_armour) 192 185 ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); 193 186 // current_passphrase=has_passphrase ? passphrase : nopassphrase; … … 200 193 201 194 // Tidy up 202 if (has_armour)195 // if (has_armour) 203 196 ops_reader_pop_dearmour(pinfo); 204 197 … … 217 210 } 218 211 219 void test_rsa_signature_noarmour_nopassphrase(void) 220 { 212 static void test_rsa_signature_noarmour_nopassphrase(void) 213 { 214 CU_FAIL("Test TODO: Sign file with no armour and no passphrase"); 215 #ifdef TBD 216 221 217 int armour=0; 222 218 assert(pub_keyring.nkeys); … … 229 225 test_rsa_signature(armour,filename_rsa_noarmour_nopassphrase, alpha_skey, OPS_HASH_SHA512); 230 226 #endif 231 } 232 233 void test_rsa_signature_noarmour_passphrase(void) 234 { 227 #endif 228 } 229 230 static void test_rsa_signature_noarmour_passphrase(void) 231 { 232 CU_FAIL("Test TODO: Sign file with no armour and passphrase"); 233 #ifdef TBD 235 234 int armour=0; 236 235 assert(pub_keyring.nkeys); 237 236 test_rsa_signature(armour,filename_rsa_noarmour_passphrase, bravo_skey, OPS_HASH_SHA1); 238 } 239 240 void test_rsa_signature_armour_nopassphrase(void) 241 { 237 #endif 238 } 239 240 static void test_rsa_signature_armour_nopassphrase(void) 241 { 242 CU_FAIL("Test TODO: Sign file with armour and no passphrase"); 243 #ifdef TBD 242 244 int armour=1; 243 245 assert(pub_keyring.nkeys); 244 246 test_rsa_signature(armour,filename_rsa_armour_nopassphrase, alpha_skey, OPS_HASH_SHA1); 245 } 246 247 void test_rsa_signature_armour_passphrase(void) 248 { 247 #endif 248 } 249 250 static void test_rsa_signature_armour_passphrase(void) 251 { 252 CU_FAIL("Test TODO: Sign file with armour and passphrase"); 253 #ifdef TBD 249 254 int armour=1; 250 255 assert(pub_keyring.nkeys); 251 256 test_rsa_signature(armour,filename_rsa_armour_passphrase, bravo_skey, OPS_HASH_SHA1); 257 #endif 258 } 259 260 static void test_rsa_signature_clearsign_nopassphrase(void) 261 { 262 assert(pub_keyring.nkeys); 263 test_rsa_signature_clearsign(filename_rsa_armour_nopassphrase, alpha_skey, OPS_HASH_SHA1); 264 } 265 266 static void test_rsa_signature_clearsign_passphrase(void) 267 { 268 assert(pub_keyring.nkeys); 269 test_rsa_signature_clearsign(filename_rsa_armour_passphrase, bravo_skey, OPS_HASH_SHA1); 252 270 } 253 271 … … 262 280 // add tests to suite 263 281 264 #ifdef TBD265 282 if (NULL == CU_add_test(suite, "Unarmoured, no passphrase", test_rsa_signature_noarmour_nopassphrase)) 266 283 return NULL; … … 268 285 if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_signature_noarmour_passphrase)) 269 286 return NULL; 270 #endif /*TBD*/271 287 272 288 if (NULL == CU_add_test(suite, "Armoured, no passphrase", test_rsa_signature_armour_nopassphrase)) 273 289 return NULL; 274 290 275 #ifdef TBD276 291 if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_signature_armour_passphrase)) 277 292 return NULL; 278 #endif 293 294 if (NULL == CU_add_test(suite, "Clearsigned, no passphrase", test_rsa_signature_clearsign_nopassphrase)) 295 return NULL; 296 297 if (NULL == CU_add_test(suite, "Clearsigned, passphrase", test_rsa_signature_clearsign_passphrase)) 298 return NULL; 279 299 280 300 return suite; 281 301 } 282 302 283 CU_pSuite suite_rsa_signature_GPGtest()284 {285 CU_pSuite suite = NULL;286 287 suite = CU_add_suite("RSA Signature Suite (GPG interop)", init_suite_rsa_signature_gpgtest, clean_suite_rsa_signature);288 289 if (!suite)290 return NULL;291 292 // add tests to suite293 294 #ifdef TBD295 if (NULL == CU_add_test(suite, "Unarmoured, no passphrase", test_rsa_signature_noarmour_nopassphrase))296 return NULL;297 298 if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_signature_noarmour_passphrase))299 return NULL;300 #endif /*TBD*/301 302 if (NULL == CU_add_test(suite, "Armoured, no passphrase", test_rsa_signature_armour_nopassphrase))303 return NULL;304 305 if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_signature_armour_passphrase))306 return NULL;307 308 309 return suite;310 }311 312 303 // EOF openpgpsdk/trunk/tests/test_rsa_verify.c
r523 r525 16 16 #include "tests.h" 17 17 18 static int do_gpgtest=0;19 20 18 #ifndef ATTRIBUTE_UNUSED 21 19 … … 28 26 #endif /* ATTRIBUTE_UNUSED */ 29 27 28 static char *filename_rsa_armour_nopassphrase="gpg_signed_armour_nopassphrase.txt"; 29 static char *filename_rsa_armour_passphrase="gpg_signed_armour_passphrase.txt"; 30 30 31 static char *filename_rsa_noarmour_nopassphrase="gpg_signed_noarmour_nopassphrase.txt"; 31 static char *filename_rsa_armour_nopassphrase="gpg_signed_armour_nopassphrase.txt"; 32 static char *filename_rsa_noarmour_passphrase="gpg_signed_armour_nopassphrase.txt"; 33 static char *filename_rsa_armour_passphrase="gpg_signed_armour_passphrase.txt"; 34 35 static char *filename_rsa_clearsign_armour_nopassphrase="gpg_clearsigned_armour_nopassphrase.txt"; 32 static char *filename_rsa_noarmour_passphrase="gpg_signed_noarmour_passphrase.txt"; 33 34 static char *filename_rsa_clearsign_nopassphrase="gpg_clearsigned_nopassphrase.txt"; 35 static char *filename_rsa_clearsign_passphrase="gpg_clearsigned_passphrase.txt"; 36 36 37 37 /* Signature verification suite initialization. … … 43 43 char cmd[MAXBUF+1]; 44 44 45 do_gpgtest=0;46 47 45 // Create SIGNED test files 48 46 47 create_testfile(filename_rsa_armour_nopassphrase); 48 create_testfile(filename_rsa_armour_passphrase); 49 49 50 create_testfile(filename_rsa_noarmour_nopassphrase); 50 create_testfile(filename_rsa_armour_nopassphrase);51 51 create_testfile(filename_rsa_noarmour_passphrase); 52 create_testfile(filename_rsa_armour_passphrase);53 52 54 53 // Now sign the test files with GPG … … 59 58 { return 1; } 60 59 61 snprintf(cmd,MAXBUF,"%s -- compress-level 0 --sign --local-user %s --armor %s/%s",60 snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --sign --local-user %s --armor %s/%s", 62 61 gpgcmd, alpha_name, dir, filename_rsa_armour_nopassphrase); 63 62 if (system(cmd)) 64 63 { return 1; } 65 64 66 snprintf(cmd,MAXBUF,"%s -- compress-level 0 --sign --local-user %s --passphrase %s %s/%s",65 snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --sign --local-user %s --passphrase %s %s/%s", 67 66 gpgcmd, bravo_name, bravo_passphrase, dir, filename_rsa_noarmour_passphrase); 68 67 if (system(cmd)) 69 68 { return 1; } 70 69 71 snprintf(cmd,MAXBUF,"%s -- compress-level 0 --sign --local-user %s --passphrase %s --armor %s/%s",70 snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --sign --local-user %s --passphrase %s --armor %s/%s", 72 71 gpgcmd, bravo_name, bravo_passphrase, dir, filename_rsa_armour_passphrase); 73 72 if (system(cmd)) … … 78 77 */ 79 78 80 create_testfile(filename_rsa_clearsign_armour_nopassphrase); 79 create_testfile(filename_rsa_clearsign_nopassphrase); 80 create_testfile(filename_rsa_clearsign_passphrase); 81 81 82 82 // and sign them 83 83 84 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); 85 gpgcmd, alpha_name, dir, filename_rsa_clearsign_nopassphrase); 86 if (system(cmd)) 87 { return 1; } 88 89 snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign --local-user %s --passphrase %s --armor %s/%s", 90 gpgcmd, bravo_name, bravo_passphrase, dir, filename_rsa_clearsign_passphrase); 86 91 if (system(cmd)) 87 92 { return 1; } 88 93 89 94 // Return success 90 return 0;91 }92 93 int init_suite_rsa_verify_gpgtest(void)94 {95 init_suite_rsa_verify();96 97 do_gpgtest=1;98 99 95 return 0; 100 96 } … … 176 172 } 177 173 178 void test_rsa_verify_noarmour_nopassphrase(void)174 static void test_rsa_verify_noarmour_nopassphrase(void) 179 175 { 180 176 // int clearsign=0; … … 187 183 } 188 184 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 199 #ifdef TBD 200 void test_rsa_encrypt_armour_singlekey(void) 201 { 202 int armour=1; 203 char *user_id="Alpha (RSA, no passphrase) <alpha@test.com>"; 204 const ops_key_data_t *pub_key=ops_keyring_find_key_by_userid(&pub_keyring, user_id); 205 assert(pub_key); 206 test_rsa_encrypt(armour,pub_key,filename_rsa_armour_singlekey); 207 } 208 209 void test_rsa_encrypt_noarmour_passphrase(void) 210 { 185 static void test_rsa_verify_noarmour_passphrase(void) 186 { 187 // int clearsign=0; 211 188 int armour=0; 212 189 int passphrase=1; 213 test_rsa_encrypt(armour,passphrase,filename_rsa_noarmour_passphrase); 214 } 215 216 void test_rsa_encrypt_armour_passphrase(void) 190 assert(pub_keyring.nkeys); 191 test_rsa_verify(armour,passphrase,filename_rsa_noarmour_passphrase,NULL); 192 } 193 194 static void test_rsa_verify_armour_nopassphrase(void) 195 { 196 int armour=1; 197 int passphrase=0; 198 assert(pub_keyring.nkeys); 199 test_rsa_verify(armour,passphrase,filename_rsa_armour_nopassphrase,NULL); 200 } 201 202 static void test_rsa_verify_armour_passphrase(void) 217 203 { 218 204 int armour=1; 219 205 int passphrase=1; 220 test_rsa_encrypt(armour,passphrase,filename_rsa_armour_passphrase); 221 } 222 #endif /*TBD*/ 206 assert(pub_keyring.nkeys); 207 test_rsa_verify(armour,passphrase,filename_rsa_armour_passphrase,NULL); 208 } 209 210 static void test_rsa_verify_clearsign_nopassphrase(void) 211 { 212 // int clearsign=1; 213 int armour=1; 214 int passphrase=0; 215 assert(pub_keyring.nkeys); 216 217 test_rsa_verify(armour,passphrase,filename_rsa_clearsign_nopassphrase,NULL); 218 } 219 220 static void test_rsa_verify_clearsign_passphrase(void) 221 { 222 // int clearsign=1; 223 int armour=1; 224 int passphrase=1; 225 assert(pub_keyring.nkeys); 226 227 test_rsa_verify(armour,passphrase,filename_rsa_clearsign_passphrase,NULL); 228 } 229 223 230 224 231 CU_pSuite suite_rsa_verify() … … 232 239 // add tests to suite 233 240 234 if (NULL == CU_add_test(suite, "Clearsigned, armoured, no passphrase", test_rsa_verify_clearsign_armour_nopassphrase)) 241 if (NULL == CU_add_test(suite, "Clearsigned, no passphrase", test_rsa_verify_clearsign_nopassphrase)) 242 return NULL; 243 244 if (NULL == CU_add_test(suite, "Clearsigned, passphrase", test_rsa_verify_clearsign_passphrase)) 245 return NULL; 246 247 if (NULL == CU_add_test(suite, "Armoured, no passphrase", test_rsa_verify_armour_nopassphrase)) 248 return NULL; 249 250 if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_verify_armour_passphrase)) 235 251 return NULL; 236 252 … … 238 254 return NULL; 239 255 240 /*241 256 if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_verify_noarmour_passphrase)) 242 257 return NULL; 243 */ 258 244 259 return suite; 245 260 } 246 261 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 suite256 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 262 // EOF
