Attention is currently required from: Arne Schwabe.
Hello Arne Schwabe,
I'd like you to do a code review.
Please visit
https://gerrit.openvpn.net/c/openvpn/+/1998?usp=email
to review the following change.
Change subject: Check for null-bytes in certificate subjects
......................................................................
Check for null-bytes in certificate subjects
This is a partial backport of commit cf4384ee "Check for null-bytes in
certificate subjects" from the release/2.7 branch.
When using the OpenSSL library, we escaped embedded null-bytes in a
certificate's subject in x509_get_subject(), but in
extract_x509_field_ssl(), we copied any null-bytes that are contained in
the field value. When using the option --verify-x509-name, this could
lead to an incorrect name being accepted. For example, the common name
"admin\0impersonator" would be accepted when running with
--verify-x509-name admin name.
To fix this, this commit makes x509_get_subject() return an error if the
subject contains an embedded null-byte. This way, OpenVPN won't connect
with peers that present such certificates.
As a defense-in-depth measure, we also check for null-bytes in
extract_x509_field_ssl() in case a future version of OpenVPN has a code
path that avoids x509_get_subject().
With Mbed TLS, the x509_get_subject() function already returned an error
when there is an embedded null-byte. (As of Mbed TLS 3.5.) Since the
mbedtls backend code changed significantly between 2.6 and 2.7 and 2.6
is in maintenance mode, we're not backporting the Mbed TLS defense in
depth measure back to the ssl_verify_mbedtls.c.
Discovered and reported by BreachX Zero Day Labs, using Typhon AI Mil v2.
Contributing Researcher: Vivek Parikh.
CVE: 2026-84790
Reported-by: Vivek Parikh <[email protected]>
Github: OpenVPN/openvpn-private-issues#163
Change-Id: I88b17af9988aa640ca04c765b6e79dd1c8f822c7
Signed-off-by: Steffan Karger <[email protected]>
---
M src/openvpn/ssl_verify_openssl.c
1 file changed, 36 insertions(+), 14 deletions(-)
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/98/1998/2
diff --git a/src/openvpn/ssl_verify_openssl.c b/src/openvpn/ssl_verify_openssl.c
index ec3a7cf..ead961f 100644
--- a/src/openvpn/ssl_verify_openssl.c
+++ b/src/openvpn/ssl_verify_openssl.c
@@ -206,12 +206,14 @@
X509_NAME_ENTRY *x509ne = NULL;
ASN1_STRING *asn1 = NULL;
unsigned char *buf = NULL;
+ result_t ret = FAILURE;
+
ASN1_OBJECT *field_name_obj = OBJ_txt2obj(field_name, 0);
if (field_name_obj == NULL)
{
msg(D_TLS_ERRORS, "Invalid X509 attribute name '%s'", field_name);
- return FAILURE;
+ goto exit;
}
ASSERT(size > 0);
@@ -227,32 +229,33 @@
/* Nothing found */
if (lastpos == -1)
{
- return FAILURE;
+ goto exit;
}
x509ne = X509_NAME_get_entry(x509, lastpos);
if (!x509ne)
{
- return FAILURE;
+ goto exit;
}
asn1 = X509_NAME_ENTRY_get_data(x509ne);
if (!asn1)
{
- return FAILURE;
+ goto exit;
}
- if (ASN1_STRING_to_UTF8(&buf, asn1) < 0)
+ int length = ASN1_STRING_to_UTF8(&buf, asn1);
+ if (length < 0 || (size_t)length != strlen((char *)buf))
{
- return FAILURE;
+ goto exit;
}
strncpynt(out, (char *)buf, size);
- {
- const result_t ret = (strlen((char *)buf) < size) ? SUCCESS : FAILURE;
- OPENSSL_free(buf);
- return ret;
- }
+ ret = (strlen((char *)buf) < size) ? SUCCESS : FAILURE;
+
+exit:
+ OPENSSL_free(buf);
+ return ret;
}
result_t
@@ -376,9 +379,9 @@
goto err;
}
- X509_NAME_print_ex(subject_bio, X509_get_subject_name(cert),
- 0, XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_FN_SN
- |ASN1_STRFLGS_UTF8_CONVERT | ASN1_STRFLGS_ESC_CTRL);
+ /* Get the subject with unescaped control characters so that we can check
for null bytes. */
+ X509_NAME_print_ex(subject_bio, X509_get_subject_name(cert), 0,
+ XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_FN_SN |
ASN1_STRFLGS_UTF8_CONVERT);
if (BIO_eof(subject_bio))
{
@@ -386,6 +389,25 @@
}
BIO_get_mem_ptr(subject_bio, &subject_mem);
+ if (memchr(subject_mem->data, 0, subject_mem->length) != NULL)
+ {
+ msg(M_WARN, "ERROR: Certificate subject contains a '\\0' byte.");
+ goto err;
+ }
+
+ /* Now output the subject with escaped control characters. */
+ if (BIO_reset(subject_bio) != 1)
+ {
+ goto err;
+ }
+ X509_NAME_print_ex(subject_bio, X509_get_subject_name(cert), 0,
+ XN_FLAG_SEP_CPLUS_SPC | XN_FLAG_FN_SN |
ASN1_STRFLGS_UTF8_CONVERT
+ | ASN1_STRFLGS_ESC_CTRL);
+ if (BIO_eof(subject_bio))
+ {
+ goto err;
+ }
+ BIO_get_mem_ptr(subject_bio, &subject_mem);
subject = gc_malloc(subject_mem->length + 1, false, gc);
--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/1998?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.openvpn.net/settings?usp=email
Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: release/2.6
Gerrit-Change-Id: I88b17af9988aa640ca04c765b6e79dd1c8f822c7
Gerrit-Change-Number: 1998
Gerrit-PatchSet: 2
Gerrit-Owner: Steffan Karger <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel