Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions java/org/apache/catalina/authenticator/SSLAuthenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public SSLAuthenticator() {
}

private final Log log = LogFactory.getLog(SSLAuthenticator.class); // must not be static
private static final String AUTH_HEADER_VALUE_CLIENT_CERTIFICATE = "ClientCertificate";

/**
* Authenticate the user by checking for the existence of a certificate chain, validating it against the trust
Expand Down Expand Up @@ -92,6 +93,7 @@ protected boolean doAuthenticate(Request request, HttpServletResponse response)
if (containerLog.isDebugEnabled()) {
containerLog.debug(sm.getString("sslAuthenticatorValve.noCertificates"));
}
response.setHeader(AUTH_HEADER_NAME, AUTH_HEADER_VALUE_CLIENT_CERTIFICATE);
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.certificates"));
return false;
}
Expand All @@ -102,6 +104,7 @@ protected boolean doAuthenticate(Request request, HttpServletResponse response)
if (containerLog.isDebugEnabled()) {
containerLog.debug(sm.getString("sslAuthenticatorValve.authFailed"));
}
response.setHeader(AUTH_HEADER_NAME, AUTH_HEADER_VALUE_CLIENT_CERTIFICATE);
response.sendError(HttpServletResponse.SC_UNAUTHORIZED, sm.getString("authenticator.unauthorized"));
return false;
}
Expand Down
11 changes: 10 additions & 1 deletion test/org/apache/tomcat/util/net/TestClientCert.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Assert;
import org.junit.Assume;
Expand Down Expand Up @@ -190,7 +192,10 @@ private void doTestClientCertPost(int bodySize, boolean expectProtectedFail)

// Protected resource
res.recycle();
int rc = postUrl(body, "https://localhost:" + getPort() + "/protected", res, null);

Map<String, List<String>> resHeaders = new HashMap<String,List<String>>();

int rc = postUrl(body, "https://localhost:" + getPort() + "/protected", res, resHeaders);

count = TesterSupport.getLastClientAuthRequestedIssuerCount();
if (log.isDebugEnabled()) {
Expand All @@ -202,6 +207,10 @@ private void doTestClientCertPost(int bodySize, boolean expectProtectedFail)

if (expectProtectedFail) {
Assert.assertEquals(401, rc);
// Per RFC - https://httpwg.org/specs/rfc9110.html#field.www-authenticate
Assert.assertNotNull(
"a 401 (Unauthorized) response MUST send a WWW-Authenticate header field containing at least one challenge",
resHeaders.get("WWW-Authenticate"));
// POST body buffer fails so TLS handshake never happens
Assert.assertEquals(0, count);
} else {
Expand Down