vsevex / whixp

Lightweight XMPP client, purely written in Dart.
MIT License
10 stars 3 forks source link

HandshakeException: Handshake error while connecting to xmpp server #45

Closed nilesh-darji closed 1 month ago

nilesh-darji commented 2 months ago

Hii, great project.

Logs


> I/flutter ( 5460): [Whixp] 17:27:49.664 An error occured while Securing Socket: HandshakeException: Handshake error in client (OS Error:

I/flutter ( 5460): [Whixp] 17:27:49.585 Resetting reconnection policy
I/flutter ( 5460): [Whixp] 17:27:49.588 Trying to connect to chats.stage.com on port 5222
I/flutter ( 5460): [Whixp] 17:27:49.625 SEND: <stream:stream to='chats.stage.com' xmlns:stream='http://etherx.jabber.org/streams' xmlns='jabber:client' xml:lang='en' version='1.0'>
I/flutter ( 5460): [Whixp] 17:27:49.630 Resetting reconnection policy
I/flutter ( 5460): [Whixp] 17:27:49.649 RECEIVED: <stream:features xmlns="http://etherx.jabber.org/streams"><starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'><required/></starttls></stream:features>
E/flutter ( 5460): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: Creation failed, path = '/whixp' (OS Error: Read-only file system, errno = 30)
E/flutter ( 5460): #0      _checkForErrorResponse (dart:io/common.dart:55:9)
E/flutter ( 5460): #1      _Directory.create.<anonymous closure> (dart:io/directory_impl.dart:109:9)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #2      BackendManager.open (package:hive/src/backend/vm/backend_manager.dart:34:7)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #3      HiveImpl._openBox (package:hive/src/hive_impl.dart:101:21)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #4      HiveImpl.openBox (package:hive/src/hive_impl.dart:142:12)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #5      HiveController.initialize (package:whixp/src/database/controller.dart:33:14)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): 
E/flutter ( 5460): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: FileSystemException: Creation failed, path = '/whixp' (OS Error: Read-only file system, errno = 30)
E/flutter ( 5460): #0      _checkForErrorResponse (dart:io/common.dart:55:9)
E/flutter ( 5460): #1      _Directory.create.<anonymous closure> (dart:io/directory_impl.dart:109:9)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #2      BackendManager.open (package:hive/src/backend/vm/backend_manager.dart:34:7)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #3      HiveImpl._openBox (package:hive/src/hive_impl.dart:101:21)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #4      HiveImpl.openBox (package:hive/src/hive_impl.dart:142:12)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #5      HiveController.initialize (package:whixp/src/database/controller.dart:33:14)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): 
I/flutter ( 5460): [Whixp] 17:27:49.664 An error occured while Securing Socket: HandshakeException: Handshake error in client (OS Error: 
I/flutter ( 5460):  WRONG_VERSION_NUMBER(tls_record.cc:231))
E/flutter ( 5460): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Instance of 'SecureSocketException'
E/flutter ( 5460): #0      _TCPConnecta._upgradeConnection (package:connecta/src/_tcp.dart:184:7)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #1      Connecta.upgradeConnection (package:connecta/src/connecta.dart:151:29)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #2      Connection.startTLS (package:whixp/src/connection.dart:335:7)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #3      Whixp._setup.<anonymous closure> (package:whixp/src/client.dart:106:9)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): #4      Whixp._handleStreamFeatures (package:whixp/src/client.dart:210:24)
E/flutter ( 5460): <asynchronous suspension>
E/flutter ( 5460): 

Sample Code

final whixp = Whixp(
                        jabberID: 'admin@chats.stage.com',
                        password:
                            'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIx1MjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyLCJleHAiOjE3ODczMTIyMjl9.3Sx33lNlSN2cYiBqRmtjI67_DG4hGf-gkiJ6DAtgDGQ',
                        host: 'chats.stage.com',
                        internalDatabasePath: '/whixp',
                        onBadCertificateCallback: (cert) => true,
                        logger: Log(
                          enableWarning: true,
                          enableError: true,
                          includeTimestamp: true,
                        ),
                        disableStartTLS: true,
                        useIPv6: true,
                        reconnectionPolicy: RandomBackoffReconnectionPolicy(
                          0,
                          2,
                        ),
                      );
                      whixp
                        ..addEventHandler<TransportState>('state', (state) {
                          if (state == TransportState.disconnected) whixp.connect();
                        })
                        ..connect();

I am using ejabberd server

vsevex commented 2 months ago

Hi.

If you are trying to connect using StartTLS, you need to declare the SecurityContext via the context property (ensure that you have declared the SSL certificate and corresponding key); otherwise, you cannot upgrade your socket connection due to the lack of SSL pinning in the Dart language. Setting DisableStartTLS to true means that you will not upgrade your connection later, so it will continue over a non-secure socket channel. Additionally, ensure that you are providing a secure port if you are using DirectTLS (in ejabberd server, this port is 5223 by default).

On the other hand, if you are using Whixp in Flutter, make sure you have declared the internal database path inside the project files (you can use path_provider to get the documents path and address this path in the declaration. e.g. "documents_path/whixp"). If you are using Dart, just provide a folder name, and it will automatically create a folder under the given name (e.g., “whixp”).