當前位置: 首頁>>代碼示例>>Java>>正文


Java SSLHandshakeException類代碼示例

本文整理匯總了Java中javax.net.ssl.SSLHandshakeException的典型用法代碼示例。如果您正苦於以下問題:Java SSLHandshakeException類的具體用法?Java SSLHandshakeException怎麽用?Java SSLHandshakeException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SSLHandshakeException類屬於javax.net.ssl包,在下文中一共展示了SSLHandshakeException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: retryRequest

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    if (LOGGER.isTraceEnabled()) {
        LOGGER.trace("Decide about retry #" + executionCount + " for exception " + exception.getMessage());
    }

    if (executionCount >= _maxRetryCount) {
        // Do not retry if over max retry count
        return false;
    } else if (exception instanceof NoHttpResponseException) {
        // Retry if the server dropped connection on us
        return true;
    } else if (exception instanceof SSLHandshakeException) {
        // Do not retry on SSL handshake exception
        return false;
    }

    HttpRequest request = (HttpRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
    boolean idempotent = !(request instanceof HttpEntityEnclosingRequest);
    // Retry if the request is considered idempotent
    return idempotent;
}
 
開發者ID:crawler-commons,項目名稱:http-fetcher,代碼行數:23,代碼來源:SimpleHttpFetcher.java

示例2: testExcludedCiphers

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
/**
 * Test that verifies that excluded ciphers (SSL_RSA_WITH_RC4_128_SHA,
 * TLS_ECDH_ECDSA_WITH_RC4_128_SHA,TLS_ECDH_RSA_WITH_RC4_128_SHA,
 * TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,TLS_ECDHE_RSA_WITH_RC4_128_SHA) are not
 * available for negotiation during SSL connection.
 */
@Test
public void testExcludedCiphers() throws Exception {
  URL url = new URL(baseUrl, "/echo?a=b&c=d");
  HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
  SSLSocketFactory sslSocketF = clientSslFactory.createSSLSocketFactory();
  PrefferedCipherSSLSocketFactory testPreferredCipherSSLSocketF
      = new PrefferedCipherSSLSocketFactory(sslSocketF,
          excludeCiphers.split(","));
  conn.setSSLSocketFactory(testPreferredCipherSSLSocketF);
  assertFalse("excludedCipher list is empty", excludeCiphers.isEmpty());
  try {
    InputStream in = conn.getInputStream();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copyBytes(in, out, 1024);
    fail("No Ciphers in common, SSLHandshake must fail.");
  } catch (SSLHandshakeException ex) {
    LOG.info("No Ciphers in common, expected succesful test result.", ex);
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:26,代碼來源:TestSSLHttpServer.java

示例3: testOneEnabledCiphers

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
/** Test that verified that additionally included cipher
 * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA is only available cipher for working
 * TLS connection from client to server disabled for all other common ciphers.
 */
@Test
public void testOneEnabledCiphers() throws Exception {
  URL url = new URL(baseUrl, "/echo?a=b&c=d");
  HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
  SSLSocketFactory sslSocketF = clientSslFactory.createSSLSocketFactory();
  PrefferedCipherSSLSocketFactory testPreferredCipherSSLSocketF
      = new PrefferedCipherSSLSocketFactory(sslSocketF,
          oneEnabledCiphers.split(","));
  conn.setSSLSocketFactory(testPreferredCipherSSLSocketF);
  assertFalse("excludedCipher list is empty", oneEnabledCiphers.isEmpty());
  try {
    InputStream in = conn.getInputStream();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copyBytes(in, out, 1024);
    assertEquals(out.toString(), "a:b\nc:d\n");
    LOG.info("Atleast one additional enabled cipher than excluded ciphers,"
        + " expected successful test result.");
  } catch (SSLHandshakeException ex) {
    fail("Atleast one additional cipher available for successful handshake."
        + " Unexpected test failure: " + ex);
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:27,代碼來源:TestSSLHttpServer.java

示例4: retryRequest

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {
    if (executionCount >= 5) {// 如果已經重試了5次,就放棄
        return false;
    }
    if (exception instanceof NoHttpResponseException) {// 如果服務器丟掉了連接,那麽就重試
        return true;
    }
    if (exception instanceof InterruptedIOException) {// 超時
        return false;
    }
    if (exception instanceof SSLHandshakeException) {// 不要重試SSL握手異常
        return false;
    }
    if (exception instanceof UnknownHostException) {// 目標服務器不可達
        return false;
    }
    if (exception instanceof ConnectTimeoutException) {// 連接被拒絕
        return false;
    }
    if (exception instanceof SSLException) {// SSL握手異常
        return false;
    }
    HttpClientContext clientContext = HttpClientContext.adapt(context);
    HttpRequest request = clientContext.getRequest();
    // 如果請求是冪等的,就再次嘗試
    if (!(request instanceof HttpEntityEnclosingRequest)) {
        return true;
    }
    return false;
}
 
開發者ID:adealjason,項目名稱:dtsopensource,代碼行數:32,代碼來源:HttpProtocolParent.java

示例5: testExclusiveEnabledCiphers

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
/** Test verifies that mutually exclusive server's disabled cipher suites and
 * client's enabled cipher suites can successfully establish TLS connection.
 */
@Test
public void testExclusiveEnabledCiphers() throws Exception {
  URL url = new URL(baseUrl, "/echo?a=b&c=d");
  HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
  SSLSocketFactory sslSocketF = clientSslFactory.createSSLSocketFactory();
  PrefferedCipherSSLSocketFactory testPreferredCipherSSLSocketF
      = new PrefferedCipherSSLSocketFactory(sslSocketF,
          exclusiveEnabledCiphers.split(","));
  conn.setSSLSocketFactory(testPreferredCipherSSLSocketF);
  assertFalse("excludedCipher list is empty",
      exclusiveEnabledCiphers.isEmpty());
  try {
    InputStream in = conn.getInputStream();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    IOUtils.copyBytes(in, out, 1024);
    assertEquals(out.toString(), "a:b\nc:d\n");
    LOG.info("Atleast one additional enabled cipher than excluded ciphers,"
        + " expected successful test result.");
  } catch (SSLHandshakeException ex) {
    fail("Atleast one additional cipher available for successful handshake."
        + " Unexpected test failure: " + ex);
  }
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:27,代碼來源:TestSSLHttpServer.java

示例6: checkError

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
public void checkError(Throwable e){
    try {
        throwable = e;
        fireBaseReportError(e);
        Crashlytics.logException(e);
        e.printStackTrace();

        if (e instanceof HttpException) {
            int code = getHttpErrorCode(e);
            httpMessage(code);
        }
        else if (e instanceof ConnectException) {
            showToast(mContext.getString(R.string.slow_internet));
        } else if (e instanceof UnknownHostException || e instanceof SocketTimeoutException) {
            showToast(mContext.getString(R.string.internet_not_connected));
        } else if (e instanceof SSLHandshakeException || e instanceof SSLPeerUnverifiedException) {
            showToast(mContext.getString(R.string.server_problem));
        } else {
            showToast(mContext.getString(R.string.unknown_error_msg));
        }
    }
    catch (Exception err){
        err.printStackTrace();
    }
}
 
開發者ID:afiqiqmal,項目名稱:My-Android-Base-Code,代碼行數:26,代碼來源:ErrorUtils.java

示例7: testInvalidCertificate

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
@Test
public void testInvalidCertificate() throws Exception {
    NetworkServer server = createServer();

    get(server.start(newServerAddress()));

    NetworkSslConfig ssl = new NetworkSslConfig()
        .withProvider(context().ssl().get().getProvider())
        .withKeyStorePath("ssl/hekate-test2.jks")
        .withKeyStorePassword("hekate-test2")
        .withTrustStorePath("ssl/hekate-test2.jks")
        .withTrustStorePassword("hekate-test2");

    NetworkClient<String> client = createClient(cfg ->
        cfg.setSsl(NettySslUtils.clientContext(ssl, context().resources()))
    );

    try {
        client.connect(server.address(), new NetworkClientCallbackMock<>()).get();

        fail("Error was expected.");
    } catch (ExecutionException e) {
        assertTrue(getStacktrace(e), ErrorUtils.isCausedBy(SSLHandshakeException.class, e));
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:26,代碼來源:InvalidSslConfigurationTest.java

示例8: retryRequest

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
@Override
public boolean retryRequest(IOException exception, int executionCount, HttpContext context) {

    if (executionCount >= 3) {// 如果已經重試了3次,就放棄
        return false;
    }

    if (exception instanceof NoHttpResponseException) {// 如果服務器丟掉了連接,那麽就重試
        return true;
    }

    if (exception instanceof SSLHandshakeException) {// 不要重試SSL握手異常
        return false;
    }

    if (exception instanceof InterruptedIOException) {// 超時
        return true;
    }

    if (exception instanceof UnknownHostException) {// 目標服務器不可達
        return false;
    }

    if (exception instanceof ConnectTimeoutException) {// 連接被拒絕
        return false;
    }

    if (exception instanceof SSLException) {// ssl握手異常
        return false;
    }

    HttpClientContext clientContext = HttpClientContext.adapt(context);
    HttpRequest request = clientContext.getRequest();

    // 如果請求是冪等的,就再次嘗試
    if (!(request instanceof HttpEntityEnclosingRequest)) {
        return true;
    }
    return false;
}
 
開發者ID:fengzhizi715,項目名稱:PicCrawler,代碼行數:41,代碼來源:RetryHandler.java

示例9: errorMessage

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
private String errorMessage(Exception ex) {
   String msg = Messages.CONNECTION_FAILED;
   if (ex instanceof IOException || ex instanceof SecurityException) {
       Throwable cause = null;
       Throwable c = ex.getCause();
       while (c != null) {
           cause = c;
           c = c.getCause();
       }
       if (cause instanceof ConnectException) {
           return msg + ": " + cause.getMessage();
       } else if (cause instanceof UnknownHostException) {
           return Resources.format(Messages.UNKNOWN_HOST, cause.getMessage());
       } else if (cause instanceof NoRouteToHostException) {
           return msg + ": " + cause.getMessage();
       } else if (cause instanceof FailedLoginException) {
           return msg + ": " + cause.getMessage();
       } else if (cause instanceof SSLHandshakeException) {
           return msg + ": "+ cause.getMessage();
       }
    } else if (ex instanceof MalformedURLException) {
       return Resources.format(Messages.INVALID_URL, ex.getMessage());
    }
    return msg + ": " + ex.getMessage();
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:26,代碼來源:JConsole.java

示例10: checkConstraints

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:21,代碼來源:DHCrypt.java

示例11: getAgreedSecret

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:ECDHCrypt.java

示例12: testNoConnect

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
private static void testNoConnect(int port, int rmiPort) throws Exception {
    try {
        testConnect(port, rmiPort);
        throw new Exception("Didn't expect the management agent running");
    } catch (Exception e) {
        Throwable t = e;
        while (t != null) {
            if (t instanceof NoSuchObjectException ||
                t instanceof ConnectException ||
                t instanceof SSLHandshakeException) {
                break;
            }
            t = t.getCause();
        }
        if (t == null) {
            throw new Exception("Unexpected exception", e);
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:JMXStartStopTest.java

示例13: testNoConnect

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
private static void testNoConnect(int port, int rmiPort) throws Exception {
    try {
        testConnect(port, rmiPort);
        throw new Exception("Didn't expect the management agent running");
    } catch (Exception e) {
        Throwable t = e;
        while (t != null) {
            if (t instanceof RemoteException ||
                t instanceof SSLHandshakeException ||
                t instanceof ConnectException) {
                break;
            }
            t = t.getCause();
        }
        if (t == null) {
            throw new Exception("Unexpected exception", e);
        }
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:JMXStartStopTest.java

示例14: downloadFile

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
protected byte[] downloadFile(String xpath, String fitxer) {
	
	//System.setProperty ("jsse.enableSNIExtension", "false");
	
	FileDownloader downloader = new FileDownloader(driver);
	driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
	boolean isPresent = driver.findElements(By.xpath(xpath)).size() > 0;
	driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
	assertTrue("Enllaç al fitxer " + fitxer + " no existeix" , isPresent);
	
	byte[] downloadedFile = null;
	
	try {
		downloadedFile = downloader.downloadFile(driver.findElement(By.xpath(xpath)));
	} catch (SSLHandshakeException certEx) {
		certEx.printStackTrace();
		fail("No s'ha pogut descarregar el fitxer " + fitxer + ". Error de certificat.");
	} catch (Exception e) {
		e.printStackTrace();
		fail("No s'ha pogut descarregar el fitxer " + fitxer);
	}
	
	assertThat(downloader.getHTTPStatusOfLastDownloadAttempt(), is(equalTo(200)));
	
	return downloadedFile;
}
 
開發者ID:GovernIB,項目名稱:helium,代碼行數:27,代碼來源:BaseTest.java

示例15: onFailure

import javax.net.ssl.SSLHandshakeException; //導入依賴的package包/類
@Override
public void onFailure(@NonNull Call<MediathekAnswer> call, @NonNull Throwable t) {
	adapter.setLoading(false);
	swipeRefreshLayout.setRefreshing(false);

	if (!call.isCanceled()) {
		// ignore canceled calls, because it most likely was canceled by app code
		Timber.e(t);

		if (t instanceof SSLHandshakeException || t instanceof UnknownServiceException) {
			showError(R.string.error_mediathek_ssl_error);
		} else {
			showError(R.string.error_mediathek_info_not_available);
		}
	}
}
 
開發者ID:cemrich,項目名稱:zapp,代碼行數:17,代碼來源:MediathekListFragment.java


注:本文中的javax.net.ssl.SSLHandshakeException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。