All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mat Martineau <mathew.j.martineau@linux.intel.com>
To: ell@lists.01.org
Subject: [PATCH v2 3/3] tls: Validate cert chain using l_keyring
Date: Mon, 24 Oct 2016 14:36:33 -0700	[thread overview]
Message-ID: <20161024213633.10668-3-mathew.j.martineau@linux.intel.com> (raw)
In-Reply-To: <20161024213633.10668-1-mathew.j.martineau@linux.intel.com>

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

---
 ell/tls.c | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 54 insertions(+), 1 deletion(-)

diff --git a/ell/tls.c b/ell/tls.c
index bc4c210..3879b50 100644
--- a/ell/tls.c
+++ b/ell/tls.c
@@ -2464,10 +2464,63 @@ static const struct pkcs1_encryption_oid {
 	},
 };
 
+static void tls_key_cleanup(struct l_key **p)
+{
+	l_key_free_norevoke(*p);
+}
+
+static bool tls_cert_verify_with_keyring(struct tls_cert *cert,
+						struct l_keyring *ring)
+{
+	if (!cert)
+		return true;
+
+	if (tls_cert_verify_with_keyring(cert->issuer, ring)) {
+		L_AUTO_CLEANUP_VAR(struct l_key *, key, tls_key_cleanup);
+
+		key = l_key_new(L_KEY_RSA, cert->asn1, cert->size);
+		if (!key)
+			return false;
+
+		return l_keyring_link(ring, key);
+	}
+
+	return false;
+}
+
+static void tls_keyring_cleanup(struct l_keyring **p)
+{
+	l_keyring_free(*p);
+}
+
 bool tls_cert_verify_certchain(struct tls_cert *certchain,
 				struct tls_cert *ca_cert)
 {
-	return true;
+	L_AUTO_CLEANUP_VAR(struct l_keyring *, ca_ring, tls_keyring_cleanup);
+	L_AUTO_CLEANUP_VAR(struct l_keyring *, verify_ring,
+				tls_keyring_cleanup);
+
+	ca_ring = NULL;
+	verify_ring = NULL;
+
+	if (ca_cert) {
+		L_AUTO_CLEANUP_VAR(struct l_key *, ca_key, tls_key_cleanup);
+		ca_key = NULL;
+
+		ca_ring = l_keyring_new(L_KEYRING_SIMPLE, NULL);
+		if (!ca_ring)
+			return false;
+
+		ca_key = l_key_new(L_KEY_RSA, ca_cert->asn1, ca_cert->size);
+		if (!ca_key || !l_keyring_link(ca_ring, ca_key))
+			return false;
+	}
+
+	verify_ring = l_keyring_new(L_KEYRING_TRUSTED_ASYM_CHAIN, ca_ring);
+	if (!verify_ring)
+		return false;
+
+	return tls_cert_verify_with_keyring(certchain, verify_ring);
 }
 
 void tls_cert_free_certchain(struct tls_cert *cert)
-- 
2.10.1


  parent reply	other threads:[~2016-10-24 21:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-24 21:36 [PATCH v2 1/3] unit: Fix memory leak in trust chain test Mat Martineau
2016-10-24 21:36 ` [PATCH v2 2/3] key: Make key/keychain revocation optional when freeing Mat Martineau
2016-10-25  1:59   ` Denis Kenzior
2016-10-24 21:36 ` Mat Martineau [this message]
2016-10-25  2:19   ` [PATCH v2 3/3] tls: Validate cert chain using l_keyring Denis Kenzior
2016-10-25  1:59 ` [PATCH v2 1/3] unit: Fix memory leak in trust chain test Denis Kenzior

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=20161024213633.10668-3-mathew.j.martineau@linux.intel.com \
    --to=mathew.j.martineau@linux.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.