亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網(wǎng)為廣大站長提供免費收錄網(wǎng)站服務(wù),提交前請做好本站友鏈:【 網(wǎng)站目錄:http://www.430618.com 】, 免友鏈快審服務(wù)(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網(wǎng)站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

本文介紹了如何使用IBMJSSE2默認提供程序從SSLContext獲取所有TLS會話?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我使用IBMJSSEProvider2作為TLS連接的默認設(shè)置,并使用以下代碼顯示有關(guān)TLS會話的信息:

SSLSessionContext sslSessionContext = SSLContext.getDefault().getClientSessionContext();
Enumeration<byte[]> sessionIds = sslSessionContext.getIds();
while (sessionIds.hasMoreElements()) {
  SSLSession sslSession = sslSessionContext.getSession(sessionIds.nextElement());
  writer.write("Client: " + sslSession.getPeerHost() + ":" + sslSession.getPeerPort() + "
");
  writer.write("	Protocol: " + sslSession.getProtocol() + "
");
  writer.write("	SessionID: " + byteArrayToHex(sslSession.getId()) + "
");
  writer.write("	CipherSuite: " + sslSession.getCipherSuite() + "
");
  for (X509Certificate certificate : sslSession.getPeerCertificateChain()) {
    writer.write("	X509 Certificate: " + certificate.getSubjectDN() + "
");
    writer.write("		Issuer: " + certificate.getIssuerDN().getName() + "
");
    writer.write("		Algorithm: " + certificate.getSigAlgName() + "
");
    writer.write("		Validity: " + certificate.getNotAfter() + "
");
  }
}

上面的代碼在一個WebSphere8.5實例上運行。當我運行該算法時,它不會打印有關(guān)我使用Spring3.2中的RestTemplate實現(xiàn)連接到任何HTTPS URL的任何信息。
使用其他提供程序(如Oracle提供程序)顯示了相關(guān)信息。我是否遺漏了使其正常工作的內(nèi)容?

我正在嘗試創(chuàng)建一個簡單的解決方案來解決一個活動的WebSphere實例支持哪些TLS版本的問題。當然,對于實時客戶端,不建議這樣做。

推薦答案

問題可能是底層庫沒有使用WebSphere上的默認上下文。因此,我必須創(chuàng)建一個定制的客戶端,使其使用特定的SSLContext,這樣我就可以列出我需要的所有信息。以下是實現(xiàn)此目的的代碼:

    private static String URL = "https://www.google.com";
    private static String TRUST_STORE_FILE = "/Users/xpto/trust.p12";
    private static String TRUST_STORE_PASS = "truststore";
    private static String TRUST_STORE_TYPE = "PKCS12";
    private static String TLS_VERSION = "TLSv1.2";

    public static void main(String[] args) throws Exception {
        KeyStore keyStore = KeyStore.getInstance(TRUST_STORE_TYPE);
        keyStore.load(new FileInputStream(TRUST_STORE_FILE), TRUST_STORE_PASS.toCharArray());

        SSLContext sslContext = SSLContexts
                .custom()
                .loadTrustMaterial(keyStore)
                .useProtocol(TLS_VERSION)
                .build();

        HttpComponentsClientHttpRequestFactory clientFactory = new HttpComponentsClientHttpRequestFactory(HttpClients
                .custom()
                .setSSLSocketFactory(new SSLConnectionSocketFactory(sslContext))
                .build());

        RestTemplate restTemplate = new RestTemplate(clientFactory);

        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setContentType(MediaType.APPLICATION_JSON);
        requestHeaders.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));

        HttpEntity<String> requestEntity = new HttpEntity<String>(requestHeaders);
        print("Requesting: " + URL);
        ResponseEntity<String> response = restTemplate.exchange(URL, HttpMethod.GET, requestEntity, String.class);
        print("Response: " + response.getBody());

        printSSLContextInfo(sslContext);
    }

    private static void printSSLContextInfo(SSLContext sslContext) throws Exception {
        print("-------------
Printing TLS Client Information");
        SSLSessionContext sslSessionContext = sslContext.getClientSessionContext();
        Enumeration<byte[]> sessionIds = sslSessionContext.getIds();
        while (sessionIds.hasMoreElements()) {
            SSLSession sslSession = sslSessionContext.getSession(sessionIds.nextElement());
            print("Client: " + sslSession.getPeerHost() + ":" + sslSession.getPeerPort());
            print("	Protocol: " + sslSession.getProtocol());
            print("	SessionID: " + byteArrayToHex(sslSession.getId()));
            print("	CipherSuite: " + sslSession.getCipherSuite());
            for (X509Certificate certificate : sslSession.getPeerCertificateChain()) {
                print("	X509 Certificate: " + certificate.getSubjectDN());
                print("		Issuer: " + certificate.getIssuerDN().getName());
                print("		Algorithm: " + certificate.getSigAlgName());
                print("		Validity: " + certificate.getNotAfter());
            }
        }
    }

    public static String byteArrayToHex(byte[] a) {
        StringBuilder sb = new StringBuilder(a.length * 2);
        for (byte b : a)
            sb.append(String.format("%02x", b));
        return sb.toString();
    }

    public static void print(Object msg) {
        System.out.println(msg);
    }

這篇關(guān)于如何使用IBMJSSE2默認提供程序從SSLContext獲取所有TLS會話?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,

分享到:
標簽:IBMJSSE2 會話 如何使用 提供 程序 獲取 默認
用戶無頭像

網(wǎng)友整理

注冊時間:

網(wǎng)站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網(wǎng)站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網(wǎng)站吧!
最新入駐小程序

數(shù)獨大挑戰(zhàn)2018-06-03

數(shù)獨一種數(shù)學(xué)游戲,玩家需要根據(jù)9

答題星2018-06-03

您可以通過答題星輕松地創(chuàng)建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學(xué)四六

運動步數(shù)有氧達人2018-06-03

記錄運動步數(shù),積累氧氣值。還可偷

每日養(yǎng)生app2018-06-03

每日養(yǎng)生,天天健康

體育訓(xùn)練成績評定2018-06-03

通用課目體育訓(xùn)練成績評定