aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatarLibravatar william <william@25thandclement.com> 2015-03-04 17:51:26 -0800
committerLibravatarLibravatar william <william@25thandclement.com> 2015-03-04 17:51:26 -0800
commit6f9c187aaaf0549d5d95317d9b4eb62609280906 (patch)
tree9247ba207cc1509e0a45decb437f499f550d8cf9 /src
parent978fce0097361adfe473c033d7d61878e73c072a (diff)
parente08e76d91148fb360c918ac08be4c7c6ad76e749 (diff)
downloadluaossl-6f9c187aaaf0549d5d95317d9b4eb62609280906.tar.gz
luaossl-6f9c187aaaf0549d5d95317d9b4eb62609280906.tar.bz2
luaossl-6f9c187aaaf0549d5d95317d9b4eb62609280906.zip
Merge branch 'daurnimator-alpn'
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 6e3039f..562927d 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -4516,6 +4516,44 @@ static int sx_setEphemeralKey(lua_State *L) {
return 1;
} /* sx_setEphemeralKey() */
+static int sx_setAlpnProtos(lua_State *L) {
+ SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS);
+ size_t len;
+ const char *tmp;
+ unsigned protos_len = 0;
+ luaL_Buffer B;
+ luaL_checktype(L, 2, LUA_TTABLE);
+ luaL_buffinit(L, &B);
+
+ while (1) {
+ protos_len++;
+ lua_rawgeti(L, 2, protos_len);
+ switch (lua_type(L, -1)) {
+ case LUA_TNIL:
+ goto done;
+ case LUA_TSTRING:
+ break;
+ default:
+ return luaL_argerror(L, 2, "array of strings expected");
+ }
+ tmp = luaL_checklstring(L, -1, &len);
+ luaL_argcheck(L, len > 0 && len <= UCHAR_MAX, 2, "proto string length invalid");
+ luaL_addchar(&B, (unsigned char)len);
+ luaL_addlstring(&B, tmp, len);
+ lua_pop(L, 1);
+ }
+done:
+ luaL_pushresult(&B);
+ tmp = lua_tolstring(L, -1, &len);
+ if (0 != SSL_CTX_set_alpn_protos(ctx, (const unsigned char*)tmp, len)) {
+ lua_pushnil(L);
+ return 1;
+ }
+
+ lua_pushboolean(L, 1);
+
+ return 1;
+} /* sx_setAlpnprotos */
static int sx__gc(lua_State *L) {
SSL_CTX **ud = luaL_checkudata(L, 1, SSL_CTX_CLASS);
@@ -4540,6 +4578,7 @@ static const luaL_Reg sx_methods[] = {
{ "setPrivateKey", &sx_setPrivateKey },
{ "setCipherList", &sx_setCipherList },
{ "setEphemeralKey", &sx_setEphemeralKey },
+ { "setAlpnProtos", &sx_setAlpnProtos },
{ NULL, NULL },
};
@@ -4790,6 +4829,18 @@ static int ssl_getClientVersion(lua_State *L) {
return 1;
} /* ssl_getClientVersion() */
+static int ssl_getAlpnSelected(lua_State *L) {
+ SSL *ssl = checksimple(L, 1, SSL_CLASS);
+ const unsigned char *data;
+ unsigned len;
+ SSL_get0_alpn_selected(ssl, &data, &len);
+ if (0 == len) {
+ lua_pushnil(L);
+ } else {
+ lua_pushlstring(L, data, len);
+ }
+ return 1;
+} /*ssl_getAlpnSelected */
static int ssl__gc(lua_State *L) {
SSL **ud = luaL_checkudata(L, 1, SSL_CLASS);
@@ -4814,6 +4865,7 @@ static const luaL_Reg ssl_methods[] = {
{ "setHostName", &ssl_setHostName },
{ "getVersion", &ssl_getVersion },
{ "getClientVersion", &ssl_getClientVersion },
+ { "getAlpnSelected", &ssl_getAlpnSelected },
{ NULL, NULL },
};