ClientHandshaker extends Handshaker { @Override public void startHandshake() throws HandshakeException { handshakeStarted(); ClientHello startMessage = new ClientHello(maxProtocolVersion, supportedCipherSuites, supportedSignatureAlgorithms, supportedClientCertificateTypes, supportedServerCertificateTypes, supportedGroups, session.getPeer()); clientRandom = startMessage.getRandom(); startMessage.addCompressionMethod(CompressionMethod.NULL); addConnectionId(startMessage); addRecordSizeLimit(startMessage); addMaxFragmentLength(startMessage); addServerNameIndication(startMessage); flightNumber = 1; clientHello = startMessage; DTLSFlight flight = new DTLSFlight(session, flightNumber); wrapMessage(flight, startMessage); sendFlight(flight); states = SEVER_CERTIFICATE; statesIndex = 0; } ClientHandshaker(DTLSSession session, RecordLayer recordLayer, ScheduledExecutorService timer, Connection connection,
			DtlsConnectorConfig config, boolean probe); @Override void startHandshake(); @Override boolean isProbing(); @Override void resetProbing(); @Override boolean isRemovingConnection();  }
@Test public void testServerCertExtPrefersX509WithTrustStore() throws Exception { givenAClientHandshaker(true); handshaker.startHandshake(); ClientHello clientHello = getClientHello(recordLayer.getSentFlight()); assertPreferredServerCertificateExtension(clientHello, CertificateType.X_509); }
@Test public void testServerCertExtPrefersX509WithEmptyTrustStore() throws Exception { givenAClientHandshaker(localPeer, false, true); handshaker.startHandshake(); ClientHello clientHello = getClientHello(recordLayer.getSentFlight()); assertPreferredServerCertificateExtension(clientHello, CertificateType.X_509); }
@Test public void testServerCertExtPrefersRawPublicKeysWithoutTrustStore() throws Exception { givenAClientHandshaker(localPeer, null, false, false, true, false); handshaker.startHandshake(); ClientHello clientHello = getClientHello(recordLayer.getSentFlight()); assertPreferredServerCertificateExtension(clientHello, CertificateType.RAW_PUBLIC_KEY); }
@Test public void testClientHelloLacksServerNameExtensionForMessageWithoutVirtualHost() throws Exception { givenAClientHandshaker(null, false); handshaker.startHandshake(); ClientHello clientHello = getClientHello(recordLayer.getSentFlight()); assertNull(clientHello.getServerNameExtension()); }
@Test public void testClientHelloLacksServerNameExtensionForDisabledSni() throws Exception { givenAClientHandshaker(localPeer, serverName, false, false, false, false); handshaker.startHandshake(); ClientHello clientHello = getClientHello(recordLayer.getSentFlight()); assertNull(clientHello.getServerNameExtension()); }
@Test public void testClientHelloContainsServerNameExtensionForMessageWithVirtualHost() throws Exception { givenAClientHandshaker(serverName, false); handshaker.startHandshake(); ClientHello clientHello = getClientHello(recordLayer.getSentFlight()); assertNotNull(clientHello.getServerNameExtension()); assertThat( clientHello.getServerNameExtension().getServerNames().getServerName(NameType.HOST_NAME).getNameAsString(), is(serverName)); }
@Test public void testClientReceivesBrokenServerHello() throws Exception { givenAClientHandshaker(false); handshaker.startHandshake(); ClientHello clientHello = getClientHello(recordLayer.getSentFlight()); assertNotNull(clientHello); CipherSuite cipherSuite = clientHello.getCipherSuites().get(0); HelloExtensions extensions = new HelloExtensions(); extensions.addExtension(ConnectionIdExtension.fromConnectionId(ConnectionId.EMPTY)); ServerHello serverHello = new ServerHello(clientHello.getClientVersion(), new Random(), new SessionId(), cipherSuite, CompressionMethod.NULL, extensions, localPeer); Record record = DtlsTestTools.getRecordForMessage(0, 1, serverHello, localPeer); record.applySession(handshaker.session); try { handshaker.processMessage(record); fail("Broken SERVER_HELLO not detected!"); } catch (HandshakeException ex) { assertThat(ex.getAlert().getLevel(), is(AlertLevel.FATAL)); assertThat(ex.getAlert().getDescription(), is(AlertDescription.UNSUPPORTED_EXTENSION)); } }