Socket connections and operations on port 443 are successful. To connect on any other port results in the following error: "5274 Failed to establish secure connection (TLS Handshake).

 

I have a question about establishing a secure socket connection for an MQL5 advisor. My setup includes MT5 on Windows 11 and a Node.js server on VMware Ubuntu.

 Connections and operations on port 443 are successful.

However, attempting to connect on any other port results in the following error: "5274 Failed to establish secure connection (TLS Handshake)."

The ports are unblocked, and their availability has been verified on both Windows and Ubuntu, with the server listening on the required port. I can also see connection attempts and packet exchanges between the advisor and the server on port 8000, as evidenced by the output of sudo tcpdump -i any port 8000.

Is it possible to establish a secure connection on a port other than 443 in MT5? If so, could you please provide some guidance on how to resolve the issues with setting up a secure connection? Perhaps some additional settings are needed?

Below is the MQL5 code for establishing a secure connection:

The certificates have also been correctly configured, and it is possible to easily connect using openssl s_client -connect. If you have further advice or adjustments that could help, I would appreciate it.

Thank you.


void Auth()
  {
  string  jsonAuth = "{";
        jsonAuth += "\"login\":" + login + ",";
        jsonAuth += "\"email\":\"" + Email + "\",";
        jsonAuth += "\"key\":\"" + SecretKey + "\",";
        jsonAuth += "\"platform\":\"" + "MT5" + "\"";
        jsonAuth += "}";

             string   auth = "{";
              auth += "\"event\":\"v1-login\","; 
              auth += "\"body\":" + jsonAuth;
              auth += "}"; 
   int socket = SocketCreate();
   if(socket!=INVALID_HANDLE)
     {
      if(SocketConnect(socket,Address,Port,5000))
        {
         Print("Connected: ",Address,":",Port);
         bool hand = SocketTlsHandshake(socket, Address);
         Print(hand, GetLastError());
        }
    
         string   subject,issuer,serial,thumbprint;
         datetime expiration;

      int dataSize = StringLen(auth); 
     uchar dataBuffer[];
     ArrayResize(dataBuffer, dataSize);
     for (int i = 0; i < dataSize; i++)
     {
         dataBuffer[i] = (uchar)auth[i];
     }
     SocketTlsSend(socket, dataBuffer, dataSize);
     }
 }
 

First, when attempting to establish a secure connection using SocketTlsHandshake(), the function will try to connect to the specified address and port using default TLS settings. These default settings may not be compatible with your server's TLS configuration, leading to "TLS Handshake" error.

To resolve this issue you need to configure TLS settings on MT5 side to match your server's TLS configuration.

This can be done by using the SocketTlsSetValue() function to set various TLS options before calling SocketTlsHandshake()

The best way to proceed with this Task would be here https://www.mql5.com/en/job

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2024.05.27
  • www.mql5.com
The largest freelance service with MQL5 application developers