javax.net.ssl.StandardConstants Java Examples
The following examples show how to use
javax.net.ssl.StandardConstants.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerTlsChannel.java From tls-channel with MIT License | 6 votes |
private Optional<SNIServerName> getServerNameIndication() throws IOException, EofException { inEncrypted.prepare(); try { int recordHeaderSize = readRecordHeaderSize(); while (inEncrypted.buffer.position() < recordHeaderSize) { if (!inEncrypted.buffer.hasRemaining()) { inEncrypted.enlarge(); } TlsChannelImpl.readFromChannel(underlying, inEncrypted.buffer); // IO block } inEncrypted.buffer.flip(); Map<Integer, SNIServerName> serverNames = TlsExplorer.explore(inEncrypted.buffer); inEncrypted.buffer.compact(); SNIServerName hostName = serverNames.get(StandardConstants.SNI_HOST_NAME); if (hostName instanceof SNIHostName) { SNIHostName sniHostName = (SNIHostName) hostName; return Optional.of(sniHostName); } else { return Optional.empty(); } } finally { inEncrypted.release(); } }
Example #2
Source File: Utilities.java From openjsse with GNU General Public License v2.0 | 5 votes |
/** * Puts {@code hostname} into the {@code serverNames} list. * <P> * If the {@code serverNames} does not look like a legal FQDN, it will * not be put into the returned list. * <P> * Note that the returned list does not allow duplicated name type. * * @return a list of {@link SNIServerName} */ static List<SNIServerName> addToSNIServerNameList( List<SNIServerName> serverNames, String hostname) { SNIHostName sniHostName = rawToSNIHostName(hostname); if (sniHostName == null) { return serverNames; } int size = serverNames.size(); List<SNIServerName> sniList = (size != 0) ? new ArrayList<SNIServerName>(serverNames) : new ArrayList<SNIServerName>(1); boolean reset = false; for (int i = 0; i < size; i++) { SNIServerName serverName = sniList.get(i); if (serverName.getType() == StandardConstants.SNI_HOST_NAME) { sniList.set(i, sniHostName); if (SSLLogger.isOn && SSLLogger.isOn("ssl")) { SSLLogger.fine( "the previous server name in SNI (" + serverName + ") was replaced with (" + sniHostName + ")"); } reset = true; break; } } if (!reset) { sniList.add(sniHostName); } return Collections.<SNIServerName>unmodifiableList(sniList); }
Example #3
Source File: SSLSocketTest.java From j2objc with Apache License 2.0 | 5 votes |
public void test_SSLSocket_SNIHostName() throws Exception { TestSSLContext c = TestSSLContext.create(); final SSLSocket client = (SSLSocket) c.clientContext.getSocketFactory().createSocket(); SSLParameters clientParams = client.getSSLParameters(); clientParams.setServerNames(Collections.singletonList( (SNIServerName) new SNIHostName("www.example.com"))); client.setSSLParameters(clientParams); SSLParameters serverParams = c.serverSocket.getSSLParameters(); serverParams.setSNIMatchers(Collections.singletonList( SNIHostName.createSNIMatcher("www\\.example\\.com"))); c.serverSocket.setSSLParameters(serverParams); client.connect(new InetSocketAddress(c.host, c.port)); final SSLSocket server = (SSLSocket) c.serverSocket.accept(); ExecutorService executor = Executors.newSingleThreadExecutor(); Future<Void> future = executor.submit(new Callable<Void>() { @Override public Void call() throws Exception { client.startHandshake(); return null; } }); executor.shutdown(); server.startHandshake(); SSLSession serverSession = server.getSession(); assertTrue(serverSession instanceof ExtendedSSLSession); ExtendedSSLSession extendedServerSession = (ExtendedSSLSession) serverSession; List<SNIServerName> requestedNames = extendedServerSession.getRequestedServerNames(); assertNotNull(requestedNames); assertEquals(1, requestedNames.size()); SNIServerName serverName = requestedNames.get(0); assertEquals(StandardConstants.SNI_HOST_NAME, serverName.getType()); assertTrue(serverName instanceof SNIHostName); SNIHostName serverHostName = (SNIHostName) serverName; assertEquals("www.example.com", serverHostName.getAsciiName()); }