diff options
| author | daurnimator <quae@daurnimator.com> | 2015-02-28 19:36:41 -0500 |
|---|---|---|
| committer | daurnimator <quae@daurnimator.com> | 2015-02-28 19:36:41 -0500 |
| commit | 55fd8c9610fd2dda02eb436de8c03a0fa5704048 (patch) | |
| tree | 897850250535d17183f2578e5457cdc6fcc030be /src | |
| parent | 978fce0097361adfe473c033d7d61878e73c072a (diff) | |
| download | luaossl-55fd8c9610fd2dda02eb436de8c03a0fa5704048.tar.gz luaossl-55fd8c9610fd2dda02eb436de8c03a0fa5704048.tar.bz2 luaossl-55fd8c9610fd2dda02eb436de8c03a0fa5704048.zip | |
Bind SSL_CTX_set_alpn_protos and SSL_get0_alpn_selected
Diffstat (limited to 'src')
| -rw-r--r-- | src/openssl.c | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c index 6e3039f..ab19410 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
| @@ -4516,6 +4516,44 @@ static int sx_setEphemeralKey(lua_State *L) { | |||
| 4516 | return 1; | 4516 | return 1; |
| 4517 | } /* sx_setEphemeralKey() */ | 4517 | } /* sx_setEphemeralKey() */ |
| 4518 | 4518 | ||
| 4519 | static int sx_setAlpnProtos(lua_State *L) { | ||
| 4520 | SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS); | ||
| 4521 | size_t len; | ||
| 4522 | const char *tmp; | ||
| 4523 | unsigned protos_len = 0; | ||
| 4524 | luaL_Buffer B; | ||
| 4525 | luaL_checktype(L, 2, LUA_TTABLE); | ||
| 4526 | luaL_buffinit(L, &B); | ||
| 4527 | |||
| 4528 | while (1) { | ||
| 4529 | protos_len++; | ||
| 4530 | lua_rawgeti(L, 2, protos_len); | ||
| 4531 | switch (lua_type(L, -1)) { | ||
| 4532 | case LUA_TNIL: | ||
| 4533 | goto done; | ||
| 4534 | case LUA_TSTRING: | ||
| 4535 | break; | ||
| 4536 | default: | ||
| 4537 | return luaL_argerror(L, 2, "array of strings expected"); | ||
| 4538 | } | ||
| 4539 | tmp = luaL_checklstring(L, -1, &len); | ||
| 4540 | luaL_argcheck(L, len <= UCHAR_MAX, 2, "proto string too long"); | ||
| 4541 | luaL_addchar(&B, (unsigned char)len); | ||
| 4542 | luaL_addlstring(&B, tmp, len); | ||
| 4543 | lua_pop(L, 1); | ||
| 4544 | } | ||
| 4545 | done: | ||
| 4546 | luaL_pushresult(&B); | ||
| 4547 | |||
| 4548 | if (0 != SSL_CTX_set_alpn_protos(ctx, (const unsigned char*)lua_tostring(L, -1), protos_len)) { | ||
| 4549 | lua_pushnil(L); | ||
| 4550 | return 1; | ||
| 4551 | } | ||
| 4552 | |||
| 4553 | lua_pushboolean(L, 1); | ||
| 4554 | |||
| 4555 | return 1; | ||
| 4556 | } /* sx_setAlpnprotos */ | ||
| 4519 | 4557 | ||
| 4520 | static int sx__gc(lua_State *L) { | 4558 | static int sx__gc(lua_State *L) { |
| 4521 | SSL_CTX **ud = luaL_checkudata(L, 1, SSL_CTX_CLASS); | 4559 | SSL_CTX **ud = luaL_checkudata(L, 1, SSL_CTX_CLASS); |
| @@ -4540,6 +4578,7 @@ static const luaL_Reg sx_methods[] = { | |||
| 4540 | { "setPrivateKey", &sx_setPrivateKey }, | 4578 | { "setPrivateKey", &sx_setPrivateKey }, |
| 4541 | { "setCipherList", &sx_setCipherList }, | 4579 | { "setCipherList", &sx_setCipherList }, |
| 4542 | { "setEphemeralKey", &sx_setEphemeralKey }, | 4580 | { "setEphemeralKey", &sx_setEphemeralKey }, |
| 4581 | { "setAlpnProtos", &sx_setAlpnProtos }, | ||
| 4543 | { NULL, NULL }, | 4582 | { NULL, NULL }, |
| 4544 | }; | 4583 | }; |
| 4545 | 4584 | ||
| @@ -4790,6 +4829,18 @@ static int ssl_getClientVersion(lua_State *L) { | |||
| 4790 | return 1; | 4829 | return 1; |
| 4791 | } /* ssl_getClientVersion() */ | 4830 | } /* ssl_getClientVersion() */ |
| 4792 | 4831 | ||
| 4832 | static int ssl_getAlpnSelected(lua_State *L) { | ||
| 4833 | SSL *ssl = checksimple(L, 1, SSL_CLASS); | ||
| 4834 | const unsigned char *data; | ||
| 4835 | unsigned len; | ||
| 4836 | SSL_get0_alpn_selected(ssl, &data, &len); | ||
| 4837 | if (0 == len) { | ||
| 4838 | lua_pushnil(L); | ||
| 4839 | } else { | ||
| 4840 | lua_pushlstring(L, data, len); | ||
| 4841 | } | ||
| 4842 | return 1; | ||
| 4843 | } /*ssl_getAlpnSelected */ | ||
| 4793 | 4844 | ||
| 4794 | static int ssl__gc(lua_State *L) { | 4845 | static int ssl__gc(lua_State *L) { |
| 4795 | SSL **ud = luaL_checkudata(L, 1, SSL_CLASS); | 4846 | SSL **ud = luaL_checkudata(L, 1, SSL_CLASS); |
| @@ -4814,6 +4865,7 @@ static const luaL_Reg ssl_methods[] = { | |||
| 4814 | { "setHostName", &ssl_setHostName }, | 4865 | { "setHostName", &ssl_setHostName }, |
| 4815 | { "getVersion", &ssl_getVersion }, | 4866 | { "getVersion", &ssl_getVersion }, |
| 4816 | { "getClientVersion", &ssl_getClientVersion }, | 4867 | { "getClientVersion", &ssl_getClientVersion }, |
| 4868 | { "getAlpnSelected", &ssl_getAlpnSelected }, | ||
| 4817 | { NULL, NULL }, | 4869 | { NULL, NULL }, |
| 4818 | }; | 4870 | }; |
| 4819 | 4871 | ||
