summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Ahern <william@server.local>2012-10-09 17:57:36 -0700
committerWilliam Ahern <william@server.local>2012-10-09 17:57:36 -0700
commit048e5f3b22e512ed4b4273306511fea3f1c29161 (patch)
tree37981a86e99ee4a276c366dad725519ef76d8543
parent46d774932292ad7a6993e07820451add9c98979a (diff)
downloadluaossl-048e5f3b22e512ed4b4273306511fea3f1c29161.tar.gz
luaossl-048e5f3b22e512ed4b4273306511fea3f1c29161.tar.bz2
luaossl-048e5f3b22e512ed4b4273306511fea3f1c29161.zip
-n
add setCertificate and setPrivateKey
-rw-r--r--openssl.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/openssl.c b/openssl.c
index fd96d15..fb4f719 100644
--- a/openssl.c
+++ b/openssl.c
@@ -3008,6 +3008,40 @@ static int sx_getVerify(lua_State *L) {
3008} /* sx_getVerify() */ 3008} /* sx_getVerify() */
3009 3009
3010 3010
3011static int sx_setCertificate(lua_State *L) {
3012 SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS);
3013 X509 *crt = X509_dup(checksimple(L, 2, X509_CERT_CLASS));
3014 int ok;
3015
3016 ok = SSL_CTX_use_certificate(ctx, crt);
3017 X509_free(crt);
3018
3019 if (!ok)
3020 return throwssl(L, "ssl.context:setCertificate");
3021
3022 lua_pushboolean(L, 1);
3023
3024 return 1;
3025} /* sx_setCertificate() */
3026
3027
3028static int sx_setPrivateKey(lua_State *L) {
3029 SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS);
3030 EVP_PKEY *key = checksimple(L, 2, PUBKEY_CLASS);
3031
3032 /*
3033 * NOTE: No easy way to dup the key, but a shared reference should
3034 * be okay as keys are less mutable than certificates.
3035 */
3036 if (!SSL_CTX_use_PrivateKey(ctx, key))
3037 return throwssl(L, "ssl.context:setPrivateKey");
3038
3039 lua_pushboolean(L, 1);
3040
3041 return 1;
3042} /* sx_setPrivateKey() */
3043
3044
3011static int sx__gc(lua_State *L) { 3045static int sx__gc(lua_State *L) {
3012 SSL_CTX **ud = luaL_checkudata(L, 1, SSL_CTX_CLASS); 3046 SSL_CTX **ud = luaL_checkudata(L, 1, SSL_CTX_CLASS);
3013 3047
@@ -3022,7 +3056,9 @@ static const luaL_Reg sx_methods[] = {
3022 { "setStore", &sx_setStore }, 3056 { "setStore", &sx_setStore },
3023 { "setVerify", &sx_setVerify }, 3057 { "setVerify", &sx_setVerify },
3024 { "getVerify", &sx_getVerify }, 3058 { "getVerify", &sx_getVerify },
3025 { NULL, NULL }, 3059 { "setCertificate", &sx_setCertificate },
3060 { "setPrivateKey", &sx_setPrivateKey },
3061 { NULL, NULL },
3026}; 3062};
3027 3063
3028static const luaL_Reg sx_metatable[] = { 3064static const luaL_Reg sx_metatable[] = {