How to establish a secure socket connection using the C++ library Websocket++?


Sarod Ugara

I can make a regular WS connection using the utility client here, https://github.com/zaphoyd/websocketpp/blob/master/tutorials/utility_client/step6.cpp

However, I need to try a secure WS connection and have replaced the configuration with the one below and linked the required libraries.

typedef websocketpp::client<websocketpp::config::asio_tls_client> client;

My handler looks like:

typedef std::shared_ptr<boost::asio::ssl::context> context_ptr;

// part of class connection_metadata
static context_ptr on_tls_init(websocketpp::connection_hdl) {
    context_ptr ctx = std::make_shared<boost::asio::ssl::context>(boost::asio::ssl::context::sslv23);

    try {
        ctx->set_options(boost::asio::ssl::context::default_workarounds |
                         boost::asio::ssl::context::no_sslv2 |
                         boost::asio::ssl::context::no_sslv3 |
                         boost::asio::ssl::context::single_dh_use);
    } catch (std::exception& e) {
        std::cout <<"Error in context pointer: "<< e.what() << std::endl;
    }
    return ctx;
}

// part of class websocket_endpoint 
con->set_tls_init_handler(bind(&connection_metadata::on_tls_init,metadata_ptr,std::placeholders::_1));

When I try the following line to get the connection:

client::connection_ptr con = m_endpoint.get_connection(uri, ec);

I received:

Connection creation attempt failed

Sarod Ugara

I have solved the problem due to : https://groups.google.com/forum/#!topic/websocketpp/SimAUzwZUVM

I had to make on_tls_inita static function and use it like this (before getting the connection):m_endpoint.set_tls_init_handler(connection_metadata::on_tls_init)

m_endpointWhere is the client object .

Related


How to establish a secure connection to websocket on localhost?

impostor We have an application running on a POS terminal that should receive data from an application running on the same computer, while displaying content from a remote site loaded over HTTPS. In order to receive data from the local application we want to u

Unable to establish secure websocket connection with gdax

space monkey I'm trying to connect to a GDAX websocket feed from C# (target framework: Core 2.0) I am using this NodeJS implementation as a reference. my code: var ws = new WebSocket("wss://ws-feed.gdax.com"); ws.Security.AllowUnstrustedCertificate = true; //

C# how to establish UDP socket connection

多 多 · (Tordor Yanev ( Unhandled Exception: System.Net.Sockets.SocketException: The attempted operation is not supported by the referenced object type I try to map ip to V6 same exception namespace ConsoleApp1 { using System.Net; using System.Net.Socket

C# how to establish UDP socket connection

多 多 · (Tordor Yanev ( Unhandled Exception: System.Net.Sockets.SocketException: The attempted operation is not supported by the referenced object type I try to map ip to V6 same exception namespace ConsoleApp1 { using System.Net; using System.Net.Socket

How to establish TLS connection using rustls library?

username The documentation provides an example - unfortunately it doesn't compile; a lot of things have been renamed and the interface of the ClientSessionconstructor has changed. I managed to fix the bug to a point where it compiles, but not to a point where

How to establish TLS connection using rustls library?

username The documentation provides an example - unfortunately it doesn't compile; a lot of things have been renamed and the interface of the ClientSessionconstructor has changed. I managed to fix the bug to a point where it compiles, but not to a point where

How to establish TLS connection using rustls library?

username The documentation provides an example - unfortunately it doesn't compile; a lot of things have been renamed and the interface of the ClientSessionconstructor has changed. I managed to fix the bug to a point where it compiles, but not to a point where

How to establish TLS connection using rustls library?

username The documentation provides an example - unfortunately it doesn't compile; a lot of things have been renamed and the interface of the ClientSessionconstructor has changed. I managed to fix the bug to a point where it compiles, but not to a point where

How to establish TLS connection using rustls library?

username The documentation provides an example - unfortunately it doesn't compile; a lot of things have been renamed and the interface of the ClientSessionconstructor has changed. I managed to fix the bug to a point where it compiles, but not to a point where

Secure socket connection using C++

Dziaji I am trying to get an SSL/TLS connection to work in Windows. Right now, I'm using Schannel, but I'm not sure if this is the correct approach. Here is my code. InitializeSecurityContextA() function throws exception #include "windows.h" #pragma comment(li

How to catch "Unable to establish a secure connection"

Polo Hole Set I have a website and some people with older computers or browsers are unable to establish a connection to the secure part of our website. What I want to do is catch connection errors and then reroute them to a screen explaining why this is happen

How to establish a Websocket connection in Angular unit tests?

wr I'm developing an Angular (v 6.1.0) application that communicates with the backend via Websocket. So far everything is working fine except for the unit tests. I've created a mock backend to test my component, but I can't get a connection between the mock ba

How to establish a Websocket connection in Angular unit tests?

wr I'm developing an Angular (v 6.1.0) application that communicates with the backend via Websocket. So far everything is working fine except for the unit tests. I've created a mock backend to test my component, but I can't get a connection between the mock ba

How to establish a Websocket connection in Angular unit tests?

wr I'm developing an Angular (v 6.1.0) application that communicates with the backend via Websocket. So far everything is working fine except for the unit tests. I've created a mock backend to test my component, but I can't get a connection between the mock ba

Using Secure WebSocket in C#

Benjamin 54 I am using Fleck to implement websocket functionality in my MVC application. In local setup I have https scheme with self signed certificate and in production setup I have paid for the certificate. This is the syntax given in the docs. var server =