Boost、asio、https 和主机/证书验证
Boost, asio, https, and host/certificate verifcation
我正在查看Boost的SSL客户端。评论中提到了OpenSSL(对不起,没有行号(:
// The verify callback can be used to check whether the certificate that is
// being presented is valid for the peer. For example, RFC 2818 describes
// the steps involved in doing this for HTTPS. Consult the OpenSSL
// documentation for more details. Note that the callback is called once
// for each certificate in the certificate chain, starting from the root
// certificate authority.
正确使用和验证OpenSSL可能很棘手。根据经验,我知道我必须执行以下操作才能正确使用库:
- 禁用上下文对象的 SSLv2、SSLv3 和压缩
- 为链构建和检查提供正确的根证书
- 调用
SSL_get_peer_certificate
并验证证书是否为非 NULL - 呼叫
SSL_get_verify_result
并验证结果是否X509_V_OK
- 执行名称匹配(CN 或 SAN 必须与请求的主机匹配(
OpenSSL 1.1.0 将提供名称检查,但目前仅在 HEAD 中。从 OpenSSL 更改日志:
Integrate hostname, email address and IP address checking with certificate
verification. New verify options supporting checking in opensl utility.
和:
New functions to check a hostname email or IP address against a
certificate. Add options x509 utility to print results of checks against
a certificate.
我没有看到 Boost 在哪里执行客户端代码中的任何配置或检查。
Boost 究竟在配置什么,在使用 SSL 时,它在asio
库组件中检查或验证什么?
简短回答:来自您引用的链接的 Boost 回调函数不会验证任何内容。它返回OpenSSL(通过bool preverified
(提供给它的任何初步验证结果。如果需要任何细粒度验证(如 CN 匹配等(,则必须通过回调显式完成。
长答案:当OpenSSL(或OpenSSL的Boost包装器(调用验证函数时,在本例中为bool verify_certificate(bool preverified, boost::asio::ssl::verify_context& ctx)
,OpenSSL已经完成了一组初步(或强制性(验证。文档中对此进行了说明。
从最深的嵌套级别(根 CA 证书(开始检查证书链,然后向上检查对等方的证书。在每个级别检查签名和颁发者属性。每当发现验证错误时,错误号存储在x509_ctx中,并以 preverify_ok=0 调用verify_callback。通过应用 X509_CTX_store_* 函数verify_callback可以找到有问题的证书并执行其他步骤(请参阅示例(。如果未发现证书错误,则在升级到下一级别之前,将使用 preverify_ok=1 调用verify_callback。
该文档还引用了一个示例,说明如何编写更细粒度的验证回调。您可以根据自己的需求从中汲取灵感。
编辑:为了确保Boost的内部回调函数除了调用应用程序回调函数之外不会做任何特殊的事情,我看了一下engine.ipp,这是一个C++模块,它调用OpenSSL的SSL_set_verify
来设置回调函数。看看verify_callback_function
是如何实现的。它只是调用应用程序回调。
- 如何使用OPENSL使用OCSP验证证书
- 如何使用相应的 X509 证书验证专用 RSA 签名签名
- 如何读取证书以使用 openssl 验证签名
- 使用 WinInet 的客户端身份验证(证书 + 私钥)
- 证书验证在客户端服务器通信中使用boost :: asio和openssl失败
- 如何验证视频卡驱动程序证书
- 验证 x509 证书
- 无法使用OpenSSL验证服务器证书
- 使用libcurl的CA证书身份验证
- Boost、asio、https 和主机/证书验证
- Casablanca C++Rest-如何禁用证书验证
- 获取POCO HTTPSClientSession发送请求时出错-证书验证失败
- 如何在Windows上禁用LDAP认证的证书验证
- 如何在C++中使用openssl创建证书验证的信任链
- 服务器证书验证失败.CAfile: ca.pem CRLfile:无
- Casablanca c++ Rest SDK -如何在websocket上禁用证书验证
- 使用SSL通配符证书验证主机
- OpenSSL在证书验证错误时自行终止
- 是否有任何库支持具有EMSA-PSS编码技术和证书验证的RSASSA-PSS.
- ssl证书验证上的多线程c++应用程序内存泄漏