aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatarLibravatar William Ahern <william@server.local> 2012-10-09 17:57:36 -0700
committerLibravatarLibravatar William 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) {
} /* sx_getVerify() */
+static int sx_setCertificate(lua_State *L) {
+ SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS);
+ X509 *crt = X509_dup(checksimple(L, 2, X509_CERT_CLASS));
+ int ok;
+
+ ok = SSL_CTX_use_certificate(ctx, crt);
+ X509_free(crt);
+
+ if (!ok)
+ return throwssl(L, "ssl.context:setCertificate");
+
+ lua_pushboolean(L, 1);
+
+ return 1;
+} /* sx_setCertificate() */
+
+
+static int sx_setPrivateKey(lua_State *L) {
+ SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS);
+ EVP_PKEY *key = checksimple(L, 2, PUBKEY_CLASS);
+
+ /*
+ * NOTE: No easy way to dup the key, but a shared reference should
+ * be okay as keys are less mutable than certificates.
+ */
+ if (!SSL_CTX_use_PrivateKey(ctx, key))
+ return throwssl(L, "ssl.context:setPrivateKey");
+
+ lua_pushboolean(L, 1);
+
+ return 1;
+} /* sx_setPrivateKey() */
+
+
static int sx__gc(lua_State *L) {
SSL_CTX **ud = luaL_checkudata(L, 1, SSL_CTX_CLASS);
@@ -3022,7 +3056,9 @@ static const luaL_Reg sx_methods[] = {
{ "setStore", &sx_setStore },
{ "setVerify", &sx_setVerify },
{ "getVerify", &sx_getVerify },
- { NULL, NULL },
+ { "setCertificate", &sx_setCertificate },
+ { "setPrivateKey", &sx_setPrivateKey },
+ { NULL, NULL },
};
static const luaL_Reg sx_metatable[] = {