use of javax.net.ssl.X509TrustManager in project android_frameworks_base by DirtyUnicorns.
the class X509TrustManagerExtensionsTest method testNormalUseCase.
public void testNormalUseCase() throws Exception {
String defaultAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(defaultAlgorithm);
String defaultKeystoreType = KeyStore.getDefaultType();
tmf.init(KeyStore.getInstance(defaultKeystoreType));
TrustManager[] tms = tmf.getTrustManagers();
for (TrustManager tm : tms) {
if (tm instanceof X509TrustManager) {
new X509TrustManagerExtensions((X509TrustManager) tm);
return;
}
}
fail();
}
use of javax.net.ssl.X509TrustManager in project AisenWeiBo by wangdan.
the class HttpsUtility method getOkHttpClient.
public OkHttpClient getOkHttpClient() {
if (mOKHttpClient == null) {
try {
mOKHttpClient = new OkHttpClient();
mOKHttpClient.setConnectTimeout(GlobalContext.CONN_TIMEOUT, TimeUnit.MILLISECONDS);
mOKHttpClient.setReadTimeout(GlobalContext.READ_TIMEOUT, TimeUnit.MILLISECONDS);
TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { tm }, null);
mOKHttpClient.setSslSocketFactory(sslContext.getSocketFactory());
} catch (Throwable e) {
e.printStackTrace();
}
}
return mOKHttpClient;
}
use of javax.net.ssl.X509TrustManager in project wildfly by wildfly.
the class TestHttpClientUtils method getHttpsClient.
/**
*@param credentialsProvider optional cred provider
* @return client that doesn't verify https connections
*/
public static CloseableHttpClient getHttpsClient(CredentialsProvider credentialsProvider) {
try {
SSLContext ctx = SSLContext.getInstance("TLS");
X509TrustManager tm = new X509TrustManager() {
public void checkClientTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] xcs, String string) throws CertificateException {
}
public X509Certificate[] getAcceptedIssuers() {
return null;
}
};
ctx.init(null, new TrustManager[] { tm }, null);
ctx.init(null, new TrustManager[] { tm }, null);
SSLConnectionSocketFactory sslConnectionFactory = new SSLConnectionSocketFactory(ctx, new NoopHostnameVerifier());
Registry<ConnectionSocketFactory> registry = RegistryBuilder.<ConnectionSocketFactory>create().register("https", sslConnectionFactory).build();
HttpClientConnectionManager ccm = new BasicHttpClientConnectionManager(registry);
HttpClientBuilder builder = HttpClientBuilder.create().setSSLSocketFactory(sslConnectionFactory).setSSLHostnameVerifier(new NoopHostnameVerifier()).setConnectionManager(ccm);
if (credentialsProvider != null) {
builder.setDefaultCredentialsProvider(credentialsProvider);
}
return builder.build();
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
use of javax.net.ssl.X509TrustManager in project pictureapp by EyeSeeTea.
the class UnsafeOkHttpsClientFactory method getUnsafeOkHttpClient.
public static OkHttpClient getUnsafeOkHttpClient() {
try {
// Create a trust manager that does not validate certificate chains
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
} };
// Install the all-trusting trust manager
final SSLContext sslContext = SSLContext.getInstance("SSL");
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// Create an ssl socket factory with our all-trusting manager
final SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient okHttpClient = new OkHttpClient();
okHttpClient.setSslSocketFactory(sslSocketFactory);
okHttpClient.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return okHttpClient;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of javax.net.ssl.X509TrustManager in project quorrabot by GloriousEggroll.
the class SingularityAPI method StartService.
public void StartService() {
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new java.security.cert.X509Certificate[] {};
}
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
} };
try {
SSLContext mySSLContext = SSLContext.getInstance("TLS");
mySSLContext.init(null, null, null);
IO.Options opts = new IO.Options();
opts.sslContext = mySSLContext;
opts.hostnameVerifier = new NullHostnameVerifier();
webSocket = IO.socket(apiURL);
webSocket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
//com.gmt2001.Console.out.println("GameWisp API: Connected to Singularity");
webSocket.emit("authentication", new JSONObject().put("key", gwIdentifier).put("access_token", AccessToken));
}
});
webSocket.on("unauthorized", new Emitter.Listener() {
@Override
public void call(Object... args) {
JSONObject jsonObject = new JSONObject(args[0].toString());
com.gmt2001.Console.err.println("GameWisp API: Authorization Failed: " + jsonObject.getString("message"));
com.gmt2001.Console.err.println("Token: " + AccessToken + " Session ID: " + SessionID + " Client ID: " + gwIdentifier);
}
});
webSocket.on("authenticated", new Emitter.Listener() {
@Override
public void call(Object... args) {
//com.gmt2001.Console.out.println("GameWisp API: Authenticated");
JSONObject jsonObject = new JSONObject(args[0].toString());
if (!jsonObject.has("session")) {
com.gmt2001.Console.err.println("GameWisp API: Missing Session in Authenticated Return JSON");
Authenticated = false;
return;
}
SessionID = jsonObject.getString("session");
Authenticated = true;
}
});
webSocket.on("app-channel-connected", new Emitter.Listener() {
@Override
public void call(Object... args) {
if (Authenticated) {
if (Quorrabot.enableDebugging) {
com.gmt2001.Console.out.println("GameWisp API: Connected to Channel");
} else {
com.gmt2001.Console.out.println("GameWisp API: Connected and Ready for Requests");
}
ChannelConnected = true;
} else {
com.gmt2001.Console.out.println("GameWisp API: Connected to Channel; Missing Session ID; Unusable Session");
ChannelConnected = false;
}
}
});
webSocket.on("subscriber-new", new Emitter.Listener() {
@Override
public void call(Object... args) {
com.gmt2001.Console.out.println("GameWisp API: subscriber-new received");
JSONObject jsonObject = new JSONObject(args[0].toString());
if (!jsonObject.has("data")) {
return;
}
if (!jsonObject.getJSONObject("data").has("usernames")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("usernames").has("twitch")) {
return;
}
if (!jsonObject.getJSONObject("data").has("tier")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("tier").has("level")) {
return;
}
String username = jsonObject.getJSONObject("data").getJSONObject("usernames").getString("twitch");
int tier = jsonObject.getJSONObject("data").getJSONObject("tier").getInt("level");
EventBus.instance().post(new GameWispSubscribeEvent(username, tier));
}
});
webSocket.on("subscriber-anniversary", new Emitter.Listener() {
@Override
public void call(Object... args) {
com.gmt2001.Console.out.println("GameWisp API: subscriber-anniversary received");
JSONObject jsonObject = new JSONObject(args[0].toString());
if (!jsonObject.has("data")) {
return;
}
if (!jsonObject.getJSONObject("data").has("subscriber")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("subscriber").has("usernames")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("subscriber").getJSONObject("usernames").has("twitch")) {
return;
}
if (!jsonObject.getJSONObject("data").has("month_count")) {
return;
}
String username = jsonObject.getJSONObject("data").getJSONObject("subscriber").getJSONObject("usernames").getString("twitch");
int tier = jsonObject.getJSONObject("data").getJSONObject("subscriber").getJSONObject("tier").getInt("level");
int months = jsonObject.getJSONObject("data").getInt("month_count");
EventBus.instance().post(new GameWispAnniversaryEvent(username, months, tier));
}
});
webSocket.on("subscriber-benefits-change", new Emitter.Listener() {
@Override
public void call(Object... args) {
com.gmt2001.Console.out.println("GameWisp API: subscriber-benefits-change received");
JSONObject jsonObject = new JSONObject(args[0].toString());
if (!jsonObject.has("data")) {
return;
}
if (!jsonObject.getJSONObject("data").has("usernames")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("usernames").has("twitch")) {
return;
}
if (!jsonObject.has("tier")) {
return;
}
if (!jsonObject.getJSONObject("tier").has("level")) {
return;
}
String username = jsonObject.getJSONObject("data").getJSONObject("usernames").getString("twitch");
int tier = jsonObject.getJSONObject("tier").getInt("level");
EventBus.instance().post(new GameWispBenefitsEvent(username, tier));
}
});
/**
* Status Change Values:
* https://gamewisp.readme.io/docs/subscriber-new active - a
* currently active subscriber trial - a subscriber on a trial code
* grace_period - a canceled subscriber that is still received
* benefits billing_grace_period - a canceled subscriber still
* receiving benefits that was canceled due to a payment processing
* error inactive - a subscriber that is canceled and receiving no
* benefits twitch - a subscriber that is receiving free benefits
* from a partnered Twitch streamer.
*/
webSocket.on("subscriber-status-change", new Emitter.Listener() {
@Override
public void call(Object... args) {
com.gmt2001.Console.out.println("GameWisp API: subscriber-status-changed received");
JSONObject jsonObject = new JSONObject(args[0].toString());
if (!jsonObject.has("data")) {
return;
}
if (!jsonObject.getJSONObject("data").has("usernames")) {
return;
}
if (!jsonObject.getJSONObject("data").getJSONObject("usernames").has("twitch")) {
return;
}
if (!jsonObject.getJSONObject("data").has("status")) {
return;
}
String username = jsonObject.getJSONObject("data").getJSONObject("usernames").getString("twitch");
String status = jsonObject.getJSONObject("data").getString("status");
EventBus.instance().post(new GameWispChangeEvent(username, status));
}
});
webSocket.on(Socket.EVENT_DISCONNECT, new Emitter.Listener() {
@Override
public void call(Object... args) {
com.gmt2001.Console.out.println("GameWisp API: Disconnected");
}
});
webSocket.connect();
} catch (Exception ex) {
com.gmt2001.Console.err.println("GameWisp API: Exception: " + ex.getMessage());
}
}
Aggregations