我正在使用C ++ boost SSL套接字服务器。如何从SSL连接证书中解析CN?
我正在使用context_.set_verify_callback(boost :: bind(&ProxyServer :: verify_certificate,this,_1,_2));检查crt-info:
bool verify_certificate(bool preverified, boost::asio::ssl::verify_context& ctx)
{
char subject_name[256];
X509* cert = X509_STORE_CTX_get_current_cert(ctx.native_handle());
X509_NAME_oneline(X509_get_subject_name(cert), subject_name, 256);
std::cout << "Verifying:\n" << subject_name << std::endl;
CN = FUNC.split(FUNC.split (subject_name, "CN=") [1], "/")[0];
return preverified;
}
,并且工作正常。我得到:
/ C = ua / ST = Kiev / L = Kiev / O = test / OU = test / CN = test00005
然后我需要在handle_read中获取此信息:
课程 { 上市: 会话(boost :: asio :: io_context&io_context, boost :: asio :: ssl :: context&context) :socket_(io_context,上下文) { }
ssl_socket::lowest_layer_type& socket()
{
return socket_.lowest_layer();
}
void stop()
{
socket().close();
}
void start(int num)
{
socket_.async_handshake(boost::asio::ssl::stream_base::server,
boost::bind(&Session::handle_handshake, this,
boost::asio::placeholders::error, num));
}
void handle_handshake(const boost::system::error_code& error, int num)
{
if (!error)
{
socket_.async_read_some(boost::asio::buffer(data_, max_length),
boost::bind(&Session::handle_read, this,
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred, num));
}
else
{
delete this;
}
}
void handle_read(const boost::system::error_code& error,
size_t bytes_transferred, int num)
{
if (!error)
{
,我不知道如何从那里获取pars证书。请帮忙,谢谢!