Search in sources :

Example 6 with TlsClientProtocol

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;
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) TlsClientProtocol(org.openecard.bouncycastle.tls.TlsClientProtocol) ClientCertDefaultTlsClient(org.openecard.crypto.tls.ClientCertDefaultTlsClient) BcTlsCrypto(org.openecard.bouncycastle.tls.crypto.impl.bc.BcTlsCrypto) CertificateVerifierBuilder(org.openecard.crypto.tls.verify.CertificateVerifierBuilder) KeyLengthVerifier(org.openecard.crypto.tls.verify.KeyLengthVerifier) TlsCrypto(org.openecard.bouncycastle.tls.crypto.TlsCrypto) BcTlsCrypto(org.openecard.bouncycastle.tls.crypto.impl.bc.BcTlsCrypto) HostnameVerifier(org.openecard.crypto.tls.verify.HostnameVerifier) CertificateVerifier(org.openecard.crypto.tls.CertificateVerifier) DynamicAuthentication(org.openecard.crypto.tls.auth.DynamicAuthentication) SocketAddress(java.net.SocketAddress) InetSocketAddress(java.net.InetSocketAddress) Socket(java.net.Socket) JavaSecVerifier(org.openecard.crypto.tls.verify.JavaSecVerifier) SocketWrapper(org.openecard.crypto.tls.SocketWrapper)

Example 7 with TlsClientProtocol

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();
}
Also used : TlsClientProtocol(org.openecard.bouncycastle.tls.TlsClientProtocol) SkipException(org.testng.SkipException) Socket(java.net.Socket) SkipException(org.testng.SkipException) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 8 with TlsClientProtocol

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);
    }
}
Also used : TlsClientProtocol(org.openecard.bouncycastle.tls.TlsClientProtocol) ConnectionError(org.openecard.addons.cg.ex.ConnectionError) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) StreamHttpClientConnection(org.openecard.transport.httpcore.StreamHttpClientConnection)

Example 9 with TlsClientProtocol

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;
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) TlsClientProtocol(org.openecard.bouncycastle.tls.TlsClientProtocol) Socket(java.net.Socket)

Example 10 with TlsClientProtocol

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;
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) TlsClientProtocol(org.openecard.bouncycastle.tls.TlsClientProtocol) Socket(java.net.Socket)

Aggregations

TlsClientProtocol (org.openecard.bouncycastle.tls.TlsClientProtocol)10 Socket (java.net.Socket)7 IOException (java.io.IOException)5 StreamHttpClientConnection (org.openecard.transport.httpcore.StreamHttpClientConnection)4 InputStream (java.io.InputStream)3 OutputStream (java.io.OutputStream)3 URISyntaxException (java.net.URISyntaxException)3 BcTlsCrypto (org.openecard.bouncycastle.tls.crypto.impl.bc.BcTlsCrypto)3 Test (org.testng.annotations.Test)3 HttpEntity (org.openecard.apache.http.HttpEntity)2 HttpResponse (org.openecard.apache.http.HttpResponse)2 BasicHttpEntityEnclosingRequest (org.openecard.apache.http.message.BasicHttpEntityEnclosingRequest)2 BasicHttpContext (org.openecard.apache.http.protocol.BasicHttpContext)2 HttpContext (org.openecard.apache.http.protocol.HttpContext)2 HttpRequestExecutor (org.openecard.apache.http.protocol.HttpRequestExecutor)2 TlsCrypto (org.openecard.bouncycastle.tls.crypto.TlsCrypto)2 ClientCertDefaultTlsClient (org.openecard.crypto.tls.ClientCertDefaultTlsClient)2 DynamicAuthentication (org.openecard.crypto.tls.auth.DynamicAuthentication)2 JavaSecVerifier (org.openecard.crypto.tls.verify.JavaSecVerifier)2 InetSocketAddress (java.net.InetSocketAddress)1