|
|
ca1eb8 |
From f0d437220d5c76f6b09dee5c5744397549fc3813 Mon Sep 17 00:00:00 2001
|
|
|
ca1eb8 |
From: Lukas Slebodnik <lslebodn@redhat.com>
|
|
|
ca1eb8 |
Date: Tue, 31 Jul 2018 20:44:16 +0000
|
|
|
ca1eb8 |
Subject: [PATCH] crypto-tests: Add unit test for s3crypt_sha512
|
|
|
ca1eb8 |
|
|
|
ca1eb8 |
Resolves:
|
|
|
ca1eb8 |
https://pagure.io/SSSD/sssd/issue/3791
|
|
|
ca1eb8 |
|
|
|
ca1eb8 |
Merges: https://pagure.io/SSSD/sssd/pull-request/3792
|
|
|
ca1eb8 |
|
|
|
ca1eb8 |
Reviewed-by: Jakub Hrozek <jhrozek@redhat.com>
|
|
|
ca1eb8 |
---
|
|
|
ca1eb8 |
src/tests/crypto-tests.c | 32 ++++++++++++++++++++++++++++++++
|
|
|
ca1eb8 |
1 file changed, 32 insertions(+)
|
|
|
ca1eb8 |
|
|
|
ca1eb8 |
diff --git a/src/tests/crypto-tests.c b/src/tests/crypto-tests.c
|
|
|
ca1eb8 |
index 2e826a41b3c1302b87c7136cc37b7c4df02a0584..6f5e22a878ad9e40b73b23915d08395b3f6f2e3d 100644
|
|
|
ca1eb8 |
--- a/src/tests/crypto-tests.c
|
|
|
ca1eb8 |
+++ b/src/tests/crypto-tests.c
|
|
|
ca1eb8 |
@@ -201,6 +201,37 @@ START_TEST(test_sss_encrypt_decrypt)
|
|
|
ca1eb8 |
}
|
|
|
ca1eb8 |
END_TEST
|
|
|
ca1eb8 |
|
|
|
ca1eb8 |
+START_TEST(test_s3crypt_sha512)
|
|
|
ca1eb8 |
+{
|
|
|
ca1eb8 |
+ int ret;
|
|
|
ca1eb8 |
+ char *salt;
|
|
|
ca1eb8 |
+ char *userhash;
|
|
|
ca1eb8 |
+ char *comphash;
|
|
|
ca1eb8 |
+ const char *password = "password123";
|
|
|
ca1eb8 |
+ const char *expected_hash = "$6$tU67Q/9h3tm5WJ.U$aL9gjCfiSZQewHTI6A4/MHCVWrMCiJZ.gNXEIw6HO39XGbg.s2nTyGlYXeoQyQtDll3XSbIZN41fJEC3v7ELy0";
|
|
|
ca1eb8 |
+
|
|
|
ca1eb8 |
+ test_ctx = talloc_new(NULL);
|
|
|
ca1eb8 |
+ fail_if(test_ctx == NULL);
|
|
|
ca1eb8 |
+
|
|
|
ca1eb8 |
+ ret = s3crypt_gen_salt(test_ctx, &salt);
|
|
|
ca1eb8 |
+ fail_if(ret != 0);
|
|
|
ca1eb8 |
+
|
|
|
ca1eb8 |
+ ret = s3crypt_sha512(test_ctx, password, salt, &userhash);
|
|
|
ca1eb8 |
+ fail_if(ret != 0);
|
|
|
ca1eb8 |
+
|
|
|
ca1eb8 |
+ ret = s3crypt_sha512(test_ctx, password, userhash, &comphash);
|
|
|
ca1eb8 |
+ fail_if(ret != 0);
|
|
|
ca1eb8 |
+ ck_assert_str_eq(userhash, comphash);
|
|
|
ca1eb8 |
+ talloc_free(comphash);
|
|
|
ca1eb8 |
+
|
|
|
ca1eb8 |
+ ret = s3crypt_sha512(test_ctx, password, expected_hash, &comphash);
|
|
|
ca1eb8 |
+ fail_if(ret != 0);
|
|
|
ca1eb8 |
+ ck_assert_str_eq(expected_hash, comphash);
|
|
|
ca1eb8 |
+
|
|
|
ca1eb8 |
+ talloc_free(test_ctx);
|
|
|
ca1eb8 |
+}
|
|
|
ca1eb8 |
+END_TEST
|
|
|
ca1eb8 |
+
|
|
|
ca1eb8 |
Suite *crypto_suite(void)
|
|
|
ca1eb8 |
{
|
|
|
ca1eb8 |
Suite *s = suite_create("sss_crypto");
|
|
|
ca1eb8 |
@@ -216,6 +247,7 @@ Suite *crypto_suite(void)
|
|
|
ca1eb8 |
tcase_add_test(tc, test_base64_encode);
|
|
|
ca1eb8 |
tcase_add_test(tc, test_base64_decode);
|
|
|
ca1eb8 |
tcase_add_test(tc, test_sss_encrypt_decrypt);
|
|
|
ca1eb8 |
+ tcase_add_test(tc, test_s3crypt_sha512);
|
|
|
ca1eb8 |
/* Add all test cases to the test suite */
|
|
|
ca1eb8 |
suite_add_tcase(s, tc);
|
|
|
ca1eb8 |
|
|
|
ca1eb8 |
--
|
|
|
ca1eb8 |
2.14.4
|
|
|
ca1eb8 |
|