All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Zaborowski <andrew.zaborowski@intel.com>
To: ell@lists.01.org
Subject: [PATCH 6/9] unit: Move tls_cert_load_file to relevant unit tests
Date: Thu, 13 Dec 2018 20:57:43 +0100	[thread overview]
Message-ID: <20181213195746.32144-6-andrew.zaborowski@intel.com> (raw)
In-Reply-To: <20181213195746.32144-1-andrew.zaborowski@intel.com>

[-- Attachment #1: Type: text/plain, Size: 4129 bytes --]

tls_cert_load_file and l_pem_load_certificate have no users other than
the two unit tests and have little to do with TLS.
---
 unit/test-key.c | 26 ++++++++++++++++++++------
 unit/test-tls.c | 28 +++++++++++++++++++++-------
 2 files changed, 41 insertions(+), 13 deletions(-)

diff --git a/unit/test-key.c b/unit/test-key.c
index 53fb394..6b519f5 100644
--- a/unit/test-key.c
+++ b/unit/test-key.c
@@ -392,6 +392,20 @@ static void test_simple_keyring(const void *data)
 	l_key_free(key2);
 }
 
+static struct l_cert *load_cert_file(const char *filename)
+{
+	const uint8_t *der;
+	size_t len;
+	char *label;
+
+	der = l_pem_load_file(filename, 0, &label, &len);
+	if (!der)
+		return NULL;
+
+	l_free(label);
+	return l_cert_new_from_der(der, len);
+}
+
 static void test_trusted_keyring(const void *data)
 {
 	struct l_keyring *ring;
@@ -402,9 +416,9 @@ static void test_trusted_keyring(const void *data)
 	struct l_key *key;
 	bool success;
 
-	cacert = tls_cert_load_file(CERTDIR "cert-ca.pem");
+	cacert = load_cert_file(CERTDIR "cert-ca.pem");
 	assert(cacert);
-	cert = tls_cert_load_file(CERTDIR "cert-server.pem");
+	cert = load_cert_file(CERTDIR "cert-server.pem");
 	assert(cert);
 
 	cakey = l_cert_get_pubkey(cacert);
@@ -447,11 +461,11 @@ static void test_trust_chain(const void *data)
 	struct l_key *key;
 	bool success;
 
-	cacert = tls_cert_load_file(CERTDIR "cert-ca.pem");
+	cacert = load_cert_file(CERTDIR "cert-ca.pem");
 	assert(cacert);
-	intcert = tls_cert_load_file(CERTDIR "cert-intca.pem");
+	intcert = load_cert_file(CERTDIR "cert-intca.pem");
 	assert(intcert);
-	cert = tls_cert_load_file(CERTDIR "cert-entity-int.pem");
+	cert = load_cert_file(CERTDIR "cert-entity-int.pem");
 	assert(cert);
 
 	cakey = l_cert_get_pubkey(cacert);
@@ -543,7 +557,7 @@ static void test_key_crypto(const void *data)
 	int hash = L_CHECKSUM_NONE;
 	int rsa = L_KEY_RSA_PKCS1_V1_5;
 
-	cert = tls_cert_load_file(CERTDIR "cert-client.pem");
+	cert = load_cert_file(CERTDIR "cert-client.pem");
 	assert(cert);
 	pubkey = l_cert_get_pubkey(cert);
 	assert(pubkey);
diff --git a/unit/test-tls.c b/unit/test-tls.c
index f39d95a..2b5d16b 100644
--- a/unit/test-tls.c
+++ b/unit/test-tls.c
@@ -210,6 +210,20 @@ static void test_tls12_prf(const void *data)
 	assert(!memcmp(out_buf, test->expected, test->out_len));
 }
 
+static struct l_cert *load_cert_file(const char *filename)
+{
+	const uint8_t *der;
+	size_t len;
+	char *label;
+
+	der = l_pem_load_file(filename, 0, &label, &len);
+	if (!der)
+		return NULL;
+
+	l_free(label);
+	return l_cert_new_from_der(der, len);
+}
+
 static void test_certificates(const void *data)
 {
 	struct l_queue *cacert;
@@ -246,13 +260,13 @@ static void test_certificates(const void *data)
 	assert(l_certchain_verify(chain2, twocas, NULL));
 
 	chain3 = certchain_new_from_leaf(
-			tls_cert_load_file(CERTDIR "cert-server.pem"));
+			load_cert_file(CERTDIR "cert-server.pem"));
 	certchain_link_issuer(chain3,
-			tls_cert_load_file(CERTDIR "cert-entity-int.pem"));
+			load_cert_file(CERTDIR "cert-entity-int.pem"));
 	certchain_link_issuer(chain3,
-			tls_cert_load_file(CERTDIR "cert-intca.pem"));
+			load_cert_file(CERTDIR "cert-intca.pem"));
 	certchain_link_issuer(chain3,
-			tls_cert_load_file(CERTDIR "cert-ca.pem"));
+			load_cert_file(CERTDIR "cert-ca.pem"));
 	assert(chain3);
 
 	assert(!l_certchain_verify(chain3, wrongca, NULL));
@@ -261,11 +275,11 @@ static void test_certificates(const void *data)
 	assert(!l_certchain_verify(chain3, twocas, NULL));
 
 	chain4 = certchain_new_from_leaf(
-			tls_cert_load_file(CERTDIR "cert-entity-int.pem"));
+			load_cert_file(CERTDIR "cert-entity-int.pem"));
 	certchain_link_issuer(chain4,
-			tls_cert_load_file(CERTDIR "cert-intca.pem"));
+			load_cert_file(CERTDIR "cert-intca.pem"));
 	certchain_link_issuer(chain4,
-			tls_cert_load_file(CERTDIR "cert-ca.pem"));
+			load_cert_file(CERTDIR "cert-ca.pem"));
 	assert(chain4);
 
 	assert(!l_certchain_verify(chain4, wrongca, NULL));
-- 
2.19.1


  parent reply	other threads:[~2018-12-13 19:57 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-12-13 19:57 [PATCH 1/9] tls: Don't send Client Hello in l_tls_new Andrew Zaborowski
2018-12-13 19:57 ` [PATCH 2/9] unit: Call l_tls_start in tls tests Andrew Zaborowski
2018-12-13 19:57 ` [PATCH 3/9] tls: Add TLS version number printf macros Andrew Zaborowski
2018-12-14 15:53   ` Denis Kenzior
2018-12-14 18:48     ` Andrew Zaborowski
2018-12-13 19:57 ` [PATCH 4/9] tls: Implement l_tls_set_version_range Andrew Zaborowski
2018-12-14 15:55   ` Denis Kenzior
2018-12-13 19:57 ` [PATCH 5/9] unit: Test TLS 1.0, 1.1 and 1.2 Andrew Zaborowski
2018-12-13 19:57 ` Andrew Zaborowski [this message]
2018-12-14 16:01   ` [PATCH 6/9] unit: Move tls_cert_load_file to relevant unit tests Denis Kenzior
2018-12-13 19:57 ` [PATCH 7/9] tls, pem: Drop tls_cert_load_file, l_pem_load_certificate Andrew Zaborowski
2018-12-13 19:57 ` [PATCH 8/9] tls: Allow user to set custom list of cipher suites Andrew Zaborowski
2018-12-14 16:33   ` Denis Kenzior
2018-12-14 19:12     ` Andrew Zaborowski
2018-12-14 19:28       ` Denis Kenzior
2018-12-14 19:49         ` Andrew Zaborowski
2018-12-14 19:57           ` Denis Kenzior
2018-12-13 19:57 ` [PATCH 9/9] unit: Test many TLS cipher suite and version combinations Andrew Zaborowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20181213195746.32144-6-andrew.zaborowski@intel.com \
    --to=andrew.zaborowski@intel.com \
    --cc=ell@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.