diff options
Diffstat (limited to 'trust')
-rw-r--r-- | trust/Makefile.am | 3 | ||||
-rw-r--r-- | trust/parser.c | 38 | ||||
-rw-r--r-- | trust/tests/files/cacert3.pem | 42 | ||||
-rw-r--r-- | trust/tests/test-parser.c | 26 |
4 files changed, 108 insertions, 1 deletions
diff --git a/trust/Makefile.am b/trust/Makefile.am index 413bb51..75684cc 100644 --- a/trust/Makefile.am +++ b/trust/Makefile.am @@ -30,7 +30,8 @@ p11_kit_trust_la_LIBADD = \ $(top_builddir)/common/libp11-data.la \ $(top_builddir)/common/libp11-library.la \ $(top_builddir)/common/libp11-compat.la \ - $(LIBTASN1_LIBS) + $(LIBTASN1_LIBS) \ + $(NULL) p11_kit_trust_la_LDFLAGS = \ -no-undefined -module -avoid-version \ diff --git a/trust/parser.c b/trust/parser.c index ef72474..65d7855 100644 --- a/trust/parser.c +++ b/trust/parser.c @@ -42,6 +42,7 @@ #include "library.h" #include "module.h" #include "parser.h" +#include "pem.h" #include "pkcs11x.h" #include <libtasn1.h> @@ -992,7 +993,44 @@ parse_der_x509_certificate (p11_parser *parser, return P11_PARSE_SUCCESS; } +static void +on_pem_block (const char *type, + const unsigned char *contents, + size_t length, + void *user_data) +{ + p11_parser *parser = user_data; + int ret; + + if (strcmp (type, "CERTIFICATE") == 0) { + ret = parse_der_x509_certificate (parser, contents, length); + + } else { + p11_debug ("Saw unsupported or unrecognized PEM block of type %s", type); + ret = P11_PARSE_SUCCESS; + } + + if (ret != P11_PARSE_SUCCESS) + p11_message ("Couldn't parse PEM block of type %s", type); +} + +static int +parse_pem_certificates (p11_parser *parser, + const unsigned char *data, + size_t length) +{ + int num; + + num = p11_pem_parse ((const char *)data, length, on_pem_block, parser); + + if (num == 0) + return P11_PARSE_UNRECOGNIZED; + + return P11_PARSE_SUCCESS; +} + static parser_func all_parsers[] = { + parse_pem_certificates, parse_der_x509_certificate, NULL, }; diff --git a/trust/tests/files/cacert3.pem b/trust/tests/files/cacert3.pem new file mode 100644 index 0000000..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aMMVpyA4RS5qb1MyJFCsgLDYq4Nm+QCaGrvdfVTi5xotSu+qdUK+s1jVq3 +VIgv7nSf7UgWyg1I0JTTrKSi9iTfkuO960NAkW4cGI5WtIIS86mTn9S8nK2cde5a +lxuV53QtHA+wLJef+6kzOXrnAzqSjiL2jA3k2X4Ndhj3AfnvlpaiVXPAPHG0HRpW +Q7fDCo1y/OIQCQtBzoyUoPkD/XFzS4pXM+WOdH4VAQDmzEoc53+VGS3FpQyLu7Xt +hbNc09+4ufLKxw0BFKxwWMWMjTPUnWajGlCVI/xI4AZDEtnNp4Y5LzZyo4AQ5OHz +0ctbGsDkgJp8E3MGT9ujayQKurMcvEp4u+XjdTilSKeiHq921F73OIZWWonO1sOn +ebJSoMbxhbQljPI/lrMQ2Y1sVzufb4Y6GIIiNsiwkTjbKqGTqoQ/9SdlrnPVyNXT +d+pLncdBu8fA46A/5H2kjXPmEkvfoXNzczqA6NXLji/L6hOn1kGLrPo8idck9U60 +4GGSt/M3mMS+lqO3ig== +-----END CERTIFICATE----- diff --git a/trust/tests/test-parser.c b/trust/tests/test-parser.c index c224669..0a0a9d1 100644 --- a/trust/tests/test-parser.c +++ b/trust/tests/test-parser.c @@ -107,6 +107,31 @@ test_parse_der_certificate (CuTest *cu) } static void +test_parse_pem_certificate (CuTest *cu) +{ + CK_ATTRIBUTE *attrs; + CK_ATTRIBUTE *attr; + int ret; + + setup (cu); + + ret = p11_parse_file (test.parser, SRCDIR "/files/cacert3.pem", + 0, on_parse_object, cu); + CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret); + + /* Should have gotten certificate and a trust object */ + CuAssertIntEquals (cu, 2, test.objects->num); + + attrs = test.objects->elem[0]; + test_check_cacert3_ca (cu, attrs, NULL); + + attr = p11_attrs_find (attrs, CKA_TRUSTED); + CuAssertPtrEquals (cu, NULL, attr); + + teardown (cu); +} + +static void test_parse_anchor (CuTest *cu) { CK_ATTRIBUTE *attrs; @@ -294,6 +319,7 @@ main (void) p11_message_quiet (); SUITE_ADD_TEST (suite, test_parse_der_certificate); + SUITE_ADD_TEST (suite, test_parse_pem_certificate); SUITE_ADD_TEST (suite, test_parse_anchor); SUITE_ADD_TEST (suite, test_parse_no_sink); SUITE_ADD_TEST (suite, test_parse_invalid_file); |