]> www.wagner.pp.ru Git - openssl-gost/engine.git/commitdiff
Make test programs less hard-coded
authorRichard Levitte <richard@levitte.org>
Sat, 1 May 2021 06:36:55 +0000 (08:36 +0200)
committerDmitry Belyavskiy <beldmit@users.noreply.github.com>
Sun, 2 May 2021 13:10:29 +0000 (16:10 +0300)
The following programs had a hard coded load of the gost engine.
This changes them to rely more on the testing environment, and to
load engines through configuration files.

This affects: test_ciphers.c, test_context.c, test_derive.c,
test_digest.c, test_params.c, test_sign.c, test_tls.c

CMakeLists.txt
test/engine.cnf [new file with mode: 0644]
test_ciphers.c
test_context.c
test_derive.c
test_digest.c
test_params.c
test_sign.c
test_tls.c

index 2f6c8b50642ebe9ba09a25d7cd13db2048048b25..ee1e080a28fe2c93f571be1b4205ec82d69dd5c7 100644 (file)
@@ -183,15 +183,23 @@ set(GOST_ENGINE_SOURCE_FILES
         gost_eng.c
         )
 
+set(TEST_ENVIRONMENT
+        CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
+        PERL5LIB=${CMAKE_CURRENT_SOURCE_DIR}/test
+        OPENSSL_ENGINES=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
+        OPENSSL_PROGRAM=${OPENSSL_PROGRAM}
+        OPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
+        OPENSSL_CONF=${CMAKE_CURRENT_SOURCE_DIR}/test/engine.cnf
+        )
 add_executable(test_digest test_digest.c)
-target_link_libraries(test_digest gost_core ${OPENSSL_CRYPTO_LIBRARY})
-add_test(NAME digest
-       COMMAND test_digest)
+target_link_libraries(test_digest ${OPENSSL_CRYPTO_LIBRARY})
+add_test(NAME digest COMMAND test_digest)
+set_tests_properties(digest PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}")
 
 add_executable(test_ciphers test_ciphers.c)
-target_link_libraries(test_ciphers gost_core ${OPENSSL_CRYPTO_LIBRARY})
-add_test(NAME ciphers
-       COMMAND test_ciphers)
+target_link_libraries(test_ciphers ${OPENSSL_CRYPTO_LIBRARY})
+add_test(NAME ciphers COMMAND test_ciphers)
+set_tests_properties(ciphers PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}")
 
 add_executable(test_curves test_curves.c)
 target_link_libraries(test_curves gost_core ${OPENSSL_CRYPTO_LIBRARY})
@@ -199,29 +207,29 @@ add_test(NAME curves
        COMMAND test_curves)
 
 add_executable(test_params test_params.c)
-target_link_libraries(test_params gost_core ${OPENSSL_CRYPTO_LIBRARY})
-add_test(NAME parameters
-       COMMAND test_params)
+target_link_libraries(test_params ${OPENSSL_CRYPTO_LIBRARY})
+add_test(NAME parameters COMMAND test_params)
+set_tests_properties(parameters PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}")
 
 add_executable(test_derive test_derive.c)
-target_link_libraries(test_derive gost_core ${OPENSSL_CRYPTO_LIBRARY})
-add_test(NAME derive
-       COMMAND test_derive)
+target_link_libraries(test_derive ${OPENSSL_CRYPTO_LIBRARY})
+add_test(NAME derive COMMAND test_derive)
+set_tests_properties(derive PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}")
 
 add_executable(test_sign test_sign.c)
-target_link_libraries(test_sign gost_core ${OPENSSL_CRYPTO_LIBRARY})
-add_test(NAME sign/verify
-       COMMAND test_sign)
+target_link_libraries(test_sign ${OPENSSL_CRYPTO_LIBRARY})
+add_test(NAME sign/verify COMMAND test_sign)
+set_tests_properties(sign/verify PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}")
 
 add_executable(test_tls test_tls.c)
-target_link_libraries(test_tls gost_core ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY})
-add_test(NAME TLS
-       COMMAND test_tls)
+target_link_libraries(test_tls ${OPENSSL_CRYPTO_LIBRARY} ${OPENSSL_SSL_LIBRARY})
+add_test(NAME TLS COMMAND test_tls)
+set_tests_properties(TLS PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}")
 
 add_executable(test_context test_context.c)
-target_link_libraries(test_context gost_core ${OPENSSL_CRYPTO_LIBRARY})
-add_test(NAME context
-       COMMAND test_context)
+target_link_libraries(test_context ${OPENSSL_CRYPTO_LIBRARY})
+add_test(NAME context COMMAND test_context)
+set_tests_properties(context PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}")
 
 add_executable(test_keyexpimp test_keyexpimp.c)
 #target_compile_definitions(test_keyexpimp PUBLIC -DOPENSSL_LOAD_CONF)
@@ -238,14 +246,6 @@ if(NOT SKIP_PERL_TESTS)
     execute_process(COMMAND perl -MTest2::V0 -e ""
        ERROR_QUIET RESULT_VARIABLE HAVE_TEST2_V0)
     if(NOT HAVE_TEST2_V0)
-        set(TEST_ENVIRONMENT
-          CMAKE_CURRENT_SOURCE_DIR=${CMAKE_CURRENT_SOURCE_DIR}
-          PERL5LIB=${CMAKE_CURRENT_SOURCE_DIR}/test
-          OPENSSL_ENGINES=${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
-          OPENSSL_PROGRAM=${OPENSSL_PROGRAM}
-          OPENSSL_CRYPTO_LIBRARY=${OPENSSL_CRYPTO_LIBRARY}
-          OPENSSL_CONF=${CMAKE_CURRENT_SOURCE_DIR}/test/empty.cnf
-          )
        add_test(NAME engine
            COMMAND prove --merge -PWrapOpenSSL ${CMAKE_CURRENT_SOURCE_DIR}/test)
        set_tests_properties(engine PROPERTIES ENVIRONMENT "${TEST_ENVIRONMENT}")
diff --git a/test/engine.cnf b/test/engine.cnf
new file mode 100644 (file)
index 0000000..c75b518
--- /dev/null
@@ -0,0 +1,7 @@
+openssl_conf = openssl_def
+[openssl_def]
+engines = engines
+[engines]
+gost = gost_conf
+[gost_conf]
+default_algorithms = ALL
index 77810e731642e33db2b5501dfa1615d03e8f9b2e..a88c28154497d7c321e6cde547df705aee09573f 100644 (file)
@@ -463,13 +463,7 @@ int main(int argc, char **argv)
     /* Trigger SIGBUS for unaligned access. */
     sysmips(MIPS_FIXADE, 0);
 #endif
-    setenv("OPENSSL_ENGINES", ENGINE_DIR, 0);
     OPENSSL_add_all_algorithms_conf();
-    ERR_load_crypto_strings();
-    ENGINE *eng;
-    T(eng = ENGINE_by_id("gost"));
-    T(ENGINE_init(eng));
-    T(ENGINE_set_default(eng, ENGINE_METHOD_ALL));
 
     for (t = testcases; t->nid; t++) {
        int inplace;
@@ -489,7 +483,9 @@ int main(int argc, char **argv)
                t->iv, t->iv_size, t->acpkm);
     }
 
+    ENGINE *eng;
     ENGINE_CIPHERS_PTR fn_c;
+    T(eng = ENGINE_by_id("gost"));
     T(fn_c = ENGINE_get_ciphers(eng));
     const int *nids;
     int n, k;
@@ -501,8 +497,6 @@ int main(int argc, char **argv)
        if (!t->nid)
            printf(cMAGENT "Cipher %s is untested!" cNORM "\n", OBJ_nid2sn(nids[k]));
     }
-
-    ENGINE_finish(eng);
     ENGINE_free(eng);
 
     if (ret)
index 0db2163f7f117edb30deb11f6910722df503988a..1e284c0689fab2879fdcb0039a2d966b766d55e4 100644 (file)
@@ -245,13 +245,7 @@ int main(int argc, char **argv)
 {
     int ret = 0;
 
-    setenv("OPENSSL_ENGINES", ENGINE_DIR, 0);
     OPENSSL_add_all_algorithms_conf();
-    ERR_load_crypto_strings();
-    ENGINE *eng;
-    T(eng = ENGINE_by_id("gost"));
-    T(ENGINE_init(eng));
-    T(ENGINE_set_default(eng, ENGINE_METHOD_ALL));
 
     const struct testcase_cipher *tc;
     for (tc = testcases_ciphers; tc->nid; tc++) {
@@ -263,9 +257,6 @@ int main(int argc, char **argv)
        ret |= test_contexts_digest(td->nid, td->mac);
     }
 
-    ENGINE_finish(eng);
-    ENGINE_free(eng);
-
     if (ret)
        printf(cDRED "= Some tests FAILED!" cNORM "\n");
     else
index c93549cd762b481d520f8706ee55c437bd85c146..c99ccef5acbbb0383349a213cbc55541ff4a18a2 100644 (file)
@@ -364,13 +364,7 @@ int main(int argc, char **argv)
 {
     int ret = 0;
 
-    setenv("OPENSSL_ENGINES", ENGINE_DIR, 0);
     OPENSSL_add_all_algorithms_conf();
-    ERR_load_crypto_strings();
-    ENGINE *eng;
-    T(eng = ENGINE_by_id("gost"));
-    T(ENGINE_init(eng));
-    T(ENGINE_set_default(eng, ENGINE_METHOD_ALL));
 
     int i;
     for (i = 0; i < OSSL_NELEM(derive_tests); i++)
@@ -389,9 +383,6 @@ int main(int argc, char **argv)
         ret |= test_derive_alg("gost2012_512", "C", i);
     }
 
-    ENGINE_finish(eng);
-    ENGINE_free(eng);
-
     if (ret)
         printf(cDRED "= Some tests FAILED!" cNORM "\n");
     else
index bebbf7a97ca899fc89f889a9aca06ab2a8b4dec4..8500233a03d2dd4d486e6367157f45fa54ee3b8d 100644 (file)
@@ -821,13 +821,7 @@ int main(int argc, char **argv)
     /* Trigger SIGBUS for unaligned access. */
     sysmips(MIPS_FIXADE, 0);
 #endif
-    setenv("OPENSSL_ENGINES", ENGINE_DIR, 0);
     OPENSSL_add_all_algorithms_conf();
-    ERR_load_crypto_strings();
-    ENGINE *eng;
-    T(eng = ENGINE_by_id("gost"));
-    T(ENGINE_init(eng));
-    T(ENGINE_set_default(eng, ENGINE_METHOD_ALL));
 
     const struct hash_testvec *tv;
     for (tv = testvecs; tv->nid; tv++) {
@@ -837,7 +831,9 @@ int main(int argc, char **argv)
            ret |= do_synthetic_test(tv);
     }
 
+    ENGINE *eng;
     ENGINE_DIGESTS_PTR fn_c;
+    T(eng = ENGINE_by_id("gost"));
     T(fn_c = ENGINE_get_digests(eng));
     const int *nids;
     int n, k;
@@ -849,8 +845,6 @@ int main(int argc, char **argv)
        if (!tv->nid)
            printf(cMAGENT "Digest %s is untested!" cNORM "\n", OBJ_nid2sn(nids[k]));
     }
-
-    ENGINE_finish(eng);
     ENGINE_free(eng);
 
     if (ret)
index 4e6317e796995b0f40e4b0a4f8b74c240e32dfe4..89bae3d43f1a966ee9aacc2781ad243b94f466aa 100644 (file)
@@ -1160,13 +1160,7 @@ int main(int argc, char **argv)
 {
     int ret = 0;
 
-    setenv("OPENSSL_ENGINES", ENGINE_DIR, 0);
     OPENSSL_add_all_algorithms_conf();
-    ERR_load_crypto_strings();
-    ENGINE *eng;
-    T(eng = ENGINE_by_id("gost"));
-    T(ENGINE_init(eng));
-    T(ENGINE_set_default(eng, ENGINE_METHOD_ALL));
 
     struct test_param **tpp;
     for (tpp = test_params; *tpp; tpp++)
@@ -1176,9 +1170,6 @@ int main(int argc, char **argv)
     for (tc = test_certs; tc->cert; tc++)
        ret |= test_cert(tc);
 
-    ENGINE_finish(eng);
-    ENGINE_free(eng);
-
     if (ret)
        printf(cDRED "= Some tests FAILED!" cNORM "\n");
     else
index 983b63ef83cd11e05e4f06d4b353f63148f30d23..d785b75b2dc49c5256a4e25584b7e3884bedea70 100644 (file)
@@ -7,7 +7,6 @@
  * See https://www.openssl.org/source/license.html for details
  */
 
-#include "e_gost_err.h"
 #include "gost_lcl.h"
 #include <openssl/evp.h>
 #include <openssl/rand.h>
@@ -17,6 +16,7 @@
 #include <openssl/ec.h>
 #include <openssl/bn.h>
 #include <openssl/store.h>
+#include <openssl/engine.h>
 #include <string.h>
 #include <stdlib.h>
 
@@ -318,21 +318,12 @@ int main(int argc, char **argv)
 {
     int ret = 0;
 
-    setenv("OPENSSL_ENGINES", ENGINE_DIR, 0);
     OPENSSL_add_all_algorithms_conf();
-    ERR_load_crypto_strings();
-    ENGINE *eng;
-    T(eng = ENGINE_by_id("gost"));
-    T(ENGINE_init(eng));
-    T(ENGINE_set_default(eng, ENGINE_METHOD_ALL));
 
     struct test_sign *sp;
     for (sp = test_signs; sp->name; sp++)
        ret |= test_sign(sp);
 
-    ENGINE_finish(eng);
-    ENGINE_free(eng);
-
     if (ret)
        printf(cDRED "= Some tests FAILED!" cNORM "\n");
     else
index 216fb2a8f263d5922a70d1f2733134011f841057..a6ac41eb264946069bdf2f8d91053b639b76d19e 100644 (file)
@@ -355,13 +355,7 @@ int main(int argc, char **argv)
 {
     int ret = 0;
 
-    setenv("OPENSSL_ENGINES", ENGINE_DIR, 0);
     OPENSSL_add_all_algorithms_conf();
-    ERR_load_crypto_strings();
-    ENGINE *eng;
-    T(eng = ENGINE_by_id("gost"));
-    T(ENGINE_init(eng));
-    T(ENGINE_set_default(eng, ENGINE_METHOD_ALL));
 
     char *p;
     if ((p = getenv("VERBOSE")))
@@ -377,9 +371,6 @@ int main(int argc, char **argv)
     ret |= test("gost2012_512", "B");
     ret |= test("gost2012_512", "C");
 
-    ENGINE_finish(eng);
-    ENGINE_free(eng);
-
     if (ret)
        printf(cDRED "= Some tests FAILED!\n" cNORM);
     else