CertificateFetcher { public static Certificate fetchServerCertificate(Config config) { WorkflowConfigurationFactory factory = new WorkflowConfigurationFactory(config); WorkflowTrace trace = factory.createTlsEntryWorkflowtrace(config.getDefaultClientConnection()); trace.addTlsAction(new SendAction(new ClientHelloMessage(config))); trace.addTlsAction(new ReceiveTillAction(new CertificateMessage(config))); State state = new State(config, trace); WorkflowExecutor workflowExecutor = WorkflowExecutorFactory.createWorkflowExecutor( WorkflowExecutorType.DEFAULT, state); try { workflowExecutor.executeWorkflow(); if (!state.getTlsContext().getTransportHandler().isClosed()) { state.getTlsContext().getTransportHandler().closeConnection(); } } catch (IOException | WorkflowExecutionException E) { LOGGER.warn("Could not fetch ServerCertificate"); LOGGER.debug(E); } return state.getTlsContext().getServerCertificate(); } private  CertificateFetcher(); static PublicKey fetchServerPublicKey(Config config); static Certificate fetchServerCertificate(Config config);  }
@Test @Category(IntegrationTests.class) public void testFetchServerCertificate() throws Exception { byte[] actualEncoded = CertificateFetcher.fetchServerCertificate(config).getCertificateList()[0].getEncoded(); Certificate actual = CertificateFactory.getInstance("X.509").generateCertificate( new ByteArrayInputStream(actualEncoded)); assertNotNull(actual); assertEquals(expectedCertificate, actual); }