php sslv3握手失败,Boost Beast握手:sslv3警报握手失败错误

本文探讨了使用BoostBeast库连接WebSocket服务器时遇到的SSL握手失败问题,并提供了详细的源代码示例,包括配置和错误处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我正在使用Boost Beast连接到一个Web Socket服务器,但是我一直收到一个错误

Resolving push-private.kucoin.com:443...

Performing SSL handshake...

terminate called after throwing an instance of 'boost::wrapexcept<:system::system_error>'

what(): handshake: sslv3 alert handshake failure

Aborted (core dumped)

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include "root_certificates.hpp"

using namespace std;

namespace beast = boost::beast; // from

namespace http = beast::http; // from

namespace websocket = beast::websocket; // from

namespace net = boost::asio; // from

namespace ssl = boost::asio::ssl; // from

using tcp = boost::asio::ip::tcp; // from

int main() {

// for a new token, make a POST request to https://api.kucoin.com/api/v1/bullet-public

const auto token = "2neAiuYvAU61ZDXANAGAsiL4-iAExhsBXZxftpOeh_55i3Ysy2q2LEsEWU64mdzUOPusi34M_wGoSf7iNyEWJ3XLno4x6QqZaEm7Ya4KUfToabAuI1Do9tiYB9J6i9GjsxUuhPw3BlrzazF6ghq4L2ls_Ixv_6qQ8ZRhwt_6WmM=.ianWlE3VQZogjKRmJ-tpyg==";

auto const host = "push-private.kucoin.com";

auto const port = "443";

auto const text = "hello world";

// The io_context is required for all I/O

net::io_context ioc;

// The SSL context is required, and holds certificates

boost::asio::ssl::context ctx(boost::asio::ssl::context::sslv23);

ctx.set_options(

boost::asio::ssl::context::default_workarounds

| boost::asio::ssl::context::no_sslv2

| boost::asio::ssl::context::no_sslv3

);

ctx.set_default_verify_paths();

// This holds the root certificate used for verification

load_root_certificates(ctx);

// These objects perform our I/O

tcp::resolver resolver{ioc};

websocket::stream<:ssl_stream>> ws{ioc, ctx};

// Look up the domain name

cout << "Resolving " << host << ":" << port << "..." << endl;

auto const results = resolver.resolve(host, port);

// Make the connection on the IP address we get from a lookup

net::connect(ws.next_layer().next_layer(), results.begin(), results.end());

// Perform the SSL handshake

cout << "Performing SSL handshake..." << endl;

ws.next_layer().handshake(ssl::stream_base::client);

// Set a decorator to change the User-Agent of the handshake

ws.set_option(websocket::stream_base::decorator([](websocket::request_type& req){

req.set(http::field::user_agent,

std::string(BOOST_BEAST_VERSION_STRING) +

" websocket-client-coro");

}));

// Perform the websocket handshake

cout << "Performing the websocket handshake..." << endl;

ws.handshake(host, "/endpoint");

// Send the message

cout << "Sending '" << text << "'..." << endl;

ws.write(net::buffer(std::string(text)));

// This buffer will hold the incoming message

beast::flat_buffer buffer;

// Read a message into our buffer

cout << "Waiting for web socket server to respond..." << endl;

ws.read(buffer);

// Close the WebSocket connection

ws.close(websocket::close_code::normal);

// The make_printable() function helps print a ConstBufferSequence

cout << "This is the data received from the server:" << endl;

std::cout << beast::make_printable(buffer.data()) << std::endl;

return 0;

}

编译选项:

g++ -std=c++17 test.cpp -l boost_system -l crypto -l ssl -pthread && ./a.out

gcc版本9.1.0(Ubuntu9.1.0-2ubuntu2~19.04)

任何建议都将不胜感激。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值