Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

双向认证时,未发送客户端证书,但是在代码中调用SSL_do_handshake依然返回了成功,如何能判断是否真的成功? #568

Open
wolf-hunter404 opened this issue Jan 15, 2024 · 2 comments

Comments

@wolf-hunter404
Copy link

wolf-hunter404 commented Jan 15, 2024

服务中间件:Tengine+铜锁v8.3.3
大致的代码如下,能确认服务端配置的是双向认证,在使用WireShark抓包时,也能看到alert警告。
但是SSL_do_handshake依然返回成功标识,因为我只是想验证握手是否成功,不需要发送实际的业务数据。
这样的情况该如何判断呢,或者怎么获取alert?

SSL_CTX ctx = SSL_CTX_new(NTLS_client_method());
    
SSL_CTX_enable_ntls(ctx);
SSL_CTX_enable_sm_tls13_strict(ctx);
SSL_CTX_clear_mode(ctx, SSL_MODE_AUTO_RETRY);
SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL);

BIO* conn = BIO_new_connect(host.c_str());

SSL ssl = SSL_new(ctx);
SSL_set_bio(ssl, conn, conn);
SSL_set_connect_state(ssl);

//开始握手
//就算双向认证时没有发送客户端证书,握手依然会返回成功标识,但是内部实际已经失败,抓包后也能监控到alert
int ret = SSL_do_handshake(ssl);
@InfoHunter
Copy link
Member

看起来你需要用这个:

#include <openssl/ssl.h>

int SSL_get_error(const SSL *ssl, int ret);

@wolf-hunter404
Copy link
Author

看起来你需要用这个:

#include <openssl/ssl.h>

int SSL_get_error(const SSL *ssl, int ret);

谢谢,我尝试过使用这个函数,好像不太对,因为按照文档的描述,SSL_do_handshake返回1时表示握手成功完成,双向认证不发送客户端证书也会返回1,导致无法判断握手是不是真的成功。
我也尝试过使用SSL_set_msg_callback、SSL_set_msg_callback_arg这两个函数来获取Alert警告,但是只能获取到了客户端向服务端发送的close notify,服务端响应回的Alert获取不到。
因为要连接的服务不确定是HTTPS Server还是普通的TLCP Server,只是想检查握手有没有问题,确保服务端配置是可用的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants