Search in sources :

Example 81 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project jdk8u_jdk by JetBrains.

the class ECDHCrypt method getAgreedSecret.

// called by ServerHandshaker
SecretKey getAgreedSecret(byte[] encodedPoint) throws SSLHandshakeException {
    try {
        ECParameterSpec params = publicKey.getParams();
        ECPoint point = JsseJce.decodePoint(encodedPoint, params.getCurve());
        KeyFactory kf = JsseJce.getKeyFactory("EC");
        ECPublicKeySpec spec = new ECPublicKeySpec(point, params);
        PublicKey peerPublicKey = kf.generatePublic(spec);
        return getAgreedSecret(peerPublicKey);
    } catch (GeneralSecurityException | java.io.IOException e) {
        throw (SSLHandshakeException) new SSLHandshakeException("Could not generate secret").initCause(e);
    }
}
Also used : ECPublicKey(java.security.interfaces.ECPublicKey) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 82 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project jdk8u_jdk by JetBrains.

the class DHCrypt method checkConstraints.

// Check constraints of the specified DH public key.
void checkConstraints(AlgorithmConstraints constraints, BigInteger peerPublicValue) throws SSLHandshakeException {
    try {
        KeyFactory kf = JsseJce.getKeyFactory("DiffieHellman");
        DHPublicKeySpec spec = new DHPublicKeySpec(peerPublicValue, modulus, base);
        DHPublicKey publicKey = (DHPublicKey) kf.generatePublic(spec);
        // check constraints of DHPublicKey
        if (!constraints.permits(EnumSet.of(CryptoPrimitive.KEY_AGREEMENT), publicKey)) {
            throw new SSLHandshakeException("DHPublicKey does not comply to algorithm constraints");
        }
    } catch (GeneralSecurityException gse) {
        throw (SSLHandshakeException) new SSLHandshakeException("Could not generate DHPublicKey").initCause(gse);
    }
}
Also used : DHPublicKey(javax.crypto.interfaces.DHPublicKey) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 83 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project jdk8u_jdk by JetBrains.

the class ECDHCrypt method getAgreedSecret.

// called by ClientHandshaker with either the server's static or
// ephemeral public key
SecretKey getAgreedSecret(PublicKey peerPublicKey) throws SSLHandshakeException {
    try {
        KeyAgreement ka = JsseJce.getKeyAgreement("ECDH");
        ka.init(privateKey);
        ka.doPhase(peerPublicKey, true);
        return ka.generateSecret("TlsPremasterSecret");
    } catch (GeneralSecurityException e) {
        throw (SSLHandshakeException) new SSLHandshakeException("Could not generate secret").initCause(e);
    }
}
Also used : KeyAgreement(javax.crypto.KeyAgreement) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 84 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project platform_external_apache-http by android.

the class Connection method openHttpConnection.

/**
     * @return true on success
     */
private boolean openHttpConnection(Request req) {
    long now = SystemClock.uptimeMillis();
    int error = EventHandler.OK;
    Exception exception = null;
    try {
        // reset the certificate to null before opening a connection
        mCertificate = null;
        mHttpClientConnection = openConnection(req);
        if (mHttpClientConnection != null) {
            mHttpClientConnection.setSocketTimeout(SOCKET_TIMEOUT);
            mHttpContext.setAttribute(HTTP_CONNECTION, mHttpClientConnection);
        } else {
            // we tried to do SSL tunneling, failed,
            // and need to drop the request;
            // we have already informed the handler
            req.mFailCount = RETRY_REQUEST_LIMIT;
            return false;
        }
    } catch (UnknownHostException e) {
        if (HttpLog.LOGV)
            HttpLog.v("Failed to open connection");
        error = EventHandler.ERROR_LOOKUP;
        exception = e;
    } catch (IllegalArgumentException e) {
        if (HttpLog.LOGV)
            HttpLog.v("Illegal argument exception");
        error = EventHandler.ERROR_CONNECT;
        req.mFailCount = RETRY_REQUEST_LIMIT;
        exception = e;
    } catch (SSLConnectionClosedByUserException e) {
        // hack: if we have an SSL connection failure,
        // we don't want to reconnect
        req.mFailCount = RETRY_REQUEST_LIMIT;
        // no error message
        return false;
    } catch (SSLHandshakeException e) {
        // hack: if we have an SSL connection failure,
        // we don't want to reconnect
        req.mFailCount = RETRY_REQUEST_LIMIT;
        if (HttpLog.LOGV)
            HttpLog.v("SSL exception performing handshake");
        error = EventHandler.ERROR_FAILED_SSL_HANDSHAKE;
        exception = e;
    } catch (IOException e) {
        error = EventHandler.ERROR_CONNECT;
        exception = e;
    }
    if (HttpLog.LOGV) {
        long now2 = SystemClock.uptimeMillis();
        HttpLog.v("Connection.openHttpConnection() " + (now2 - now) + " " + mHost);
    }
    if (error == EventHandler.OK) {
        return true;
    } else {
        if (req.mFailCount < RETRY_REQUEST_LIMIT) {
            // requeue
            mRequestFeeder.requeueRequest(req);
            req.mFailCount++;
        } else {
            httpFailure(req, error, exception);
        }
        return error == EventHandler.OK;
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) IOException(java.io.IOException) ParseException(org.apache.http.ParseException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) HttpException(org.apache.http.HttpException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Example 85 with SSLHandshakeException

use of javax.net.ssl.SSLHandshakeException in project bnd by bndtools.

the class HttpConnectorTest method testConnectHTTPSBadCertificate.

public static void testConnectHTTPSBadCertificate() throws Exception {
    HttpBasicAuthURLConnector connector = new HttpBasicAuthURLConnector();
    Map<String, String> config = new HashMap<String, String>();
    config.put("configs", "testdata/http_auth.properties");
    connector.setProperties(config);
    try {
        connector.connect(new URL(getUrl(false) + "securebundles/dummybundle.jar"));
        fail("Should have thrown error: invalid server certificate");
    } catch (IOException e) {
        // expected
        assertTrue(e instanceof SSLHandshakeException);
    }
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) URL(java.net.URL) SSLHandshakeException(javax.net.ssl.SSLHandshakeException)

Aggregations

SSLHandshakeException (javax.net.ssl.SSLHandshakeException)90 IOException (java.io.IOException)29 Test (org.junit.Test)22 CertificateException (java.security.cert.CertificateException)18 URL (java.net.URL)15 SSLException (javax.net.ssl.SSLException)15 SocketException (java.net.SocketException)13 HttpsURLConnection (javax.net.ssl.HttpsURLConnection)12 SSLProtocolException (javax.net.ssl.SSLProtocolException)10 Socket (java.net.Socket)9 SSLSocket (javax.net.ssl.SSLSocket)9 SSLPeerUnverifiedException (javax.net.ssl.SSLPeerUnverifiedException)8 SocketTimeoutException (java.net.SocketTimeoutException)7 SSLSession (javax.net.ssl.SSLSession)7 InputStream (java.io.InputStream)6 SSLSocketFactory (javax.net.ssl.SSLSocketFactory)6 Channel (io.netty.channel.Channel)5 InetSocketAddress (java.net.InetSocketAddress)5 MalformedURLException (java.net.MalformedURLException)5 ClosedChannelException (java.nio.channels.ClosedChannelException)5