Index: openpgpsdk/trunk/tests/Makefile.template =================================================================== --- openpgpsdk/trunk/tests/Makefile.template (revision 521) +++ openpgpsdk/trunk/tests/Makefile.template (revision 525) @@ -21,14 +21,8 @@ TESTOBJ= $(TESTSRC:.c=.o) -GPGTESTSRC= tests_gpg.c -GPGTESTOBJ= $(GPGTESTSRC:.c=.o) - -all: Makefile $(CUNIT_LIB) .depend tests tests_gpg +all: Makefile $(CUNIT_LIB) .depend tests tests: $(CUNIT_LIB) $(TESTOBJ) $(COMMONTESTOBJ) $(LIBDEPS) $(CC) $(LDFLAGS) -o tests $(TESTOBJ) $(COMMONTESTOBJ) $(LIBS) - -tests_gpg: $(CUNIT_LIB) $(GPGTESTOBJ) $(COMMONTESTOBJ) $(LIBDEPS) - $(CC) $(LDFLAGS) -o tests_gpg $(GPGTESTOBJ) $(COMMONTESTOBJ) $(LIBS) $(CUNIT_LIB): Index: openpgpsdk/trunk/tests/test_common.c =================================================================== --- openpgpsdk/trunk/tests/test_common.c (revision 523) +++ openpgpsdk/trunk/tests/test_common.c (revision 525) @@ -49,5 +49,5 @@ assert(strlen(dir)); - snprintf(gpgcmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s",dir); + snprintf(gpgcmd,MAXBUF,"gpg --quiet --no-tty --homedir=%s --openpgp",dir); setup_test_keys(); Index: openpgpsdk/trunk/tests/test_rsa_encrypt.c =================================================================== --- openpgpsdk/trunk/tests/test_rsa_encrypt.c (revision 521) +++ openpgpsdk/trunk/tests/test_rsa_encrypt.c (revision 525) @@ -11,6 +11,4 @@ #include "tests.h" - -static int do_gpgtest=0; static char *filename_rsa_noarmour_nopassphrase_singlekey="enc_rsa_noarmour_np_singlekey.txt"; @@ -86,6 +84,4 @@ int init_suite_rsa_encrypt(void) { - do_gpgtest=0; - // Create RSA test files @@ -99,13 +95,4 @@ // Return success - return 0; - } - -int init_suite_rsa_encrypt_gpgtest(void) - { - init_suite_rsa_encrypt(); - - do_gpgtest=1; - return 0; } @@ -170,5 +157,5 @@ char decrypted_file[MAXBUF+1]; char *suffix= has_armour ? "asc" : "gpg"; - char *gpgtest = do_gpgtest ? "gpgtest_" : ""; + // char *gpgtest = do_gpgtest ? "gpgtest_" : ""; int fd_in=0; int fd_out=0; @@ -197,5 +184,5 @@ } - snprintf(encrypted_file,MAXBUF,"%s/%s%s.%s",dir,gpgtest,filename,suffix); + snprintf(encrypted_file,MAXBUF,"%s/%s.%s",dir,filename,suffix); #ifdef WIN32 fd_out=open(encrypted_file,O_WRONLY | O_CREAT | O_EXCL | O_BINARY, 0600); @@ -258,26 +245,21 @@ */ - if (do_gpgtest) - { - // File contents should match - check with GPG + // File contents should match - check with GPG - if (pub_key==alpha_pub_keydata) - pp[0]='\0'; - else if (pub_key==bravo_pub_keydata) - snprintf(pp,MAXBUF," --passphrase %s ", bravo_passphrase); - snprintf(decrypted_file,MAXBUF,"%s/decrypted_%s",dir,filename); - snprintf(cmd,MAXBUF,"gpg --quiet --no-tty --decrypt --output=%s --homedir %s %s %s",decrypted_file, dir, pp, encrypted_file); - // printf("cmd: %s\n", cmd); - rtn=system(cmd); - CU_ASSERT(rtn==0); - CU_ASSERT(file_compare(myfile,decrypted_file)==0); - } - else - { - // File contents should match - checking with OPS + if (pub_key==alpha_pub_keydata) + pp[0]='\0'; + else if (pub_key==bravo_pub_keydata) + snprintf(pp,MAXBUF," --passphrase %s ", bravo_passphrase); + snprintf(decrypted_file,MAXBUF,"%s/decrypted_%s",dir,filename); + snprintf(cmd,MAXBUF,"%s --decrypt --output=%s %s %s",gpgcmd, decrypted_file, pp, encrypted_file); + // printf("cmd: %s\n", cmd); + rtn=system(cmd); + CU_ASSERT(rtn==0); + CU_ASSERT(file_compare(myfile,decrypted_file)==0); + + // File contents should match - checking with OPS - testtext=create_testtext(filename); - test_rsa_decrypt(encrypted_file,testtext); - } + testtext=create_testtext(filename); + test_rsa_decrypt(encrypted_file,testtext); } @@ -359,18 +341,3 @@ } -CU_pSuite suite_rsa_encrypt_GPGtest() - { - CU_pSuite suite = NULL; - - suite = CU_add_suite("RSA Encryption Suite (GPG interoperability)", init_suite_rsa_encrypt_gpgtest, clean_suite_rsa_encrypt); - - if (!suite) - return NULL; - - if (!add_tests(suite)) - return NULL; - - return suite; - } - // EOF Index: openpgpsdk/trunk/tests/test_rsa_signature.c =================================================================== --- openpgpsdk/trunk/tests/test_rsa_signature.c (revision 523) +++ openpgpsdk/trunk/tests/test_rsa_signature.c (revision 525) @@ -18,5 +18,4 @@ static int debug=0; -static int do_gpgtest=0; static char *filename_rsa_noarmour_nopassphrase="ops_rsa_signed_noarmour_nopassphrase.txt"; @@ -24,4 +23,6 @@ static char *filename_rsa_armour_nopassphrase="ops_rsa_signed_armour_nopassphrase.txt"; static char *filename_rsa_armour_passphrase="ops_rsa_signed_armour_passphrase.txt"; +static char *filename_rsa_clearsign_nopassphrase="ops_rsa_signed_clearsign_nopassphrase.txt"; +static char *filename_rsa_clearsign_passphrase="ops_rsa_signed_clearsign_passphrase.txt"; /* Signature suite initialization. @@ -32,6 +33,4 @@ int init_suite_rsa_signature(void) { - do_gpgtest=0; - // Create test files @@ -40,4 +39,6 @@ create_testfile(filename_rsa_armour_nopassphrase); create_testfile(filename_rsa_armour_passphrase); + create_testfile(filename_rsa_clearsign_nopassphrase); + create_testfile(filename_rsa_clearsign_passphrase); // Return success @@ -45,23 +46,14 @@ } -int init_suite_rsa_signature_gpgtest(void) - { - init_suite_rsa_signature(); - - do_gpgtest=1; +int clean_suite_rsa_signature(void) + { + ops_finish(); + + reset_vars(); return 0; } -int clean_suite_rsa_signature(void) - { - ops_finish(); - - reset_vars(); - - return 0; - } - -static void test_rsa_signature(const int has_armour, const char *filename, const ops_secret_key_t *skey, ops_hash_algorithm_t hash_alg) +static void test_rsa_signature_clearsign(const char *filename, const ops_secret_key_t *skey, ops_hash_algorithm_t hash_alg) { unsigned char keyid[OPS_KEY_ID_SIZE]; @@ -71,5 +63,6 @@ char myfile[MAXBUF+1]; char signed_file[MAXBUF+1]; - char *suffix= has_armour ? "asc" : "gpg"; + // char *suffix= has_armour ? "asc" : "gpg"; + char *suffix= "asc"; int fd_in=0; int fd_out=0; @@ -106,5 +99,5 @@ // OPS code armours signatures by default - assert(has_armour); + // assert(has_armour); // set up signature @@ -189,5 +182,5 @@ // Set up armour/passphrase options - if (has_armour) + // if (has_armour) ops_reader_push_dearmour(pinfo,ops_false,ops_false,ops_false); // current_passphrase=has_passphrase ? passphrase : nopassphrase; @@ -200,5 +193,5 @@ // Tidy up - if (has_armour) + // if (has_armour) ops_reader_pop_dearmour(pinfo); @@ -217,6 +210,9 @@ } -void test_rsa_signature_noarmour_nopassphrase(void) - { +static void test_rsa_signature_noarmour_nopassphrase(void) + { + CU_FAIL("Test TODO: Sign file with no armour and no passphrase"); +#ifdef TBD + int armour=0; assert(pub_keyring.nkeys); @@ -229,25 +225,47 @@ test_rsa_signature(armour,filename_rsa_noarmour_nopassphrase, alpha_skey, OPS_HASH_SHA512); #endif - } - -void test_rsa_signature_noarmour_passphrase(void) - { +#endif + } + +static void test_rsa_signature_noarmour_passphrase(void) + { + CU_FAIL("Test TODO: Sign file with no armour and passphrase"); +#ifdef TBD int armour=0; assert(pub_keyring.nkeys); test_rsa_signature(armour,filename_rsa_noarmour_passphrase, bravo_skey, OPS_HASH_SHA1); - } - -void test_rsa_signature_armour_nopassphrase(void) - { +#endif + } + +static void test_rsa_signature_armour_nopassphrase(void) + { + CU_FAIL("Test TODO: Sign file with armour and no passphrase"); +#ifdef TBD int armour=1; assert(pub_keyring.nkeys); test_rsa_signature(armour,filename_rsa_armour_nopassphrase, alpha_skey, OPS_HASH_SHA1); - } - -void test_rsa_signature_armour_passphrase(void) - { +#endif + } + +static void test_rsa_signature_armour_passphrase(void) + { + CU_FAIL("Test TODO: Sign file with armour and passphrase"); +#ifdef TBD int armour=1; assert(pub_keyring.nkeys); test_rsa_signature(armour,filename_rsa_armour_passphrase, bravo_skey, OPS_HASH_SHA1); +#endif + } + +static void test_rsa_signature_clearsign_nopassphrase(void) + { + assert(pub_keyring.nkeys); + test_rsa_signature_clearsign(filename_rsa_armour_nopassphrase, alpha_skey, OPS_HASH_SHA1); + } + +static void test_rsa_signature_clearsign_passphrase(void) + { + assert(pub_keyring.nkeys); + test_rsa_signature_clearsign(filename_rsa_armour_passphrase, bravo_skey, OPS_HASH_SHA1); } @@ -262,5 +280,4 @@ // add tests to suite -#ifdef TBD if (NULL == CU_add_test(suite, "Unarmoured, no passphrase", test_rsa_signature_noarmour_nopassphrase)) return NULL; @@ -268,45 +285,19 @@ if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_signature_noarmour_passphrase)) return NULL; -#endif /*TBD*/ if (NULL == CU_add_test(suite, "Armoured, no passphrase", test_rsa_signature_armour_nopassphrase)) return NULL; -#ifdef TBD if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_signature_armour_passphrase)) return NULL; -#endif + + if (NULL == CU_add_test(suite, "Clearsigned, no passphrase", test_rsa_signature_clearsign_nopassphrase)) + return NULL; + + if (NULL == CU_add_test(suite, "Clearsigned, passphrase", test_rsa_signature_clearsign_passphrase)) + return NULL; return suite; } -CU_pSuite suite_rsa_signature_GPGtest() -{ - CU_pSuite suite = NULL; - - suite = CU_add_suite("RSA Signature Suite (GPG interop)", init_suite_rsa_signature_gpgtest, clean_suite_rsa_signature); - - if (!suite) - return NULL; - - // add tests to suite - -#ifdef TBD - if (NULL == CU_add_test(suite, "Unarmoured, no passphrase", test_rsa_signature_noarmour_nopassphrase)) - return NULL; - - if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_signature_noarmour_passphrase)) - return NULL; -#endif /*TBD*/ - - if (NULL == CU_add_test(suite, "Armoured, no passphrase", test_rsa_signature_armour_nopassphrase)) - return NULL; - - if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_signature_armour_passphrase)) - return NULL; - - - return suite; -} - // EOF Index: openpgpsdk/trunk/tests/test_rsa_verify.c =================================================================== --- openpgpsdk/trunk/tests/test_rsa_verify.c (revision 523) +++ openpgpsdk/trunk/tests/test_rsa_verify.c (revision 525) @@ -16,6 +16,4 @@ #include "tests.h" -static int do_gpgtest=0; - #ifndef ATTRIBUTE_UNUSED @@ -28,10 +26,12 @@ #endif /* ATTRIBUTE_UNUSED */ +static char *filename_rsa_armour_nopassphrase="gpg_signed_armour_nopassphrase.txt"; +static char *filename_rsa_armour_passphrase="gpg_signed_armour_passphrase.txt"; + static char *filename_rsa_noarmour_nopassphrase="gpg_signed_noarmour_nopassphrase.txt"; -static char *filename_rsa_armour_nopassphrase="gpg_signed_armour_nopassphrase.txt"; -static char *filename_rsa_noarmour_passphrase="gpg_signed_armour_nopassphrase.txt"; -static char *filename_rsa_armour_passphrase="gpg_signed_armour_passphrase.txt"; - -static char *filename_rsa_clearsign_armour_nopassphrase="gpg_clearsigned_armour_nopassphrase.txt"; +static char *filename_rsa_noarmour_passphrase="gpg_signed_noarmour_passphrase.txt"; + +static char *filename_rsa_clearsign_nopassphrase="gpg_clearsigned_nopassphrase.txt"; +static char *filename_rsa_clearsign_passphrase="gpg_clearsigned_passphrase.txt"; /* Signature verification suite initialization. @@ -43,12 +43,11 @@ char cmd[MAXBUF+1]; - do_gpgtest=0; - // Create SIGNED test files + create_testfile(filename_rsa_armour_nopassphrase); + create_testfile(filename_rsa_armour_passphrase); + create_testfile(filename_rsa_noarmour_nopassphrase); - create_testfile(filename_rsa_armour_nopassphrase); create_testfile(filename_rsa_noarmour_passphrase); - create_testfile(filename_rsa_armour_passphrase); // Now sign the test files with GPG @@ -59,15 +58,15 @@ { return 1; } - snprintf(cmd,MAXBUF,"%s --compress-level 0 --sign --local-user %s --armor %s/%s", + snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --sign --local-user %s --armor %s/%s", gpgcmd, alpha_name, dir, filename_rsa_armour_nopassphrase); if (system(cmd)) { return 1; } - snprintf(cmd,MAXBUF,"%s --compress-level 0 --sign --local-user %s --passphrase %s %s/%s", + snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --sign --local-user %s --passphrase %s %s/%s", gpgcmd, bravo_name, bravo_passphrase, dir, filename_rsa_noarmour_passphrase); if (system(cmd)) { return 1; } - snprintf(cmd,MAXBUF,"%s --compress-level 0 --sign --local-user %s --passphrase %s --armor %s/%s", + snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --sign --local-user %s --passphrase %s --armor %s/%s", gpgcmd, bravo_name, bravo_passphrase, dir, filename_rsa_armour_passphrase); if (system(cmd)) @@ -78,23 +77,20 @@ */ - create_testfile(filename_rsa_clearsign_armour_nopassphrase); + create_testfile(filename_rsa_clearsign_nopassphrase); + create_testfile(filename_rsa_clearsign_passphrase); // and sign them snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign --local-user %s --armor %s/%s", - gpgcmd, alpha_name, dir, filename_rsa_clearsign_armour_nopassphrase); + gpgcmd, alpha_name, dir, filename_rsa_clearsign_nopassphrase); + if (system(cmd)) + { return 1; } + + snprintf(cmd,MAXBUF,"%s --openpgp --compress-level 0 --clearsign --local-user %s --passphrase %s --armor %s/%s", + gpgcmd, bravo_name, bravo_passphrase, dir, filename_rsa_clearsign_passphrase); if (system(cmd)) { return 1; } // Return success - return 0; - } - -int init_suite_rsa_verify_gpgtest(void) - { - init_suite_rsa_verify(); - - do_gpgtest=1; - return 0; } @@ -176,5 +172,5 @@ } -void test_rsa_verify_noarmour_nopassphrase(void) +static void test_rsa_verify_noarmour_nopassphrase(void) { // int clearsign=0; @@ -187,38 +183,49 @@ } -void test_rsa_verify_clearsign_armour_nopassphrase(void) - { - // int clearsign=1; - int armour=1; - int passphrase=0; - assert(pub_keyring.nkeys); - - test_rsa_verify(armour,passphrase,filename_rsa_clearsign_armour_nopassphrase,NULL); - } - -#ifdef TBD -void test_rsa_encrypt_armour_singlekey(void) - { - int armour=1; - char *user_id="Alpha (RSA, no passphrase) "; - const ops_key_data_t *pub_key=ops_keyring_find_key_by_userid(&pub_keyring, user_id); - assert(pub_key); - test_rsa_encrypt(armour,pub_key,filename_rsa_armour_singlekey); - } - -void test_rsa_encrypt_noarmour_passphrase(void) - { +static void test_rsa_verify_noarmour_passphrase(void) + { + // int clearsign=0; int armour=0; int passphrase=1; - test_rsa_encrypt(armour,passphrase,filename_rsa_noarmour_passphrase); - } - -void test_rsa_encrypt_armour_passphrase(void) + assert(pub_keyring.nkeys); + test_rsa_verify(armour,passphrase,filename_rsa_noarmour_passphrase,NULL); + } + +static void test_rsa_verify_armour_nopassphrase(void) + { + int armour=1; + int passphrase=0; + assert(pub_keyring.nkeys); + test_rsa_verify(armour,passphrase,filename_rsa_armour_nopassphrase,NULL); + } + +static void test_rsa_verify_armour_passphrase(void) { int armour=1; int passphrase=1; - test_rsa_encrypt(armour,passphrase,filename_rsa_armour_passphrase); - } -#endif /*TBD*/ + assert(pub_keyring.nkeys); + test_rsa_verify(armour,passphrase,filename_rsa_armour_passphrase,NULL); + } + +static void test_rsa_verify_clearsign_nopassphrase(void) + { + // int clearsign=1; + int armour=1; + int passphrase=0; + assert(pub_keyring.nkeys); + + test_rsa_verify(armour,passphrase,filename_rsa_clearsign_nopassphrase,NULL); + } + +static void test_rsa_verify_clearsign_passphrase(void) + { + // int clearsign=1; + int armour=1; + int passphrase=1; + assert(pub_keyring.nkeys); + + test_rsa_verify(armour,passphrase,filename_rsa_clearsign_passphrase,NULL); + } + CU_pSuite suite_rsa_verify() @@ -232,5 +239,14 @@ // add tests to suite - if (NULL == CU_add_test(suite, "Clearsigned, armoured, no passphrase", test_rsa_verify_clearsign_armour_nopassphrase)) + if (NULL == CU_add_test(suite, "Clearsigned, no passphrase", test_rsa_verify_clearsign_nopassphrase)) + return NULL; + + if (NULL == CU_add_test(suite, "Clearsigned, passphrase", test_rsa_verify_clearsign_passphrase)) + return NULL; + + if (NULL == CU_add_test(suite, "Armoured, no passphrase", test_rsa_verify_armour_nopassphrase)) + return NULL; + + if (NULL == CU_add_test(suite, "Armoured, passphrase", test_rsa_verify_armour_passphrase)) return NULL; @@ -238,33 +254,9 @@ return NULL; - /* if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_verify_noarmour_passphrase)) return NULL; - */ + return suite; } -CU_pSuite suite_rsa_verify_GPGtest() -{ - CU_pSuite suite = NULL; - - suite = CU_add_suite("RSA Verification Suite (GPG interop)", init_suite_rsa_verify_gpgtest, clean_suite_rsa_verify); - if (!suite) - return NULL; - - // add tests to suite - - if (NULL == CU_add_test(suite, "Clearsigned, armoured, no passphrase", test_rsa_verify_clearsign_armour_nopassphrase)) - return NULL; - - if (NULL == CU_add_test(suite, "Unarmoured, no passphrase", test_rsa_verify_noarmour_nopassphrase)) - return NULL; - - /* - if (NULL == CU_add_test(suite, "Unarmoured, passphrase", test_rsa_verify_noarmour_passphrase)) - return NULL; - */ - return suite; -} - // EOF