SNI configuration in cxf client(3.1.2)

我们两清 提交于 2019-12-21 22:03:27

问题


I want to set custom SNI hostname(SNI configuration) while making rest call using CXF client(3.1.2). I'm using java 8.I'm able to do the same thing using HTTPClient(see below strong textcode snipped for reference), but I'm not able to figure out how to do the same using CXF client.

// For HTTP client

 private SSLConnectionSocketFactory createSSLConnectionSocketFactory(String sniHostanme,
        SSLContext sslContext){

    // Fix for host name verifier, need to implement----------------------
    SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[] { "TLSv1.2" }, null,
            SSLConnectionSocketFactory.getDefaultHostnameVerifier()) {
        @Override
        protected void prepareSocket(SSLSocket socket) throws IOException {
            try {
        //      System.out.println("************ setting socket HOST property *************");

                // If SNI is required
                if (StringUtils.isNotBlank(sniHostanme)) {
                    log.debug("SNI HOSTNAME = "+sniHostanme);

                    List<SNIServerName> sniServerNames = new ArrayList<>();
                    sniServerNames.add(new SNIHostName(sniHostanme));

                    SSLParameters sslParam = new SSLParameters();
                    sslParam.setServerNames(sniServerNames);
                    socket.setSSLParameters(sslParam);
                }
                // PropertyUtils.setProperty(socket, "host", "ws.mastercard.com");
            } catch (Exception ex) {
                log.error(ex.getMessage());
            }
            // super.prepareSocket(socket);
        }

    };
    return sslsf;
}

回答1:


Use org.apache.cxf.configuration.jsse.TLSClientParameters class and public final void setCertAlias(String ctAlias) method to set the cert alias used on server side this is useful when keystore has multiple certs.Hopefully this will help you.



来源:https://stackoverflow.com/questions/52252184/sni-configuration-in-cxf-client3-1-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!