File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed
tinodesdk/src/main/java/co/tinode/tinodesdk Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 13
13
import java .util .Map ;
14
14
import java .util .concurrent .TimeUnit ;
15
15
16
+ import javax .net .ssl .HttpsURLConnection ;
17
+ import javax .net .ssl .SSLHandshakeException ;
18
+ import javax .net .ssl .SSLSession ;
19
+ import javax .net .ssl .SSLSocket ;
20
+
16
21
/**
17
22
* A thinly wrapped websocket connection.
18
23
*/
@@ -108,8 +113,19 @@ private void connectSocket(final boolean reconnect) {
108
113
} else {
109
114
connectBlocking (CONNECTION_TIMEOUT , TimeUnit .MILLISECONDS );
110
115
}
116
+
117
+ if ("wss" .equals (uri .getScheme ())) {
118
+ // SNI: Verify server host name.
119
+ SSLSession sess = ((SSLSocket ) getSocket ()).getSession ();
120
+ String hostName = uri .getHost ();
121
+ if (!HttpsURLConnection .getDefaultHostnameVerifier ().verify (hostName , sess )) {
122
+ close ();
123
+ throw new SSLHandshakeException ("SNI verification failed. Expected: '" + uri .getHost () +
124
+ "', actual: '" + sess .getPeerPrincipal () + "'" );
125
+ }
126
+ }
111
127
} catch (Exception ex ) {
112
- Log .d (TAG , "socketConnectionRunnable exception! " , ex );
128
+ Log .i (TAG , "WS connection failed " , ex );
113
129
if (mListener != null ) {
114
130
mListener .onError (Connection .this , ex );
115
131
}
You can’t perform that action at this time.
0 commit comments