當前位置: 首頁>>代碼示例>>Java>>正文


Java SSLServerSocket.getSupportedProtocols方法代碼示例

本文整理匯總了Java中javax.net.ssl.SSLServerSocket.getSupportedProtocols方法的典型用法代碼示例。如果您正苦於以下問題:Java SSLServerSocket.getSupportedProtocols方法的具體用法?Java SSLServerSocket.getSupportedProtocols怎麽用?Java SSLServerSocket.getSupportedProtocols使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.net.ssl.SSLServerSocket的用法示例。


在下文中一共展示了SSLServerSocket.getSupportedProtocols方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: main

import javax.net.ssl.SSLServerSocket; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception {
//        try {
            SSLServerSocketFactory ssf =
                (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
            SSLServerSocket ss = (SSLServerSocket)ssf.createServerSocket();
            String[] protocols = ss.getSupportedProtocols();
            for (int i = 0; i < protocols.length; i++) {
//                try {
                    if (protocols[i].equals("SSLv2Hello")) {
                        continue;
                    }
                    SSLContext sslc = SSLContext.getInstance(protocols[i]);
                    SSLSessionContext sslsc = sslc.getServerSessionContext();
                    System.out.println("Protocol: " + protocols[i]);
                    sslsc.setSessionTimeout(Integer.MAX_VALUE);
                    int newtime = sslsc.getSessionTimeout();
                    if (newtime != Integer.MAX_VALUE) {
                        throw new Exception ("Expected timeout: " +
                            Integer.MAX_VALUE + ", got instead: " +
                            newtime);
                    }
//                } catch (Exception e) {
//                }
            }
//        } catch (Exception e) {
//            System.out.println(e);
//        }
        System.out.println("Finished");
    }
 
開發者ID:vicmarcal,項目名稱:JAVA_UNIT,代碼行數:30,代碼來源:Timeout.java

示例2: testSetEnabledProtocolsAffectsGetter

import javax.net.ssl.SSLServerSocket; //導入方法依賴的package包/類
@Test
public void testSetEnabledProtocolsAffectsGetter() throws Exception {
    SSLServerSocket socket =
            (SSLServerSocket) SSLServerSocketFactory.getDefault().createServerSocket();
    String[] protocols = new String[] {socket.getSupportedProtocols()[0]};
    socket.setEnabledProtocols(protocols);
    assertEquals(Arrays.asList(protocols), Arrays.asList(socket.getEnabledProtocols()));
}
 
開發者ID:google,項目名稱:conscrypt,代碼行數:9,代碼來源:SSLServerSocketTest.java

示例3: testGetSupportedProtocols

import javax.net.ssl.SSLServerSocket; //導入方法依賴的package包/類
/**
 * getSupportedProtocols() method testing.
 */
public void testGetSupportedProtocols() throws Exception {
    SSLServerSocket ssocket = createSSLServerSocket();
    String[] supported = ssocket.getSupportedProtocols();
    assertNotNull(supported);
    assertFalse(supported.length == 0);
    supported[0] = "NOT_SUPPORTED_PROTOCOL";
    supported = ssocket.getSupportedProtocols();
    for (int i=0; i<supported.length; i++) {
        if ("NOT_SUPPORTED_PROTOCOL".equals(supported[i])) {
            fail("Modification of the returned result "
                    + "causes the modification of the internal state");
        }
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:18,代碼來源:SSLServerSocketImplTest.java

示例4: testGetEnabledProtocols

import javax.net.ssl.SSLServerSocket; //導入方法依賴的package包/類
/**
 * getEnabledProtocols() method testing.
 */
public void testGetEnabledProtocols() throws Exception {
    SSLServerSocket ssocket = createSSLServerSocket();
    String[] enabled = ssocket.getEnabledProtocols();
    assertNotNull(enabled);
    String[] supported = ssocket.getSupportedProtocols();
    for (int i=0; i<enabled.length; i++) {
        //System.out.println("Checking of "+enabled[i]);
        found: {
            for (int j=0; j<supported.length; j++) {
                if (enabled[i].equals(supported[j])) {
                    break found;
                }
            }
            fail("Enabled protocol does not belong to the set "
                    + "of supported protocols: " + enabled[i]);
        }
    }
    ssocket.setEnabledProtocols(supported);
    for (int i=0; i<supported.length; i++) {
        enabled = new String[supported.length - i];
        System.arraycopy(supported, i,
                enabled, 0, supported.length-i);
        //System.out.println("");
        //for (int k=0; k<supported.length - i; k++) {
        //    System.out.println("---- "+enabled[k]);
        //}
        ssocket.setEnabledProtocols(enabled);
        String[] result = ssocket.getEnabledProtocols();
        if (result.length != enabled.length) {
            fail("Returned result does not correspond to expected.");
        }
        for (int k=0; k<result.length; k++) {
            found: {
                for (int n=0; n<enabled.length; n++) {
                    if (result[k].equals(enabled[n])) {
                        break found;
                    }
                }
                if (result.length != enabled.length) {
                    fail("Returned result does not correspond "
                            + "to expected.");
                }
            }
        }
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:50,代碼來源:SSLServerSocketImplTest.java

示例5: testSetEnabledProtocols

import javax.net.ssl.SSLServerSocket; //導入方法依賴的package包/類
/**
 * setEnabledProtocols(String[] protocols) method testing.
 */
public void testSetEnabledProtocols() throws Exception {
    SSLServerSocket ssocket = createSSLServerSocket();
    String[] enabled = ssocket.getEnabledProtocols();
    assertNotNull(enabled);
    String[] supported = ssocket.getSupportedProtocols();
    for (int i=0; i<enabled.length; i++) {
        //System.out.println("Checking of "+enabled[i]);
        found: {
            for (int j=0; j<supported.length; j++) {
                if (enabled[i].equals(supported[j])) {
                    break found;
                }
            }
            fail("Enabled suite does not belong to the set "
                    + "of supported cipher suites: " + enabled[i]);
        }
    }
    ssocket.setEnabledProtocols(supported);
    ssocket.setEnabledProtocols(enabled);
    ssocket.setEnabledProtocols(supported);
    String[] more_than_supported = new String[supported.length+1];
    for (int i=0; i<supported.length+1; i++) {
        more_than_supported[i]
            = "NOT_SUPPORTED_PROTOCOL";
        System.arraycopy(supported, 0,
                more_than_supported, 0, i);
        System.arraycopy(supported, i,
                more_than_supported, i+1, supported.length-i);
        try {
            ssocket.setEnabledProtocols(more_than_supported);
            fail("Expected IllegalArgumentException was not thrown");
        } catch (IllegalArgumentException e) { }
    }
    enabled = ssocket.getEnabledProtocols();
    enabled[0] = "NOT_SUPPORTED_PROTOCOL";
    enabled = ssocket.getEnabledProtocols();
    for (int i=0; i<enabled.length; i++) {
        if ("NOT_SUPPORTED_PROTOCOL".equals(enabled[i])) {
            fail("Modification of the returned result "
                    + "causes the modification of the internal state");
        }
    }
}
 
開發者ID:shannah,項目名稱:cn1,代碼行數:47,代碼來源:SSLServerSocketImplTest.java


注:本文中的javax.net.ssl.SSLServerSocket.getSupportedProtocols方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。