summaryrefslogtreecommitdiff
path: root/trust/tests
diff options
context:
space:
mode:
authorStef Walter <stefw@gnome.org>2013-01-04 15:50:13 +0100
committerStef Walter <stefw@gnome.org>2013-02-05 14:54:53 +0100
commit7e61265ced3f33685b68bb6e2c7505485cfe0177 (patch)
tree0c7be55f59d4032a091f3687559091e22aa95d0a /trust/tests
parent8b02ff64b30311a4730b60dd72590435f56fb3a2 (diff)
Refactor how parsing of ASN.1 data and certificate extensions work
Diffstat (limited to 'trust/tests')
-rw-r--r--trust/tests/test-data.h28
-rw-r--r--trust/tests/test-parser.c103
2 files changed, 2 insertions, 129 deletions
diff --git a/trust/tests/test-data.h b/trust/tests/test-data.h
index 300e342..b07830d 100644
--- a/trust/tests/test-data.h
+++ b/trust/tests/test-data.h
@@ -32,6 +32,8 @@
* Author: Stef Walter <stefw@gnome.org>
*/
+#include "pkcs11.h"
+
#include <sys/types.h>
#ifndef TEST_DATA_H_
@@ -228,30 +230,4 @@ static const char test_cacert3_ca_serial[] = {
0x02, 0x03, 0x0a, 0x41, 0x8a,
};
-static const char test_ku_ds_and_np[] = {
- 0x03, 0x03, 0x07, 0xc0, 0x00,
-};
-
-static const char test_ku_none[] = {
- 0x03, 0x03, 0x07, 0x00, 0x00,
-};
-
-static const char test_ku_cert_crl_sign[] = {
- 0x03, 0x03, 0x07, 0x06, 0x00,
-};
-
-static const char test_eku_server_and_client[] = {
- 0x30, 0x14, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x01, 0x06, 0x08, 0x2b, 0x06,
- 0x01, 0x05, 0x05, 0x07, 0x03, 0x02,
-};
-
-static const char test_eku_none[] = {
- 0x30, 0x00,
-};
-
-static const char test_eku_client_email_and_timestamp[] = {
- 0x30, 0x1e, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x06, 0x08, 0x2b, 0x06,
- 0x01, 0x05, 0x05, 0x07, 0x03, 0x04, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x08,
-};
-
#endif /* TEST_DATA_H_ */
diff --git a/trust/tests/test-parser.c b/trust/tests/test-parser.c
index 5bb690a..80f0f07 100644
--- a/trust/tests/test-parser.c
+++ b/trust/tests/test-parser.c
@@ -518,105 +518,6 @@ test_parse_unrecognized (CuTest *cu)
teardown (cu);
}
-struct {
- const char *eku;
- size_t length;
- const unsigned char *expected[16];
-} extended_key_usage_fixtures[] = {
- { test_eku_server_and_client, sizeof (test_eku_server_and_client),
- { P11_OID_CLIENT_AUTH, P11_OID_SERVER_AUTH, NULL }, },
- { test_eku_none, sizeof (test_eku_none),
- { NULL, }, },
- { test_eku_client_email_and_timestamp, sizeof (test_eku_client_email_and_timestamp),
- { P11_OID_CLIENT_AUTH, P11_OID_EMAIL_PROTECTION, P11_OID_TIME_STAMPING }, },
- { NULL },
-};
-
-static void
-test_parse_extended_key_usage (CuTest *cu)
-{
- p11_dict *ekus;
- int i, j;
-
- setup (cu);
-
- for (i = 0; extended_key_usage_fixtures[i].eku != NULL; i++) {
- ekus = p11_parse_extended_key_usage (test.parser,
- (const unsigned char *)extended_key_usage_fixtures[i].eku,
- extended_key_usage_fixtures[i].length);
- CuAssertPtrNotNull (cu, ekus);
-
- for (j = 0; extended_key_usage_fixtures[i].expected[j] != NULL; j++)
- CuAssertTrue (cu, p11_dict_get (ekus, extended_key_usage_fixtures[i].expected[j]) != NULL);
- CuAssertIntEquals (cu, j, p11_dict_size (ekus));
-
- p11_dict_free (ekus);
- }
-
- teardown (cu);
-}
-
-static void
-test_bad_extended_key_usage (CuTest *cu)
-{
- p11_dict *ekus;
-
- setup (cu);
-
- ekus = p11_parse_extended_key_usage (test.parser, (const unsigned char *)"blah", 4);
- CuAssertPtrEquals (cu, NULL, ekus);
-
- teardown (cu);
-}
-
-struct {
- const char *ku;
- size_t length;
- unsigned int expected;
-} key_usage_fixtures[] = {
- { test_ku_ds_and_np, sizeof (test_ku_ds_and_np), P11_KU_DIGITAL_SIGNATURE | P11_KU_NON_REPUDIATION },
- { test_ku_none, sizeof (test_ku_none), 0 },
- { test_ku_cert_crl_sign, sizeof (test_ku_cert_crl_sign), P11_KU_KEY_CERT_SIGN | P11_KU_CRL_SIGN },
- { NULL },
-};
-
-static void
-test_parse_key_usage (CuTest *cu)
-{
- unsigned int ku;
- int i;
- int ret;
-
- setup (cu);
-
- for (i = 0; key_usage_fixtures[i].ku != NULL; i++) {
- ku = 0;
-
- ret = p11_parse_key_usage (test.parser,
- (const unsigned char *)key_usage_fixtures[i].ku,
- key_usage_fixtures[i].length, &ku);
- CuAssertIntEquals (cu, P11_PARSE_SUCCESS, ret);
-
- CuAssertIntEquals (cu, key_usage_fixtures[i].expected, ku);
- }
-
- teardown (cu);
-}
-
-static void
-test_bad_key_usage (CuTest *cu)
-{
- unsigned int ku;
- int ret;
-
- setup (cu);
-
- ret = p11_parse_key_usage (test.parser, (const unsigned char *)"blah", 4, &ku);
- CuAssertIntEquals (cu, P11_PARSE_UNRECOGNIZED, ret);
-
- teardown (cu);
-}
-
int
main (void)
{
@@ -628,10 +529,6 @@ main (void)
p11_debug_init ();
p11_message_quiet ();
- SUITE_ADD_TEST (suite, test_bad_extended_key_usage);
- SUITE_ADD_TEST (suite, test_parse_extended_key_usage);
- SUITE_ADD_TEST (suite, test_bad_key_usage);
- SUITE_ADD_TEST (suite, test_parse_key_usage);
SUITE_ADD_TEST (suite, test_parse_der_certificate);
SUITE_ADD_TEST (suite, test_parse_pem_certificate);
SUITE_ADD_TEST (suite, test_parse_openssl_trusted);