@@ -25,10 +25,11 @@ class SIPUAWebSocketImpl {
2525 handleQueue ();
2626 logger.i ('connect $_url , ${webSocketSettings .extraHeaders }, $protocols ' );
2727 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 {
3233 _socket = await WebSocket .connect (_url,
3334 protocols: protocols, headers: webSocketSettings.extraHeaders);
3435 }
@@ -69,8 +70,7 @@ class SIPUAWebSocketImpl {
6970 return _socket != null && _socket! .readyState == WebSocket .connecting;
7071 }
7172
72- /// For test only.
73- Future <WebSocket > _connectForBadCertificate (
73+ Future <WebSocket > _connectWithBadCertificateHandling (
7474 String url, WebSocketSettings webSocketSettings) async {
7575 try {
7676 Random r = Random ();
@@ -84,8 +84,25 @@ class SIPUAWebSocketImpl {
8484
8585 client.badCertificateCallback =
8686 (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+ }
89106 };
90107
91108 Uri parsed_uri = Uri .parse (url);
0 commit comments