use of org.openecard.bouncycastle.tls.TlsClientProtocol in project open-ecard by ecsec.
the class HttpConnectProxy method connectSocket.
private Socket connectSocket() throws IOException {
// Socket object connecting to proxy
Socket sock = new Socket();
SocketAddress addr = new InetSocketAddress(proxyHost, proxyPort);
sock.setKeepAlive(true);
// this is pretty much, but not a problem, as this only shifts the responsibility to the server
sock.setSoTimeout(5 * 60 * 1000);
sock.connect(addr, 60 * 1000);
// evaluate scheme
if ("HTTPS".equals(proxyScheme)) {
TlsCrypto crypto = new BcTlsCrypto(ReusableSecureRandom.getInstance());
ClientCertDefaultTlsClient tlsClient = new ClientCertDefaultTlsClient(crypto, proxyHost, true);
DynamicAuthentication tlsAuth = new DynamicAuthentication(proxyHost);
if (proxyValidate) {
CertificateVerifier cv = new CertificateVerifierBuilder().and(new HostnameVerifier()).and(new KeyLengthVerifier()).and(new JavaSecVerifier()).build();
tlsAuth.setCertificateVerifier(cv);
}
tlsClient.setAuthentication(tlsAuth);
TlsClientProtocol proto = new TlsClientProtocol(sock.getInputStream(), sock.getOutputStream());
proto.connect(tlsClient);
// wrap socket
Socket tlsSock = new SocketWrapper(sock, proto.getInputStream(), proto.getOutputStream());
return tlsSock;
} else {
return sock;
}
}
use of org.openecard.bouncycastle.tls.TlsClientProtocol in project open-ecard by ecsec.
the class JavaSecVerifierTest method testVerificationNoError.
@Test
public void testVerificationNoError() throws IOException {
final String hostName = "github.com";
TlsClientProtocol handler;
DefaultTlsClientImpl c;
try {
// open connection
Socket socket = new Socket(hostName, 443);
assertTrue(socket.isConnected());
assertTrue(socket.isBound());
assertFalse(socket.isClosed());
// connect client
c = new DefaultTlsClientImpl(hostName);
handler = new TlsClientProtocol(socket.getInputStream(), socket.getOutputStream());
} catch (Exception ex) {
throw new SkipException("Unable to create TLS client.");
}
// do TLS handshake
handler.connect(c);
handler.close();
}
use of org.openecard.bouncycastle.tls.TlsClientProtocol in project open-ecard by ecsec.
the class ChipGateway method openHttpStream.
private void openHttpStream() throws ConnectionError, InvalidRedirectUrlException {
try {
LOG.debug("Opening connection to ChipGateway server.");
TlsClientProtocol handler = tlsHandler.createTlsConnection();
conn = new StreamHttpClientConnection(handler.getInputStream(), handler.getOutputStream());
LOG.debug("Connection to ChipGateway server established.");
} catch (IOException | URISyntaxException ex) {
throw new ConnectionError(token.finalizeErrorAddress(ResultMinor.COMMUNICATION_ERROR), CONNECTION_OPEN_FAILED, ex);
}
}
use of org.openecard.bouncycastle.tls.TlsClientProtocol in project open-ecard by ecsec.
the class TlsConnectionHandler method createTlsConnection.
public TlsClientProtocol createTlsConnection(ProtocolVersion tlsVersion) throws IOException, URISyntaxException {
// normal procedure, create a new channel
Socket socket = ProxySettings.getDefault().getSocket("https", hostname, port);
tlsClient.setClientVersion(tlsVersion);
// TLS
InputStream sockIn = socket.getInputStream();
OutputStream sockOut = socket.getOutputStream();
TlsClientProtocol handler = new TlsClientProtocol(sockIn, sockOut);
handler.connect(tlsClient);
return handler;
}
use of org.openecard.bouncycastle.tls.TlsClientProtocol in project open-ecard by ecsec.
the class TlsConnectionHandler method createNewTlsConnection.
private TlsClientProtocol createNewTlsConnection(ProtocolVersion tlsVersion) throws IOException, URISyntaxException {
Socket socket = ProxySettings.getDefault().getSocket("https", hostname, port);
tlsClient.setClientVersion(tlsVersion);
// TLS
InputStream sockIn = socket.getInputStream();
OutputStream sockOut = socket.getOutputStream();
TlsClientProtocol handler = new TlsClientProtocol(sockIn, sockOut);
handler.connect(tlsClient);
return handler;
}
Aggregations