use of javax.net.ssl.SSLContext in project AndroidAsync by koush.
the class AsyncSSLSocketMiddleware method createConfiguredSSLEngine.
protected SSLEngine createConfiguredSSLEngine(GetSocketData data, String host, int port) {
SSLContext sslContext = getSSLContext();
SSLEngine sslEngine = sslContext.createSSLEngine();
for (AsyncSSLEngineConfigurator configurator : engineConfigurators) {
configurator.configureEngine(sslEngine, data, host, port);
}
return sslEngine;
}
use of javax.net.ssl.SSLContext in project AndroidAsync by koush.
the class SSLTests method testKeys.
public void testKeys() throws Exception {
KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
ks.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
kmf.init(ks, "storepass".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
KeyStore ts = KeyStore.getInstance(KeyStore.getDefaultType());
ts.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
tmf.init(ts);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
AsyncHttpServer httpServer = new AsyncHttpServer();
httpServer.listenSecure(8888, sslContext);
httpServer.get("/", new HttpServerRequestCallback() {
@Override
public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
response.send("hello");
}
});
Thread.sleep(1000);
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setSSLContext(sslContext);
AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setTrustManagers(tmf.getTrustManagers());
AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet("https://localhost:8888/"), null).get();
}
use of javax.net.ssl.SSLContext in project quickstarts by jboss-switchyard.
the class CamelNettyBindingTest method sendTextMessageThroughTcp.
@Test
public void sendTextMessageThroughTcp() throws Exception {
// replace existing implementation for testing purposes
_testKit.removeService("SecuredGreetingService");
final MockHandler greetingService = _testKit.registerInOnlyService("SecuredGreetingService");
greetingService.forwardInToOut();
KeyStore keystore = KeyStore.getInstance("JKS");
keystore.load(new FileInputStream("users.jks"), "changeit".toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(keystore);
SSLContext context = SSLContext.getInstance("TLS");
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keystore, "changeit".toCharArray());
context.init(keyManagerFactory.getKeyManagers(), tmf.getTrustManagers(), null);
SSLSocketFactory sf = context.getSocketFactory();
Socket clientSocket = sf.createSocket("localhost", 3939);
DataOutputStream outputStream = new DataOutputStream(clientSocket.getOutputStream());
// lets write payload directly as bytes to avoid encoding mismatches
outputStream.write(PAYLOAD.getBytes());
outputStream.flush();
// sleep a bit to receive message on camel side
Thread.sleep(50);
clientSocket.close();
greetingService.waitForOKMessage();
final LinkedBlockingQueue<Exchange> recievedMessages = greetingService.getMessages();
assertThat(recievedMessages, is(notNullValue()));
final Exchange recievedExchange = recievedMessages.iterator().next();
assertThat(PAYLOAD, is(equalTo(recievedExchange.getMessage().getContent(String.class))));
}
use of javax.net.ssl.SSLContext in project quickstarts by jboss-switchyard.
the class WorkServiceMain method main.
public static void main(String... args) throws Exception {
Set<String> policies = new HashSet<String>();
for (String arg : args) {
arg = Strings.trimToNull(arg);
if (arg != null) {
if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) {
policies.add(arg);
} else {
LOGGER.error(MAVEN_USAGE);
throw new Exception(MAVEN_USAGE);
}
}
}
if (policies.contains(HELP)) {
LOGGER.info(MAVEN_USAGE);
} else {
final String scheme;
final int port;
if (policies.contains(CONFIDENTIALITY)) {
scheme = "https";
port = getPort(8443);
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, null, null);
SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
Scheme https = new Scheme(scheme, port, sf);
SchemeRegistry sr = new SchemeRegistry();
sr.register(https);
} else {
scheme = "http";
port = getPort(8080);
}
String[] userPass = policies.contains(CLIENT_AUTHENTICATION) ? new String[] { "kermit", "the-frog-1" } : null;
invokeWorkService(scheme, port, getContext(), userPass);
}
}
use of javax.net.ssl.SSLContext in project quickstarts by jboss-switchyard.
the class WorkServiceMain method main.
public static void main(String... args) throws Exception {
Set<String> policies = new HashSet<String>();
for (String arg : args) {
arg = Strings.trimToNull(arg);
if (arg != null) {
if (arg.equals(CONFIDENTIALITY) || arg.equals(CLIENT_AUTHENTICATION) || arg.equals(HELP)) {
policies.add(arg);
} else {
LOGGER.error(MAVEN_USAGE);
throw new Exception(MAVEN_USAGE);
}
}
}
if (policies.contains(HELP)) {
LOGGER.info(MAVEN_USAGE);
} else {
final String scheme;
final int port;
if (policies.contains(CONFIDENTIALITY)) {
scheme = "https";
port = getPort(8443);
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, null, null);
SSLSocketFactory sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
Scheme https = new Scheme(scheme, port, sf);
SchemeRegistry sr = new SchemeRegistry();
sr.register(https);
} else {
scheme = "http";
port = getPort(8080);
}
String[] userPass = policies.contains(CLIENT_AUTHENTICATION) ? new String[] { "kermit", "the-frog-1" } : null;
invokeWorkService(scheme, port, getContext(), userPass);
}
}
Aggregations