From 2be55821c1ffab99b91c76c43c91dd95db1c21c7 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 4 Jul 2013 15:43:26 +0200 Subject: trust: Add p11_oid_hash() and various oid strings --- trust/oid.c | 13 +++++++++++++ trust/oid.h | 7 +++++++ trust/tests/test-oid.c | 19 ++++++++++++++----- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/trust/oid.c b/trust/oid.c index b4b0bf6..dff4148 100644 --- a/trust/oid.c +++ b/trust/oid.c @@ -34,10 +34,12 @@ #include "config.h" +#include "hash.h" #include "oid.h" #include #include +#include #include /* @@ -60,6 +62,17 @@ p11_oid_simple (const unsigned char *oid, (size_t)oid[1] == len - 2); /* matches length */ } +unsigned int +p11_oid_hash (const void *oid) +{ + uint32_t hash; + int len; + + len = p11_oid_length (oid); + p11_hash_murmur3 (&hash, oid, len, NULL); + return hash; +} + bool p11_oid_equal (const void *oid_one, const void *oid_two) diff --git a/trust/oid.h b/trust/oid.h index dee6b10..cf510fe 100644 --- a/trust/oid.h +++ b/trust/oid.h @@ -40,6 +40,8 @@ bool p11_oid_simple (const unsigned char *oid, int len); +unsigned int p11_oid_hash (const void *oid); + bool p11_oid_equal (const void *oid_one, const void *oid_two); @@ -74,6 +76,7 @@ static const unsigned char P11_OID_OU[] = */ static const unsigned char P11_OID_SUBJECT_KEY_IDENTIFIER[] = { 0x06, 0x03, 0x55, 0x1d, 0x0e }; +static const char P11_OID_SUBJECT_KEY_IDENTIFIER_STR[] = "2.5.29.14"; /* * 2.5.29.15: KeyUsage @@ -82,6 +85,7 @@ static const unsigned char P11_OID_SUBJECT_KEY_IDENTIFIER[] = */ static const unsigned char P11_OID_KEY_USAGE[] = { 0x06, 0x03, 0x55, 0x1d, 0x0f }; +static const char P11_OID_KEY_USAGE_STR[] = { "2.5.29.15" }; enum { P11_KU_DIGITAL_SIGNATURE = 128, @@ -102,6 +106,7 @@ enum { */ static const unsigned char P11_OID_BASIC_CONSTRAINTS[] = { 0x06, 0x03, 0x55, 0x1d, 0x13 }; +static const char P11_OID_BASIC_CONSTRAINTS_STR[] = "2.5.29.19"; /* * 2.5.29.37: ExtendedKeyUsage @@ -110,6 +115,7 @@ static const unsigned char P11_OID_BASIC_CONSTRAINTS[] = */ static const unsigned char P11_OID_EXTENDED_KEY_USAGE[] = { 0x06, 0x03, 0x55, 0x1d, 0x25 }; +static const char P11_OID_EXTENDED_KEY_USAGE_STR[] = "2.5.29.37"; /* * 1.3.6.1.4.1.3319.6.10.1: OpenSSL reject extension @@ -136,6 +142,7 @@ static const unsigned char P11_OID_EXTENDED_KEY_USAGE[] = */ static const unsigned char P11_OID_OPENSSL_REJECT[] = { 0x06, 0x0a, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x99, 0x77, 0x06, 0x0a, 0x01 }; +static const char P11_OID_OPENSSL_REJECT_STR[] = "1.3.6.1.4.1.3319.6.10.1"; /* * 1.3.6.1.5.5.7.3.1: Server Auth diff --git a/trust/tests/test-oid.c b/trust/tests/test-oid.c index 05945d9..0635d0a 100644 --- a/trust/tests/test-oid.c +++ b/trust/tests/test-oid.c @@ -61,11 +61,11 @@ test_known_oids (void) size_t length; const char *string; } known_oids[] = { - { P11_OID_SUBJECT_KEY_IDENTIFIER, sizeof (P11_OID_SUBJECT_KEY_IDENTIFIER), "2.5.29.14", }, - { P11_OID_KEY_USAGE, sizeof (P11_OID_KEY_USAGE), "2.5.29.15", }, - { P11_OID_BASIC_CONSTRAINTS, sizeof (P11_OID_BASIC_CONSTRAINTS), "2.5.29.19" }, - { P11_OID_EXTENDED_KEY_USAGE, sizeof (P11_OID_EXTENDED_KEY_USAGE), "2.5.29.37" }, - { P11_OID_OPENSSL_REJECT, sizeof (P11_OID_OPENSSL_REJECT), "1.3.6.1.4.1.3319.6.10.1" }, + { P11_OID_SUBJECT_KEY_IDENTIFIER, sizeof (P11_OID_SUBJECT_KEY_IDENTIFIER), P11_OID_SUBJECT_KEY_IDENTIFIER_STR, }, + { P11_OID_KEY_USAGE, sizeof (P11_OID_KEY_USAGE), P11_OID_KEY_USAGE_STR, }, + { P11_OID_BASIC_CONSTRAINTS, sizeof (P11_OID_BASIC_CONSTRAINTS), P11_OID_BASIC_CONSTRAINTS_STR }, + { P11_OID_EXTENDED_KEY_USAGE, sizeof (P11_OID_EXTENDED_KEY_USAGE), P11_OID_EXTENDED_KEY_USAGE_STR }, + { P11_OID_OPENSSL_REJECT, sizeof (P11_OID_OPENSSL_REJECT), P11_OID_OPENSSL_REJECT_STR }, { P11_OID_SERVER_AUTH, sizeof (P11_OID_SERVER_AUTH), P11_OID_SERVER_AUTH_STR }, { P11_OID_CLIENT_AUTH, sizeof (P11_OID_CLIENT_AUTH), P11_OID_CLIENT_AUTH_STR }, { P11_OID_CODE_SIGNING, sizeof (P11_OID_CODE_SIGNING), P11_OID_CODE_SIGNING_STR }, @@ -109,10 +109,19 @@ test_known_oids (void) asn1_delete_structure (&definitions); } +static void +test_hash (void) +{ + assert_num_cmp (p11_oid_hash (P11_OID_CN), !=, 0); + assert_num_cmp (p11_oid_hash (P11_OID_CN), ==, p11_oid_hash (P11_OID_CN)); + assert_num_cmp (p11_oid_hash (P11_OID_CN), !=, p11_oid_hash (P11_OID_BASIC_CONSTRAINTS)); +} + int main (int argc, char *argv[]) { p11_test (test_known_oids, "/oids/known"); + p11_test (test_hash, "/oids/hash"); return p11_test_run (argc, argv); } -- cgit v1.1