Encryption initialization failed: An error occurred while sending the request

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

Dorian1453
Posts: 2
Joined: 27 Jan 2021, 03:00

Encryption initialization failed: An error occurred while sending the request

Postby Dorian1453 » 27 Jan 2021, 03:30

Hi there,

I am currently trying to get an SSL connection setup on my multiplayer game in Unity. The connection itself seems to be working fine, but as soon as I try to use sfs.initCrypto(); after the successful connection I get an error message that says "Encryption initialization failed: An error occurred while sending the request". I'm not too sure where to go from here, so I am hoping posting on here will be of some help.

I am using Unity version 2020.2.1f1, SFS2X version 2.16.3 and C# API version 1.7.13.

On the server side logs, I don't get any errors besides the session being created and removed:

Code: Select all

27 Jan 2021
02:59:50,478   INFO   SocketReader   bitswarm.sessions.DefaultSessionManager   Session created: { Id: 15, Type: DEFAULT, Logged: No, IP: x.x.x.x:63103 } on Server port: 9933 <---> 63103
27 Jan 2021
03:00:19,737   INFO   SocketReader   bitswarm.sessions.DefaultSessionManager   Session removed: { Id: 15, Type: DEFAULT, Logged: No, IP: x.x.x.x:63103 }
27 Jan 2021
03:00:41,938   INFO   SocketReader   bitswarm.sessions.DefaultSessionManager   Session created: { Id: 16, Type: DEFAULT, Logged: No, IP: x.x.x.x:63111 } on Server port: 9933 <---> 63111
27 Jan 2021
03:01:46,183   INFO   Scheduler1-thread-1   bitswarm.sessions.DefaultSessionManager   Session removed: { Id: 16, Type: DEFAULT, Logged: No, IP: x.x.x.x:63111 }


On the client side logs, I get the following:

Code: Select all

Connection established successfully
SFS2X API version: 1.7.13
Connection mode is: Socket
Encryption initialization failed: An error occurred while sending the request


And here is the code I am using in C# to connect and initialize the crypto:

Code: Select all

 void Start()
    {
        //Start our SmartFox Instance
        sfs = new SmartFox();
       


        //Addd Event Listeners to our inital SmartFox Instance
        sfs.AddEventListener(SFSEvent.CONNECTION, OnConnection);
        sfs.AddEventListener(SFSEvent.USER_ENTER_ROOM, OnUserEnterRoom);
        sfs.AddEventListener(SFSEvent.LOGIN, OnLogin);
        sfs.AddEventListener(SFSEvent.LOGIN_ERROR, OnLoginError);
        sfs.AddEventListener(SFSEvent.LOGOUT, OnLogout);
        sfs.AddEventListener(SFSEvent.CRYPTO_INIT, OnEncrypted);

        sfs.Connect(cfg);



    }
   
       public void OnConnection(BaseEvent evt)
    {
        if ((bool)evt.Params["success"])
        {
            sfs.InitCrypto();
        }
        else
        {
            Debug.Log("Connection failed");
        }

    }
   
       void OnEncrypted(BaseEvent evt)
    {
        if((bool)evt.Params["success"])
        {
            Debug.Log("Encryption successful");
        }
        else
        {
            Debug.LogError("Encryption failed! Reason: " + (string)evt.Params["errorMessage"]);
        }
    }


I would also like to point out that I am working on a Mac whereas my friend is on PC and cannot reproduce this bug. I have also tested the SSL connection using the Advanced Connector Unity example as well, which results in the same outcome. Any help would be greatly appreciated :)
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Encryption initialization failed: An error occurred while sending the request

Postby Lapo » 27 Jan 2021, 09:27

Hi,
it seems strange that the error occurs only on Mac and not on Windows.
I assume that the SSL certificate was deployed correctly and you can see the green lock when you connect to the SFS2X https-server via a browser. Right?

The first thing to check is the integrity of the SSL certificate. It can happen that a certificate looks properly deployed and yet the certificate chain is incorrect and causes SSL exceptions on certain clients (and not on others).

I'd recommend checking the domain you're using with a tool like this --> https://www.digicert.com/help/

Let us know.
Lapo
--
gotoAndPlay()
...addicted to flash games
Dorian1453
Posts: 2
Joined: 27 Jan 2021, 03:00

Re: Encryption initialization failed: An error occurred while sending the request

Postby Dorian1453 » 27 Jan 2021, 12:29

Hi Lapo,

Thank you for the quick reply. So I checked whatsmychaincert.com and apparently my certificate's chain was installed incorrectly. :oops: I downloaded the correct chain from the website and installed it using the Smartfox Admin Tool and everything seems to be in working order now. :D Thank you for your help!
User avatar
Lapo
Site Admin
Posts: 22999
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Encryption initialization failed: An error occurred while sending the request

Postby Lapo » 27 Jan 2021, 14:56

Excellent :)
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 39 guests