All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] cert: Try TLS format in l_cert_load_container_file
@ 2021-04-28 17:30 Andrew Zaborowski
  2021-04-28 17:30 ` [PATCH 2/3] tools: Convert certchain-verify to l_cert_load_container_file Andrew Zaborowski
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Andrew Zaborowski @ 2021-04-28 17:30 UTC (permalink / raw)
  To: ell

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

---
 ell/cert.c | 26 ++++++++++++++++++++++++--
 1 file changed, 24 insertions(+), 2 deletions(-)

diff --git a/ell/cert.c b/ell/cert.c
index 14631b2..141ea1c 100644
--- a/ell/cert.c
+++ b/ell/cert.c
@@ -35,6 +35,8 @@
 #include "pem-private.h"
 #include "cert.h"
 #include "cert-private.h"
+#include "tls.h"
+#include "tls-private.h"
 #include "missing.h"
 
 #define X509_CERTIFICATE_POS			0
@@ -1635,14 +1637,34 @@ LIB_EXPORT bool l_cert_load_container_file(const char *filename,
 		if (err != -ENOMSG)
 			goto close;
 
-		/* Try PEM */
+		/* Try other formats */
+	}
+
+	/*
+	 * For backwards compatibility try the TLS internal struct Certificate
+	 * format as may be captured by PCAP (no future support guaranteed).
+	 */
+	if (out_certchain && !password && file.st.st_size &&
+			tls_parse_certificate_list(file.data, file.st.st_size,
+							out_certchain) == 0) {
+		error = false;
+
+		if (out_privkey)
+			*out_privkey = NULL;
+
+		if (out_encrypted)
+			*out_encrypted = false;
+
+		goto close;
 	}
 
 	/*
 	 * RFC 7486 allows whitespace and possibly other data before the
 	 * PEM "encapsulation boundary" so rather than check if the start
 	 * of the data looks like PEM, we fall back to this format if the
-	 * data didn't look like anything else we knew about.
+	 * data didn't look like anything else we knew about.  Note this
+	 * succeeds for empty files and files without any PEM markers,
+	 * returning NULL chain and privkey.
 	 */
 	if (cert_try_load_pem_format((const char *) file.data, file.st.st_size,
 					password, out_certchain, out_privkey,
-- 
2.27.0

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-28 18:28 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-28 17:30 [PATCH 1/3] cert: Try TLS format in l_cert_load_container_file Andrew Zaborowski
2021-04-28 17:30 ` [PATCH 2/3] tools: Convert certchain-verify to l_cert_load_container_file Andrew Zaborowski
2021-04-28 17:30 ` [PATCH 3/3] tls: Proceed after l_certchain_verify failure if no CA certs Andrew Zaborowski
2021-04-28 18:28 ` [PATCH 1/3] cert: Try TLS format in l_cert_load_container_file Denis Kenzior

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.