bump engine.io-client, add setDefaultHostnameVerifier method
This commit is contained in:
@@ -3,6 +3,7 @@ package com.github.nkzawa.socketio.client;
|
||||
|
||||
import com.github.nkzawa.socketio.parser.Parser;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URI;
|
||||
@@ -27,6 +28,10 @@ public class IO {
|
||||
Manager.defaultSSLContext = sslContext;
|
||||
}
|
||||
|
||||
public static void setDefaultHostnameVerifier(HostnameVerifier hostnameVerifier) {
|
||||
Manager.defaultHostnameVerifier = hostnameVerifier;
|
||||
}
|
||||
|
||||
private IO() {}
|
||||
|
||||
public static Socket socket(String uri) throws URISyntaxException {
|
||||
|
||||
@@ -6,10 +6,11 @@ import com.github.nkzawa.socketio.parser.Packet;
|
||||
import com.github.nkzawa.socketio.parser.Parser;
|
||||
import com.github.nkzawa.thread.EventThread;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import java.net.URI;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -70,6 +71,7 @@ public class Manager extends Emitter {
|
||||
public static final String EVENT_TRANSPORT = Engine.EVENT_TRANSPORT;
|
||||
|
||||
/*package*/ static SSLContext defaultSSLContext;
|
||||
/*package*/ static HostnameVerifier defaultHostnameVerifier;
|
||||
|
||||
/*package*/ ReadyState readyState = null;
|
||||
|
||||
@@ -120,6 +122,9 @@ public class Manager extends Emitter {
|
||||
if (opts.sslContext == null) {
|
||||
opts.sslContext = defaultSSLContext;
|
||||
}
|
||||
if (opts.hostnameVerifier == null) {
|
||||
opts.hostnameVerifier = defaultHostnameVerifier;
|
||||
}
|
||||
this.opts = opts;
|
||||
this.nsps = new ConcurrentHashMap<String, Socket>();
|
||||
this.subs = new LinkedList<On.Handle>();
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.JUnit4;
|
||||
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.KeyManagerFactory;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManagerFactory;
|
||||
@@ -20,15 +21,12 @@ import java.util.concurrent.LinkedBlockingQueue;
|
||||
@RunWith(JUnit4.class)
|
||||
public class SSLConnectionTest extends Connection {
|
||||
|
||||
static {
|
||||
// for test on localhost
|
||||
javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier(
|
||||
new javax.net.ssl.HostnameVerifier(){
|
||||
public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
|
||||
return hostname.equals("localhost");
|
||||
}
|
||||
});
|
||||
}
|
||||
static HostnameVerifier hostnameVerifier = new javax.net.ssl.HostnameVerifier(){
|
||||
public boolean verify(String hostname, javax.net.ssl.SSLSession sslSession) {
|
||||
return hostname.equals("localhost");
|
||||
}
|
||||
};
|
||||
|
||||
private Socket socket;
|
||||
|
||||
@@ -68,6 +66,7 @@ public class SSLConnectionTest extends Connection {
|
||||
@After
|
||||
public void tearDown() {
|
||||
IO.setDefaultSSLContext(null);
|
||||
IO.setDefaultHostnameVerifier(null);
|
||||
}
|
||||
|
||||
@Test(timeout = TIMEOUT)
|
||||
@@ -75,6 +74,7 @@ public class SSLConnectionTest extends Connection {
|
||||
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
|
||||
IO.Options opts = createOptions();
|
||||
opts.sslContext = createSSLContext();
|
||||
opts.hostnameVerifier = hostnameVerifier;
|
||||
socket = client(opts);
|
||||
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
|
||||
@Override
|
||||
@@ -97,6 +97,7 @@ public class SSLConnectionTest extends Connection {
|
||||
public void defaultSSLContext() throws Exception {
|
||||
final BlockingQueue<Object> values = new LinkedBlockingQueue<Object>();
|
||||
IO.setDefaultSSLContext(createSSLContext());
|
||||
IO.setDefaultHostnameVerifier(hostnameVerifier);
|
||||
socket = client();
|
||||
socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user