Changeset 4288

Show
Ignore:
Timestamp:
03/04/09 14:09:32 (4 years ago)
Author:
Cyrus
Message:

Set /etc/private.rsa as default key for axTLS contexts
More openssl - axTLS fixes

Location:
luci/trunk/libs/nixio
Files:
1 removed
1 modified

Legend:

Unmodified
Added
Removed
  • luci/trunk/libs/nixio/src/tls-context.c

    r4275 r4288  
    4444    const char *method = luaL_optlstring(L, 1, "tlsv1", NULL); 
    4545 
     46    luaL_getmetatable(L, NIXIO_TLS_CTX_META); 
    4647    SSL_CTX **ctx = lua_newuserdata(L, sizeof(SSL_CTX *)); 
    4748    if (!ctx) { 
     
    5051 
    5152    /* create userdata */ 
    52     luaL_getmetatable(L, NIXIO_TLS_CTX_META); 
     53    lua_pushvalue(L, -2); 
    5354    lua_setmetatable(L, -2); 
     55    lua_getfield(L, -1, "tls_defaultkey"); 
    5456 
    5557    if (!strcmp(method, "tlsv1")) { 
     
    6163    } 
    6264 
    63  
    64     SSL_CTX_set_options(*ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3); 
    65  
    6665    if (!(*ctx)) { 
    6766        return luaL_error(L, "unable to create TLS context"); 
    6867    } 
     68 
     69    const char *autoload = lua_tostring(L, -1); 
     70    if (autoload) { 
     71        SSL_CTX_use_PrivateKey_file(*ctx, autoload, SSL_FILETYPE_PEM); 
     72    } 
     73    lua_pop(L, 1); 
     74 
     75    SSL_CTX_set_options(*ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3); 
    6976 
    7077    return 1; 
     
    203210    luaL_register(L, NULL, R); 
    204211 
     212#ifndef WITH_AXTLS 
     213    lua_pushliteral(L, "openssl"); 
     214#else 
     215    lua_pushliteral(L, "axtls"); 
     216#endif 
     217    lua_setfield(L, -2, "tls_provider"); 
     218 
    205219    /* create context metatable */ 
    206220    luaL_newmetatable(L, NIXIO_TLS_CTX_META); 
     
    208222    lua_setfield(L, -2, "__index"); 
    209223    luaL_register(L, NULL, CTX_M); 
    210     lua_pop(L, 1); 
    211 } 
     224#ifdef WITH_AXTLS 
     225    lua_pushliteral(L, "/etc/private.rsa"); 
     226    lua_setfield(L, -2, "tls_defaultkey"); 
     227#endif 
     228    lua_setfield(L, -2, "meta_tls_context"); 
     229}