From: "selvanair (Code Review)" Date: Thu, 9 Apr 2026 01:36:04 +0000 References: Reply-To: selva.nair@...277..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net Message-ID: <7c42735bcfb874cb92a81ae2084bf779776300a7-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="6erYe6E65sY="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: verify_x509_name: Improve the error message on failure List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: openvpn-devel --6erYe6E65sY= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: plaisthos. Hello plaisthos, I'd like you to do a code review. Please visit http://gerrit.openvpn.net/c/openvpn/+/1624?usp=3Demail to review the following change. Change subject: verify_x509_name: Improve the error message on failure ...................................................................... verify_x509_name: Improve the error message on failure Print the actual string that was used for the match instead of the whole subject. Github: closes OpenVPN/openvpn#992 Change-Id: I6e7947ab81cf229f0d27714dd563a07ace6bd38a Signed-off-by: Selva Nair --- M src/openvpn/ssl_verify.c 1 file changed, 22 insertions(+), 11 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/24/1624/1 diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c index d44f25f..21b516d 100644 --- a/src/openvpn/ssl_verify.c +++ b/src/openvpn/ssl_verify.c @@ -369,21 +369,32 @@ /* verify X509 name or username against --verify-x509-[user]name */ if (opt->verify_x509_type !=3D VERIFY_X509_NONE) { - if ((opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_DN - && strcmp(opt->verify_x509_name, subject) =3D=3D 0) - || (opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_RDN - && strcmp(opt->verify_x509_name, common_name) =3D=3D 0) - || (opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_RDN_PREFIX - && strncmp(opt->verify_x509_name, common_name, strlen(opt-= >verify_x509_name)) =3D=3D 0)) + const char *err_fmt =3D "VERIFY X509NAME ERROR: %s, must be %s"; + const char *match_str =3D common_name; + bool verified =3D false; + switch (opt->verify_x509_type) { - msg(D_HANDSHAKE, "VERIFY X509NAME OK: %s", subject); + case VERIFY_X509_SUBJECT_DN: + match_str =3D subject; + verified =3D !strcmp(opt->verify_x509_name, match_str); + break; + case VERIFY_X509_SUBJECT_RDN: + verified =3D !strcmp(opt->verify_x509_name, match_str); + break; + case VERIFY_X509_SUBJECT_RDN_PREFIX: + err_fmt =3D "VERIFY X509NAME ERROR: %s, must start with %s= "; + verified =3D !strncmp(opt->verify_x509_name, match_str, st= rlen(opt->verify_x509_name)); + break; + default: + ASSERT(0); /* should not happen */ + break; } - else + if (!verified) { - msg(D_HANDSHAKE, "VERIFY X509NAME ERROR: %s, must be %s", subj= ect, - opt->verify_x509_name); - return FAILURE; /* Reject connection */ + msg(D_HANDSHAKE, err_fmt, match_str, opt->verify_x509_name); + return FAILURE; } + msg(D_HANDSHAKE, "VERIFY X509NAME OK: %s", subject); } return SUCCESS; -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1624?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newchange Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I6e7947ab81cf229f0d27714dd563a07ace6bd38a Gerrit-Change-Number: 1624 Gerrit-PatchSet: 1 Gerrit-Owner: selvanair Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos --6erYe6E65sY= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is cur= rently required from: plaisthos.

selvanair would like plaisthos to review this change.

V= iew Change

verify_x509_name: Improve the error message=
 on failure

Print the actual string that was used for the match inst= ead of the
whole subject.

Github: closes OpenVPN/openvpn#992
<= br>Change-Id: I6e7947ab81cf229f0d27714dd563a07ace6bd38a
Signed-off-by: S= elva Nair <selva.nair@...277...>
---
M src/openvpn/ssl_verify.c=
1 file changed, 22 insertions(+), 11 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/24/1624/=
1
diff --git a/src/openvpn/ssl_verify.c b/src/openvpn/ssl_verify.c<=
/span>
index d44f25f..21b516d 100644
--- a/src/ope= nvpn/ssl_verify.c
+++ b/src/openvpn/ssl_verify.c
= @@ -369,21 +369,32 @@
/* verify X509 name or use= rname against --verify-x509-[user]name */
if (opt->= verify_x509_type !=3D VERIFY_X509_NONE)
{
- if ((opt->verify_x509_t= ype =3D=3D VERIFY_X509_SUBJECT_DN

- && strcmp(opt->verify_x509_name, subjec= t) =3D=3D 0)
- = || (opt->verify_x509_type =3D=3D VERIFY_X509_SUBJECT_RDN
- && strcmp(= opt->verify_x509_name, common_name) =3D=3D 0)
- || (opt->verify_x509_type =3D=3D = VERIFY_X509_SUBJECT_RDN_PREFIX
- && strncmp(opt->verify_x509_name, commo= n_name, strlen(opt->verify_x509_name)) =3D=3D 0))
+ const char *err_fmt =3D "VER= IFY X509NAME ERROR: %s, must be %s";
+ const char *match_str =3D common_name;=
+ bool verified =3D = false;
+ switc= h (opt->verify_x509_type)
{
- msg(D_HANDSHAKE, "VERIFY= X509NAME OK: %s", subject);
+ case VERIFY_X509_SUBJECT_DN:
+ match_str =3D subject;
+ verif= ied =3D !strcmp(opt->verify_x509_name, match_str);
+ break;
+ case VERIFY_X509_SUBJECT_R= DN:
+ = verified =3D !strcmp(opt->verify_x509_name, match_str);
+ break;
+ case VERIFY_X509_SUBJ= ECT_RDN_PREFIX:

+ = err_fmt =3D "VERIFY X509NAME ERROR: %s, must start with %s= ";
+ = verified =3D !strncmp(opt->verify_x509_name, match_str, strlen(opt-&= gt;verify_x509_name));
+ default:
+ ASSERT(0); /* should not happen */
+ break;
}
- e= lse
+ if (!ver= ified)
{
- msg(D_HANDSHAKE, "VERIFY X509NAME ERROR: %s, m= ust be %s", subject,
- opt->verify_x509_name);
- return FAILURE; /* Reject connection *= /
+ msg(D_= HANDSHAKE, err_fmt, match_str, opt->verify_x509_name);
+ return FAILURE; }
+ = msg(D_HANDSHAKE, "VERIFY X509NAME OK: %s", subject);=
}

return SUCCESS;

To view, visit change 1624. To unsubscribe, or= for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I6e7947ab81cf229f0d27714dd56= 3a07ace6bd38a
Gerrit-Change-Number: 1624
Gerrit-PatchSet: 1
Gerrit-Owner: selvanair <selva.nair@...1354...= ..>
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
= --6erYe6E65sY=--