我正在寫一個HTTPS服務器,我需要從使用SNI的ssl_accept()之前的客戶端獲取主機名。我正在使用SSL_CTX_set_tlsext_servername_callback()來接收主機名,但回調根本不會被調用。這裏是我的部分代碼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);
}
非常感謝:))) – Omeriko