use of javax.net.ssl.HttpsURLConnection in project android_frameworks_base by crdroidandroid.
the class TestUtils method assertUrlConnectionSucceeds.
public static void assertUrlConnectionSucceeds(SSLContext context, String host, int port) throws Exception {
URL url = new URL("https://" + host + ":" + port);
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setSSLSocketFactory(context.getSocketFactory());
connection.getInputStream();
}
use of javax.net.ssl.HttpsURLConnection in project dropbox-sdk-java by dropbox.
the class StandardHttpRequestor method prepRequest.
private HttpURLConnection prepRequest(String url, Iterable<Header> headers) throws IOException {
URL urlObject = new URL(url);
HttpURLConnection conn = (HttpURLConnection) urlObject.openConnection(config.getProxy());
conn.setConnectTimeout((int) config.getConnectTimeoutMillis());
conn.setReadTimeout((int) config.getReadTimeoutMillis());
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
// instead of HttpsURLConnection. So we have to check here.
if (conn instanceof HttpsURLConnection) {
SSLConfig.apply((HttpsURLConnection) conn);
configureConnection((HttpsURLConnection) conn);
} else {
logCertificatePinningWarning();
}
configure(conn);
for (Header header : headers) {
conn.addRequestProperty(header.getKey(), header.getValue());
}
return conn;
}
use of javax.net.ssl.HttpsURLConnection in project bnd by bndtools.
the class HttpsUtil method disableServerVerification.
static void disableServerVerification(URLConnection connection) throws GeneralSecurityException {
if (!(connection instanceof HttpsURLConnection))
return;
HttpsURLConnection httpsConnection = (HttpsURLConnection) connection;
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkServerTrusted(X509Certificate[] certs, String authType) throws CertificateException {
}
public void checkClientTrusted(X509Certificate[] certs, String authType) throws CertificateException {
}
} };
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new SecureRandom());
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
httpsConnection.setSSLSocketFactory(sslSocketFactory);
HostnameVerifier trustAnyHost = new HostnameVerifier() {
public boolean verify(String string, SSLSession session) {
return true;
}
};
httpsConnection.setHostnameVerifier(trustAnyHost);
}
use of javax.net.ssl.HttpsURLConnection in project bnd by bndtools.
the class HttpsVerification method handle.
/**
* Ensure Https verification is disabled or matches given certificates
*/
public void handle(URLConnection connection) throws Exception {
if (connection instanceof HttpsURLConnection && matches(connection)) {
HttpsURLConnection https = (HttpsURLConnection) connection;
init();
https.setSSLSocketFactory(factory);
https.setHostnameVerifier(verifier);
}
}
use of javax.net.ssl.HttpsURLConnection in project bnd by bndtools.
the class BndAuthentication method handle.
public void handle(URLConnection connection) throws Exception {
if (!(connection instanceof HttpURLConnection) || !matches(connection))
return;
if (!(connection instanceof HttpsURLConnection))
logger.debug("bnd authentication should only be used with https: {}", connection.getURL());
init();
// Build up Authorization header
StringBuilder sb = new StringBuilder(identity);
// Get the date header, set it if not set
String dateHeader = connection.getRequestProperty("Date");
if (dateHeader == null) {
synchronized (httpFormat) {
dateHeader = httpFormat.format(new Date());
}
connection.setRequestProperty("Date", dateHeader);
}
// Ok, calculate the signature
Signature hmac = Signature.getInstance("SHA1withRSA");
hmac.initSign(privateKey);
// never non-ascii
hmac.update(dateHeader.getBytes());
// Finish the header
sb.append(Base64.encodeBase64(hmac.sign()));
connection.setRequestProperty(X_A_QUTE_AUTHORIZATION, sb.toString());
}
Aggregations