org.bouncycastle.jsse.util.URLConnectionUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of bctls-fips Show documentation
Show all versions of bctls-fips Show documentation
The Bouncy Castle Java APIs for the TLS, including a JSSE provider. The APIs are designed primarily to be used in conjunction with the BC FIPS provider. The APIs may also be used with other providers although if being used in a FIPS context it is the responsibility of the user to ensure that any other providers used are FIPS certified and used appropriately.
package org.bouncycastle.jsse.util;
import java.io.IOException;
import java.io.InputStream;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLSocketFactory;
public class URLConnectionUtil
{
protected final SSLSocketFactory sslSocketFactory;
public URLConnectionUtil()
{
this(null);
}
public URLConnectionUtil(SSLSocketFactory sslSocketFactory)
{
this.sslSocketFactory = sslSocketFactory;
}
public URLConnection openConnection(URL url) throws IOException
{
return configureConnection(url, url.openConnection());
}
public URLConnection openConnection(URL url, Proxy proxy) throws IOException
{
return configureConnection(url, url.openConnection(proxy));
}
/** @deprecated Use {@link #openStream(URL)} instead */
public InputStream openInputStream(URL url) throws IOException
{
return openConnection(url).getInputStream();
}
public InputStream openStream(URL url) throws IOException
{
return openConnection(url).getInputStream();
}
protected URLConnection configureConnection(URL url, URLConnection connection)
{
if (!(connection instanceof HttpsURLConnection))
{
return connection;
}
HttpsURLConnection https = (HttpsURLConnection)connection;
SSLSocketFactory delegate = this.sslSocketFactory;
if (null == delegate)
{
delegate = https.getSSLSocketFactory();
}
https.setSSLSocketFactory(createSSLSocketFactory(delegate, url));
return https;
}
protected SSLSocketFactory createSSLSocketFactory(SSLSocketFactory delegate, URL url)
{
return new SNISocketFactory(delegate, url);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy