summaryrefslogtreecommitdiff
path: root/trust
diff options
context:
space:
mode:
Diffstat (limited to 'trust')
-rw-r--r--trust/builder.c5
-rw-r--r--trust/tests/test-builder.c71
2 files changed, 74 insertions, 2 deletions
diff --git a/trust/builder.c b/trust/builder.c
index 53201ed..b23d018 100644
--- a/trust/builder.c
+++ b/trust/builder.c
@@ -257,14 +257,12 @@ calc_date (node_asn *node,
ret = asn1_read_value (node, sub, buf, &len);
return_val_if_fail (ret == ASN1_SUCCESS, false);
timet = p11_asn1_parse_general (buf, &when);
- return_val_if_fail (timet >= 0, false);
} else if (strcmp (buf, "utcTime") == 0) {
len = sizeof (buf) - 1;
ret = asn1_read_value (node, sub, buf, &len);
return_val_if_fail (ret == ASN1_SUCCESS, false);
timet = p11_asn1_parse_utc (buf, &when);
- return_val_if_fail (timet >= 0, false);
} else {
return_val_if_reached (false);
@@ -272,6 +270,9 @@ calc_date (node_asn *node,
free (sub);
+ if (timet < 0)
+ return false;
+
assert (sizeof (date->year) == 4);
snprintf ((char *)buf, 5, "%04d", 1900 + when.tm_year);
memcpy (date->year, buf, 4);
diff --git a/trust/tests/test-builder.c b/trust/tests/test-builder.c
index 3212bac..723a251 100644
--- a/trust/tests/test-builder.c
+++ b/trust/tests/test-builder.c
@@ -514,6 +514,76 @@ test_build_extension (CuTest *cu)
teardown (cu);
}
+/* This certificate has and end date in 2067 */
+static const unsigned char cert_distant_end_date[] = {
+ 0x30, 0x82, 0x01, 0x6a, 0x30, 0x82, 0x01, 0x14, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x02, 0x03,
+ 0xe7, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00,
+ 0x30, 0x28, 0x31, 0x26, 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1d, 0x66, 0x61, 0x72,
+ 0x2d, 0x69, 0x6e, 0x2d, 0x74, 0x68, 0x65, 0x2d, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2e, 0x65,
+ 0x78, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x20, 0x17, 0x0d, 0x31, 0x33,
+ 0x30, 0x33, 0x32, 0x37, 0x31, 0x36, 0x34, 0x39, 0x33, 0x33, 0x5a, 0x18, 0x0f, 0x32, 0x30, 0x36,
+ 0x37, 0x31, 0x32, 0x32, 0x39, 0x31, 0x36, 0x34, 0x39, 0x33, 0x33, 0x5a, 0x30, 0x28, 0x31, 0x26,
+ 0x30, 0x24, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x1d, 0x66, 0x61, 0x72, 0x2d, 0x69, 0x6e, 0x2d,
+ 0x74, 0x68, 0x65, 0x2d, 0x66, 0x75, 0x74, 0x75, 0x72, 0x65, 0x2e, 0x65, 0x78, 0x61, 0x6d, 0x70,
+ 0x6c, 0x65, 0x2e, 0x63, 0x6f, 0x6d, 0x30, 0x5c, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86,
+ 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x4b, 0x00, 0x30, 0x48, 0x02, 0x41, 0x00, 0xe2,
+ 0x2d, 0x35, 0x70, 0x75, 0xc0, 0x07, 0x56, 0x40, 0x7d, 0x63, 0xbc, 0xd2, 0x60, 0xb3, 0xcf, 0xb8,
+ 0x3d, 0x27, 0x6e, 0x10, 0xcd, 0x42, 0x50, 0x51, 0x9d, 0x79, 0x30, 0x79, 0x5a, 0xe3, 0xc3, 0x51,
+ 0x38, 0x85, 0x4c, 0xb4, 0x91, 0xd9, 0xe6, 0x8d, 0x69, 0x6a, 0xd4, 0x9c, 0x1c, 0x49, 0xc2, 0x25,
+ 0x2a, 0xc9, 0x2b, 0xf2, 0xf4, 0x8e, 0x8a, 0x3f, 0x8b, 0x4c, 0x97, 0xc3, 0x16, 0x96, 0x99, 0x02,
+ 0x03, 0x01, 0x00, 0x01, 0xa3, 0x26, 0x30, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55, 0x1d, 0x25, 0x04,
+ 0x1b, 0x30, 0x19, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x02, 0x06, 0x08, 0x2b,
+ 0x06, 0x01, 0x05, 0x05, 0x07, 0x03, 0x04, 0x06, 0x03, 0x2a, 0x03, 0x04, 0x30, 0x0d, 0x06, 0x09,
+ 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x05, 0x05, 0x00, 0x03, 0x41, 0x00, 0xc2, 0x83,
+ 0x27, 0x32, 0x80, 0x74, 0x73, 0xe2, 0xa3, 0x92, 0xaa, 0x7c, 0xd8, 0x50, 0xf4, 0x61, 0x50, 0xb1,
+ 0x63, 0x9e, 0x29, 0xef, 0x38, 0x1d, 0xc0, 0x55, 0x20, 0x0f, 0x7e, 0xe9, 0x1f, 0xa1, 0x54, 0x1a,
+ 0x5f, 0x8c, 0x26, 0x1b, 0x66, 0x96, 0x0e, 0x64, 0x52, 0x1c, 0x00, 0x96, 0xfb, 0x81, 0x77, 0xa2,
+ 0x3a, 0x1d, 0x49, 0x0c, 0x03, 0xd5, 0x19, 0xf2, 0x6a, 0x01, 0x29, 0x31, 0xfb, 0xf5,
+};
+
+static void
+test_build_distant_end_date (CuTest *cu)
+{
+ CK_ATTRIBUTE input[] = {
+ { CKA_CLASS, &certificate, sizeof (certificate) },
+ { CKA_CERTIFICATE_TYPE, &x509, sizeof (x509) },
+ { CKA_VALUE, (void *)cert_distant_end_date, sizeof (cert_distant_end_date) },
+ { CKA_INVALID },
+ };
+
+ CK_ATTRIBUTE expected[] = {
+ { CKA_END_DATE, },
+ { CKA_START_DATE, "20130327", 8 },
+ { CKA_INVALID },
+ };
+
+ CK_ATTRIBUTE *attrs;
+ CK_RV rv;
+
+ setup (cu);
+
+ /*
+ * On a 32-bit system, the end date will be too big to compute with
+ * libc. So it'll be empty, since this is an optional field.
+ */
+ if (sizeof (time_t) <= 4) {
+ expected[0].pValue = "";
+ expected[0].ulValueLen = 0;
+ } else {
+ expected[0].pValue = "20671229";
+ expected[0].ulValueLen = 8;
+ }
+
+ attrs = NULL;
+ rv = p11_builder_build (test.builder, test.index, &attrs, p11_attrs_dup (input));
+ CuAssertIntEquals (cu, CKR_OK, rv);
+
+ test_check_attrs (cu, expected, attrs);
+ p11_attrs_free (attrs);
+
+ teardown (cu);
+}
+
static void
test_create_not_settable (CuTest *cu)
{
@@ -1666,6 +1736,7 @@ main (void)
SUITE_ADD_TEST (suite, test_build_certificate_no_type);
SUITE_ADD_TEST (suite, test_build_certificate_bad_type);
SUITE_ADD_TEST (suite, test_build_extension);
+ SUITE_ADD_TEST (suite, test_build_distant_end_date);
SUITE_ADD_TEST (suite, test_create_not_settable);
SUITE_ADD_TEST (suite, test_create_but_loadable);
SUITE_ADD_TEST (suite, test_create_unsupported);