【问题标题】:Mutual SSL connection issue in WSO2 3.0.0 APIMWSO2 3.0.0 APIM 中的相互 SSL 连接问题
【发布时间】:2020-11-06 09:43:14
【问题描述】:

相互 SSL 如何在 wso2 中工作,我正在关注链接 https://apim.docs.wso2.com/en/latest/learn/api-security/api-authentication/secure-apis-using-mutual-ssl/ 它在域为 localhost 的本地工作

但是在我们的生产环境中,我们的网关以 AWS ALB 为前端,但对于我在本地使用的相同证书和密钥,它不起作用。

日志中的错误

错误 - MutualSSLAuthenticator 相互 SSL 身份验证失败 [2020-11-02 10:20:56,302] 错误 - MutualSSLAuthenticator 相互 SSL 身份验证失败

在 wso2 文档中提到 负载均衡器需要满足以下先决条件。

终止来自客户端的相互 SSL 连接。 在 HTTP Header 中将客户端 SSL 证书传递给网关

但是从 AWS 团队我了解到“所以不可能实现客户端后端 TLS 相互身份验证,中间有一个 ALB。”

如果有人能够消除混乱,那就太好了

【问题讨论】:

    标签: amazon-web-services ssl wso2


    【解决方案1】:

    在您的场景中,负载均衡器终止与 wso2 服务器的 SSL 连接。

    因此,您必须在调用请求时在特殊标头中传递证书。

    X-WSO2-CLIENT-CERTIFICATE

    如果默认情况下不提供证书(由于 LB 级别的 SSL 终止),它会检查上述标头并提取证书。该证书将根据 client-trustore.jks 进行检查并进行身份验证。

    以下是提取和验证的逻辑。

    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;
        }
    
    
    

    希望以上内容能澄清您的疑虑。

    谢谢, 迪丽热巴

    【讨论】:

    • 我尝试在网关 client-trustore.jks 中导入证书,但如果证书在 LB 被丢弃,如何验证 wrt client-trustore.jks? i LB 登录 AWS 我没有观察到任何证书,网关日志我没有看到 X-WSO2-CLIENT-CERTIFICATE
    • @Vivek 您必须在请求中使用 X-WSO2-CLIENT-CERTIFICATE 标头值显式传递证书。 curl -k -X GET "https://localhost:8243/pizzashack/1.0.0/menu" -H "accept: application/json" -H "X-WSO2-CLIENT-CERTIFICATE: <Certificate-Here>"。如果标头被丢弃,请尝试更改用于从网关检查证书的标头值。请参考 [apim.docs.wso2.com/en/latest/learn/api-security/… 的末尾更改标头值。
    • 我尝试在标头 X-WSO2-CLIENT-CERTIFICATE 以及证书密钥中传递证书,但在网关日志中仍然出现同样的错误。
    • 我再次浏览了代码。您收到MutualSSLAuthenticator Mutual SSL authentication failure 错误的唯一可能性如下。 1 enable_client_validation = false 未在 deployment.toml 文件中配置 2. 客户端证书不是预期的格式 3. 客户端信任库中不存在证书。你能检查以上3个地方吗?注意:通过标头发送的证书应具有crt文件中的开始证书和结束证书。请参考答案中提到的代码
    • 我是否还需要使用 wso2 文档中提到的客户端证书传递密钥
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多