我正在编写一个 https 服务器。我已经创建了 csr 并使用我的测试域的根证书对其进行了签名。当客户端连接时,SSL_accept() 成功完成。我正在使用非阻塞 IO。因此,我将首先在 Windows 中使用 WSARecv() 和 IOCP 异步接收字符缓冲区中的数据。从该字符缓冲区,我将其写入 BIO(BIO_write 返回写入的字节数)并尝试使用 SSL_read() 解密该 BIO 的内容时,它返回 ssl_error_ssl 和错误字符串作为错误:00000001:lib(0):func (0):原因(1)。
我在这里添加了我的代码结构。
const SSL_METHOD *method;
SSL_CTX *ctx;
method = SSLv23_method(); /* create new server-method instance */
ctx = SSL_CTX_new(method); /* create new context from method */
if ( ctx == NULL )
{
printf("SSL Context Creation failed\n");
}
//create bio
BIO *bioIn = BIO_new(BIO_s_mem());
BIO *bioOut = BIO_new(BIO_s_mem());
/* get new SSL state with context */
SSL *clientSSL = …Run Code Online (Sandbox Code Playgroud) 我正在编写一个https服务器,我需要在使用SNI的ssl_accept()之前从客户端获取主机名。我正在使用SSL_CTX_set_tlsext_servername_callback()接收主机名,但根本没有调用回调。这是我的代码的一部分
// Server Name Indication callback from OpenSSL
static int serverNameCallback(SSL *ssl, int *ad, void *arg)
{
if (ssl == NULL)
return SSL_TLSEXT_ERR_NOACK;
const char* servername = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name);
printf("ServerName: %s\n", servername);
}
int main()
{
//some code
const SSL_METHOD *method;
SSL_CTX *ctx;
method = SSLv3_server_method();
ctx = SSL_CTX_new(method);
if ( ctx == NULL )
{
printf("SSL_ctx_new() error\n");
}
int ret = SSL_CTX_set_tlsext_servername_callback(ctx, serverNameCallback);
}
Run Code Online (Sandbox Code Playgroud)