本文整理汇总了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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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));
}
}
示例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;
}
示例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();
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
}