类javax.net.ssl.SNIMatcher源码实例Demo

下面列出了怎么用javax.net.ssl.SNIMatcher的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: openjsse   文件: ServerNameExtension.java
private static SNIServerName chooseSni(Collection<SNIMatcher> matchers,
        List<SNIServerName> sniNames) {
    if (sniNames != null && !sniNames.isEmpty()) {
        for (SNIMatcher matcher : matchers) {
            int matcherType = matcher.getType();
            for (SNIServerName sniName : sniNames) {
                if (sniName.getType() == matcherType) {
                    if (matcher.matches(sniName)) {
                        return sniName;
                    }

                    // no duplicated entry in the server names list.
                    break;
                }
            }
        }
    }

    return null;
}
 
源代码2 项目: netty-4.1.22   文件: Java8SslUtils.java
@SuppressWarnings("unchecked")
static boolean checkSniHostnameMatch(Collection<?> matchers, String hostname) {
    if (matchers != null && !matchers.isEmpty()) {
        SNIHostName name = new SNIHostName(hostname);
        Iterator<SNIMatcher> matcherIt = (Iterator<SNIMatcher>) matchers.iterator();
        while (matcherIt.hasNext()) {
            SNIMatcher matcher = matcherIt.next();
            // type 0 is for hostname
            if (matcher.getType() == 0 && matcher.matches(name)) {
                return true;
            }
        }
        return false;
    }
    return true;
}
 
源代码3 项目: Bytecoder   文件: ServerNameExtension.java
private static SNIServerName chooseSni(Collection<SNIMatcher> matchers,
        List<SNIServerName> sniNames) {
    if (sniNames != null && !sniNames.isEmpty()) {
        for (SNIMatcher matcher : matchers) {
            int matcherType = matcher.getType();
            for (SNIServerName sniName : sniNames) {
                if (sniName.getType() == matcherType) {
                    if (matcher.matches(sniName)) {
                        return sniName;
                    }

                    // no duplicated entry in the server names list.
                    break;
                }
            }
        }
    }

    return null;
}
 
源代码4 项目: openjdk-jdk9   文件: SSLEngineTestCase.java
/**
 * Returns server ssl engine.
 *
 * @param context - SSLContext to get SSLEngine from.
 * @param useSNI  - flag used to enable or disable using SNI extension.
 *                Needed for Kerberos.
 */
public static SSLEngine getServerSSLEngine(
        SSLContext context, boolean useSNI) {

    SSLEngine serverEngine = context.createSSLEngine();
    serverEngine.setUseClientMode(false);
    if (useSNI) {
        SNIMatcher matcher = SNIHostName.createSNIMatcher(SNI_PATTERN);
        List<SNIMatcher> matchers = new ArrayList<>();
        matchers.add(matcher);
        SSLParameters params = serverEngine.getSSLParameters();
        params.setSNIMatchers(matchers);
        serverEngine.setSSLParameters(params);
    }
    return serverEngine;
}
 
源代码5 项目: openjsse   文件: SSLConfiguration.java
SSLConfiguration(SSLContextImpl sslContext, boolean isClientMode) {

        // Configurations with SSLParameters, default values.
        this.userSpecifiedAlgorithmConstraints =
                SSLAlgorithmConstraints.DEFAULT;
        this.enabledProtocols =
                sslContext.getDefaultProtocolVersions(!isClientMode);
        this.enabledCipherSuites =
                sslContext.getDefaultCipherSuites(!isClientMode);
        this.clientAuthType = ClientAuthType.CLIENT_AUTH_NONE;

        this.identificationProtocol = null;
        this.serverNames = Collections.<SNIServerName>emptyList();
        this.sniMatchers = Collections.<SNIMatcher>emptyList();
        this.preferLocalCipherSuites = false;

        this.applicationProtocols = new String[0];
        this.enableRetransmissions = sslContext.isDTLS();
        this.maximumPacketSize = 0;         // please reset it explicitly later

        this.maximumProtocolVersion = ProtocolVersion.NONE;
        for (ProtocolVersion pv : enabledProtocols) {
            if (pv.compareTo(maximumProtocolVersion) > 0) {
                this.maximumProtocolVersion = pv;
            }
        }

        // Configurations per SSLSocket or SSLEngine instance.
        this.isClientMode = isClientMode;
        this.enableSessionCreation = true;
        this.socketAPSelector = null;
        this.engineAPSelector = null;

        this.handshakeListeners = null;
        this.noSniExtension = false;
        this.noSniMatcher = false;
    }
 
源代码6 项目: dragonwell8_jdk   文件: ServerNameExtension.java
boolean isMatched(Collection<SNIMatcher> matchers) {
    if (sniMap != null && !sniMap.isEmpty()) {
        for (SNIMatcher matcher : matchers) {
            SNIServerName sniName = sniMap.get(matcher.getType());
            if (sniName != null && (!matcher.matches(sniName))) {
                return false;
            }
        }
    }

    return true;
}
 
源代码7 项目: dragonwell8_jdk   文件: SSLServerSocketImpl.java
/**
 * Applies SSLParameters to newly accepted connections.
 */
@Override
synchronized public void setSSLParameters(SSLParameters params) {
    super.setSSLParameters(params);

    // the super implementation does not handle the following parameters
    identificationProtocol = params.getEndpointIdentificationAlgorithm();
    algorithmConstraints = params.getAlgorithmConstraints();
    preferLocalCipherSuites = params.getUseCipherSuitesOrder();
    Collection<SNIMatcher> matchers = params.getSNIMatchers();
    if (matchers != null) {
        sniMatchers = params.getSNIMatchers();
    }
}
 
源代码8 项目: dragonwell8_jdk   文件: UnboundSSLUtils.java
static SSLEchoServer init(String cipherSuiteFilter,
        String sniPattern) throws NoSuchAlgorithmException, IOException {
    SSLContext context = SSLContext.getDefault();
    SSLServerSocketFactory ssf =
            (SSLServerSocketFactory) context.getServerSocketFactory();
    SSLServerSocket ssocket =
            (SSLServerSocket) ssf.createServerSocket(0);

    // specify enabled cipher suites
    if (cipherSuiteFilter != null) {
        String[] ciphersuites = UnboundSSLUtils.filterStringArray(
                ssf.getSupportedCipherSuites(), cipherSuiteFilter);
        System.out.println("Server: enabled cipher suites: "
                + Arrays.toString(ciphersuites));
        ssocket.setEnabledCipherSuites(ciphersuites);
    }

    // specify SNI matcher pattern
    if (sniPattern != null) {
        System.out.println("Server: set SNI matcher: " + sniPattern);
        SNIMatcher matcher = SNIHostName.createSNIMatcher(sniPattern);
        List<SNIMatcher> matchers = new ArrayList<>();
        matchers.add(matcher);
        SSLParameters params = ssocket.getSSLParameters();
        params.setSNIMatchers(matchers);
        ssocket.setSSLParameters(params);
    }

    return new SSLEchoServer(ssocket);
}
 
源代码9 项目: netty-4.1.22   文件: Java8SslTestUtils.java
static void setSNIMatcher(SSLParameters parameters) {
    SNIMatcher matcher = new SNIMatcher(0) {
        @Override
        public boolean matches(SNIServerName sniServerName) {
            return false;
        }
    };
    parameters.setSNIMatchers(Collections.singleton(matcher));
}
 
源代码10 项目: TencentKona-8   文件: ServerNameExtension.java
boolean isMatched(Collection<SNIMatcher> matchers) {
    if (sniMap != null && !sniMap.isEmpty()) {
        for (SNIMatcher matcher : matchers) {
            SNIServerName sniName = sniMap.get(matcher.getType());
            if (sniName != null && (!matcher.matches(sniName))) {
                return false;
            }
        }
    }

    return true;
}
 
源代码11 项目: TencentKona-8   文件: SSLServerSocketImpl.java
/**
 * Applies SSLParameters to newly accepted connections.
 */
@Override
synchronized public void setSSLParameters(SSLParameters params) {
    super.setSSLParameters(params);

    // the super implementation does not handle the following parameters
    identificationProtocol = params.getEndpointIdentificationAlgorithm();
    algorithmConstraints = params.getAlgorithmConstraints();
    preferLocalCipherSuites = params.getUseCipherSuitesOrder();
    Collection<SNIMatcher> matchers = params.getSNIMatchers();
    if (matchers != null) {
        sniMatchers = params.getSNIMatchers();
    }
}
 
源代码12 项目: TencentKona-8   文件: UnboundSSLUtils.java
static SSLEchoServer init(String cipherSuiteFilter,
        String sniPattern) throws NoSuchAlgorithmException, IOException {
    SSLContext context = SSLContext.getDefault();
    SSLServerSocketFactory ssf =
            (SSLServerSocketFactory) context.getServerSocketFactory();
    SSLServerSocket ssocket =
            (SSLServerSocket) ssf.createServerSocket(0);

    // specify enabled cipher suites
    if (cipherSuiteFilter != null) {
        String[] ciphersuites = UnboundSSLUtils.filterStringArray(
                ssf.getSupportedCipherSuites(), cipherSuiteFilter);
        System.out.println("Server: enabled cipher suites: "
                + Arrays.toString(ciphersuites));
        ssocket.setEnabledCipherSuites(ciphersuites);
    }

    // specify SNI matcher pattern
    if (sniPattern != null) {
        System.out.println("Server: set SNI matcher: " + sniPattern);
        SNIMatcher matcher = SNIHostName.createSNIMatcher(sniPattern);
        List<SNIMatcher> matchers = new ArrayList<>();
        matchers.add(matcher);
        SSLParameters params = ssocket.getSSLParameters();
        params.setSNIMatchers(matchers);
        ssocket.setSSLParameters(params);
    }

    return new SSLEchoServer(ssocket);
}
 
源代码13 项目: jdk8u60   文件: ServerNameExtension.java
boolean isMatched(Collection<SNIMatcher> matchers) {
    if (sniMap != null && !sniMap.isEmpty()) {
        for (SNIMatcher matcher : matchers) {
            SNIServerName sniName = sniMap.get(matcher.getType());
            if (sniName != null && (!matcher.matches(sniName))) {
                return false;
            }
        }
    }

    return true;
}
 
源代码14 项目: jdk8u60   文件: SSLServerSocketImpl.java
/**
 * Applies SSLParameters to newly accepted connections.
 */
@Override
synchronized public void setSSLParameters(SSLParameters params) {
    super.setSSLParameters(params);

    // the super implementation does not handle the following parameters
    identificationProtocol = params.getEndpointIdentificationAlgorithm();
    algorithmConstraints = params.getAlgorithmConstraints();
    preferLocalCipherSuites = params.getUseCipherSuitesOrder();
    Collection<SNIMatcher> matchers = params.getSNIMatchers();
    if (matchers != null) {
        sniMatchers = params.getSNIMatchers();
    }
}
 
源代码15 项目: openjdk-jdk8u   文件: ServerNameExtension.java
boolean isMatched(Collection<SNIMatcher> matchers) {
    if (sniMap != null && !sniMap.isEmpty()) {
        for (SNIMatcher matcher : matchers) {
            SNIServerName sniName = sniMap.get(matcher.getType());
            if (sniName != null && (!matcher.matches(sniName))) {
                return false;
            }
        }
    }

    return true;
}
 
源代码16 项目: openjdk-jdk8u   文件: SSLServerSocketImpl.java
/**
 * Applies SSLParameters to newly accepted connections.
 */
@Override
synchronized public void setSSLParameters(SSLParameters params) {
    super.setSSLParameters(params);

    // the super implementation does not handle the following parameters
    identificationProtocol = params.getEndpointIdentificationAlgorithm();
    algorithmConstraints = params.getAlgorithmConstraints();
    preferLocalCipherSuites = params.getUseCipherSuitesOrder();
    Collection<SNIMatcher> matchers = params.getSNIMatchers();
    if (matchers != null) {
        sniMatchers = params.getSNIMatchers();
    }
    applicationProtocols = params.getApplicationProtocols();
}
 
源代码17 项目: openjdk-jdk8u   文件: UnboundSSLUtils.java
static SSLEchoServer init(String cipherSuiteFilter,
        String sniPattern) throws NoSuchAlgorithmException, IOException {
    SSLContext context = SSLContext.getDefault();
    SSLServerSocketFactory ssf =
            (SSLServerSocketFactory) context.getServerSocketFactory();
    SSLServerSocket ssocket =
            (SSLServerSocket) ssf.createServerSocket(0);

    // specify enabled cipher suites
    if (cipherSuiteFilter != null) {
        String[] ciphersuites = UnboundSSLUtils.filterStringArray(
                ssf.getSupportedCipherSuites(), cipherSuiteFilter);
        System.out.println("Server: enabled cipher suites: "
                + Arrays.toString(ciphersuites));
        ssocket.setEnabledCipherSuites(ciphersuites);
    }

    // specify SNI matcher pattern
    if (sniPattern != null) {
        System.out.println("Server: set SNI matcher: " + sniPattern);
        SNIMatcher matcher = SNIHostName.createSNIMatcher(sniPattern);
        List<SNIMatcher> matchers = new ArrayList<>();
        matchers.add(matcher);
        SSLParameters params = ssocket.getSSLParameters();
        params.setSNIMatchers(matchers);
        ssocket.setSSLParameters(params);
    }

    return new SSLEchoServer(ssocket);
}
 
源代码18 项目: openjdk-jdk8u-backup   文件: ServerNameExtension.java
boolean isMatched(Collection<SNIMatcher> matchers) {
    if (sniMap != null && !sniMap.isEmpty()) {
        for (SNIMatcher matcher : matchers) {
            SNIServerName sniName = sniMap.get(matcher.getType());
            if (sniName != null && (!matcher.matches(sniName))) {
                return false;
            }
        }
    }

    return true;
}
 
源代码19 项目: openjdk-jdk8u-backup   文件: SSLServerSocketImpl.java
/**
 * Applies SSLParameters to newly accepted connections.
 */
@Override
synchronized public void setSSLParameters(SSLParameters params) {
    super.setSSLParameters(params);

    // the super implementation does not handle the following parameters
    identificationProtocol = params.getEndpointIdentificationAlgorithm();
    algorithmConstraints = params.getAlgorithmConstraints();
    preferLocalCipherSuites = params.getUseCipherSuitesOrder();
    Collection<SNIMatcher> matchers = params.getSNIMatchers();
    if (matchers != null) {
        sniMatchers = params.getSNIMatchers();
    }
}
 
源代码20 项目: openjdk-jdk8u-backup   文件: UnboundSSLUtils.java
static SSLEchoServer init(String cipherSuiteFilter,
        String sniPattern) throws NoSuchAlgorithmException, IOException {
    SSLContext context = SSLContext.getDefault();
    SSLServerSocketFactory ssf =
            (SSLServerSocketFactory) context.getServerSocketFactory();
    SSLServerSocket ssocket =
            (SSLServerSocket) ssf.createServerSocket(0);

    // specify enabled cipher suites
    if (cipherSuiteFilter != null) {
        String[] ciphersuites = UnboundSSLUtils.filterStringArray(
                ssf.getSupportedCipherSuites(), cipherSuiteFilter);
        System.out.println("Server: enabled cipher suites: "
                + Arrays.toString(ciphersuites));
        ssocket.setEnabledCipherSuites(ciphersuites);
    }

    // specify SNI matcher pattern
    if (sniPattern != null) {
        System.out.println("Server: set SNI matcher: " + sniPattern);
        SNIMatcher matcher = SNIHostName.createSNIMatcher(sniPattern);
        List<SNIMatcher> matchers = new ArrayList<>();
        matchers.add(matcher);
        SSLParameters params = ssocket.getSSLParameters();
        params.setSNIMatchers(matchers);
        ssocket.setSSLParameters(params);
    }

    return new SSLEchoServer(ssocket);
}
 
源代码21 项目: Bytecoder   文件: SSLConfiguration.java
SSLConfiguration(SSLContextImpl sslContext, boolean isClientMode) {

        // Configurations with SSLParameters, default values.
        this.algorithmConstraints = SSLAlgorithmConstraints.DEFAULT;
        this.enabledProtocols =
                sslContext.getDefaultProtocolVersions(!isClientMode);
        this.enabledCipherSuites =
                sslContext.getDefaultCipherSuites(!isClientMode);
        this.clientAuthType = ClientAuthType.CLIENT_AUTH_NONE;

        this.identificationProtocol = null;
        this.serverNames = Collections.<SNIServerName>emptyList();
        this.sniMatchers = Collections.<SNIMatcher>emptyList();
        this.preferLocalCipherSuites = true;

        this.applicationProtocols = new String[0];
        this.enableRetransmissions = sslContext.isDTLS();
        this.maximumPacketSize = 0;         // please reset it explicitly later

        this.maximumProtocolVersion = ProtocolVersion.NONE;
        for (ProtocolVersion pv : enabledProtocols) {
            if (pv.compareTo(maximumProtocolVersion) > 0) {
                this.maximumProtocolVersion = pv;
            }
        }

        // Configurations per SSLSocket or SSLEngine instance.
        this.isClientMode = isClientMode;
        this.enableSessionCreation = true;
        this.socketAPSelector = null;
        this.engineAPSelector = null;

        this.handshakeListeners = null;
        this.noSniExtension = false;
        this.noSniMatcher = false;
    }
 
源代码22 项目: openjdk-jdk9   文件: ServerNameExtension.java
boolean isMatched(Collection<SNIMatcher> matchers) {
    if (sniMap != null && !sniMap.isEmpty()) {
        for (SNIMatcher matcher : matchers) {
            SNIServerName sniName = sniMap.get(matcher.getType());
            if (sniName != null && (!matcher.matches(sniName))) {
                return false;
            }
        }
    }

    return true;
}
 
源代码23 项目: openjdk-jdk9   文件: SSLServerSocketImpl.java
/**
 * Applies SSLParameters to newly accepted connections.
 */
@Override
public synchronized void setSSLParameters(SSLParameters params) {
    super.setSSLParameters(params);

    // the super implementation does not handle the following parameters
    identificationProtocol = params.getEndpointIdentificationAlgorithm();
    algorithmConstraints = params.getAlgorithmConstraints();
    preferLocalCipherSuites = params.getUseCipherSuitesOrder();
    Collection<SNIMatcher> matchers = params.getSNIMatchers();
    if (matchers != null) {
        sniMatchers = params.getSNIMatchers();
    }
    applicationProtocols = params.getApplicationProtocols();
}
 
源代码24 项目: openjdk-jdk9   文件: UnboundSSLUtils.java
static SSLEchoServer init(String cipherSuiteFilter,
        String sniPattern) throws NoSuchAlgorithmException, IOException {
    SSLContext context = SSLContext.getDefault();
    SSLServerSocketFactory ssf =
            (SSLServerSocketFactory) context.getServerSocketFactory();
    SSLServerSocket ssocket =
            (SSLServerSocket) ssf.createServerSocket(0);

    // specify enabled cipher suites
    if (cipherSuiteFilter != null) {
        String[] ciphersuites = UnboundSSLUtils.filterStringArray(
                ssf.getSupportedCipherSuites(), cipherSuiteFilter);
        System.out.println("Server: enabled cipher suites: "
                + Arrays.toString(ciphersuites));
        ssocket.setEnabledCipherSuites(ciphersuites);
    }

    // specify SNI matcher pattern
    if (sniPattern != null) {
        System.out.println("Server: set SNI matcher: " + sniPattern);
        SNIMatcher matcher = SNIHostName.createSNIMatcher(sniPattern);
        List<SNIMatcher> matchers = new ArrayList<>();
        matchers.add(matcher);
        SSLParameters params = ssocket.getSSLParameters();
        params.setSNIMatchers(matchers);
        ssocket.setSSLParameters(params);
    }

    return new SSLEchoServer(ssocket);
}
 
源代码25 项目: jdk8u-jdk   文件: ServerNameExtension.java
boolean isMatched(Collection<SNIMatcher> matchers) {
    if (sniMap != null && !sniMap.isEmpty()) {
        for (SNIMatcher matcher : matchers) {
            SNIServerName sniName = sniMap.get(matcher.getType());
            if (sniName != null && (!matcher.matches(sniName))) {
                return false;
            }
        }
    }

    return true;
}
 
源代码26 项目: jdk8u-jdk   文件: SSLServerSocketImpl.java
/**
 * Applies SSLParameters to newly accepted connections.
 */
@Override
synchronized public void setSSLParameters(SSLParameters params) {
    super.setSSLParameters(params);

    // the super implementation does not handle the following parameters
    identificationProtocol = params.getEndpointIdentificationAlgorithm();
    algorithmConstraints = params.getAlgorithmConstraints();
    preferLocalCipherSuites = params.getUseCipherSuitesOrder();
    Collection<SNIMatcher> matchers = params.getSNIMatchers();
    if (matchers != null) {
        sniMatchers = params.getSNIMatchers();
    }
}
 
源代码27 项目: jdk8u-jdk   文件: UnboundSSLUtils.java
static SSLEchoServer init(String cipherSuiteFilter,
        String sniPattern) throws NoSuchAlgorithmException, IOException {
    SSLContext context = SSLContext.getDefault();
    SSLServerSocketFactory ssf =
            (SSLServerSocketFactory) context.getServerSocketFactory();
    SSLServerSocket ssocket =
            (SSLServerSocket) ssf.createServerSocket(0);

    // specify enabled cipher suites
    if (cipherSuiteFilter != null) {
        String[] ciphersuites = UnboundSSLUtils.filterStringArray(
                ssf.getSupportedCipherSuites(), cipherSuiteFilter);
        System.out.println("Server: enabled cipher suites: "
                + Arrays.toString(ciphersuites));
        ssocket.setEnabledCipherSuites(ciphersuites);
    }

    // specify SNI matcher pattern
    if (sniPattern != null) {
        System.out.println("Server: set SNI matcher: " + sniPattern);
        SNIMatcher matcher = SNIHostName.createSNIMatcher(sniPattern);
        List<SNIMatcher> matchers = new ArrayList<>();
        matchers.add(matcher);
        SSLParameters params = ssocket.getSSLParameters();
        params.setSNIMatchers(matchers);
        ssocket.setSSLParameters(params);
    }

    return new SSLEchoServer(ssocket);
}
 
源代码28 项目: hottub   文件: ServerNameExtension.java
boolean isMatched(Collection<SNIMatcher> matchers) {
    if (sniMap != null && !sniMap.isEmpty()) {
        for (SNIMatcher matcher : matchers) {
            SNIServerName sniName = sniMap.get(matcher.getType());
            if (sniName != null && (!matcher.matches(sniName))) {
                return false;
            }
        }
    }

    return true;
}
 
源代码29 项目: hottub   文件: SSLServerSocketImpl.java
/**
 * Applies SSLParameters to newly accepted connections.
 */
@Override
synchronized public void setSSLParameters(SSLParameters params) {
    super.setSSLParameters(params);

    // the super implementation does not handle the following parameters
    identificationProtocol = params.getEndpointIdentificationAlgorithm();
    algorithmConstraints = params.getAlgorithmConstraints();
    preferLocalCipherSuites = params.getUseCipherSuitesOrder();
    Collection<SNIMatcher> matchers = params.getSNIMatchers();
    if (matchers != null) {
        sniMatchers = params.getSNIMatchers();
    }
}
 
源代码30 项目: openjdk-8-source   文件: ServerNameExtension.java
boolean isMatched(Collection<SNIMatcher> matchers) {
    if (sniMap != null && !sniMap.isEmpty()) {
        for (SNIMatcher matcher : matchers) {
            SNIServerName sniName = sniMap.get(matcher.getType());
            if (sniName != null && (!matcher.matches(sniName))) {
                return false;
            }
        }
    }

    return true;
}