1
|
package eu.dnetlib.data.collector.plugins;
|
2
|
|
3
|
import java.io.IOException;
|
4
|
import java.net.HttpURLConnection;
|
5
|
import java.net.URL;
|
6
|
import javax.net.ssl.HostnameVerifier;
|
7
|
import javax.net.ssl.HttpsURLConnection;
|
8
|
import javax.net.ssl.SSLProtocolException;
|
9
|
import javax.net.ssl.SSLSession;
|
10
|
|
11
|
import eu.dnetlib.data.collector.rmi.CollectorServiceException;
|
12
|
import org.junit.Before;
|
13
|
import org.junit.Ignore;
|
14
|
import org.junit.Test;
|
15
|
|
16
|
public class HttpConnectorTest {
|
17
|
|
18
|
private HttpConnector connector;
|
19
|
|
20
|
private static final String URL = "https://researchdata.ands.org.au/registry/services/oai?verb=Identify";
|
21
|
private static final String URL_MISCONFIGURED_SERVER = "https://www.alexandria.unisg.ch/cgi/oai2?verb=Identify";
|
22
|
private static final String URL_GOODSNI_SERVER = "https://air.unimi.it/oai/openaire?verb=Identify";
|
23
|
|
24
|
|
25
|
static {
|
26
|
System.setProperty("javax.net.debug", "ssl,handshake");
|
27
|
}
|
28
|
|
29
|
@Before
|
30
|
public void setUp() {
|
31
|
connector = new HttpConnector();
|
32
|
System.setProperty("jsse.enableSNIExtension", "true");
|
33
|
}
|
34
|
|
35
|
@Test
|
36
|
@Ignore
|
37
|
public void testGetInputSource() throws CollectorServiceException {
|
38
|
System.out.println(connector.getInputSource(URL));
|
39
|
}
|
40
|
|
41
|
@Test
|
42
|
@Ignore
|
43
|
public void testMisconfiguredServers() throws CollectorServiceException {
|
44
|
System.out.println(connector.getInputSource(URL_MISCONFIGURED_SERVER));
|
45
|
}
|
46
|
|
47
|
@Test
|
48
|
@Ignore
|
49
|
public void testMisconfiguredServers2() throws IOException {
|
50
|
HttpURLConnection urlConn = (HttpURLConnection) new URL(URL_MISCONFIGURED_SERVER).openConnection();
|
51
|
urlConn.getResponseMessage();
|
52
|
}
|
53
|
|
54
|
@Test
|
55
|
public void testDisablingSNI() throws IOException {
|
56
|
HttpURLConnection urlConn = null;
|
57
|
try {
|
58
|
urlConn = (HttpURLConnection) new URL(URL_MISCONFIGURED_SERVER).openConnection();
|
59
|
urlConn.getResponseMessage();
|
60
|
} catch(SSLProtocolException sslExce) {
|
61
|
if (sslExce.getMessage() != null && sslExce.getMessage().equals("handshake alert: unrecognized_name")) {
|
62
|
System.out.println("Server has misconfigured SSL SNI (handshake alert: unrecognized_name). Trying to disable SNI");
|
63
|
if (urlConn instanceof HttpsURLConnection) {
|
64
|
HttpsURLConnection httpsUrlConnection = (HttpsURLConnection) urlConn;
|
65
|
httpsUrlConnection.setHostnameVerifier(new HostnameVerifier() {
|
66
|
public boolean verify( String s, SSLSession sess ) {
|
67
|
return true;
|
68
|
}});
|
69
|
|
70
|
}
|
71
|
urlConn.getResponseMessage();
|
72
|
}
|
73
|
}
|
74
|
}
|
75
|
|
76
|
@Test
|
77
|
public void testGoodServers() throws CollectorServiceException {
|
78
|
System.out.println(connector.getInputSource(URL_GOODSNI_SERVER));
|
79
|
}
|
80
|
|
81
|
|
82
|
}
|