]> granicus.if.org Git - p11-kit/commitdiff
trust: Avoid confusion in DER/PEM decoding
authorDaiki Ueno <dueno@redhat.com>
Tue, 27 Sep 2016 09:30:23 +0000 (11:30 +0200)
committerDaiki Ueno <ueno@gnu.org>
Wed, 30 Nov 2016 15:08:25 +0000 (16:08 +0100)
Previously p11-kit-trust.so tried to interpret certificate as PEM format
first.  This could cause potential conflict if the certificate were
actually in DER format and contained a PEM marker strings.

https://bugs.freedesktop.org/show_bug.cgi?id=92063

trust/test-token.c
trust/test-trust.h
trust/token.c

index d55798096640ba107277033d879e18d600aad0b8..ad22fcb3e5c050aa43b59cd15eab76e90416f83e 100644 (file)
@@ -404,6 +404,23 @@ test_load_found (void)
        assert (p11_index_find (test.index, cert, -1) != 0);
 }
 
+static void
+test_load_contrived (void)
+{
+       int ret;
+       p11_index *index;
+
+       p11_test_file_write (test.directory, "contrived.der", test_contrived_der,
+                            sizeof (test_contrived_der));
+
+       ret = p11_token_load (test.token);
+       assert_num_eq (ret, 1);
+
+       index = p11_token_index (test.token);
+       ret = p11_index_size (index);
+       assert_num_eq (ret, 3);
+}
+
 static void
 test_reload_changed (void)
 {
@@ -780,6 +797,7 @@ main (int argc,
        p11_test (test_load_already, "/token/load-already");
        p11_test (test_load_unreadable, "/token/load-unreadable");
        p11_test (test_load_gone, "/token/load-gone");
+       p11_test (test_load_contrived, "/token/load-contrived");
        p11_test (test_reload_changed, "/token/reload-changed");
        p11_test (test_reload_gone, "/token/reload-gone");
        p11_test (test_reload_no_origin, "/token/reload-no-origin");
index 81c779c3826e2cef8ef6e925d71272188be255e4..5ce3508d26d06503d82575f61592d99827e7c5ba 100644 (file)
@@ -357,6 +357,102 @@ static const unsigned char example_public_key[] = {
        0x15, 0x02, 0x03, 0x01, 0x00, 0x01
 };
 
+static const char test_contrived_der[] = {
+       0x30, 0x82, 0x05, 0xbd, 0x30, 0x82, 0x05, 0x62, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x0c, 0x57,
+       0xea, 0x3b, 0x20, 0x31, 0x8a, 0x20, 0x40, 0xac, 0xad, 0x0a, 0xf1, 0x30, 0x0a, 0x06, 0x08, 0x2a,
+       0x86, 0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x30, 0x82, 0x02, 0x46, 0x31, 0x82, 0x02, 0x42, 0x30,
+       0x82, 0x02, 0x3e, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x82, 0x02, 0x35, 0x63, 0x6f, 0x6e, 0x74,
+       0x72, 0x69, 0x76, 0x65, 0x64, 0x20, 0x6f, 0x75, 0x74, 0x65, 0x72, 0x20, 0x63, 0x61, 0x0a, 0x2d,
+       0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45, 0x47, 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46,
+       0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x42, 0x5a,
+       0x6a, 0x43, 0x43, 0x41, 0x51, 0x79, 0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x4d, 0x56,
+       0x2b, 0x6f, 0x36, 0x41, 0x67, 0x51, 0x70, 0x74, 0x75, 0x63, 0x6c, 0x62, 0x5a, 0x34, 0x72, 0x4d,
+       0x41, 0x6f, 0x47, 0x43, 0x43, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x42, 0x41, 0x4d, 0x43, 0x4d,
+       0x42, 0x30, 0x78, 0x47, 0x7a, 0x41, 0x5a, 0x42, 0x67, 0x4e, 0x56, 0x0a, 0x42, 0x41, 0x4d, 0x54,
+       0x45, 0x6d, 0x4e, 0x76, 0x62, 0x6e, 0x52, 0x79, 0x61, 0x58, 0x5a, 0x6c, 0x5a, 0x43, 0x42, 0x70,
+       0x62, 0x6d, 0x35, 0x6c, 0x63, 0x69, 0x42, 0x6a, 0x59, 0x54, 0x41, 0x65, 0x46, 0x77, 0x30, 0x78,
+       0x4e, 0x6a, 0x41, 0x35, 0x4d, 0x6a, 0x63, 0x77, 0x4f, 0x54, 0x49, 0x78, 0x4d, 0x44, 0x5a, 0x61,
+       0x46, 0x77, 0x30, 0x78, 0x4e, 0x7a, 0x41, 0x35, 0x4d, 0x6a, 0x63, 0x77, 0x0a, 0x4f, 0x54, 0x49,
+       0x78, 0x4d, 0x44, 0x5a, 0x61, 0x4d, 0x42, 0x30, 0x78, 0x47, 0x7a, 0x41, 0x5a, 0x42, 0x67, 0x4e,
+       0x56, 0x42, 0x41, 0x4d, 0x54, 0x45, 0x6d, 0x4e, 0x76, 0x62, 0x6e, 0x52, 0x79, 0x61, 0x58, 0x5a,
+       0x6c, 0x5a, 0x43, 0x42, 0x70, 0x62, 0x6d, 0x35, 0x6c, 0x63, 0x69, 0x42, 0x6a, 0x59, 0x54, 0x42,
+       0x5a, 0x4d, 0x42, 0x4d, 0x47, 0x42, 0x79, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x0a, 0x41, 0x67,
+       0x45, 0x47, 0x43, 0x43, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x41, 0x77, 0x45, 0x48, 0x41, 0x30,
+       0x49, 0x41, 0x42, 0x4f, 0x55, 0x7a, 0x42, 0x77, 0x4a, 0x51, 0x6b, 0x70, 0x55, 0x69, 0x76, 0x6b,
+       0x65, 0x70, 0x4a, 0x51, 0x79, 0x7a, 0x76, 0x59, 0x64, 0x6b, 0x41, 0x4d, 0x38, 0x4c, 0x4a, 0x64,
+       0x77, 0x37, 0x72, 0x61, 0x71, 0x4f, 0x58, 0x39, 0x72, 0x46, 0x79, 0x58, 0x71, 0x4b, 0x0a, 0x38,
+       0x44, 0x52, 0x57, 0x50, 0x75, 0x71, 0x67, 0x79, 0x74, 0x32, 0x6e, 0x38, 0x34, 0x4c, 0x6b, 0x64,
+       0x35, 0x72, 0x78, 0x61, 0x70, 0x41, 0x62, 0x36, 0x63, 0x39, 0x45, 0x37, 0x66, 0x43, 0x38, 0x63,
+       0x34, 0x36, 0x71, 0x44, 0x34, 0x31, 0x45, 0x54, 0x61, 0x32, 0x6a, 0x4d, 0x6a, 0x41, 0x77, 0x4d,
+       0x41, 0x38, 0x47, 0x41, 0x31, 0x55, 0x64, 0x45, 0x77, 0x45, 0x42, 0x2f, 0x77, 0x51, 0x46, 0x0a,
+       0x4d, 0x41, 0x4d, 0x42, 0x41, 0x66, 0x38, 0x77, 0x48, 0x51, 0x59, 0x44, 0x56, 0x52, 0x30, 0x4f,
+       0x42, 0x42, 0x59, 0x45, 0x46, 0x50, 0x49, 0x4b, 0x67, 0x4c, 0x36, 0x78, 0x6f, 0x4d, 0x6b, 0x7a,
+       0x54, 0x6d, 0x56, 0x4c, 0x77, 0x72, 0x53, 0x4b, 0x64, 0x76, 0x58, 0x46, 0x45, 0x44, 0x73, 0x66,
+       0x4d, 0x41, 0x6f, 0x47, 0x43, 0x43, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x42, 0x41, 0x4d, 0x43,
+       0x0a, 0x41, 0x30, 0x67, 0x41, 0x4d, 0x45, 0x55, 0x43, 0x49, 0x45, 0x4a, 0x46, 0x64, 0x75, 0x32,
+       0x61, 0x61, 0x4e, 0x63, 0x41, 0x4b, 0x4e, 0x77, 0x4b, 0x4b, 0x75, 0x6d, 0x6d, 0x52, 0x33, 0x52,
+       0x59, 0x65, 0x4f, 0x49, 0x6b, 0x33, 0x45, 0x4c, 0x53, 0x61, 0x65, 0x46, 0x6e, 0x39, 0x6e, 0x6b,
+       0x6d, 0x38, 0x36, 0x39, 0x6c, 0x41, 0x69, 0x45, 0x41, 0x7a, 0x2b, 0x70, 0x2b, 0x6d, 0x39, 0x36,
+       0x78, 0x0a, 0x45, 0x63, 0x39, 0x4d, 0x64, 0x66, 0x6b, 0x61, 0x6c, 0x6e, 0x74, 0x71, 0x6d, 0x6d,
+       0x4b, 0x46, 0x33, 0x55, 0x59, 0x31, 0x2f, 0x6b, 0x65, 0x4f, 0x66, 0x59, 0x5a, 0x62, 0x6b, 0x4f,
+       0x6e, 0x46, 0x48, 0x45, 0x59, 0x3d, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20,
+       0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d,
+       0x0a, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x39, 0x32, 0x37, 0x30, 0x39, 0x32, 0x35, 0x35,
+       0x32, 0x5a, 0x17, 0x0d, 0x31, 0x37, 0x30, 0x39, 0x32, 0x37, 0x30, 0x39, 0x32, 0x35, 0x35, 0x32,
+       0x5a, 0x30, 0x82, 0x02, 0x46, 0x31, 0x82, 0x02, 0x42, 0x30, 0x82, 0x02, 0x3e, 0x06, 0x03, 0x55,
+       0x04, 0x03, 0x0c, 0x82, 0x02, 0x35, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x69, 0x76, 0x65, 0x64, 0x20,
+       0x6f, 0x75, 0x74, 0x65, 0x72, 0x20, 0x63, 0x61, 0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x42, 0x45,
+       0x47, 0x49, 0x4e, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46, 0x49, 0x43, 0x41, 0x54, 0x45, 0x2d,
+       0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x4d, 0x49, 0x49, 0x42, 0x5a, 0x6a, 0x43, 0x43, 0x41, 0x51, 0x79,
+       0x67, 0x41, 0x77, 0x49, 0x42, 0x41, 0x67, 0x49, 0x4d, 0x56, 0x2b, 0x6f, 0x36, 0x41, 0x67, 0x51,
+       0x70, 0x74, 0x75, 0x63, 0x6c, 0x62, 0x5a, 0x34, 0x72, 0x4d, 0x41, 0x6f, 0x47, 0x43, 0x43, 0x71,
+       0x47, 0x53, 0x4d, 0x34, 0x39, 0x42, 0x41, 0x4d, 0x43, 0x4d, 0x42, 0x30, 0x78, 0x47, 0x7a, 0x41,
+       0x5a, 0x42, 0x67, 0x4e, 0x56, 0x0a, 0x42, 0x41, 0x4d, 0x54, 0x45, 0x6d, 0x4e, 0x76, 0x62, 0x6e,
+       0x52, 0x79, 0x61, 0x58, 0x5a, 0x6c, 0x5a, 0x43, 0x42, 0x70, 0x62, 0x6d, 0x35, 0x6c, 0x63, 0x69,
+       0x42, 0x6a, 0x59, 0x54, 0x41, 0x65, 0x46, 0x77, 0x30, 0x78, 0x4e, 0x6a, 0x41, 0x35, 0x4d, 0x6a,
+       0x63, 0x77, 0x4f, 0x54, 0x49, 0x78, 0x4d, 0x44, 0x5a, 0x61, 0x46, 0x77, 0x30, 0x78, 0x4e, 0x7a,
+       0x41, 0x35, 0x4d, 0x6a, 0x63, 0x77, 0x0a, 0x4f, 0x54, 0x49, 0x78, 0x4d, 0x44, 0x5a, 0x61, 0x4d,
+       0x42, 0x30, 0x78, 0x47, 0x7a, 0x41, 0x5a, 0x42, 0x67, 0x4e, 0x56, 0x42, 0x41, 0x4d, 0x54, 0x45,
+       0x6d, 0x4e, 0x76, 0x62, 0x6e, 0x52, 0x79, 0x61, 0x58, 0x5a, 0x6c, 0x5a, 0x43, 0x42, 0x70, 0x62,
+       0x6d, 0x35, 0x6c, 0x63, 0x69, 0x42, 0x6a, 0x59, 0x54, 0x42, 0x5a, 0x4d, 0x42, 0x4d, 0x47, 0x42,
+       0x79, 0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x0a, 0x41, 0x67, 0x45, 0x47, 0x43, 0x43, 0x71, 0x47,
+       0x53, 0x4d, 0x34, 0x39, 0x41, 0x77, 0x45, 0x48, 0x41, 0x30, 0x49, 0x41, 0x42, 0x4f, 0x55, 0x7a,
+       0x42, 0x77, 0x4a, 0x51, 0x6b, 0x70, 0x55, 0x69, 0x76, 0x6b, 0x65, 0x70, 0x4a, 0x51, 0x79, 0x7a,
+       0x76, 0x59, 0x64, 0x6b, 0x41, 0x4d, 0x38, 0x4c, 0x4a, 0x64, 0x77, 0x37, 0x72, 0x61, 0x71, 0x4f,
+       0x58, 0x39, 0x72, 0x46, 0x79, 0x58, 0x71, 0x4b, 0x0a, 0x38, 0x44, 0x52, 0x57, 0x50, 0x75, 0x71,
+       0x67, 0x79, 0x74, 0x32, 0x6e, 0x38, 0x34, 0x4c, 0x6b, 0x64, 0x35, 0x72, 0x78, 0x61, 0x70, 0x41,
+       0x62, 0x36, 0x63, 0x39, 0x45, 0x37, 0x66, 0x43, 0x38, 0x63, 0x34, 0x36, 0x71, 0x44, 0x34, 0x31,
+       0x45, 0x54, 0x61, 0x32, 0x6a, 0x4d, 0x6a, 0x41, 0x77, 0x4d, 0x41, 0x38, 0x47, 0x41, 0x31, 0x55,
+       0x64, 0x45, 0x77, 0x45, 0x42, 0x2f, 0x77, 0x51, 0x46, 0x0a, 0x4d, 0x41, 0x4d, 0x42, 0x41, 0x66,
+       0x38, 0x77, 0x48, 0x51, 0x59, 0x44, 0x56, 0x52, 0x30, 0x4f, 0x42, 0x42, 0x59, 0x45, 0x46, 0x50,
+       0x49, 0x4b, 0x67, 0x4c, 0x36, 0x78, 0x6f, 0x4d, 0x6b, 0x7a, 0x54, 0x6d, 0x56, 0x4c, 0x77, 0x72,
+       0x53, 0x4b, 0x64, 0x76, 0x58, 0x46, 0x45, 0x44, 0x73, 0x66, 0x4d, 0x41, 0x6f, 0x47, 0x43, 0x43,
+       0x71, 0x47, 0x53, 0x4d, 0x34, 0x39, 0x42, 0x41, 0x4d, 0x43, 0x0a, 0x41, 0x30, 0x67, 0x41, 0x4d,
+       0x45, 0x55, 0x43, 0x49, 0x45, 0x4a, 0x46, 0x64, 0x75, 0x32, 0x61, 0x61, 0x4e, 0x63, 0x41, 0x4b,
+       0x4e, 0x77, 0x4b, 0x4b, 0x75, 0x6d, 0x6d, 0x52, 0x33, 0x52, 0x59, 0x65, 0x4f, 0x49, 0x6b, 0x33,
+       0x45, 0x4c, 0x53, 0x61, 0x65, 0x46, 0x6e, 0x39, 0x6e, 0x6b, 0x6d, 0x38, 0x36, 0x39, 0x6c, 0x41,
+       0x69, 0x45, 0x41, 0x7a, 0x2b, 0x70, 0x2b, 0x6d, 0x39, 0x36, 0x78, 0x0a, 0x45, 0x63, 0x39, 0x4d,
+       0x64, 0x66, 0x6b, 0x61, 0x6c, 0x6e, 0x74, 0x71, 0x6d, 0x6d, 0x4b, 0x46, 0x33, 0x55, 0x59, 0x31,
+       0x2f, 0x6b, 0x65, 0x4f, 0x66, 0x59, 0x5a, 0x62, 0x6b, 0x4f, 0x6e, 0x46, 0x48, 0x45, 0x59, 0x3d,
+       0x0a, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x45, 0x4e, 0x44, 0x20, 0x43, 0x45, 0x52, 0x54, 0x49, 0x46,
+       0x49, 0x43, 0x41, 0x54, 0x45, 0x2d, 0x2d, 0x2d, 0x2d, 0x2d, 0x0a, 0x30, 0x59, 0x30, 0x13, 0x06,
+       0x07, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x02, 0x01, 0x06, 0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03,
+       0x01, 0x07, 0x03, 0x42, 0x00, 0x04, 0xfc, 0xc7, 0x64, 0xf8, 0x11, 0x1a, 0x27, 0x9e, 0x42, 0x2a,
+       0x23, 0xae, 0xcf, 0x61, 0x75, 0x5e, 0xb7, 0xe0, 0x11, 0xf1, 0x39, 0x92, 0xd1, 0x45, 0xe3, 0x51,
+       0xaa, 0xd6, 0x66, 0x46, 0x1e, 0xa6, 0x50, 0xb2, 0x6e, 0xf0, 0x08, 0xc0, 0x8d, 0x09, 0xdc, 0xb1,
+       0xf2, 0x95, 0xed, 0x2b, 0xdf, 0x83, 0xa8, 0x8e, 0x9b, 0x0f, 0x8a, 0x05, 0xc5, 0x6b, 0xe0, 0x9b,
+       0xc9, 0x64, 0xc1, 0x4c, 0x8e, 0xd9, 0xa3, 0x32, 0x30, 0x30, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d,
+       0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x1d, 0x06, 0x03, 0x55,
+       0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x85, 0xf2, 0xf0, 0xac, 0xc5, 0x37, 0x20, 0x96, 0x5a, 0x1e,
+       0xa1, 0x80, 0xf2, 0x06, 0x2f, 0x99, 0xd4, 0x25, 0x5b, 0x37, 0x30, 0x0a, 0x06, 0x08, 0x2a, 0x86,
+       0x48, 0xce, 0x3d, 0x04, 0x03, 0x02, 0x03, 0x49, 0x00, 0x30, 0x46, 0x02, 0x21, 0x00, 0xb9, 0xd3,
+       0x11, 0x9f, 0x0c, 0x71, 0x61, 0x6d, 0xe3, 0xa9, 0xc2, 0xb6, 0x27, 0x6c, 0x53, 0x02, 0x6d, 0x73,
+       0x52, 0x0e, 0xfc, 0x8c, 0x44, 0xad, 0x5d, 0x77, 0xed, 0xfe, 0x31, 0x53, 0xbe, 0xcd, 0x02, 0x21,
+       0x00, 0xe2, 0xa7, 0x91, 0x40, 0x21, 0x45, 0xc3, 0xb2, 0xe9, 0x54, 0x5d, 0x09, 0xa0, 0x45, 0x4f,
+       0xc2, 0x9d, 0x0b, 0xba, 0xee, 0x7a, 0x66, 0xf5, 0xd3, 0x55, 0xd7, 0xf5, 0xab, 0x22, 0xb4, 0xbd,
+       0x05,
+};
+
 static const char test_text[] = "This is the file text";
 
 static const char test_eku_server_and_client[] = {
index 47b80d888154808ce8a954f1a3e364b285cfe1b9..df6f7271377d4671cd4d3b3f055b692be6003e54 100644 (file)
@@ -840,7 +840,7 @@ p11_token_new (CK_SLOT_ID slot,
        token->parser = p11_parser_new (p11_builder_get_cache (token->builder));
        return_val_if_fail (token->parser != NULL, NULL);
        p11_parser_formats (token->parser, p11_parser_format_persist,
-                           p11_parser_format_pem, p11_parser_format_x509, NULL);
+                           p11_parser_format_x509, p11_parser_format_pem, NULL);
 
        token->loaded = p11_dict_new (p11_dict_str_hash, p11_dict_str_equal, free, free);
        return_val_if_fail (token->loaded != NULL, NULL);