use of javax.net.ssl.SSLProtocolException in project fabric8 by fabric8io.
the class KubernetesHelper method isServiceSsl.
public static boolean isServiceSsl(String host, int port, boolean trustAllCerts) {
try {
LOG.info("Checking if a service is SSL on " + host + ":" + port);
SSLSocketFactory sslsocketfactory;
if (trustAllCerts) {
sslsocketfactory = TrustEverythingSSLTrustManager.getTrustingSSLSocketFactory();
} else {
sslsocketfactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
}
Socket socket = sslsocketfactory.createSocket();
// Connect, with an explicit timeout value
socket.connect(new InetSocketAddress(host, port), 1 * 1000);
try {
InputStream in = socket.getInputStream();
OutputStream out = socket.getOutputStream();
// Write a test byte to get a reaction :)
out.write(1);
while (in.available() > 0) {
System.out.print(in.read());
}
return true;
} finally {
LOG.info("Checked if a service is SSL on " + host + ":" + port);
socket.close();
}
} catch (SSLHandshakeException e) {
LOG.error("SSL handshake failed - this probably means that you need to trust the kubernetes root SSL certificate or set the environment variable " + Utils.convertSystemPropertyNameToEnvVar(io.fabric8.kubernetes.client.Config.KUBERNETES_TRUST_CERT_SYSTEM_PROPERTY), e);
} catch (SSLProtocolException e) {
LOG.error("SSL protocol error", e);
} catch (SSLKeyException e) {
LOG.error("Bad SSL key", e);
} catch (SSLPeerUnverifiedException e) {
LOG.error("Could not verify server", e);
} catch (SSLException e) {
LOG.debug("Address does not appear to be SSL-enabled - falling back to http", e);
} catch (IOException e) {
LOG.debug("Failed to validate service", e);
}
return false;
}
use of javax.net.ssl.SSLProtocolException in project fdroidclient by f-droid.
the class IndexV1Updater method update.
/**
* @return whether this successfully found an index of this version
* @throws IndexUpdater.UpdateException
* @see org.fdroid.fdroid.net.DownloaderService#handleIntent(android.content.Intent)
*/
@Override
public boolean update() throws IndexUpdater.UpdateException {
if (repo.isSwap) {
// swap repos do not support index-v1
return false;
}
Downloader downloader = null;
try {
// read file name from file
downloader = DownloaderFactory.create(context, indexUrl);
downloader.setCacheTag(repo.lastetag);
downloader.setListener(downloadListener);
downloader.download();
if (downloader.isNotFound()) {
return false;
}
hasChanged = downloader.hasChanged();
if (!hasChanged) {
return true;
}
processDownloadedIndex(downloader.outputFile, downloader.getCacheTag());
} catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException | SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException | ProtocolException | UnknownHostException e) {
// if the above list changes, also change below and in DownloaderService.handleIntent()
Utils.debugLog(TAG, "Trying to download the index from a mirror: " + e.getMessage());
// Mirror logic here, so that the default download code is untouched.
String mirrorUrl;
String prevMirrorUrl = indexUrl;
FDroidApp.resetMirrorVars();
// 3 is the number of timeouts we have. 10s, 30s & 60s
int n = repo.getMirrorCount() * 3;
for (int i = 0; i <= n; i++) {
try {
mirrorUrl = FDroidApp.getNewMirrorOnError(prevMirrorUrl, repo);
prevMirrorUrl = mirrorUrl;
downloader = DownloaderFactory.create(context, mirrorUrl);
downloader.setCacheTag(repo.lastetag);
downloader.setListener(downloadListener);
downloader.setTimeout(FDroidApp.getTimeout());
downloader.download();
if (downloader.isNotFound()) {
return false;
}
hasChanged = downloader.hasChanged();
if (!hasChanged) {
return true;
}
processDownloadedIndex(downloader.outputFile, downloader.getCacheTag());
break;
} catch (ConnectException | HttpRetryException | NoRouteToHostException | SocketTimeoutException | SSLHandshakeException | SSLKeyException | SSLPeerUnverifiedException | SSLProtocolException | ProtocolException | UnknownHostException e2) {
// We'll just let this try the next mirror
Utils.debugLog(TAG, "Trying next mirror");
} catch (IOException e2) {
if (downloader != null) {
FileUtils.deleteQuietly(downloader.outputFile);
}
throw new IndexUpdater.UpdateException(repo, "Error getting F-Droid index file", e2);
} catch (InterruptedException e2) {
// ignored if canceled, the local database just won't be updated
}
}
} catch (IOException e) {
if (downloader != null) {
FileUtils.deleteQuietly(downloader.outputFile);
}
throw new IndexUpdater.UpdateException(repo, "Error getting F-Droid index file", e);
} catch (InterruptedException e) {
// ignored if canceled, the local database just won't be updated
}
return true;
}
Aggregations