[gnome-keyring: 3/6] gcr: Add tests for creation of fingerprints
- From: Stefan Walter <stefw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-keyring: 3/6] gcr: Add tests for creation of fingerprints
- Date: Tue, 24 May 2011 07:38:10 +0000 (UTC)
commit 28552e70b824a6c1327882291dc6e61fdaf5447e
Author: Stef Walter <stefw collabora co uk>
Date: Fri Apr 8 22:17:56 2011 +0200
gcr: Add tests for creation of fingerprints
.gitignore | 1 +
gcr/tests/Makefile.am | 1 +
gcr/tests/files/client.crt | 18 ++++
gcr/tests/files/client.key | 27 ++++++
gcr/tests/files/generic-dsa.crt | 22 +++++
gcr/tests/files/generic-dsa.key | 12 +++
gcr/tests/test-fingerprint.c | 181 +++++++++++++++++++++++++++++++++++++++
7 files changed, 262 insertions(+), 0 deletions(-)
---
diff --git a/.gitignore b/.gitignore
index f552444..b5dc3b8 100644
--- a/.gitignore
+++ b/.gitignore
@@ -119,6 +119,7 @@ run-tests
/gcr/tests/test-certificate
/gcr/tests/test-certificate-chain
/gcr/tests/test-colons
+/gcr/tests/test-fingerprint
/gcr/tests/test-gnupg-collection
/gcr/tests/test-gnupg-key
/gcr/tests/test-parser
diff --git a/gcr/tests/Makefile.am b/gcr/tests/Makefile.am
index e01cd15..eb63002 100644
--- a/gcr/tests/Makefile.am
+++ b/gcr/tests/Makefile.am
@@ -24,6 +24,7 @@ TEST_PROGS = \
test-simple-certificate \
test-certificate \
test-certificate-chain \
+ test-fingerprint \
test-pkcs11-certificate \
test-trust \
test-parser \
diff --git a/gcr/tests/files/client.crt b/gcr/tests/files/client.crt
new file mode 100644
index 0000000..04bc8ac
--- /dev/null
+++ b/gcr/tests/files/client.crt
@@ -0,0 +1,18 @@
+-----BEGIN CERTIFICATE-----
+MIIC3DCCAkUCAQkwDQYJKoZIhvcNAQEFBQAwgYYxEzARBgoJkiaJk/IsZAEZFgND
+T00xFzAVBgoJkiaJk/IsZAEZFgdFWEFNUExFMR4wHAYDVQQLExVDZXJ0aWZpY2F0
+ZSBBdXRob3JpdHkxFzAVBgNVBAMTDmNhLmV4YW1wbGUuY29tMR0wGwYJKoZIhvcN
+AQkBFg5jYUBleGFtcGxlLmNvbTAeFw0xMTAxMTgwNjA0MTFaFw0yMTAxMTUwNjA0
+MTFaMGIxEzARBgoJkiaJk/IsZAEZFgNDT00xFzAVBgoJkiaJk/IsZAEZFgdFWEFN
+UExFMQ8wDQYDVQQDEwZDbGllbnQxITAfBgkqhkiG9w0BCQEWEmNsaWVudEBleGFt
+cGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMEgNDM/dg3t
+9DHNAPz/b87LSxEaKhoZ8AcNBym3LEOdCnXGEnKf0b9lkT5caXu5GAM84ahTCJ7n
+79RVNrqGKM7jbBdSX+ZUfkqJQPhOXD2+0niYQicH92nz78kxmjlbizvd3fM1BlO+
+C/++NWf2EAhORVAjvJrHNokJp3PTNRJ1WWteHeU9PwfGmWHKVc1IgvRFMH08604I
+ZzX5CcxIg/b56g27A7CBPh/KO/qKTDLFFNGc1T2asvY/P3+PeN6y+leFHStCTu7R
+Bi/l4hczZdnwq3BGT6mnjEN7wau2s7pA067SXimNOkYi5fgwspMHi8fJWmYyBypU
+mQBRzwfm77ECAwEAATANBgkqhkiG9w0BAQUFAAOBgQA3LuElj2QB9wQvmIxk2Jmb
+IPP2/WS8dwPoCv/N3+6nTx8yRsrILf4QsnEbbsxoYO5jW4r9Kt8m8B/M7YgnBDE9
+zlm7JbXKZf2isSm5TyT627Ymzxrzs5d+7o2eS7SN1DB6PyvRh2ye7EMbyEYD8ULi
+itDUkYkssNCVivYwVvJoMg==
+-----END CERTIFICATE-----
diff --git a/gcr/tests/files/client.key b/gcr/tests/files/client.key
new file mode 100644
index 0000000..206f527
--- /dev/null
+++ b/gcr/tests/files/client.key
@@ -0,0 +1,27 @@
+-----BEGIN RSA PRIVATE KEY-----
+MIIEpQIBAAKCAQEAwSA0Mz92De30Mc0A/P9vzstLERoqGhnw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R
+C/v5W1baHQ2nD6I9omsXYB3sLjydjI+Y1ZT70lptk/4S2JWeYuOVb0GYhYD/LFMf
+hAu4i642V+kuhaTpp7ExOR3S6/ZrngNQSp6TmLFXDKgNY9BkQkEPqN8y971oOMTV
+zSM8QxC6s9q4MM4Q1OYuvjECgYEAsO2V1AW95T45Ukd1FktpFlaomyQlJ0vKgyFO
+unEFV+vhETfpFTY7SzGCHxAXVh1vo62u5Gwayo/a9qQIhepa/IRnJGNv8luyxU1D
+ZPeBQjija0PMkPd1NvNNNuafDuBpoNbX1ev0MqeRZVsN2pAZXE5gbUiNA+8NqEsu
+Yre3EFECgYEA13rXE76zZgsefx+2spjqJDUWEmTDd1460xTtxCCgL9dy4rW5bgwo
+MvINphSUXOwSkn8Oja/IvpN28zSj9W/ci5wU52P5w4blkBmuj8UoCjP2FN1b1OBa
+86mkwVsCYUyyI2apuwrHP77yeb8jXZb+reqSns3hU+HyO/nUTVmnews=
+-----END RSA PRIVATE KEY-----
diff --git a/gcr/tests/files/generic-dsa.crt b/gcr/tests/files/generic-dsa.crt
new file mode 100644
index 0000000..0d81ef2
--- /dev/null
+++ b/gcr/tests/files/generic-dsa.crt
@@ -0,0 +1,22 @@
+-----BEGIN CERTIFICATE-----
+MIIDkjCCAvugAwIBAgIBBDANBgkqhkiG9w0BAQUFADCBhjETMBEGCgmSJomT8ixk
+ARkWA0NPTTEXMBUGCgmSJomT8ixkARkWB0VYQU1QTEUxHjAcBgNVBAsTFUNlcnRp
+ZmljYXRlIEF1dGhvcml0eTEXMBUGA1UEAxMOY2EuZXhhbXBsZS5jb20xHTAbBgkq
+hkiG9w0BCQEWDmNhQGV4YW1wbGUuY29tMB4XDTA3MTIyMDE4NDc0N1oXDTA4MDEx
+OTE4NDc0N1owbDETMBEGCgmSJomT8ixkARkWA0NPTTEXMBUGCgmSJomT8ixkARkW
+B0VYQU1QTEUxFDASBgNVBAMTC0dlbmVyaWMgRFNBMSYwJAYJKoZIhvcNAQkBFhdn
+ZW5lcmljLWRzYUBleGFtcGxlLmNvbTCCAbcwggEsBgcqhkjOOAQBMIIBHwKBgQCd
+LeaVVA8HNMKFr0UUQe/bj6mJvO+I67hxn/KzCWnMjw9h6vtuTI06OI4XXmEHCVdU
+xykTkp1NSaTanoV8seEbJyyUgFQFBVaFOE8xDHp5RZghAKpdXFP2Yn8wj8y2VYSO
+veFKXj9ySj9A38nbG8mF0imBXNg/nL/EPCynR7JBVwIVAM1DKUetENlaaH+QeAO3
+IwcENMSZAoGBAJFujxH2WB5bU+sjjePwBTRev6qtYzPAXPd+srC747afIasS0Q/+
+pE0Q40bjdGNipf3fs5Cq8s0tYTYeNzAqUej1X5YI7TP+uJyRL7QdD06pg1BbdaAz
+SxnnGjf2b25IvPRdxgy1XetgOmT+qA8nXeLROgTLNOQqxG83ymuMi/w7A4GEAAKB
+gH1y5aPJgkIABsu8t9pP9jp7/C1wC+YXEFBDO1kIR5FNkGl4Ie7KpjpeL7zPe2GY
+uSSJUdMIz+/nWYiSZ2EmOTzGhqQCJO4SxrD2yVuk56MwF8Aj5YtV7qHLm76w1o2f
+80nrJzt7IhjwiLj/eyKlWwShkBv7yVMBS9HsG//hVGu/oxAwDjAMBgNVHRMBAf8E
+AjAAMA0GCSqGSIb3DQEBBQUAA4GBAPRyHCHjWKKVHZ7wSJQOS/Ve8e4DWFiuP9J8
+X4/sXEg59yWjScy9EovZVj5iELZI6OqUArvwVV6w6tewK0BAed4UGp+TyTHjPuJG
+WGxBm2AhtZUlYmpHQ+gA+E9weeFNQWP1QOATmFQ+r18eNH0rUONnR3G0XUYQTgd1
+LgEYxM4t
+-----END CERTIFICATE-----
diff --git a/gcr/tests/files/generic-dsa.key b/gcr/tests/files/generic-dsa.key
new file mode 100644
index 0000000..cdd7ca5
--- /dev/null
+++ b/gcr/tests/files/generic-dsa.key
@@ -0,0 +1,12 @@
+-----BEGIN DSA PRIVATE KEY-----
+MIIBuwIBAAKBgQCdLeaVVA8HNMKFr0UUQe/bj6mJvO+I67hxn/KzCWnMjw9h6vtu
+TI06OI4XXmEHCVdUxykTkp1NSaTanoV8seEbJyyUgFQFBVaFOE8xDHp5RZghAKpd
+XFP2Yn8wj8y2VYSOveFKXj9ySj9A38nbG8mF0imBXNg/nL/EPCynR7JBVwIVAM1D
+KUetENlaaH+QeAO3IwcENMSZAoGBAJFujxH2WB5bU+sjjePwBTRev6qtYzPAXPd+
+srC747afIasS0Q/+pE0Q40bjdGNipf3fs5Cq8s0tYTYeNzAqUej1X5YI7TP+uJyR
+L7QdD06pg1BbdaAzSxnnGjf2b25IvPRdxgy1XetgOmT+qA8nXeLROgTLNOQqxG83
+ymuMi/w7AoGAfXLlo8mCQgAGy7y32k/2Onv8LXAL5hcQUEM7WQhHkU2QaXgh7sqm
+Ol4vvM97YZi5JIlR0wjP7+dZiJJnYSY5PMaGpAIk7hLGsPbJW6TnozAXwCPli1Xu
+ocubvrDWjZ/zSesnO3siGPCIuP97IqVbBKGQG/vJUwFL0ewb/+FUa78CFHgQdcw2
+4vVlnuMrqdmrfXMvzbrw
+-----END DSA PRIVATE KEY-----
diff --git a/gcr/tests/test-fingerprint.c b/gcr/tests/test-fingerprint.c
new file mode 100644
index 0000000..c52fc9e
--- /dev/null
+++ b/gcr/tests/test-fingerprint.c
@@ -0,0 +1,181 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/*
+ Copyright (C) 2010 Collabora Ltd
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA.
+
+ Author: Stef Walter <stefw collabora co uk>
+*/
+
+#include "config.h"
+#define GCR_COMPILATION 1
+
+#include "gcr/gcr.h"
+#include "gcr/gcr-internal.h"
+#include "gcr/gcr-fingerprint.h"
+
+#include "gck/gck-test.h"
+
+#include "pkcs11/pkcs11n.h"
+
+#include "egg/egg-asn1x.h"
+#include "egg/egg-asn1-defs.h"
+#include "egg/egg-testing.h"
+
+#include <glib.h>
+
+#include <errno.h>
+
+typedef struct {
+ gpointer cert_rsa;
+ gsize n_cert_rsa;
+ gpointer key_rsa;
+ gsize n_key_rsa;
+ gpointer cert_dsa;
+ gsize n_cert_dsa;
+ gpointer key_dsa;
+ gsize n_key_dsa;
+} Test;
+
+static void
+setup (Test *test, gconstpointer unused)
+{
+ if (!g_file_get_contents ("files/client.crt", (gchar**)&test->cert_rsa,
+ &test->n_cert_rsa, NULL))
+ g_assert_not_reached ();
+ g_assert (test->cert_rsa);
+
+ if (!g_file_get_contents ("files/client.key", (gchar**)&test->key_rsa,
+ &test->n_key_rsa, NULL))
+ g_assert_not_reached ();
+ g_assert (test->key_rsa);
+
+ if (!g_file_get_contents ("files/generic-dsa.crt", (gchar**)&test->key_dsa,
+ &test->n_key_dsa, NULL))
+ g_assert_not_reached ();
+ g_assert (test->key_dsa);
+
+ if (!g_file_get_contents ("files/generic-dsa.key", (gchar**)&test->key_dsa,
+ &test->n_key_dsa, NULL))
+ g_assert_not_reached ();
+ g_assert (test->key_dsa);
+}
+
+static void
+teardown (Test *test, gconstpointer unused)
+{
+ g_free (test->cert_rsa);
+ g_free (test->key_rsa);
+ g_free (test->cert_dsa);
+ g_free (test->key_rsa);
+}
+
+static GckAttributes*
+parse_attributes_for_key (gpointer data, gsize n_data)
+{
+ GcrParser *parser;
+ GckAttributes *attrs;
+ GError *error = NULL;
+
+ parser = gcr_parser_new ();
+ gcr_parser_parse_data (parser, data, n_data, &error);
+ g_assert_no_error (error);
+
+ attrs = gcr_parser_get_parsed_attributes (parser);
+ g_assert (attrs);
+ gck_attributes_ref (attrs);
+
+ g_object_unref (parser);
+ return attrs;
+}
+
+static gconstpointer
+parse_subject_public_key_info_for_cert (gpointer data, gsize n_data, gsize *n_info)
+{
+ gconstpointer info;
+ GNode *asn;
+
+ asn = egg_asn1x_create_and_decode (pkix_asn1_tab, "Certificate", data, n_data);
+ g_assert (asn);
+
+ info = egg_asn1x_get_raw_element (egg_asn1x_node (asn, "tbsCertificate", "subjectPublicKeyInfo", NULL), n_info);
+ g_assert (info);
+
+ egg_asn1x_destroy (asn);
+ return info;
+}
+
+static void
+test_rsa (Test *test, gconstpointer unused)
+{
+ GckAttributes *key;
+ gconstpointer info;
+ gsize n_info;
+ gpointer fingerprint1, fingerprint2;
+ gsize n_fingerprint1, n_fingerprint2;
+
+ key = parse_attributes_for_key (test->key_rsa, test->n_key_rsa);
+ info = parse_subject_public_key_info_for_cert (test->cert_rsa, test->n_cert_rsa, &n_info);
+
+ fingerprint1 = _gcr_fingerprint_from_subject_public_key_info (info, n_info, G_CHECKSUM_SHA1, &n_fingerprint1);
+ fingerprint2 = _gcr_fingerprint_from_attributes (key, G_CHECKSUM_SHA1, &n_fingerprint2);
+
+ egg_assert_cmpmem (fingerprint1, n_fingerprint1, ==, fingerprint2, n_fingerprint2);
+
+ g_free (fingerprint1);
+ g_free (fingerprint2);
+ gck_attributes_unref (key);
+}
+
+static void
+test_dsa (Test *test, gconstpointer unused)
+{
+ GckAttributes *key;
+ gconstpointer info;
+ gsize n_info;
+ gpointer fingerprint1, fingerprint2;
+ gsize n_fingerprint1, n_fingerprint2;
+
+ key = parse_attributes_for_key (test->key_dsa, test->n_key_dsa);
+ info = parse_subject_public_key_info_for_cert (test->cert_dsa, test->n_cert_dsa, &n_info);
+
+ fingerprint1 = _gcr_fingerprint_from_subject_public_key_info (info, n_info, G_CHECKSUM_SHA1, &n_fingerprint1);
+ fingerprint2 = _gcr_fingerprint_from_attributes (key, G_CHECKSUM_SHA1, &n_fingerprint2);
+
+ egg_assert_cmpmem (fingerprint1, n_fingerprint1, ==, fingerprint2, n_fingerprint2);
+
+ g_free (fingerprint1);
+ g_free (fingerprint2);
+ gck_attributes_unref (key);
+}
+
+int
+main (int argc, char **argv)
+{
+ const gchar *srcdir;
+
+ g_type_init ();
+ g_test_init (&argc, &argv, NULL);
+
+ srcdir = g_getenv ("SRCDIR");
+ if (srcdir && chdir (srcdir) < 0)
+ g_error ("couldn't change directory to: %s: %s", srcdir, g_strerror (errno));
+
+ g_test_add ("/gcr/fingerprint/rsa", Test, NULL, setup, test_rsa, teardown);
+ g_test_add ("/gcr/fingerprint/dsa", Test, NULL, setup, test_dsa, teardown);
+
+ return g_test_run ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]