diff options
author | william <william@25tandclement.com> | 2014-09-16 18:11:13 -0700 |
---|---|---|
committer | william <william@25tandclement.com> | 2014-09-16 18:11:13 -0700 |
commit | 3c27b8f14a31e14dc4037803f0892445b8581a70 (patch) | |
tree | a93f06d96a810d99d9fcaad587dfcbbc46955210 /src | |
parent | 624c021edcb1250df4efced69e688ef0607feb69 (diff) | |
download | luaossl-3c27b8f14a31e14dc4037803f0892445b8581a70.tar.gz luaossl-3c27b8f14a31e14dc4037803f0892445b8581a70.tar.bz2 luaossl-3c27b8f14a31e14dc4037803f0892445b8581a70.zip |
add :getHostName and :setHostName methods to SSL object
Diffstat (limited to 'src')
-rw-r--r-- | src/openssl.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c index 03f3f8d..8efb348 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -4417,6 +4417,32 @@ static int ssl_getCipherInfo(lua_State *L) { } /* ssl_getCipherInfo() */ +static int ssl_getHostName(lua_State *L) { + SSL *ssl = checksimple(L, 1, SSL_CLASS); + const char *host; + + if (!(host = SSL_get_servername(ssl, TLSEXT_NAMETYPE_host_name))) + return 0; + + lua_pushstring(L, host); + + return 1; +} /* ssl_getHostName() */ + + +static int ssl_setHostName(lua_State *L) { + SSL *ssl = checksimple(L, 1, SSL_CLASS); + const char *host = luaL_checkstring(L, 2); + + if (!SSL_set_tlsext_host_name(ssl, host)) + return throwssl(L, "ssl:setHostName"); + + lua_pushboolean(L, 1); + + return 1; +} /* ssl_setHostName() */ + + static int ssl__gc(lua_State *L) { SSL **ud = luaL_checkudata(L, 1, SSL_CLASS); @@ -4434,6 +4460,8 @@ static const luaL_Reg ssl_methods[] = { { "getPeerCertificate", &ssl_getPeerCertificate }, { "getPeerChain", &ssl_getPeerChain }, { "getCipherInfo", &ssl_getCipherInfo }, + { "getHostName", &ssl_getHostName }, + { "setHostName", &ssl_setHostName }, { NULL, NULL }, }; |