c++ - OpenSSL 在证书验证错误时自行终止

标签 c++ ssl openssl

在 OpenSSL 中,我试图在握手期间检查证书链。
当客户端连接时,我创建了 SSL_CTX*SSL* 然后我设置了验证回调

SSL_set_verify(_ssl, SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, verify_callback);

然后在我的函数中

int verify_callback(int preverify_ok, X509_STORE_CTX *x509_ctx) {
    bool ok = false;
    [...]
    return ok ? 1 : 0;
}

(我从GitHub中复制了示例代码)
当我执行它时,如果函数返回 1,则一切正常,但当它返回 0(又名失败)时,整个过程停止(退出代码 0)

我目前正在 Win10 x64 上的 cygwin64 下编译,这是最新的

我这样做有什么问题吗?

最佳答案

文档有答案:

The return value of verify_callback controls the strategy of the further verification process. If verify_callback returns 0, the verification process is immediately stopped with "verification failed" state. If SSL_VERIFY_PEER is set, a verification failure alert is sent to the peer and the TLS/SSL handshake is terminated.

取自: https://www.openssl.org/docs/manmaster/ssl/SSL_CTX_set_verify.html

因此,您可能遗漏了异常或其他内容。

关于c++ - OpenSSL 在证书验证错误时自行终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38647399/

相关文章:

android - com.android.org.conscrypt.OpenSSLX509Certificate 无法转换为 java.security.Certificate

openssl - 这个命令有什么作用? "openssl genrsa -aes256 -out example.key 2048"

c - 链接 OpenSSL 时不引用 BIO 函数

c++ - 在 C++ 中 : how to print the digits after the decimal.

c++ - 是 “catch all” block ,它会动态分配分配的内存,然后重新抛出有效/良好的设计选择?

c++ - ctype 函数(isalpha,isdigit)在 C++ 中显示错误值

java - Secure Webservice 在 JDev 11.1.1.2 (WL Server 10.3.2) 中有效,但在 JDev 11.1.1.6 (WL Server 10.3.5) 中无效

c++ - C/C++ 将 int 转换为 short 和内联 asm(特定于 ARM)

http - 标准、非 SSL、HTTP 加密

java - 启用身份验证后 NiFi web ui 打不开