I am writing a https server and i need to get host name from client before ssl_accept() using SNI. I am using SSL_CTX_set_tlsext_servername_callback() to receive host name but the callback not at all get called. Here is part of my code
// 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);
}