summaryrefslogtreecommitdiffstats
path: root/src/tests
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2017-02-14 22:47:08 +0100
committerLukas Slebodnik <lslebodn@redhat.com>2017-09-05 15:04:00 +0200
commita20fb9cbd5f42a6ca895aea1b84347fdfea34b89 (patch)
treea06ea90fba92b7d19293028dbd6af2a53bfac4f6 /src/tests
parent781d231a12eb0c772353cc15e2c3ae1e7545e663 (diff)
downloadsssd-a20fb9cbd5f42a6ca895aea1b84347fdfea34b89.tar.gz
sssd-a20fb9cbd5f42a6ca895aea1b84347fdfea34b89.tar.xz
sssd-a20fb9cbd5f42a6ca895aea1b84347fdfea34b89.zip
certmap: add OpenSSL implementation
The OpenSSL 1.1 API is used but there is a short macro block which should added the needed compatibility if and older OpenSSL version is used. Related to https://pagure.io/SSSD/sssd/issue/3050 Reviewed-by: Lukáš Slebodník <lslebodn@redhat.com>
Diffstat (limited to 'src/tests')
-rw-r--r--src/tests/cmocka/test_certmap.c103
1 files changed, 102 insertions, 1 deletions
diff --git a/src/tests/cmocka/test_certmap.c b/src/tests/cmocka/test_certmap.c
index c998443d0..f1e73875b 100644
--- a/src/tests/cmocka/test_certmap.c
+++ b/src/tests/cmocka/test_certmap.c
@@ -40,6 +40,10 @@
#include "util/crypto/nss/nss_util.h"
#endif
+#ifdef HAVE_LIBCRYPTO
+#include <openssl/crypto.h>
+#endif
+
struct priv_sss_debug {
int level;
};
@@ -712,6 +716,65 @@ const uint8_t test_cert2_der[] = {
0xa2, 0xd3, 0x43, 0x21, 0x5b, 0xdc, 0xa2, 0x1d, 0x55, 0xa9, 0x48, 0xc5, 0xc4, 0xaa, 0xf3, 0x8b,
0xe6, 0x3e, 0x75, 0x96, 0xe4, 0x3e, 0x64, 0xaf, 0xe8, 0xa7, 0x6a, 0xb6};
+/* used to test SAN principal encoding according to RFC4556 */
+const uint8_t test_cert3_der[] = {
+0x30, 0x82, 0x03, 0x70, 0x30, 0x82, 0x02, 0x58, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x09, 0x00,
+0xe5, 0x8f, 0x16, 0xfe, 0x23, 0x4d, 0xc5, 0xd6, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
+0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x1a, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55,
+0x04, 0x03, 0x0c, 0x0f, 0x6b, 0x72, 0x62, 0x35, 0x5f, 0x70, 0x72, 0x69, 0x6e, 0x63, 0x5f, 0x74,
+0x65, 0x73, 0x74, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x37, 0x30, 0x37, 0x31, 0x32, 0x30, 0x39, 0x32,
+0x34, 0x31, 0x38, 0x5a, 0x17, 0x0d, 0x32, 0x30, 0x30, 0x34, 0x30, 0x37, 0x30, 0x39, 0x32, 0x34,
+0x31, 0x38, 0x5a, 0x30, 0x1a, 0x31, 0x18, 0x30, 0x16, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x0f,
+0x6b, 0x72, 0x62, 0x35, 0x5f, 0x70, 0x72, 0x69, 0x6e, 0x63, 0x5f, 0x74, 0x65, 0x73, 0x74, 0x30,
+0x82, 0x01, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01,
+0x05, 0x00, 0x03, 0x82, 0x01, 0x0f, 0x00, 0x30, 0x82, 0x01, 0x0a, 0x02, 0x82, 0x01, 0x01, 0x00,
+0xbf, 0x84, 0x34, 0x46, 0x37, 0x50, 0xb1, 0xca, 0x14, 0x4c, 0x6b, 0x0d, 0xe4, 0xab, 0xc1, 0xce,
+0xf4, 0xd1, 0xde, 0xca, 0xf5, 0x50, 0x46, 0x3c, 0x63, 0x0f, 0x8e, 0xb8, 0xe9, 0xf9, 0x3e, 0xc4,
+0xf3, 0x24, 0xc1, 0xe4, 0x78, 0xf6, 0xa4, 0x39, 0x6f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3c,
+0x4c, 0x70, 0x4b, 0x93, 0xd8, 0xa4, 0xb6, 0x59, 0x24, 0x77, 0x10, 0xb3, 0xc7, 0x34, 0x99, 0x6b,
+0x28, 0xbd, 0x03, 0xdb, 0xda, 0xea, 0x23, 0x19, 0x10, 0x56, 0x7e, 0xa4, 0x28, 0x04, 0x5a, 0x53,
+0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x81, 0xb8, 0x30, 0x81, 0xb5, 0x30, 0x09, 0x06, 0x03, 0x55,
+0x1d, 0x13, 0x04, 0x02, 0x30, 0x00, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03,
+0x02, 0x03, 0xa8, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04, 0x0b, 0x30, 0x09, 0x06, 0x07,
+0x2b, 0x06, 0x01, 0x05, 0x02, 0x03, 0x04, 0x30, 0x1d, 0x06, 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16,
+0x04, 0x14, 0xea, 0xd4, 0x30, 0xd7, 0x7d, 0x3b, 0xc7, 0xb4, 0x83, 0x53, 0x2c, 0xa5, 0xb9, 0xd8,
+0x1a, 0x47, 0x6b, 0xb5, 0xe5, 0x9d, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x18, 0x30,
+0x16, 0x80, 0x14, 0xea, 0xd4, 0x30, 0xd7, 0x7d, 0x3b, 0xc7, 0xb4, 0x83, 0x53, 0x2c, 0xa5, 0xb9,
+0xd8, 0x1a, 0x47, 0x6b, 0xb5, 0xe5, 0x9d, 0x30, 0x47, 0x06, 0x03, 0x55, 0x1d, 0x11, 0x04, 0x40,
+0x30, 0x3e, 0xa0, 0x3c, 0x06, 0x06, 0x2b, 0x06, 0x01, 0x05, 0x02, 0x02, 0xa0, 0x32, 0x30, 0x30,
+0xa0, 0x0b, 0x1b, 0x09, 0x53, 0x53, 0x53, 0x44, 0x2e, 0x54, 0x45, 0x53,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0x32, 0xb4, 0x07, 0x8f, 0xc4, 0x94, 0x56, 0xa6, 0x21, 0x6a, 0xb6, 0x26,
+0x05, 0x48, 0x90, 0xe0, 0x6b, 0x22, 0x35, 0x00, 0x51, 0x2e, 0xd7, 0xe8, 0x3a, 0x56, 0xa8, 0x70,
+0x7d, 0x0f, 0x9a, 0x97, 0x5a, 0xb8, 0x7f, 0x33, 0xc1, 0xe0, 0x92, 0x0f, 0xb3, 0xfe, 0x36, 0xe6,
+0x8b, 0x97, 0x58, 0x42, 0x49, 0xcb, 0x74, 0xde, 0x19, 0x59, 0x90, 0xb6, 0x36, 0x38, 0x07, 0x48,
+0x5d, 0x5b, 0xab, 0x08, 0xf0, 0x69, 0x22, 0x42, 0x08, 0x29, 0xfe, 0x43, 0xab, 0x83, 0x73, 0x74,
+0x5a, 0x3f, 0x3b, 0x5d, 0x8e, 0xca, 0x6f, 0x2d, 0xad, 0xa1, 0x6e, 0x80, 0x80, 0xd2, 0xc8, 0x16,
+0xb7, 0x67, 0x1a, 0x2d, 0x37, 0x8c, 0x20, 0x3b, 0x15, 0xef, 0xb2, 0x94, 0x86, 0x5c, 0xaf, 0xa2,
+0x61, 0x8b, 0xc7, 0xc1, 0xe4, 0xbe, 0x60, 0x5a, 0x86, 0x5c, 0x86, 0xba, 0x59, 0x97, 0x83, 0x1b,
+0x79, 0x1c, 0x7c, 0x26};
+
void test_sss_cert_get_content(void **state)
{
int ret;
@@ -802,7 +865,6 @@ FIXME:
assert_string_equal(content->subject_rdn_list[3], "CN=t u");
assert_string_equal(content->subject_rdn_list[4],
"E=test.user@email.domain");
- //"CN=t u/emailAddress=test.user@email.domain");
assert_null(content->subject_rdn_list[5]);
assert_non_null(content->san_list);
@@ -880,6 +942,21 @@ static void test_sss_certmap_match_cert(void **state)
{NULL, 0}
};
+ struct match_tests match_tests_3[] = {
+ {"KRB5:<KU>digitalSignature", 0},
+ {"KRB5:<KU>keyEncipherment", 0},
+ {"KRB5:<KU>keyAgreement", 0},
+ {"KRB5:<KU>digitalSignature,keyAgreement,keyEncipherment", 0},
+ {"KRB5:<SAN:Principal>test", 0},
+ {"KRB5:<SAN:ntPrincipal>test", ENOENT},
+ {"KRB5:<SAN:Principal>comp2", 0},
+ {"KRB5:<SAN:Principal>another", 0},
+ {"KRB5:<SAN:Principal>test/comp2/another@SSSD.TEST", 0},
+ {"KRB5:<SAN:Principal>^test/comp2/another@SSSD.TEST$", 0},
+ {"KRB5:<SAN:pkinitSAN>^test/comp2/another@SSSD.TEST$", 0},
+ {NULL, 0}
+ };
+
ret = sss_certmap_init(NULL, ext_debug, NULL, &ctx);
assert_int_equal(ret, EOK);
assert_non_null(ctx);
@@ -937,6 +1014,24 @@ static void test_sss_certmap_match_cert(void **state)
sss_certmap_free_ctx(ctx);
}
+
+ for (c = 0; match_tests_3[c].rule != NULL; c++) {
+ ret = sss_certmap_init(NULL, ext_debug, NULL, &ctx);
+ assert_int_equal(ret, EOK);
+ assert_non_null(ctx);
+ assert_null(ctx->prio_list);
+
+ print_error("Checking matching rule [%s]\n", match_tests_3[c].rule);
+
+ ret = sss_certmap_add_rule(ctx, 1, match_tests_3[c].rule, NULL, NULL);
+ assert_int_equal(ret, EOK);
+
+ ret = sss_certmap_match_cert(ctx, discard_const(test_cert3_der),
+ sizeof(test_cert3_der));
+ assert_int_equal(ret, match_tests_3[c].result);
+
+ sss_certmap_free_ctx(ctx);
+ }
}
static void test_sss_certmap_add_mapping_rule(void **state)
@@ -1385,6 +1480,8 @@ static void test_sss_certmap_get_search_filter(void **state)
assert_non_null(filter);
assert_string_equal(filter, "(userCertificate;binary=" TEST_CERT2_BIN")");
assert_null(domains);
+
+ sss_certmap_free_ctx(ctx);
}
int main(int argc, const char *argv[])
@@ -1439,5 +1536,9 @@ int main(int argc, const char *argv[])
nspr_nss_cleanup();
#endif
+#ifdef HAVE_LIBCRYPTO
+ CRYPTO_cleanup_all_ex_data(); /* to make valgrind happy */
+#endif
+
return rv;
}