@@ -25,10 +25,11 @@ class SIPUAWebSocketImpl {
25
25
handleQueue ();
26
26
logger.i ('connect $_url , ${webSocketSettings .extraHeaders }, $protocols ' );
27
27
try {
28
- if (webSocketSettings.allowBadCertificate) {
29
- /// Allow self-signed certificate, for test only.
30
- _socket = await _connectForBadCertificate (_url, webSocketSettings);
31
- } else {
28
+ if (webSocketSettings.allowBadCertificate || webSocketSettings.debugCertificate) {
29
+ // Depending on the settings, it will allow self-signed certificates or debug them.
30
+ _socket = await _connectWithBadCertificateHandling (_url, webSocketSettings);
31
+ }
32
+ else {
32
33
_socket = await WebSocket .connect (_url,
33
34
protocols: protocols, headers: webSocketSettings.extraHeaders);
34
35
}
@@ -69,8 +70,7 @@ class SIPUAWebSocketImpl {
69
70
return _socket != null && _socket! .readyState == WebSocket .connecting;
70
71
}
71
72
72
- /// For test only.
73
- Future <WebSocket > _connectForBadCertificate (
73
+ Future <WebSocket > _connectWithBadCertificateHandling (
74
74
String url, WebSocketSettings webSocketSettings) async {
75
75
try {
76
76
Random r = Random ();
@@ -84,8 +84,25 @@ class SIPUAWebSocketImpl {
84
84
85
85
client.badCertificateCallback =
86
86
(X509Certificate cert, String host, int port) {
87
- logger.w ('Allow self-signed certificate => $host :$port . ' );
88
- return true ;
87
+ if (webSocketSettings.allowBadCertificate) {
88
+ logger.w ('Allow self-signed certificate => $host :$port . ' );
89
+ return true ;
90
+ }
91
+ else if (webSocketSettings.debugCertificate){
92
+ logger.w ('Server returns a server certificate that cannot be authenticated => $host :$port . ' );
93
+ String certInfo = '\n ' ;
94
+ certInfo+= ' Certificate subject: ${cert .subject }\n ' ;
95
+ certInfo+= ' Certificate issuer: ${cert .issuer }\n ' ;
96
+ certInfo+= ' Certificate valid from: ${cert .startValidity }\n ' ;
97
+ certInfo+= ' Certificate valid to: ${cert .endValidity }\n ' ;
98
+ certInfo+= ' Certificate SHA-1 fingerprint: ${cert .sha1 }\n ' ;
99
+
100
+ logger.w ('Certificate details: {$certInfo }' );
101
+ return false ;
102
+ }
103
+ else {
104
+ return false ; // reject the certificate
105
+ }
89
106
};
90
107
91
108
Uri parsed_uri = Uri .parse (url);
0 commit comments