1
- import java .net .InetSocketAddress ;
2
1
import java .net .Socket ;
3
2
import java .nio .ByteBuffer ;
4
3
import javax .net .SocketFactory ;
@@ -25,9 +24,6 @@ public void testSSLEngineEndpointIdSetNull() throws Exception {
25
24
sslEngine .unwrap (null , null , 0 , 0 ); // $hasUnsafeCertTrust
26
25
}
27
26
28
- /**
29
- * Test the endpoint identification of SSL engine is set to null
30
- */
31
27
public void testSSLEngineEndpointIdSetEmpty () throws Exception {
32
28
SSLContext sslContext = SSLContext .getInstance ("TLS" );
33
29
SSLEngine sslEngine = sslContext .createSSLEngine ();
@@ -39,9 +35,6 @@ public void testSSLEngineEndpointIdSetEmpty() throws Exception {
39
35
sslEngine .unwrap (null , null , 0 , 0 ); // $hasUnsafeCertTrust
40
36
}
41
37
42
- /**
43
- * Test the endpoint identification of SSL engine is set to HTTPS
44
- */
45
38
public void testSSLEngineEndpointIdSafe () throws Exception {
46
39
SSLContext sslContext = SSLContext .getInstance ("TLS" );
47
40
SSLEngine sslEngine = sslContext .createSSLEngine ();
@@ -53,9 +46,6 @@ public void testSSLEngineEndpointIdSafe() throws Exception {
53
46
sslEngine .unwrap (null , null , 0 , 0 ); // Safe
54
47
}
55
48
56
- /**
57
- * Test the endpoint identification of SSL engine is set to HTTPS
58
- */
59
49
public void testSSLEngineInServerMode () throws Exception {
60
50
SSLContext sslContext = SSLContext .getInstance ("TLS" );
61
51
SSLEngine sslEngine = sslContext .createSSLEngine ();
@@ -65,95 +55,64 @@ public void testSSLEngineInServerMode() throws Exception {
65
55
sslEngine .unwrap (null , null , 0 , 0 ); // Safe
66
56
}
67
57
68
- /**
69
- * Test the endpoint identification of SSL socket is not set
70
- */
71
- public void testSSLSocketImmediatelyConnects () throws Exception {
72
- SSLContext sslContext = SSLContext .getInstance ("TLS" );
73
- SocketFactory socketFactory = sslContext .getSocketFactory ();
74
- SSLSocket socket = (SSLSocket ) socketFactory .createSocket ("www.example.com" , 443 ); // $hasUnsafeCertTrust
75
- }
76
-
77
- /**
78
- * Test the endpoint identification of SSL socket is not set
79
- */
80
58
public void testSSLSocketEndpointIdNotSet () throws Exception {
81
59
SSLContext sslContext = SSLContext .getInstance ("TLS" );
82
60
SSLSocketFactory socketFactory = sslContext .getSocketFactory ();
83
61
SSLSocket socket = (SSLSocket ) socketFactory .createSocket ();
84
- socket .connect ( new InetSocketAddress ( "www.example.com" , 443 ) ); // $hasUnsafeCertTrust
62
+ socket .getOutputStream ( ); // $hasUnsafeCertTrust
85
63
}
86
64
87
- /**
88
- * Test the endpoint identification of SSL socket is set to null
89
- */
90
65
public void testSSLSocketEndpointIdSetNull () throws Exception {
91
66
SSLContext sslContext = SSLContext .getInstance ("TLS" );
92
67
SSLSocketFactory socketFactory = sslContext .getSocketFactory ();
93
68
SSLSocket socket = (SSLSocket ) socketFactory .createSocket ();
94
69
SSLParameters sslParameters = socket .getSSLParameters ();
95
70
sslParameters .setEndpointIdentificationAlgorithm (null );
96
71
socket .setSSLParameters (sslParameters );
97
- socket .connect ( new InetSocketAddress ( "www.example.com" , 443 ) ); // $hasUnsafeCertTrust
72
+ socket .getOutputStream ( ); // $hasUnsafeCertTrust
98
73
}
99
74
100
- /**
101
- * Test the endpoint identification of SSL socket is set to empty
102
- */
103
75
public void testSSLSocketEndpointIdSetEmpty () throws Exception {
104
76
SSLContext sslContext = SSLContext .getInstance ("TLS" );
105
77
SSLSocketFactory socketFactory = sslContext .getSocketFactory ();
106
78
SSLSocket socket = (SSLSocket ) socketFactory .createSocket ();
107
79
SSLParameters sslParameters = socket .getSSLParameters ();
108
80
sslParameters .setEndpointIdentificationAlgorithm ("" );
109
81
socket .setSSLParameters (sslParameters );
110
- socket .connect ( new InetSocketAddress ( "www.example.com" , 443 ) ); // $hasUnsafeCertTrust
82
+ socket .getOutputStream ( ); // $hasUnsafeCertTrust
111
83
}
112
84
113
- /**
114
- * Test the endpoint identification of SSL socket is not set
115
- */
116
85
public void testSSLSocketEndpointIdAfterConnecting () throws Exception {
117
86
SSLContext sslContext = SSLContext .getInstance ("TLS" );
118
87
SSLSocketFactory socketFactory = sslContext .getSocketFactory ();
119
- SSLSocket socket = (SSLSocket ) socketFactory .createSocket ("www.example.com" , 443 ); // $hasUnsafeCertTrust
88
+ SSLSocket socket = (SSLSocket ) socketFactory .createSocket ();
89
+ socket .getOutputStream (); // $hasUnsafeCertTrust
120
90
SSLParameters sslParameters = socket .getSSLParameters ();
121
91
sslParameters .setEndpointIdentificationAlgorithm ("HTTPS" );
122
92
socket .setSSLParameters (sslParameters );
123
93
}
124
94
125
- /**
126
- * Test the endpoint identification of SSL socket is not set
127
- */
128
95
public void testSSLSocketEndpointIdSafe () throws Exception {
129
96
SSLContext sslContext = SSLContext .getInstance ("TLS" );
130
97
SSLSocketFactory socketFactory = sslContext .getSocketFactory ();
131
98
SSLSocket socket = (SSLSocket ) socketFactory .createSocket ();
132
99
SSLParameters sslParameters = socket .getSSLParameters ();
133
100
sslParameters .setEndpointIdentificationAlgorithm ("HTTPS" );
134
101
socket .setSSLParameters (sslParameters );
135
- socket .connect ( new InetSocketAddress ( "www.example.com" , 443 ) ); // Safe
102
+ socket .getOutputStream ( ); // Safe
136
103
}
137
104
138
- /**
139
- * Test the endpoint identification of regular socket is not set
140
- */
141
105
public void testSocketEndpointIdNotSet () throws Exception {
142
106
SocketFactory socketFactory = SocketFactory .getDefault ();
143
- Socket socket = socketFactory .createSocket ("www.example.com" , 80 ); // Safe
107
+ Socket socket = socketFactory .createSocket ("www.example.com" , 80 );
108
+ socket .getOutputStream (); // Safe
144
109
}
145
110
146
- /**
147
- * Test the enableHostnameVerification of RabbitMQConnectionFactory is not set
148
- */
149
111
public void testRabbitMQFactoryEnableHostnameVerificationNotSet () throws Exception {
150
112
ConnectionFactory connectionFactory = new ConnectionFactory ();
151
113
connectionFactory .useSslProtocol (); // $hasUnsafeCertTrust
152
114
}
153
115
154
- /**
155
- * Test the enableHostnameVerification of RabbitMQConnectionFactory is not set
156
- */
157
116
public void testRabbitMQFactorySafe () throws Exception {
158
117
ConnectionFactory connectionFactory = new ConnectionFactory ();
159
118
connectionFactory .useSslProtocol (); // Safe
0 commit comments