use of javax.net.ssl.SSLHandshakeException in project XobotOS by xamarin.
the class HandshakeIODataStream method append.
private void append(byte[] src, int from, int length) {
if (read_pos == read_pos_end) {
// start reading state after writing
if (write_pos_beg != write_pos) {
// but inbound handshake data has been received.
throw new AlertException(AlertProtocol.UNEXPECTED_MESSAGE, new SSLHandshakeException("Handshake message has been received before " + "the last oubound message had been sent."));
}
if (read_pos < write_pos) {
read_pos = write_pos;
read_pos_end = read_pos;
}
}
if (read_pos_end + length > buff_size) {
enlargeBuffer(read_pos_end + length - buff_size);
}
System.arraycopy(src, from, buffer, read_pos_end, length);
read_pos_end += length;
}
use of javax.net.ssl.SSLHandshakeException in project zaproxy by zaproxy.
the class ExtensionAutoUpdate method getLatestVersionInfo.
protected AddOnCollection getLatestVersionInfo(final CheckForUpdateCallback callback) {
if (latestVersionInfo == null) {
if (this.remoteCallThread == null || !this.remoteCallThread.isAlive()) {
this.remoteCallThread = new Thread() {
@Override
public void run() {
// Using a thread as the first call could timeout
// and we dont want the ui to hang in the meantime
this.setName("ZAP-cfu");
String shortUrl;
String longUrl;
if (Constant.isDevBuild()) {
shortUrl = ZAP_VERSIONS_DEV_XML_SHORT;
longUrl = ZAP_VERSIONS_DEV_XML_FULL;
} else if (Constant.isDailyBuild()) {
shortUrl = ZAP_VERSIONS_WEEKLY_XML_SHORT;
longUrl = ZAP_VERSIONS_DEV_XML_FULL;
} else {
shortUrl = ZAP_VERSIONS_REL_XML_SHORT;
longUrl = ZAP_VERSIONS_REL_XML_FULL;
}
logger.debug("Getting latest version info from " + shortUrl);
try {
latestVersionInfo = new AddOnCollection(getRemoteConfigurationUrl(shortUrl), getPlatform(), false);
} catch (Exception e1) {
logger.debug("Failed to access " + shortUrl, e1);
logger.debug("Getting latest version info from " + longUrl);
try {
latestVersionInfo = new AddOnCollection(getRemoteConfigurationUrl(longUrl), getPlatform(), false);
} catch (SSLHandshakeException e2) {
if (callback != null) {
callback.insecureUrl(longUrl, e2);
}
} catch (InvalidCfuUrlException e2) {
if (callback != null) {
callback.insecureUrl(longUrl, e2);
}
} catch (Exception e2) {
logger.debug("Failed to access " + longUrl, e2);
}
}
if (callback != null && latestVersionInfo != null) {
logger.debug("Calling callback with " + latestVersionInfo);
callback.gotLatestData(latestVersionInfo);
}
logger.debug("Done");
}
};
this.remoteCallThread.start();
}
if (callback == null) {
// Synchronous, but include a 30 sec max anyway
int i = 0;
while (latestVersionInfo == null && this.remoteCallThread.isAlive() && i < 30) {
try {
Thread.sleep(1000);
i++;
} catch (InterruptedException e) {
// Ignore
}
}
}
}
return latestVersionInfo;
}
use of javax.net.ssl.SSLHandshakeException in project GNS by MobilityFirst.
the class AuthTestClient method testIt.
private void testIt(String jksFile) {
try {
String https_url = "https://localhost:24803/";
URL url;
url = new URL(https_url);
HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setSSLSocketFactory(getSSLFactory(jksFile));
conn.setRequestMethod("GET");
conn.setDoOutput(true);
conn.setUseCaches(false);
try (BufferedReader bir = new BufferedReader(new InputStreamReader(conn.getInputStream()))) {
String line;
while ((line = bir.readLine()) != null) {
System.out.println(line);
}
}
conn.disconnect();
} catch (SSLHandshakeException | SocketException e) {
System.out.println(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.net.ssl.SSLHandshakeException in project robovm by robovm.
the class SSLSocketTest method test_SSLSocket_clientAuth_bogusAlias.
public void test_SSLSocket_clientAuth_bogusAlias() throws Exception {
TestSSLContext c = TestSSLContext.create();
SSLContext clientContext = SSLContext.getInstance("TLS");
X509KeyManager keyManager = new X509KeyManager() {
@Override
public String chooseClientAlias(String[] keyType, Principal[] issuers, Socket socket) {
return "bogus";
}
@Override
public String chooseServerAlias(String keyType, Principal[] issuers, Socket socket) {
throw new AssertionError();
}
@Override
public X509Certificate[] getCertificateChain(String alias) {
// return null for "bogus" alias
return null;
}
@Override
public String[] getClientAliases(String keyType, Principal[] issuers) {
throw new AssertionError();
}
@Override
public String[] getServerAliases(String keyType, Principal[] issuers) {
throw new AssertionError();
}
@Override
public PrivateKey getPrivateKey(String alias) {
// return null for "bogus" alias
return null;
}
};
clientContext.init(new KeyManager[] { keyManager }, new TrustManager[] { c.clientTrustManager }, null);
SSLSocket client = (SSLSocket) clientContext.getSocketFactory().createSocket(c.host, c.port);
final SSLSocket server = (SSLSocket) c.serverSocket.accept();
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Void> future = executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
server.setNeedClientAuth(true);
server.startHandshake();
fail();
} catch (SSLHandshakeException expected) {
}
return null;
}
});
executor.shutdown();
try {
client.startHandshake();
fail();
} catch (SSLHandshakeException expected) {
// before we would get a NullPointerException from passing
// due to the null PrivateKey return by the X509KeyManager.
}
future.get();
client.close();
server.close();
c.close();
}
use of javax.net.ssl.SSLHandshakeException in project robovm by robovm.
the class SSLHandshakeExceptionTest method test_Constructor01.
/**
* Test for <code>SSLHandshakeException(String)</code> constructor Assertion:
* constructs SSLHandshakeException with detail message msg. Parameter
* <code>msg</code> is not null.
*/
public void test_Constructor01() {
SSLHandshakeException sslE;
for (int i = 0; i < msgs.length; i++) {
sslE = new SSLHandshakeException(msgs[i]);
assertEquals("getMessage() must return: ".concat(msgs[i]), sslE.getMessage(), msgs[i]);
assertNull("getCause() must return null", sslE.getCause());
}
}
Aggregations