moonbridge

changeset 245:29322b2a1af8

Require "mode" parameter passed to tlsconf function
author jbe
date Mon Aug 22 00:40:30 2016 +0200 (2016-08-22)
parents 832741713761
children 00e1ee683355
files moonbridge_io.c
line diff
     1.1 --- a/moonbridge_io.c	Sun Aug 21 16:12:11 2016 +0200
     1.2 +++ b/moonbridge_io.c	Mon Aug 22 00:40:30 2016 +0200
     1.3 @@ -1681,6 +1681,17 @@
     1.4    luaL_setmetatable(L, MOONBR_IO_TLSCONF_MT_REGKEY);
     1.5    lua_pushvalue(L, 1);
     1.6    lua_setuservalue(L, -2);
     1.7 +#if LUA_VERSION_NUM >= 503
     1.8 +  if (lua_getfield(L, 1, "mode") == LUA_TSTRING) value = lua_tostring(L, -1);
     1.9 +#else
    1.10 +  lua_getfield(L, 1, "mode");
    1.11 +  if (lua_type(L, -1) == LUA_TSTRING) value = lua_tostring(L, -1);
    1.12 +#endif
    1.13 +  else value = "";
    1.14 +  if (strcmp(value, "server") && strcmp(value, "client")) {
    1.15 +    luaL_argcheck(L, 0, 1, "field \"mode\" must be set to \"server\" or \"client\"");
    1.16 +  }
    1.17 +  lua_pop(L, 1);
    1.18    moonbr_io_tlsconf_string("CA file",          "ca_file",   tls_config_set_ca_file);
    1.19    moonbr_io_tlsconf_string("CA path",          "ca_path",   tls_config_set_ca_path);
    1.20    moonbr_io_tlsconf_binary("CA",               "ca_mem",    tls_config_set_ca_mem);
    1.21 @@ -1688,9 +1699,17 @@
    1.22    moonbr_io_tlsconf_binary("certificate",      "cert_mem",  tls_config_set_cert_mem);
    1.23    moonbr_io_tlsconf_string("key file",         "key_file",  tls_config_set_key_file);
    1.24    moonbr_io_tlsconf_binary("key",              "key_mem",   tls_config_set_key_mem);
    1.25 +#if LUA_VERSION_NUM >= 503
    1.26 +  valuetype = lua_getfield(L, 1, "verify_client");
    1.27 +#else
    1.28    lua_getfield(L, 1, "verify_client");
    1.29 +#endif
    1.30    if (lua_toboolean(L, -1)) {
    1.31 +#if LUA_VERSION_NUM >= 503
    1.32 +    if (valuetype == LUA_TSTRING) value = lua_tostring(L, -1);
    1.33 +#else
    1.34      if (lua_type(L, -1) == LUA_TSTRING) value = lua_tostring(L, -1);
    1.35 +#endif
    1.36      else value = "";
    1.37      if (!strcmp(value, "required")) {
    1.38        tls_config_verify_client(tlsconf);

Impressum / About Us