use of javax.net.ssl.SSLSession in project pulsar by yahoo.
the class ServerCnx method handleConnect.
@Override
protected void handleConnect(CommandConnect connect) {
checkArgument(state == State.Start);
if (service.isAuthenticationEnabled()) {
try {
String authMethod = "none";
if (connect.hasAuthMethodName()) {
authMethod = connect.getAuthMethodName();
} else if (connect.hasAuthMethod()) {
// Legacy client is passing enum
authMethod = connect.getAuthMethod().name().substring(10).toLowerCase();
}
String authData = connect.getAuthData().toStringUtf8();
ChannelHandler sslHandler = ctx.channel().pipeline().get(PulsarChannelInitializer.TLS_HANDLER);
SSLSession sslSession = null;
if (sslHandler != null) {
sslSession = ((SslHandler) sslHandler).engine().getSession();
}
authRole = getBrokerService().getAuthenticationService().authenticate(new AuthenticationDataCommand(authData, remoteAddress, sslSession), authMethod);
log.info("[{}] Client successfully authenticated with {} role {}", remoteAddress, authMethod, authRole);
} catch (AuthenticationException e) {
String msg = "Unable to authenticate";
log.warn("[{}] {}: {}", remoteAddress, msg, e.getMessage());
ctx.writeAndFlush(Commands.newError(-1, ServerError.AuthenticationError, msg));
close();
return;
}
}
if (log.isDebugEnabled()) {
log.debug("Received CONNECT from {}", remoteAddress);
}
ctx.writeAndFlush(Commands.newConnected(connect));
state = State.Connected;
remoteEndpointProtocolVersion = connect.getProtocolVersion();
}
use of javax.net.ssl.SSLSession in project CloudReader by youlookwhat.
the class HttpUtils method getUnsafeOkHttpClient.
public OkHttpClient getUnsafeOkHttpClient() {
try {
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[] {};
}
} };
// Install the all-trusting trust manager
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new SecureRandom());
// Create an ssl socket factory with our all-trusting manager
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
okBuilder.readTimeout(20, TimeUnit.SECONDS);
okBuilder.connectTimeout(10, TimeUnit.SECONDS);
okBuilder.writeTimeout(20, TimeUnit.SECONDS);
okBuilder.addInterceptor(new HttpHeadInterceptor());
okBuilder.addInterceptor(getInterceptor());
okBuilder.sslSocketFactory(sslSocketFactory);
okBuilder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Log.d("HttpUtils", "==come");
return true;
}
});
return okBuilder.build();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.net.ssl.SSLSession in project OpenAM by OpenRock.
the class AMSetupUtils method openConnection.
private static HttpURLConnection openConnection(String urlString) throws IOException {
URL url = new URL(urlString);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
if (url.getProtocol().equals(HTTPS)) {
HttpsURLConnection sslConnection = (HttpsURLConnection) connection;
sslConnection.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
}
return connection;
}
use of javax.net.ssl.SSLSession in project opennms by OpenNMS.
the class VmwareConfigBuilder method main.
public static void main(String[] args) throws ParseException {
String hostname = null;
String username = null;
String password = null;
String rrdRepository = null;
final Options options = new Options();
options.addOption("rrdRepository", true, "set rrdRepository path for generated config files, default: '/opt/opennms/share/rrd/snmp/'");
final CommandLineParser parser = new PosixParser();
final CommandLine cmd = parser.parse(options, args);
@SuppressWarnings("unchecked") List<String> arguments = (List<String>) cmd.getArgList();
if (arguments.size() < 3) {
usage(options, cmd);
System.exit(1);
}
hostname = arguments.remove(0);
username = arguments.remove(0);
password = arguments.remove(0);
if (cmd.hasOption("rrdRepository")) {
rrdRepository = cmd.getOptionValue("rrdRepository");
} else {
rrdRepository = "/opt/opennms/share/rrd/snmp/";
}
TrustManager[] trustAllCerts = new TrustManager[] { new AnyServerX509TrustManager() };
SSLContext sc = null;
try {
sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, null);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HostnameVerifier hv = new HostnameVerifier() {
@Override
public boolean verify(String urlHostName, SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(hv);
VmwareConfigBuilder vmwareConfigBuilder;
vmwareConfigBuilder = new VmwareConfigBuilder(hostname, username, password);
try {
vmwareConfigBuilder.generateData(rrdRepository);
} catch (Exception e) {
e.printStackTrace();
}
}
use of javax.net.ssl.SSLSession in project android_frameworks_base by ResurrectionRemix.
the class AbstractVerifier method verify.
public final void verify(String host, SSLSocket ssl) throws IOException {
if (host == null) {
throw new NullPointerException("host to verify is null");
}
SSLSession session = ssl.getSession();
Certificate[] certs = session.getPeerCertificates();
X509Certificate x509 = (X509Certificate) certs[0];
verify(host, x509);
}
Aggregations