Fix GnuTLS certvalid certificate validation - #306
Conversation
There was a problem hiding this comment.
1 issue found across 4 files
Confidence score: 5/5
- In
src/tcp.c, the newcertvalidbranch duplicates the existing certificate-verification error handling, which could allow the two paths to diverge over time; consolidate the logic or verify both blocks remain behaviorally identical.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="src/tcp.c">
<violation number="1" location="src/tcp.c:2748">
P3: The new certvalid branch duplicates the `gnutls_certificate_verify_peers2` + `callOnAuthErr(..., "certificate validation failed", RELP_RET_AUTH_CERT_INVL)` + `GNUTLS_E_CERTIFICATE_ERROR` block already in relpTcpChkPeerName_gtls (src/tcp.c ~lines 2649-2661). Both branches now perform the identical chain-status check and emit the same error. Consider factoring a shared helper (e.g. relpTcpVerifyCertChain(pThis)) and calling it from both the name and certvalid paths so future verification changes stay in one place.</violation>
</file>
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
| r = relpTcpChkPeerName(pThis, (void*)cert); | ||
| } else if(pThis->authmode == eRelpAuthMode_CertValid) { | ||
| unsigned int status = 0; | ||
| r = gnutls_certificate_verify_peers2(pThis->session, &status); |
There was a problem hiding this comment.
P3: The new certvalid branch duplicates the gnutls_certificate_verify_peers2 + callOnAuthErr(..., "certificate validation failed", RELP_RET_AUTH_CERT_INVL) + GNUTLS_E_CERTIFICATE_ERROR block already in relpTcpChkPeerName_gtls (src/tcp.c ~lines 2649-2661). Both branches now perform the identical chain-status check and emit the same error. Consider factoring a shared helper (e.g. relpTcpVerifyCertChain(pThis)) and calling it from both the name and certvalid paths so future verification changes stay in one place.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/tcp.c, line 2748:
<comment>The new certvalid branch duplicates the `gnutls_certificate_verify_peers2` + `callOnAuthErr(..., "certificate validation failed", RELP_RET_AUTH_CERT_INVL)` + `GNUTLS_E_CERTIFICATE_ERROR` block already in relpTcpChkPeerName_gtls (src/tcp.c ~lines 2649-2661). Both branches now perform the identical chain-status check and emit the same error. Consider factoring a shared helper (e.g. relpTcpVerifyCertChain(pThis)) and calling it from both the name and certvalid paths so future verification changes stay in one place.</comment>
<file context>
@@ -2743,6 +2743,14 @@ relpTcpVerifyCertificateCallback(gnutls_session_t session)
r = relpTcpChkPeerName(pThis, (void*)cert);
+ } else if(pThis->authmode == eRelpAuthMode_CertValid) {
+ unsigned int status = 0;
+ r = gnutls_certificate_verify_peers2(pThis->session, &status);
+ if(r < 0 || status != 0) {
+ callOnAuthErr(pThis, "", "certificate validation failed",
</file context>
e1bcbb1 to
93162b9
Compare
93162b9 to
c780b42
Compare
c780b42 to
c0bb2f0
Compare
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Motivation
certvalidmode accepted any presented X.509 certificate without verifying the trust chain or status.certvalidsemantics (a valid, trusted certificate chain) are enforced consistently between OpenSSL and GnuTLS code paths.Description
relpTcpVerifyCertificateCallbackcallgnutls_certificate_verify_peers2()whenpThis->authmode == eRelpAuthMode_CertValidand reject the handshake on non-zerostatusor error return, mirroring the OpenSSL path (change insrc/tcp.c).tests/tls-basic-certchain.sh).tests/tls-certvalid-untrusted.shand register it in the test suite to verifycertvalidrejects expired/untrusted client certificates.Testing
autoreconf -fi && ./configure --enable-tls && make -j2and the build completed successfully with GNUTLS and OpenSSL enabled.make checkfor TLS tests includingtls-basic-certvalid.sh,tls-basic-certvalid-mixed.sh,tls-basic-certchain.shand the newtls-certvalid-untrusted.sh; all TLS tests passed in the final test run.(cd tests && ./tls-certvalid-untrusted.sh)and it succeeded for both GnuTLS and OpenSSL backends.Codex Task
Summary by cubic
Fixes an authentication bypass in the GnuTLS
certvalidpath: previously any client certificate was accepted; now the peer chain is verified and invalid/untrusted/expired certificates are rejected, matching OpenSSL.Written for commit c0bb2f0. Summary will update on new commits.