In your scenario, the Load balancer terminates the SSL connection with the wso2 server.
Hence, you have to pass the certificate in a special header when invoking the request.
X-WSO2-CLIENT-CERTIFICATE
If the certificate is not presented by default (due to the SSL termination from the LB level), it checks the above header and extracts the certificate. That certificate will be checked against the client-trustore.jks and authenticated.
The following is the logic in which was extracted and verified.
https://github.com/wso2/carbon-apimgt/blob/master/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/handlers/Utils.java#L386
public static X509Certificate getClientCertificate(org.apache.axis2.context.MessageContext axis2MessageContext)
throws APIManagementException {
Map headers =
(Map) axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
Object sslCertObject = axis2MessageContext.getProperty(NhttpConstants.SSL_CLIENT_AUTH_CERT_X509);
X509Certificate certificateFromMessageContext = null;
if (sslCertObject != null) {
X509Certificate[] certs = (X509Certificate[]) sslCertObject;
certificateFromMessageContext = certs[0];
}
if (headers.containsKey(Utils.getClientCertificateHeader())) {
try {
if (!isClientCertificateValidationEnabled() || APIUtil
.isCertificateExistsInTrustStore(certificateFromMessageContext)){
String base64EncodedCertificate = (String) headers.get(Utils.getClientCertificateHeader());
if (base64EncodedCertificate != null) {
base64EncodedCertificate = URLDecoder.decode(base64EncodedCertificate).
replaceAll(APIConstants.BEGIN_CERTIFICATE_STRING, "")
.replaceAll(APIConstants.END_CERTIFICATE_STRING, "");
byte[] bytes = Base64.decodeBase64(base64EncodedCertificate);
try (InputStream inputStream = new ByteArrayInputStream(bytes)) {
X509Certificate x509Certificate = X509Certificate.getInstance(inputStream);
if (APIUtil.isCertificateExistsInTrustStore(x509Certificate)) {
return x509Certificate;
}else{
log.debug("Certificate in Header didn't exist in truststore");
return null;
}
} catch (IOException | CertificateException | APIManagementException e) {
String msg = "Error while converting into X509Certificate";
log.error(msg, e);
throw new APIManagementException(msg, e);
}
}
}
} catch (APIManagementException e) {
String msg = "Error while validating into Certificate Existence";
log.error(msg, e);
throw new APIManagementException(msg, e);
}
}
return certificateFromMessageContext;
}
Hope the above will clarifies your concerns.
Thanks,
Dileepa