summaryrefslogtreecommitdiff
path: root/common/tests
diff options
context:
space:
mode:
Diffstat (limited to 'common/tests')
-rw-r--r--common/tests/Makefile.am32
-rw-r--r--common/tests/frob-cert.c134
-rw-r--r--common/tests/frob-eku.c101
-rw-r--r--common/tests/frob-ku.c124
-rw-r--r--common/tests/frob-oid.c100
-rw-r--r--common/tests/test-asn1.c144
-rw-r--r--common/tests/test-base64.c204
-rw-r--r--common/tests/test-lexer.c35
-rw-r--r--common/tests/test-oid.c118
-rw-r--r--common/tests/test-pem.c341
-rw-r--r--common/tests/test-utf8.c244
-rw-r--r--common/tests/test-x509.c416
12 files changed, 11 insertions, 1982 deletions
diff --git a/common/tests/Makefile.am b/common/tests/Makefile.am
index 942bc12..637399b 100644
--- a/common/tests/Makefile.am
+++ b/common/tests/Makefile.am
@@ -22,42 +22,12 @@ CHECK_PROGS = \
test-buffer \
test-url \
test-path \
+ test-lexer \
$(NULL)
noinst_PROGRAMS = \
$(CHECK_PROGS)
-if WITH_ASN1
-
-LDADD += \
- $(top_builddir)/common/libp11-data.la \
- $(LIBTASN1_LIBS) \
- $(NULL)
-
-AM_CPPFLAGS += \
- $(LIBTASN1_CFLAGS) \
- $(NULL)
-
-CHECK_PROGS += \
- test-asn1 \
- test-base64 \
- test-lexer \
- test-pem \
- test-oid \
- test-utf8 \
- test-x509 \
- $(NULL)
-
-noinst_PROGRAMS += \
- frob-cert \
- frob-ku \
- frob-eku \
- frob-cert \
- frob-oid \
- $(NULL)
-
-endif # WITH_ASN1
-
TESTS = $(CHECK_PROGS)
LDADD += \
diff --git a/common/tests/frob-cert.c b/common/tests/frob-cert.c
deleted file mode 100644
index 71018bd..0000000
--- a/common/tests/frob-cert.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (c) 2012 Red Hat Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@gnome.org>
- */
-
-#include "config.h"
-#include "compat.h"
-
-#include <libtasn1.h>
-
-#include <sys/stat.h>
-#include <sys/types.h>
-
-#include <assert.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include "pkix.asn.h"
-
-#define err_if_fail(ret, msg) \
- do { if ((ret) != ASN1_SUCCESS) { \
- fprintf (stderr, "%s: %s\n", msg, asn1_strerror (ret)); \
- exit (1); \
- } } while (0)
-
-static ssize_t
-tlv_length (const unsigned char *data,
- size_t length)
-{
- unsigned char cls;
- int counter = 0;
- int cb, len;
- unsigned long tag;
-
- if (asn1_get_tag_der (data, length, &cls, &cb, &tag) == ASN1_SUCCESS) {
- counter += cb;
- len = asn1_get_length_der (data + cb, length - cb, &cb);
- counter += cb;
- if (len >= 0) {
- len += counter;
- if (length >= len)
- return len;
- }
- }
-
- return -1;
-}
-
-int
-main (int argc,
- char *argv[])
-{
- char message[ASN1_MAX_ERROR_DESCRIPTION_SIZE] = { 0, };
- node_asn *definitions = NULL;
- node_asn *cert = NULL;
- p11_mmap *map;
- void *data;
- size_t size;
- int start, end;
- ssize_t len;
- int ret;
-
- if (argc != 4) {
- fprintf (stderr, "usage: frob-cert struct field filename\n");
- return 2;
- }
-
- ret = asn1_array2tree (pkix_asn1_tab, &definitions, message);
- if (ret != ASN1_SUCCESS) {
- fprintf (stderr, "definitions: %s\n", message);
- return 1;
- }
-
- ret = asn1_create_element (definitions, argv[1], &cert);
- err_if_fail (ret, "Certificate");
-
- map = p11_mmap_open (argv[3], &data, &size);
- if (map == NULL) {
- fprintf (stderr, "couldn't open file: %s\n", argv[3]);
- return 1;
- }
-
- ret = asn1_der_decoding (&cert, data, size, message);
- err_if_fail (ret, message);
-
- ret = asn1_der_decoding_startEnd (cert, data, size, argv[2], &start, &end);
- err_if_fail (ret, "asn1_der_decoding_startEnd");
-
- len = tlv_length ((unsigned char *)data + start, size - start);
- assert (len >= 0);
-
- fprintf (stderr, "%lu %d %d %ld\n", (unsigned long)size, start, end, (long)len);
- fwrite ((unsigned char *)data + start, 1, len, stdout);
- fflush (stdout);
-
- p11_mmap_close (map);
-
- asn1_delete_structure (&cert);
- asn1_delete_structure (&definitions);
-
- return 0;
-}
diff --git a/common/tests/frob-eku.c b/common/tests/frob-eku.c
deleted file mode 100644
index 42bf50b..0000000
--- a/common/tests/frob-eku.c
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * Copyright (c) 2012 Red Hat Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@gnome.org>
- */
-
-#include "config.h"
-#include "compat.h"
-
-#include <libtasn1.h>
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pkix.asn.h"
-
-#define err_if_fail(ret, msg) \
- do { if ((ret) != ASN1_SUCCESS) { \
- fprintf (stderr, "%s: %s\n", msg, asn1_strerror (ret)); \
- exit (1); \
- } } while (0)
-
-int
-main (int argc,
- char *argv[])
-{
- char message[ASN1_MAX_ERROR_DESCRIPTION_SIZE] = { 0, };
- node_asn *definitions = NULL;
- node_asn *ekus = NULL;
- char *buf;
- int len;
- int ret;
- int i;
-
- ret = asn1_array2tree (pkix_asn1_tab, &definitions, message);
- if (ret != ASN1_SUCCESS) {
- fprintf (stderr, "definitions: %s\n", message);
- return 1;
- }
-
- ret = asn1_create_element (definitions, "PKIX1.ExtKeyUsageSyntax", &ekus);
- err_if_fail (ret, "ExtKeyUsageSyntax");
-
- for (i = 1; i < argc; i++) {
- ret = asn1_write_value (ekus, "", "NEW", 1);
- err_if_fail (ret, "NEW");
-
- ret = asn1_write_value (ekus, "?LAST", argv[i], strlen (argv[i]));
- err_if_fail (ret, "asn1_write_value");
- }
-
- len = 0;
- ret = asn1_der_coding (ekus, "", NULL, &len, message);
- assert (ret == ASN1_MEM_ERROR);
-
- buf = malloc (len);
- assert (buf != NULL);
- ret = asn1_der_coding (ekus, "", buf, &len, message);
- if (ret != ASN1_SUCCESS) {
- fprintf (stderr, "asn1_der_coding: %s\n", message);
- return 1;
- }
-
- fwrite (buf, 1, len, stdout);
- fflush (stdout);
-
- asn1_delete_structure (&ekus);
- asn1_delete_structure (&definitions);
-
- return 0;
-}
diff --git a/common/tests/frob-ku.c b/common/tests/frob-ku.c
deleted file mode 100644
index 00d45c6..0000000
--- a/common/tests/frob-ku.c
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Copyright (c) 2012 Red Hat Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@gnome.org>
- */
-
-#include "config.h"
-#include "compat.h"
-
-#include "oid.h"
-
-#include <libtasn1.h>
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pkix.asn.h"
-
-#define err_if_fail(ret, msg) \
- do { if ((ret) != ASN1_SUCCESS) { \
- fprintf (stderr, "%s: %s\n", msg, asn1_strerror (ret)); \
- exit (1); \
- } } while (0)
-
-int
-main (int argc,
- char *argv[])
-{
- char message[ASN1_MAX_ERROR_DESCRIPTION_SIZE] = { 0, };
- node_asn *definitions = NULL;
- node_asn *ku = NULL;
- unsigned int usage = 0;
- char bits[2];
- char *buf;
- int len;
- int ret;
- int i;
-
- for (i = 1; i < argc; i++) {
- if (strcmp (argv[i], "digital-signature") == 0)
- usage |= P11_KU_DIGITAL_SIGNATURE;
- else if (strcmp (argv[i], "non-repudiation") == 0)
- usage |= P11_KU_NON_REPUDIATION;
- else if (strcmp (argv[i], "key-encipherment") == 0)
- usage |= P11_KU_KEY_ENCIPHERMENT;
- else if (strcmp (argv[i], "data-encipherment") == 0)
- usage |= P11_KU_DATA_ENCIPHERMENT;
- else if (strcmp (argv[i], "key-agreement") == 0)
- usage |= P11_KU_KEY_AGREEMENT;
- else if (strcmp (argv[i], "key-cert-sign") == 0)
- usage |= P11_KU_KEY_CERT_SIGN;
- else if (strcmp (argv[i], "crl-sign") == 0)
- usage |= P11_KU_CRL_SIGN;
- else {
- fprintf (stderr, "unsupported or unknown key usage: %s\n", argv[i]);
- return 2;
- }
- }
-
- ret = asn1_array2tree (pkix_asn1_tab, &definitions, message);
- if (ret != ASN1_SUCCESS) {
- fprintf (stderr, "definitions: %s\n", message);
- return 1;
- }
-
- ret = asn1_create_element (definitions, "PKIX1.KeyUsage", &ku);
- err_if_fail (ret, "KeyUsage");
-
- bits[0] = usage & 0xff;
- bits[1] = (usage >> 8) & 0xff;
-
- ret = asn1_write_value (ku, "", bits, 9);
- err_if_fail (ret, "asn1_write_value");
-
- len = 0;
- ret = asn1_der_coding (ku, "", NULL, &len, message);
- assert (ret == ASN1_MEM_ERROR);
-
- buf = malloc (len);
- assert (buf != NULL);
- ret = asn1_der_coding (ku, "", buf, &len, message);
- if (ret != ASN1_SUCCESS) {
- fprintf (stderr, "asn1_der_coding: %s\n", message);
- return 1;
- }
-
- fwrite (buf, 1, len, stdout);
- fflush (stdout);
-
- asn1_delete_structure (&ku);
- asn1_delete_structure (&definitions);
-
- return 0;
-}
diff --git a/common/tests/frob-oid.c b/common/tests/frob-oid.c
deleted file mode 100644
index b4c7658..0000000
--- a/common/tests/frob-oid.c
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Copyright (c) 2012 Red Hat Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@gnome.org>
- */
-
-#include "config.h"
-#include "compat.h"
-
-#include <libtasn1.h>
-
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "pkix.asn.h"
-
-#define err_if_fail(ret, msg) \
- do { if ((ret) != ASN1_SUCCESS) { \
- fprintf (stderr, "%s: %s\n", msg, asn1_strerror (ret)); \
- exit (1); \
- } } while (0)
-int
-main (int argc,
- char *argv[])
-{
- char message[ASN1_MAX_ERROR_DESCRIPTION_SIZE] = { 0, };
- node_asn *definitions = NULL;
- node_asn *oid = NULL;
- char *buf;
- int len;
- int ret;
-
- if (argc != 2) {
- fprintf (stderr, "usage: frob-oid 1.1.1\n");
- return 2;
- }
-
- ret = asn1_array2tree (pkix_asn1_tab, &definitions, message);
- if (ret != ASN1_SUCCESS) {
- fprintf (stderr, "definitions: %s\n", message);
- return 1;
- }
-
- /* AttributeType is a OBJECT IDENTIFIER */
- ret = asn1_create_element (definitions, "PKIX1.AttributeType", &oid);
- err_if_fail (ret, "AttributeType");
-
- ret = asn1_write_value (oid, "", argv[1], strlen (argv[1]));
- err_if_fail (ret, "asn1_write_value");
-
- len = 0;
- ret = asn1_der_coding (oid, "", NULL, &len, message);
- assert (ret == ASN1_MEM_ERROR);
-
- buf = malloc (len);
- assert (buf != NULL);
- ret = asn1_der_coding (oid, "", buf, &len, message);
- if (ret != ASN1_SUCCESS) {
- fprintf (stderr, "asn1_der_coding: %s\n", message);
- return 1;
- }
-
- fwrite (buf, 1, len, stdout);
- fflush (stdout);
-
- asn1_delete_structure (&oid);
- asn1_delete_structure (&definitions);
-
- return 0;
-}
diff --git a/common/tests/test-asn1.c b/common/tests/test-asn1.c
deleted file mode 100644
index 710928c..0000000
--- a/common/tests/test-asn1.c
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * Copyright (c) 2012 Red Hat Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@gnome.org>
- */
-
-#include "config.h"
-#include "test.h"
-
-#include "asn1.h"
-#include "debug.h"
-#include "oid.h"
-#include "x509.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-struct {
- p11_dict *asn1_defs;
-} test;
-
-static void
-setup (void *unused)
-{
- test.asn1_defs = p11_asn1_defs_load ();
- assert_ptr_not_null (test.asn1_defs);
-}
-
-static void
-teardown (void *unused)
-{
- p11_dict_free (test.asn1_defs);
- memset (&test, 0, sizeof (test));
-}
-
-static void
-test_tlv_length (void)
-{
- struct {
- const char *der;
- size_t der_len;
- int expected;
- } tlv_lengths[] = {
- { "\x01\x01\x00", 3, 3 },
- { "\x01\x01\x00\x01\x02", 5, 3 },
- { "\x01\x05\x00", 3, -1 },
- { NULL }
- };
-
- int length;
- int i;
-
- for (i = 0; tlv_lengths[i].der != NULL; i++) {
- length = p11_asn1_tlv_length ((const unsigned char *)tlv_lengths[i].der, tlv_lengths[i].der_len);
- assert_num_eq (tlv_lengths[i].expected, length);
- }
-}
-
-static const unsigned 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 void
-test_asn1_cache (void)
-{
- p11_asn1_cache *cache;
- p11_dict *defs;
- node_asn *asn;
- node_asn *check;
-
- cache = p11_asn1_cache_new ();
- assert_ptr_not_null (cache);
-
- defs = p11_asn1_cache_defs (cache);
- assert_ptr_not_null (defs);
-
- asn = p11_asn1_decode (defs, "PKIX1.ExtKeyUsageSyntax",
- test_eku_server_and_client,
- sizeof (test_eku_server_and_client), NULL);
- assert_ptr_not_null (defs);
-
- /* Place the parsed data in the cache */
- p11_asn1_cache_take (cache, asn, "PKIX1.ExtKeyUsageSyntax",
- test_eku_server_and_client,
- sizeof (test_eku_server_and_client));
-
- /* Get it back out */
- check = p11_asn1_cache_get (cache, "PKIX1.ExtKeyUsageSyntax",
- test_eku_server_and_client,
- sizeof (test_eku_server_and_client));
- assert_ptr_eq (asn, check);
-
- /* Flush should remove it */
- p11_asn1_cache_flush (cache);
- check = p11_asn1_cache_get (cache, "PKIX1.ExtKeyUsageSyntax",
- test_eku_server_and_client,
- sizeof (test_eku_server_and_client));
- assert_ptr_eq (NULL, check);
-
- p11_asn1_cache_free (cache);
-}
-
-int
-main (int argc,
- char *argv[])
-{
- p11_fixture (setup, teardown);
- p11_test (test_tlv_length, "/asn1/tlv_length");
-
- p11_fixture (NULL, NULL);
- p11_test (test_asn1_cache, "/asn1/asn1_cache");
-
- return p11_test_run (argc, argv);
-}
diff --git a/common/tests/test-base64.c b/common/tests/test-base64.c
deleted file mode 100644
index ce303e8..0000000
--- a/common/tests/test-base64.c
+++ /dev/null
@@ -1,204 +0,0 @@
-/*
- * Copyright (c) 2013 Red Hat Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@redhat.com>
- */
-
-#include "config.h"
-#include "test.h"
-
-#include "base64.h"
-#include "debug.h"
-#include "message.h"
-
-#include <assert.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-static void
-check_decode_msg (const char *file,
- int line,
- const char *function,
- const char *input,
- ssize_t input_len,
- const unsigned char *expected,
- ssize_t expected_len)
-{
- unsigned char decoded[8192];
- int length;
-
- if (input_len < 0)
- input_len = strlen (input);
- if (expected_len < 0)
- expected_len = strlen ((char *)expected);
- length = p11_b64_pton (input, input_len, decoded, sizeof (decoded));
-
- if (expected == NULL) {
- if (length >= 0)
- p11_test_fail (file, line, function, "decoding should have failed");
-
- } else {
- if (length < 0)
- p11_test_fail (file, line, function, "decoding failed");
- if (expected_len != length)
- p11_test_fail (file, line, function, "wrong length: (%lu != %lu)",
- (unsigned long)expected_len, (unsigned long)length);
- if (memcmp (decoded, expected, length) != 0)
- p11_test_fail (file, line, function, "decoded wrong");
- }
-}
-
-#define check_decode_success(input, input_len, expected, expected_len) \
- check_decode_msg (__FILE__, __LINE__, __FUNCTION__, input, input_len, expected, expected_len)
-
-#define check_decode_failure(input, input_len) \
- check_decode_msg (__FILE__, __LINE__, __FUNCTION__, input, input_len, NULL, 0)
-
-static void
-test_decode_simple (void)
-{
- check_decode_success ("", 0, (unsigned char *)"", 0);
- check_decode_success ("MQ==", 0, (unsigned char *)"1", 0);
- check_decode_success ("YmxhaAo=", -1, (unsigned char *)"blah\n", -1);
- check_decode_success ("bGVlbGEK", -1, (unsigned char *)"leela\n", -1);
- check_decode_success ("bGVlbG9vCg==", -1, (unsigned char *)"leeloo\n", -1);
-}
-
-static void
-test_decode_thawte (void)
-{
- const char *input =
- "MIIEKjCCAxKgAwIBAgIQYAGXt0an6rS0mtZLL/eQ+zANBgkqhkiG9w0BAQsFADCB"
- "rjELMAkGA1UEBhMCVVMxFTATBgNVBAoTDHRoYXd0ZSwgSW5jLjEoMCYGA1UECxMf"
- "Q2VydGlmaWNhdGlvbiBTZXJ2aWNlcyBEaXZpc2lvbjE4MDYGA1UECxMvKGMpIDIw"
- "MDggdGhhd3RlLCBJbmMuIC0gRm9yIGF1dGhvcml6ZWQgdXNlIG9ubHkxJDAiBgNV"
- "BAMTG3RoYXd0ZSBQcmltYXJ5IFJvb3QgQ0EgLSBHMzAeFw0wODA0MDIwMDAwMDBa"
- "Fw0zNzEyMDEyMzU5NTlaMIGuMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMdGhhd3Rl"
- "LCBJbmMuMSgwJgYDVQQLEx9DZXJ0aWZpY2F0aW9uIFNlcnZpY2VzIERpdmlzaW9u"
- "MTgwNgYDVQQLEy8oYykgMjAwOCB0aGF3dGUsIEluYy4gLSBGb3IgYXV0aG9yaXpl"
- "ZCB1c2Ugb25seTEkMCIGA1UEAxMbdGhhd3RlIFByaW1hcnkgUm9vdCBDQSAtIEcz"
- "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsr8nLPvb2FvdeHsbnndm"
- "gcs+vHyu86YnmjSjaDFxODNi5PNxZnmxqWWjpYvVj2At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, 0x00, 0x30, 0x81,
- 0xae, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31, 0x15,
- 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0c, 0x74, 0x68, 0x61, 0x77, 0x74, 0x65, 0x2c,
- 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x1f,
- 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x53, 0x65,
- 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x20, 0x44, 0x69, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x31,
- 0x38, 0x30, 0x36, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x2f, 0x28, 0x63, 0x29, 0x20, 0x32, 0x30,
- 0x30, 0x38, 0x20, 0x74, 0x68, 0x61, 0x77, 0x74, 0x65, 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x20,
- 0x2d, 0x20, 0x46, 0x6f, 0x72, 0x20, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x64,
- 0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x6e, 0x6c, 0x79, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03, 0x55,
- 0x04, 0x03, 0x13, 0x1b, 0x74, 0x68, 0x61, 0x77, 0x74, 0x65, 0x20, 0x50, 0x72, 0x69, 0x6d, 0x61,
- 0x72, 0x79, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x20, 0x2d, 0x20, 0x47, 0x33, 0x30,
- 0x1e, 0x17, 0x0d, 0x30, 0x38, 0x30, 0x34, 0x30, 0x32, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x5a,
- 0x17, 0x0d, 0x33, 0x37, 0x31, 0x32, 0x30, 0x31, 0x32, 0x33, 0x35, 0x39, 0x35, 0x39, 0x5a, 0x30,
- 0x81, 0xae, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53, 0x31,
- 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0c, 0x74, 0x68, 0x61, 0x77, 0x74, 0x65,
- 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e, 0x31, 0x28, 0x30, 0x26, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13,
- 0x1f, 0x43, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x53,
- 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x20, 0x44, 0x69, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e,
- 0x31, 0x38, 0x30, 0x36, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x2f, 0x28, 0x63, 0x29, 0x20, 0x32,
- 0x30, 0x30, 0x38, 0x20, 0x74, 0x68, 0x61, 0x77, 0x74, 0x65, 0x2c, 0x20, 0x49, 0x6e, 0x63, 0x2e,
- 0x20, 0x2d, 0x20, 0x46, 0x6f, 0x72, 0x20, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65,
- 0x64, 0x20, 0x75, 0x73, 0x65, 0x20, 0x6f, 0x6e, 0x6c, 0x79, 0x31, 0x24, 0x30, 0x22, 0x06, 0x03,
- 0x55, 0x04, 0x03, 0x13, 0x1b, 0x74, 0x68, 0x61, 0x77, 0x74, 0x65, 0x20, 0x50, 0x72, 0x69, 0x6d,
- 0x61, 0x72, 0x79, 0x20, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x20, 0x2d, 0x20, 0x47, 0x33,
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 0x26, 0x52, 0x28, 0x01, 0x31, 0x40, 0x66, 0xd8, 0xd9, 0x24, 0xbd,
- 0xf6, 0x2a, 0xd8, 0xec, 0x21, 0x49, 0x5c, 0x9b, 0xf6, 0x7a, 0xe9, 0x7f, 0x55, 0x35, 0x7e, 0x96,
- 0x6b, 0x8d, 0x93, 0x93, 0x27, 0xcb, 0x92, 0xbb, 0xea, 0xac, 0x40, 0xc0, 0x9f, 0xc2, 0xf8, 0x80,
- 0xcf, 0x5d, 0xf4, 0x5a, 0xdc, 0xce, 0x74, 0x86, 0xa6, 0x3e, 0x6c, 0x0b, 0x53, 0xca, 0xbd, 0x92,
- 0xce, 0x19, 0x06, 0x72, 0xe6, 0x0c, 0x5c, 0x38, 0x69, 0xc7, 0x04, 0xd6, 0xbc, 0x6c, 0xce, 0x5b,
- 0xf6, 0xf7, 0x68, 0x9c, 0xdc, 0x25, 0x15, 0x48, 0x88, 0xa1, 0xe9, 0xa9, 0xf8, 0x98, 0x9c, 0xe0,
- 0xf3, 0xd5, 0x31, 0x28, 0x61, 0x11, 0x6c, 0x67, 0x96, 0x8d, 0x39, 0x99, 0xcb, 0xc2, 0x45, 0x24,
- 0x39, 0x02, 0x03, 0x01, 0x00, 0x01, 0xa3, 0x42, 0x30, 0x40, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d,
- 0x13, 0x01, 0x01, 0xff, 0x04, 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x0e, 0x06, 0x03, 0x55,
- 0x1d, 0x0f, 0x01, 0x01, 0xff, 0x04, 0x04, 0x03, 0x02, 0x01, 0x06, 0x30, 0x1d, 0x06, 0x03, 0x55,
- 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0xad, 0x6c, 0xaa, 0x94, 0x60, 0x9c, 0xed, 0xe4, 0xff, 0xfa,
- 0x3e, 0x0a, 0x74, 0x2b, 0x63, 0x03, 0xf7, 0xb6, 0x59, 0xbf, 0x30, 0x0d, 0x06, 0x09, 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0x72, 0x82, 0xe3, 0xa1, 0x09, 0xc1, 0xe9, 0x00, 0x19, 0xd3, 0x3e, 0xd4,
- 0x70, 0x6b, 0xba, 0x71, 0xa6, 0xaa, 0x58, 0xae, 0xf4, 0xbb, 0xe9, 0x6c, 0xb6, 0xef, 0x87, 0xcc,
- 0x9b, 0xbb, 0xff, 0x39, 0xe6, 0x56, 0x61, 0xd3, 0x0a, 0xa7, 0xc4, 0x5c, 0x4c, 0x60, 0x7b, 0x05,
- 0x77, 0x26, 0x7a, 0xbf, 0xd8, 0x07, 0x52, 0x2c, 0x62, 0xf7, 0x70, 0x63, 0xd9, 0x39, 0xbc, 0x6f,
- 0x1c, 0xc2, 0x79, 0xdc, 0x76, 0x29, 0xaf, 0xce, 0xc5, 0x2c, 0x64, 0x04, 0x5e, 0x88, 0x36, 0x6e,
- 0x31, 0xd4, 0x40, 0x1a, 0x62, 0x34, 0x36, 0x3f, 0x35, 0x01, 0xae, 0xac, 0x63, 0xa0,
- };
-
- check_decode_success (input, -1, output, sizeof (output));
-}
-
-int
-main (int argc,
- char *argv[])
-{
- p11_test (test_decode_simple, "/base64/decode-simple");
- p11_test (test_decode_thawte, "/base64/decode-thawte");
- return p11_test_run (argc, argv);
-}
diff --git a/common/tests/test-lexer.c b/common/tests/test-lexer.c
index ff18a89..7d18e87 100644
--- a/common/tests/test-lexer.c
+++ b/common/tests/test-lexer.c
@@ -43,7 +43,6 @@
#include "debug.h"
#include "lexer.h"
#include "message.h"
-#include "pem.h"
typedef struct {
int tok_type;
@@ -52,16 +51,6 @@ typedef struct {
} expected_tok;
static void
-on_pem_get_type (const char *type,
- const unsigned char *contents,
- size_t length,
- void *user_data)
-{
- char **result = (char **)user_data;
- *result = strdup (type);
-}
-
-static void
check_lex_msg (const char *file,
int line,
const char *function,
@@ -69,9 +58,8 @@ check_lex_msg (const char *file,
const char *input,
bool failure)
{
- unsigned int count;
p11_lexer lexer;
- char *type;
+ size_t len;
bool failed;
int i;
@@ -99,16 +87,13 @@ check_lex_msg (const char *file,
expected[i].name, lexer.tok.field.name);
break;
case TOK_PEM:
- type = NULL;
- count = p11_pem_parse (lexer.tok.pem.begin, lexer.tok.pem.length,
- on_pem_get_type, &type);
- if (count != 1)
- p11_test_fail (file, line, function, "more than one PEM block: %d", count);
- if (strcmp (expected[i].name, type) != 0)
+ len = strlen (expected[i].name);
+ if (lexer.tok.pem.length < len ||
+ strncmp (lexer.tok.pem.begin, expected[i].name, len) != 0) {
p11_test_fail (file, line, function,
- "wrong type of PEM block: (%s != %s)",
- expected[i].name, type);
- free (type);
+ "wrong type of PEM block: %s",
+ expected[i].name);
+ }
break;
case TOK_EOF:
p11_test_fail (file, line, function, "eof should not be recieved");
@@ -144,7 +129,7 @@ test_basic (void)
const expected_tok expected[] = {
{ TOK_SECTION, "the header" },
{ TOK_FIELD, "field", "value" },
- { TOK_PEM, "BLOCK1", },
+ { TOK_PEM, "-----BEGIN BLOCK1-----\n", },
{ TOK_EOF }
};
@@ -174,7 +159,7 @@ test_corners (void)
{ TOK_FIELD, "number", "3" },
{ TOK_FIELD, "number", "4" },
{ TOK_FIELD, "not-a-comment", "# value" },
- { TOK_PEM, "BLOCK1", },
+ { TOK_PEM, "-----BEGIN BLOCK1-----\r\n", },
{ TOK_EOF }
};
@@ -190,7 +175,7 @@ test_following (void)
"field: value";
const expected_tok expected[] = {
- { TOK_PEM, "BLOCK1", },
+ { TOK_PEM, "-----BEGIN BLOCK1-----\n", },
{ TOK_FIELD, "field", "value" },
{ TOK_EOF }
};
diff --git a/common/tests/test-oid.c b/common/tests/test-oid.c
deleted file mode 100644
index 05945d9..0000000
--- a/common/tests/test-oid.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (c) 2012 Red Hat Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@gnome.org>
- */
-
-#include "config.h"
-#include "test.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "debug.h"
-#include "oid.h"
-
-#include <libtasn1.h>
-
-#include "pkix.asn.h"
-
-static void
-test_known_oids (void)
-{
- char buffer[128];
- node_asn *definitions = NULL;
- node_asn *node;
- int ret;
- int len;
- int i;
-
- struct {
- const unsigned char *oid;
- 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_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 },
- { P11_OID_EMAIL_PROTECTION, sizeof (P11_OID_EMAIL_PROTECTION), P11_OID_EMAIL_PROTECTION_STR },
- { P11_OID_IPSEC_END_SYSTEM, sizeof (P11_OID_IPSEC_END_SYSTEM), P11_OID_IPSEC_END_SYSTEM_STR },
- { P11_OID_IPSEC_TUNNEL, sizeof (P11_OID_IPSEC_TUNNEL), P11_OID_IPSEC_TUNNEL_STR },
- { P11_OID_IPSEC_USER, sizeof (P11_OID_IPSEC_USER), P11_OID_IPSEC_USER_STR },
- { P11_OID_TIME_STAMPING, sizeof (P11_OID_TIME_STAMPING), P11_OID_TIME_STAMPING_STR },
- { P11_OID_RESERVED_PURPOSE, sizeof (P11_OID_RESERVED_PURPOSE), P11_OID_RESERVED_PURPOSE_STR },
- { NULL },
- };
-
- ret = asn1_array2tree (pkix_asn1_tab, &definitions, NULL);
- assert (ret == ASN1_SUCCESS);
-
- for (i = 0; known_oids[i].oid != NULL; i++) {
-
- assert (p11_oid_simple (known_oids[i].oid, known_oids[i].length));
- assert_num_eq (known_oids[i].length, p11_oid_length (known_oids[i].oid));
- assert (p11_oid_equal (known_oids[i].oid, known_oids[i].oid));
-
- if (i > 0)
- assert (!p11_oid_equal (known_oids[i].oid, known_oids[i - 1].oid));
-
- /* AttributeType is a OBJECT IDENTIFIER */
- ret = asn1_create_element (definitions, "PKIX1.AttributeType", &node);
- assert (ret == ASN1_SUCCESS);
-
- ret = asn1_der_decoding (&node, known_oids[i].oid, known_oids[i].length, NULL);
- assert (ret == ASN1_SUCCESS);
-
- len = sizeof (buffer);
- ret = asn1_read_value (node, "", buffer, &len);
- assert (ret == ASN1_SUCCESS);
-
- assert_str_eq (known_oids[i].string, buffer);
-
- asn1_delete_structure (&node);
- }
-
- asn1_delete_structure (&definitions);
-}
-
-int
-main (int argc,
- char *argv[])
-{
- p11_test (test_known_oids, "/oids/known");
- return p11_test_run (argc, argv);
-}
diff --git a/common/tests/test-pem.c b/common/tests/test-pem.c
deleted file mode 100644
index 0c7d60a..0000000
--- a/common/tests/test-pem.c
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- * Copyright (c) 2012 Red Hat Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@gnome.org>
- */
-
-#include "config.h"
-#include "test.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "compat.h"
-#include "pem.h"
-
-struct {
- const char *input;
- struct {
- const char *type;
- const char *data;
- unsigned int length;
- } output[8];
-} success_fixtures[] = {
- {
- /* one block */
- "-----BEGIN BLOCK1-----\n"
- "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
- "-----END BLOCK1-----",
- {
- {
- "BLOCK1",
- "\x69\x83\x4d\x5e\xab\x21\x95\x5c\x42\x76\x8f\x10\x7c\xa7\x97\x87"
- "\x71\x94\xcd\xdf\xf2\x9f\x82\xd8\x21\x58\x10\xaf\x1e\x1a",
- 30,
- },
- {
- NULL,
- }
- }
- },
-
- {
- /* one block, with header */
- "-----BEGIN BLOCK1-----\n"
- "Header1: value1 \n"
- " Header2: value2\n"
- "\n"
- "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
- "-----END BLOCK1-----",
- {
- {
- "BLOCK1",
- "\x69\x83\x4d\x5e\xab\x21\x95\x5c\x42\x76\x8f\x10\x7c\xa7\x97\x87"
- "\x71\x94\xcd\xdf\xf2\x9f\x82\xd8\x21\x58\x10\xaf\x1e\x1a",
- 30,
- },
- {
- NULL,
- }
- }
- },
-
- {
- /* two blocks, junk data */
- "-----BEGIN BLOCK1-----\n"
- "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
- "-----END BLOCK1-----\n"
- "blah blah\n"
- "-----BEGIN TWO-----\n"
- "oy5L157C671HyJMCf9FiK9prvPZfSch6V4EoUfylFoI1Bq6SbL53kg==\n"
- "-----END TWO-----\n"
- "trailing data",
- {
- {
- "BLOCK1",
- "\x69\x83\x4d\x5e\xab\x21\x95\x5c\x42\x76\x8f\x10\x7c\xa7\x97\x87"
- "\x71\x94\xcd\xdf\xf2\x9f\x82\xd8\x21\x58\x10\xaf\x1e\x1a",
- 30,
- },
- {
- "TWO",
- "\xa3\x2e\x4b\xd7\x9e\xc2\xeb\xbd\x47\xc8\x93\x02\x7f\xd1\x62\x2b"
- "\xda\x6b\xbc\xf6\x5f\x49\xc8\x7a\x57\x81\x28\x51\xfc\xa5\x16\x82"
- "\x35\x06\xae\x92\x6c\xbe\x77\x92",
- 40
- },
- {
- NULL,
- }
- }
- },
-
- {
- NULL,
- }
-};
-
-typedef struct {
- int input_index;
- int output_index;
- int parsed;
-} Closure;
-
-static void
-on_parse_pem_success (const char *type,
- const unsigned char *contents,
- size_t length,
- void *user_data)
-{
- Closure *cl = user_data;
-
- assert_num_eq (success_fixtures[cl->input_index].output[cl->output_index].length, length);
- assert (memcmp (success_fixtures[cl->input_index].output[cl->output_index].data, contents,
- success_fixtures[cl->input_index].output[cl->output_index].length) == 0);
-
- cl->output_index++;
- cl->parsed++;
-}
-
-static void
-test_pem_success (void)
-{
- Closure cl;
- int ret;
- int i;
- int j;
-
- for (i = 0; success_fixtures[i].input != NULL; i++) {
- cl.input_index = i;
- cl.output_index = 0;
- cl.parsed = 0;
-
- ret = p11_pem_parse (success_fixtures[i].input, strlen (success_fixtures[i].input),
- on_parse_pem_success, &cl);
-
- assert (success_fixtures[i].output[cl.output_index].type == NULL);
-
- /* Count number of outputs, return from p11_pem_parse() should match */
- for (j = 0; success_fixtures[i].output[j].type != NULL; j++);
- assert_num_eq (j, ret);
- assert_num_eq (ret, cl.parsed);
- }
-}
-
-const char *failure_fixtures[] = {
- /* too short at end of opening line */
- "-----BEGIN BLOCK1---\n"
- "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
- "-----END BLOCK1-----",
-
- /* truncated */
- "-----BEGIN BLOCK1---",
-
- /* no ending */
- "-----BEGIN BLOCK1-----\n"
- "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n",
-
- /* wrong ending */
- "-----BEGIN BLOCK1-----\n"
- "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
- "-----END BLOCK2-----",
-
- /* wrong ending */
- "-----BEGIN BLOCK1-----\n"
- "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
- "-----END INVALID-----",
-
- /* too short at end of ending line */
- "-----BEGIN BLOCK1-----\n"
- "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
- "-----END BLOCK1---",
-
- /* invalid base64 data */
- "-----BEGIN BLOCK1-----\n"
- "!!!!NNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
- "-----END BLOCK1-----",
-
- NULL,
-};
-
-static void
-on_parse_pem_failure (const char *type,
- const unsigned char *contents,
- size_t length,
- void *user_data)
-{
- assert (false && "not reached");
-}
-
-static void
-test_pem_failure (void)
-{
- int ret;
- int i;
-
- for (i = 0; failure_fixtures[i] != NULL; i++) {
- ret = p11_pem_parse (failure_fixtures[i], strlen (failure_fixtures[i]),
- on_parse_pem_failure, NULL);
- assert_num_eq (0, ret);
- }
-}
-
-typedef struct {
- const char *input;
- size_t length;
- const char *type;
- const char *output;
-} WriteFixture;
-
-static WriteFixture write_fixtures[] = {
- {
- "\x69\x83\x4d\x5e\xab\x21\x95\x5c\x42\x76\x8f\x10\x7c\xa7\x97\x87"
- "\x71\x94\xcd\xdf\xf2\x9f\x82\xd8\x21\x58\x10\xaf\x1e\x1a",
- 30, "BLOCK1",
- "-----BEGIN BLOCK1-----\n"
- "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrx4a\n"
- "-----END BLOCK1-----\n",
- },
- {
- "\x50\x31\x31\x2d\x4b\x49\x54\x0a\x0a\x50\x72\x6f\x76\x69\x64\x65"
- "\x73\x20\x61\x20\x77\x61\x79\x20\x74\x6f\x20\x6c\x6f\x61\x64\x20"
- "\x61\x6e\x64\x20\x65\x6e\x75\x6d\x65\x72\x61\x74\x65\x20\x50\x4b"
- "\x43\x53\x23\x31\x31\x20\x6d\x6f\x64\x75\x6c\x65\x73\x2e\x20\x50"
- "\x72\x6f\x76\x69\x64\x65\x73\x20\x61\x20\x73\x74\x61\x6e\x64\x61"
- "\x72\x64\x0a\x63\x6f\x6e\x66\x69\x67\x75\x72\x61\x74\x69\x6f\x6e"
- "\x20\x73\x65\x74\x75\x70\x20\x66\x6f\x72\x20\x69\x6e\x73\x74\x61"
- "\x6c\x6c\x69\x6e\x67\x20\x50\x4b\x43\x53\x23\x31\x31\x20\x6d\x6f"
- "\x64\x75\x6c\x65\x73\x20\x69\x6e\x20\x73\x75\x63\x68\x20\x61\x20"
- "\x77\x61\x79\x20\x74\x68\x61\x74\x20\x74\x68\x65\x79\x27\x72\x65"
- "\x0a\x64\x69\x73\x63\x6f\x76\x65\x72\x61\x62\x6c\x65\x2e\x0a\x0a"
- "\x41\x6c\x73\x6f\x20\x73\x6f\x6c\x76\x65\x73\x20\x70\x72\x6f\x62"
- "\x6c\x65\x6d\x73\x20\x77\x69\x74\x68\x20\x63\x6f\x6f\x72\x64\x69"
- "\x6e\x61\x74\x69\x6e\x67\x20\x74\x68\x65\x20\x75\x73\x65\x20\x6f"
- "\x66\x20\x50\x4b\x43\x53\x23\x31\x31\x20\x62\x79\x20\x64\x69\x66"
- "\x66\x65\x72\x65\x6e\x74\x0a\x63\x6f\x6d\x70\x6f\x6e\x65\x6e\x74"
- "\x73\x20\x6f\x72\x20\x6c\x69\x62\x72\x61\x72\x69\x65\x73\x20\x6c"
- "\x69\x76\x69\x6e\x67\x20\x69\x6e\x20\x74\x68\x65\x20\x73\x61\x6d"
- "\x65\x20\x70\x72\x6f\x63\x65\x73\x73\x2e\x0a",
- 299, "LONG TYPE WITH SPACES",
- "-----BEGIN LONG TYPE WITH SPACES-----\n"
- "UDExLUtJVAoKUHJvdmlkZXMgYSB3YXkgdG8gbG9hZCBhbmQgZW51bWVyYXRlIFBL\n"
- "Q1MjMTEgbW9kdWxlcy4gUHJvdmlkZXMgYSBzdGFuZGFyZApjb25maWd1cmF0aW9u\n"
- "IHNldHVwIGZvciBpbnN0YWxsaW5nIFBLQ1MjMTEgbW9kdWxlcyBpbiBzdWNoIGEg\n"
- "d2F5IHRoYXQgdGhleSdyZQpkaXNjb3ZlcmFibGUuCgpBbHNvIHNvbHZlcyBwcm9i\n"
- "bGVtcyB3aXRoIGNvb3JkaW5hdGluZyB0aGUgdXNlIG9mIFBLQ1MjMTEgYnkgZGlm\n"
- "ZmVyZW50CmNvbXBvbmVudHMgb3IgbGlicmFyaWVzIGxpdmluZyBpbiB0aGUgc2Ft\n"
- "ZSBwcm9jZXNzLgo=\n"
- "-----END LONG TYPE WITH SPACES-----\n"
- },
- {
- "\x69\x83\x4d\x5e\xab\x21\x95\x5c\x42\x76\x8f\x10\x7c\xa7\x97\x87"
- "\x71\x94\xcd\xdf\xf2\x9f\x82\xd8\x21\x58\x10\xaf",
- 28, "BLOCK1",
- "-----BEGIN BLOCK1-----\n"
- "aYNNXqshlVxCdo8QfKeXh3GUzd/yn4LYIVgQrw==\n"
- "-----END BLOCK1-----\n",
- },
- {
- NULL,
- }
-};
-
-static void
-on_parse_written (const char *type,
- const unsigned char *contents,
- size_t length,
- void *user_data)
-{
- WriteFixture *fixture = user_data;
-
- assert_str_eq (fixture->type, type);
- assert_num_eq (fixture->length, length);
- assert (memcmp (contents, fixture->input, length) == 0);
-}
-
-static void
-test_pem_write (void)
-{
- WriteFixture *fixture;
- p11_buffer buf;
- unsigned int count;
- int i;
-
- for (i = 0; write_fixtures[i].input != NULL; i++) {
- fixture = write_fixtures + i;
-
- if (!p11_buffer_init_null (&buf, 0))
- assert_not_reached ();
-
- if (!p11_pem_write ((unsigned char *)fixture->input,
- fixture->length,
- fixture->type, &buf))
- assert_not_reached ();
- assert_str_eq (fixture->output, buf.data);
- assert_num_eq (strlen (fixture->output), buf.len);
-
- count = p11_pem_parse (buf.data, buf.len, on_parse_written, fixture);
- assert_num_eq (1, count);
-
- p11_buffer_uninit (&buf);
- }
-}
-
-int
-main (int argc,
- char *argv[])
-{
- p11_test (test_pem_success, "/pem/success");
- p11_test (test_pem_failure, "/pem/failure");
- p11_test (test_pem_write, "/pem/write");
- return p11_test_run (argc, argv);
-}
diff --git a/common/tests/test-utf8.c b/common/tests/test-utf8.c
deleted file mode 100644
index 9b2c3d5..0000000
--- a/common/tests/test-utf8.c
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- * Copyright (c) 2013, Red Hat Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@collabora.co.uk>
- */
-
-#include "config.h"
-#include "test.h"
-
-#include "utf8.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#define ELEMS(x) (sizeof (x) / sizeof (x[0]))
-
-static void
-test_ucs2be (void)
-{
- char *output;
- size_t length;
- int i;
-
- struct {
- const char *output;
- size_t output_len;
- const unsigned char input[100];
- size_t input_len;
- } fixtures[] = {
- { "This is a test", 14,
- { 0x00, 'T', 0x00, 'h', 0x00, 'i', 0x00, 's', 0x00, ' ', 0x00, 'i', 0x00, 's', 0x00, ' ',
- 0x00, 'a', 0x00, ' ', 0x00, 't', 0x00, 'e', 0x00, 's', 0x00, 't' }, 28,
- },
- { "V\303\266gel", 6,
- { 0x00, 'V', 0x00, 0xF6, 0x00, 'g', 0x00, 'e', 0x00, 'l' }, 10,
- },
- { "M\303\244nwich \340\264\205", 12,
- { 0x00, 'M', 0x00, 0xE4, 0x00, 'n', 0x00, 'w', 0x00, 'i', 0x00, 'c', 0x00, 'h',
- 0x00, ' ', 0x0D, 0x05 }, 18,
- }
- };
-
- for (i = 0; i < ELEMS (fixtures); i++) {
- output = p11_utf8_for_ucs2be (fixtures[i].input,
- fixtures[i].input_len,
- &length);
-
- assert_num_eq (fixtures[i].output_len, length);
- assert_str_eq (fixtures[i].output, output);
- free (output);
- }
-}
-
-static void
-test_ucs2be_fail (void)
-{
- char *output;
- size_t length;
- int i;
-
- struct {
- const unsigned char input[100];
- size_t input_len;
- } fixtures[] = {
- { { 0x00, 'T', 0x00, 'h', 0x00, 'i', 0x00, }, 7 /* truncated */ }
- };
-
- for (i = 0; i < ELEMS (fixtures); i++) {
- output = p11_utf8_for_ucs2be (fixtures[i].input,
- fixtures[i].input_len,
- &length);
- assert_ptr_eq (NULL, output);
- }
-}
-
-static void
-test_ucs4be (void)
-{
- char *output;
- size_t length;
- int i;
-
- struct {
- const char *output;
- size_t output_len;
- const unsigned char input[100];
- size_t input_len;
- } fixtures[] = {
- { "This is a test", 14,
- { 0x00, 0x00, 0x00, 'T',
- 0x00, 0x00, 0x00, 'h',
- 0x00, 0x00, 0x00, 'i',
- 0x00, 0x00, 0x00, 's',
- 0x00, 0x00, 0x00, ' ',
- 0x00, 0x00, 0x00, 'i',
- 0x00, 0x00, 0x00, 's',
- 0x00, 0x00, 0x00, ' ',
- 0x00, 0x00, 0x00, 'a',
- 0x00, 0x00, 0x00, ' ',
- 0x00, 0x00, 0x00, 't',
- 0x00, 0x00, 0x00, 'e',
- 0x00, 0x00, 0x00, 's',
- 0x00, 0x00, 0x00, 't',
- }, 56,
- },
- { "Fun \360\220\214\231", 8,
- { 0x00, 0x00, 0x00, 'F',
- 0x00, 0x00, 0x00, 'u',
- 0x00, 0x00, 0x00, 'n',
- 0x00, 0x00, 0x00, ' ',
- 0x00, 0x01, 0x03, 0x19, /* U+10319: looks like an antenna */
- }, 20,
- }
- };
-
- for (i = 0; i < ELEMS (fixtures); i++) {
- output = p11_utf8_for_ucs4be (fixtures[i].input,
- fixtures[i].input_len,
- &length);
-
- assert_num_eq (fixtures[i].output_len, length);
- assert_str_eq (fixtures[i].output, output);
-
- free (output);
- }
-}
-
-static void
-test_ucs4be_fail (void)
-{
- char *output;
- size_t length;
- int i;
-
- struct {
- const unsigned char input[100];
- size_t input_len;
- } fixtures[] = {
- { { 0x00, 0x00, 'T',
- }, 7 /* truncated */ },
- { { 0x00, 0x00, 0x00, 'F',
- 0x00, 0x00, 0x00, 'u',
- 0x00, 0x00, 0x00, 'n',
- 0x00, 0x00, 0x00, ' ',
- 0xD8, 0x00, 0xDF, 0x19,
- }, 20,
- }
- };
-
- for (i = 0; i < ELEMS (fixtures); i++) {
- output = p11_utf8_for_ucs4be (fixtures[i].input,
- fixtures[i].input_len,
- &length);
- assert_ptr_eq (NULL, output);
- }
-}
-
-static void
-test_utf8 (void)
-{
- bool ret;
- int i;
-
- struct {
- const char *input;
- size_t input_len;
- } fixtures[] = {
- { "This is a test", 14 },
- { "Good news everyone", -1 },
- { "Fun \360\220\214\231", -1 },
- { "Fun invalid here: \xfe", 4 }, /* but limited length */
- { "V\303\266gel", 6, },
- };
-
- for (i = 0; i < ELEMS (fixtures); i++) {
- ret = p11_utf8_validate (fixtures[i].input,
- fixtures[i].input_len);
- assert_num_eq (true, ret);
- }
-}
-
-static void
-test_utf8_fail (void)
-{
- bool ret;
- int i;
-
- struct {
- const char *input;
- size_t input_len;
- } fixtures[] = {
- { "This is a test\x80", 15 },
- { "Good news everyone\x88", -1 },
- { "Bad \xe0v following chars should be |0x80", -1 },
- { "Truncated \xe0", -1 },
- };
-
- for (i = 0; i < ELEMS (fixtures); i++) {
- ret = p11_utf8_validate (fixtures[i].input,
- fixtures[i].input_len);
- assert_num_eq (false, ret);
- }
-}
-
-int
-main (int argc,
- char *argv[])
-{
- p11_test (test_ucs2be, "/utf8/ucs2be");
- p11_test (test_ucs2be_fail, "/utf8/ucs2be_fail");
- p11_test (test_ucs4be, "/utf8/ucs4be");
- p11_test (test_ucs4be_fail, "/utf8/ucs4be_fail");
- p11_test (test_utf8, "/utf8/utf8");
- p11_test (test_utf8_fail, "/utf8/utf8_fail");
- return p11_test_run (argc, argv);
-}
diff --git a/common/tests/test-x509.c b/common/tests/test-x509.c
deleted file mode 100644
index 9f7d258..0000000
--- a/common/tests/test-x509.c
+++ /dev/null
@@ -1,416 +0,0 @@
-/*
- * Copyright (c) 2012 Red Hat Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * * Redistributions of source code must retain the above
- * copyright notice, this list of conditions and the
- * following disclaimer.
- * * Redistributions in binary form must reproduce the
- * above copyright notice, this list of conditions and
- * the following disclaimer in the documentation and/or
- * other materials provided with the distribution.
- * * The names of contributors to this software may not be
- * used to endorse or promote products derived from this
- * software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
- * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
- * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
- * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
- * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
- * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
- * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
- * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
- * DAMAGE.
- *
- * Author: Stef Walter <stefw@gnome.org>
- */
-
-#include "config.h"
-#include "test.h"
-
-#include "asn1.h"
-#include "debug.h"
-#include "oid.h"
-#include "x509.h"
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#define ELEMS(x) (sizeof (x) / sizeof (x[0]))
-
-struct {
- p11_dict *asn1_defs;
-} test;
-
-static void
-setup (void *unused)
-{
- test.asn1_defs = p11_asn1_defs_load ();
- assert_ptr_not_null (test.asn1_defs);
-}
-
-static void
-teardown (void *unused)
-{
- p11_dict_free (test.asn1_defs);
- memset (&test, 0, sizeof (test));
-}
-
-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,
-};
-
-static const unsigned char test_cacert3_ca_der[] = {
- 0x30, 0x82, 0x07, 0x59, 0x30, 0x82, 0x05, 0x41, 0xa0, 0x03, 0x02, 0x01, 0x02, 0x02, 0x03, 0x0a,
- 0x41, 0x8a, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05,
- 0x00, 0x30, 0x79, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x07, 0x52, 0x6f,
- 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x15,
- 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x63, 0x61, 0x63, 0x65, 0x72,
- 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x22, 0x30, 0x20, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x19,
- 0x43, 0x41, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x53, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x20,
- 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x31, 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2a,
- 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x12, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72,
- 0x74, 0x40, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x30, 0x1e, 0x17, 0x0d,
- 0x31, 0x31, 0x30, 0x35, 0x32, 0x33, 0x31, 0x37, 0x34, 0x38, 0x30, 0x32, 0x5a, 0x17, 0x0d, 0x32,
- 0x31, 0x30, 0x35, 0x32, 0x30, 0x31, 0x37, 0x34, 0x38, 0x30, 0x32, 0x5a, 0x30, 0x54, 0x31, 0x14,
- 0x30, 0x12, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x13, 0x0b, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x20,
- 0x49, 0x6e, 0x63, 0x2e, 0x31, 0x1e, 0x30, 0x1c, 0x06, 0x03, 0x55, 0x04, 0x0b, 0x13, 0x15, 0x68,
- 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74,
- 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x1c, 0x30, 0x1a, 0x06, 0x03, 0x55, 0x04, 0x03, 0x13, 0x13, 0x43,
- 0x41, 0x63, 0x65, 0x72, 0x74, 0x20, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x20, 0x33, 0x20, 0x52, 0x6f,
- 0x6f, 0x74, 0x30, 0x82, 0x02, 0x22, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
- 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x02, 0x0f, 0x00, 0x30, 0x82, 0x02, 0x0a, 0x02, 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c,
- 0x88, 0x13, 0xf0, 0x78, 0xd9, 0x89, 0x77, 0xb5, 0x6d, 0xc5, 0x89, 0xdf, 0xbc, 0xb1, 0x7a, 0x30,
- 0x81, 0xa3, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04, 0x81, 0x9b, 0x30, 0x81, 0x98, 0x80, 0x14, 0x16,
- 0xb5, 0x32, 0x1b, 0xd4, 0xc7, 0xf3, 0xe0, 0xe6, 0x8e, 0xf3, 0xbd, 0xd2, 0xb0, 0x3a, 0xee, 0xb2,
- 0x39, 0x18, 0xd1, 0xa1, 0x7d, 0xa4, 0x7b, 0x30, 0x79, 0x31, 0x10, 0x30, 0x0e, 0x06, 0x03, 0x55,
- 0x04, 0x0a, 0x13, 0x07, 0x52, 0x6f, 0x6f, 0x74, 0x20, 0x43, 0x41, 0x31, 0x1e, 0x30, 0x1c, 0x06,
- 0x03, 0x55, 0x04, 0x0b, 0x13, 0x15, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77,
- 0x2e, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x31, 0x22, 0x30, 0x20, 0x06,
- 0x03, 0x55, 0x04, 0x03, 0x13, 0x19, 0x43, 0x41, 0x20, 0x43, 0x65, 0x72, 0x74, 0x20, 0x53, 0x69,
- 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x20, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x31,
- 0x21, 0x30, 0x1f, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x01, 0x16, 0x12,
- 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x40, 0x63, 0x61, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f,
- 0x72, 0x67, 0x82, 0x01, 0x00, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01, 0x01, 0xff, 0x04,
- 0x05, 0x30, 0x03, 0x01, 0x01, 0xff, 0x30, 0x5d, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07,
- 0x01, 0x01, 0x04, 0x51, 0x30, 0x4f, 0x30, 0x23, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07,
- 0x30, 0x01, 0x86, 0x17, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x6f, 0x63, 0x73, 0x70, 0x2e,
- 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x30, 0x28, 0x06, 0x08, 0x2b,
- 0x06, 0x01, 0x05, 0x05, 0x07, 0x30, 0x02, 0x86, 0x1c, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f,
- 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x63,
- 0x61, 0x2e, 0x63, 0x72, 0x74, 0x30, 0x4a, 0x06, 0x03, 0x55, 0x1d, 0x20, 0x04, 0x43, 0x30, 0x41,
- 0x30, 0x3f, 0x06, 0x08, 0x2b, 0x06, 0x01, 0x04, 0x01, 0x81, 0x90, 0x4a, 0x30, 0x33, 0x30, 0x31,
- 0x06, 0x08, 0x2b, 0x06, 0x01, 0x05, 0x05, 0x07, 0x02, 0x01, 0x16, 0x25, 0x68, 0x74, 0x74, 0x70,
- 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72,
- 0x67, 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x70, 0x68, 0x70, 0x3f, 0x69, 0x64, 0x3d, 0x31,
- 0x30, 0x30, 0x34, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x86, 0xf8, 0x42, 0x01, 0x08, 0x04, 0x27,
- 0x16, 0x25, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43, 0x41, 0x63,
- 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x69, 0x6e, 0x64, 0x65, 0x78, 0x2e, 0x70, 0x68,
- 0x70, 0x3f, 0x69, 0x64, 0x3d, 0x31, 0x30, 0x30, 0x50, 0x06, 0x09, 0x60, 0x86, 0x48, 0x01, 0x86,
- 0xf8, 0x42, 0x01, 0x0d, 0x04, 0x43, 0x16, 0x41, 0x54, 0x6f, 0x20, 0x67, 0x65, 0x74, 0x20, 0x79,
- 0x6f, 0x75, 0x72, 0x20, 0x6f, 0x77, 0x6e, 0x20, 0x63, 0x65, 0x72, 0x74, 0x69, 0x66, 0x69, 0x63,
- 0x61, 0x74, 0x65, 0x20, 0x66, 0x6f, 0x72, 0x20, 0x46, 0x52, 0x45, 0x45, 0x2c, 0x20, 0x67, 0x6f,
- 0x20, 0x74, 0x6f, 0x20, 0x68, 0x74, 0x74, 0x70, 0x3a, 0x2f, 0x2f, 0x77, 0x77, 0x77, 0x2e, 0x43,
- 0x41, 0x63, 0x65, 0x72, 0x74, 0x2e, 0x6f, 0x72, 0x67, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
- 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x02, 0x01, 0x00, 0x29, 0x28, 0x85,
- 0xae, 0x44, 0xa9, 0xb9, 0xaf, 0xa4, 0x79, 0x13, 0xf0, 0xa8, 0xa3, 0x2b, 0x97, 0x60, 0xf3, 0x5c,
- 0xee, 0xe3, 0x2f, 0xc1, 0xf6, 0xe2, 0x66, 0xa0, 0x11, 0xae, 0x36, 0x37, 0x3a, 0x76, 0x15, 0x04,
- 0x53, 0xea, 0x42, 0xf5, 0xf9, 0xea, 0xc0, 0x15, 0xd8, 0xa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x79, 0xb2, 0x52, 0xa0, 0xc6, 0xf1, 0x85, 0xb4, 0x25, 0x8c, 0xf2, 0x3f, 0x96, 0xb3, 0x10, 0xd9,
- 0x8d, 0x6c, 0x57, 0x3b, 0x9f, 0x6f, 0x86, 0x3a, 0x18, 0x82, 0x22, 0x36, 0xc8, 0xb0, 0x91, 0x38,
- 0xdb, 0x2a, 0xa1, 0x93, 0xaa, 0x84, 0x3f, 0xf5, 0x27, 0x65, 0xae, 0x73, 0xd5, 0xc8, 0xd5, 0xd3,
- 0x77, 0xea, 0x4b, 0x9d, 0xc7, 0x41, 0xbb, 0xc7, 0xc0, 0xe3, 0xa0, 0x3f, 0xe4, 0x7d, 0xa4, 0x8d,
- 0x73, 0xe6, 0x12, 0x4b, 0xdf, 0xa1, 0x73, 0x73, 0x73, 0x3a, 0x80, 0xe8, 0xd5, 0xcb, 0x8e, 0x2f,
- 0xcb, 0xea, 0x13, 0xa7, 0xd6, 0x41, 0x8b, 0xac, 0xfa, 0x3c, 0x89, 0xd7, 0x24, 0xf5, 0x4e, 0xb4,
- 0xe0, 0x61, 0x92, 0xb7, 0xf3, 0x37, 0x98, 0xc4, 0xbe, 0x96, 0xa3, 0xb7, 0x8a,
-};
-
-struct {
- const char *eku;
- size_t length;
- const char *expected[16];
-} extended_key_usage_fixtures[] = {
- { test_eku_server_and_client, sizeof (test_eku_server_and_client),
- { P11_OID_SERVER_AUTH_STR, P11_OID_CLIENT_AUTH_STR, 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_STR, P11_OID_EMAIL_PROTECTION_STR, P11_OID_TIME_STAMPING_STR }, },
- { NULL },
-};
-
-static void
-test_parse_extended_key_usage (void)
-{
- p11_array *ekus;
- int i, j, count;
-
- for (i = 0; extended_key_usage_fixtures[i].eku != NULL; i++) {
- ekus = p11_x509_parse_extended_key_usage (test.asn1_defs,
- (const unsigned char *)extended_key_usage_fixtures[i].eku,
- extended_key_usage_fixtures[i].length);
- assert_ptr_not_null (ekus);
-
- for (count = 0; extended_key_usage_fixtures[i].expected[count] != NULL; count++);
-
- assert_num_eq (count, ekus->num);
- for (j = 0; j < count; j++)
- assert_str_eq (ekus->elem[j], extended_key_usage_fixtures[i].expected[j]);
-
- p11_array_free (ekus);
- }
-}
-
-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 (void)
-{
- unsigned int ku;
- int i;
- bool ret;
-
- for (i = 0; key_usage_fixtures[i].ku != NULL; i++) {
- ku = 0;
-
- ret = p11_x509_parse_key_usage (test.asn1_defs,
- (const unsigned char *)key_usage_fixtures[i].ku,
- key_usage_fixtures[i].length, &ku);
- assert_num_eq (true, ret);
-
- assert_num_eq (key_usage_fixtures[i].expected, ku);
- }
-}
-
-static void
-test_parse_extension (void)
-{
- node_asn *cert;
- unsigned char *ext;
- size_t length;
- bool is_ca;
-
- cert = p11_asn1_decode (test.asn1_defs, "PKIX1.Certificate",
- test_cacert3_ca_der, sizeof (test_cacert3_ca_der), NULL);
- assert_ptr_not_null (cert);
-
- ext = p11_x509_find_extension (cert, P11_OID_BASIC_CONSTRAINTS,
- test_cacert3_ca_der, sizeof (test_cacert3_ca_der),
- &length);
- assert_ptr_not_null (ext);
- assert (length > 0);
-
- asn1_delete_structure (&cert);
-
- if (!p11_x509_parse_basic_constraints (test.asn1_defs, ext, length, &is_ca))
- assert_fail ("failed to parse message", "basic constraints");
-
- free (ext);
-}
-static void
-test_parse_extension_not_found (void)
-{
- node_asn *cert;
- unsigned char *ext;
- size_t length;
-
- cert = p11_asn1_decode (test.asn1_defs, "PKIX1.Certificate",
- test_cacert3_ca_der, sizeof (test_cacert3_ca_der), NULL);
- assert_ptr_not_null (cert);
-
- ext = p11_x509_find_extension (cert, P11_OID_OPENSSL_REJECT,
- test_cacert3_ca_der, sizeof (test_cacert3_ca_der),
- &length);
- assert_ptr_eq (NULL, ext);
-
- asn1_delete_structure (&cert);
-}
-
-static void
-test_directory_string (void)
-{
- struct {
- unsigned char input[100];
- int input_len;
- char *output;
- int output_len;
- } fixtures[] = {
- /* UTF8String */
- { { 0x0c, 0x0f, 0xc3, 0x84, ' ', 'U', 'T', 'F', '8', ' ', 's', 't', 'r', 'i', 'n', 'g', ' ', }, 17,
- "\xc3\x84 UTF8 string ", 15,
- },
-
- /* NumericString */
- { { 0x12, 0x04, '0', '1', '2', '3', }, 6,
- "0123", 4,
- },
-
- /* IA5String */
- { { 0x16, 0x04, ' ', 'A', 'B', ' ', }, 6,
- " AB ", 4
- },
-
- /* TeletexString */
- { { 0x14, 0x07, 'A', ' ', ' ', 'n', 'i', 'c', 'e' }, 9,
- "A nice", 7
- },
-
- /* PrintableString */
- { { 0x13, 0x07, 'A', ' ', ' ', 'n', 'i', 'c', 'e' }, 9,
- "A nice", 7,
- },
-
- /* UniversalString */
- { { 0x1c, 0x14, 0x00, 0x00, 0x00, 'F', 0x00, 0x00, 0x00, 'u',
- 0x00, 0x00, 0x00, 'n', 0x00, 0x00, 0x00, ' ', 0x00, 0x01, 0x03, 0x19, }, 22,
- "Fun \xf0\x90\x8c\x99", 8
- },
-
- /* BMPString */
- { { 0x1e, 0x0a, 0x00, 'V', 0x00, 0xF6, 0x00, 'g', 0x00, 'e', 0x00, 'l' }, 12,
- "V\xc3\xb6gel", 6
- },
- };
-
- char *string;
- bool unknown;
- size_t length;
- int i;
-
- for (i = 0; i < ELEMS (fixtures); i++) {
- string = p11_x509_parse_directory_string (fixtures[i].input,
- fixtures[i].input_len,
- &unknown, &length);
- assert_ptr_not_null (string);
- assert_num_eq (false, unknown);
-
- assert_num_eq (fixtures[i].output_len, length);
- assert_str_eq (fixtures[i].output, string);
- free (string);
- }
-}
-
-static void
-test_directory_string_unknown (void)
-{
- /* Not a valid choice in DirectoryString */
- unsigned char input[] = { 0x05, 0x07, 'A', ' ', ' ', 'n', 'i', 'c', 'e' };
- char *string;
- bool unknown = false;
- size_t length;
-
- string = p11_x509_parse_directory_string (input, sizeof (input), &unknown, &length);
- assert_ptr_eq (NULL, string);
- assert_num_eq (true, unknown);
-}
-
-int
-main (int argc,
- char *argv[])
-{
- p11_fixture (setup, teardown);
- p11_test (test_parse_extended_key_usage, "/x509/parse-extended-key-usage");
- p11_test (test_parse_key_usage, "/x509/parse-key-usage");
- p11_test (test_parse_extension, "/x509/parse-extension");
- p11_test (test_parse_extension_not_found, "/x509/parse-extension-not-found");
-
- p11_fixture (NULL, NULL);
- p11_test (test_directory_string, "/x509/directory-string");
- p11_test (test_directory_string_unknown, "/x509/directory-string-unknown");
- return p11_test_run (argc, argv);
-}