diff --git a/doc/luaossl.pdf b/doc/luaossl.pdf index b7a09dc..306c636 100644 Binary files a/doc/luaossl.pdf and b/doc/luaossl.pdf differ diff --git a/doc/luaossl.tex b/doc/luaossl.tex index efc6422..2109499 100644 --- a/doc/luaossl.tex +++ b/doc/luaossl.tex @@ -1069,6 +1069,10 @@ \section{Modules} \emph{Only supported since OpenSSL 1.0.2.} +\subsubsection[\fn{context:setCertificateChainFromFile}]{\fn{context:setCertificateChainFromFile($filepath$[, $format$])}} + +Sets the X.509 certificate chain \module{openssl.x509.chain} object to send during SSL connection instance handshakes, load the certificate chain from the file $filepath$. $format$ is either ``ASN1'' or ``PEM'' (default). + \subsubsection[\fn{context:setCertificateChain}]{\fn{context:setCertificateChain($chain$)}} Sets the X.509 certificate chain \module{openssl.x509.chain} object $chain$ to send during SSL connection instance handshakes. @@ -1081,6 +1085,10 @@ \section{Modules} \emph{Only supported since OpenSSL 1.0.2.} +\subsubsection[\fn{context:setPrivateKeyFromFile}]{\fn{context:setPrivateKeyFromFile($filepath$[, $format$])}} + +Sets the private key \module{openssl.pkey} object to send during SSL connection instance handshakes, load the key from the file $filepath$. $format$ is either ``ASN1'' or ``PEM'' (default). + \subsubsection[\fn{context:setPrivateKey}]{\fn{context:setPrivateKey($key$)}} Sets the private key \module{openssl.pkey} object $key$ for use during SSL connection instance handshakes. @@ -1286,6 +1294,13 @@ \section{Modules} Sets the X.509 certificate \module{openssl.x509} object $crt$ to send during SSL connection instance handshakes. See \fn{openssl.ssl.context:setCertificate}. +\subsubsection[\fn{ssl:setCertificateChainFromFile}]{\fn{ssl:setCertificateChainFromFile($filepath$[, $format$])}} + +Sets the X.509 certificate chain \module{openssl.x509.chain} object to send during SSL connection instance handshakes, load the certificate chain from the file $filepath$. $format$ is either ``ASN1'' or ``PEM'' (default). +See \fn{openssl.ssl.context:setCertificateChainFromFile}. + +\emph{Only supported since OpenSSL 1.1.0.} + \subsubsection[\fn{ssl:setCertificateChain}]{\fn{ssl:setCertificateChain($chain$)}} Sets the X.509 certificate chain \module{openssl.x509.chain} object $chain$ to send during SSL connection instance handshakes. @@ -1293,13 +1308,18 @@ \section{Modules} \emph{Only supported since OpenSSL 1.0.2.} -\subsubsection[\fn{context:getCertificateChain}]{\fn{context:getCertificateChain()}} +\subsubsection[\fn{ssl:getCertificateChain}]{\fn{ssl:getCertificateChain()}} Returns the X.509 certificate chain \module{openssl.x509.chain} object to be sent during SSL connection instance handshakes. See \fn{openssl.ssl.context:getCertificateChain}. \emph{Only supported since OpenSSL 1.0.2.} +\subsubsection[\fn{ssl:setPrivateKeyFromFile}]{\fn{ssl:setPrivateKeyFromFile($filepath$[, $format$])}} + +Sets the private key \module{openssl.pkey} object to send during SSL connection instance handshakes, load the key from the file $filepath$. $format$ is either ``ASN1'' or ``PEM'' (default). +See \fn{openssl.ssl.context:setPrivateKeyFromFile}. + \subsubsection[\fn{ssl:setPrivateKey}]{\fn{ssl:setPrivateKey($key$)}} Sets the private key \module{openssl.pkey} object $key$ for use during SSL connection instance handshakes. diff --git a/src/openssl.c b/src/openssl.c index 3a81907..d2cfeef 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -860,6 +860,25 @@ static int optencoding(lua_State *L, int index, const char *def, int allow) { return type; } /* optencoding() */ +static int optfiletype(lua_State *L, int index, const char *def) { + static const char *const opts[] = { "pem", "asn1", NULL }; + int type = 0; + + switch (auxL_checkoption(L, index, def, opts, 1)) { + case 0: + type = SSL_FILETYPE_PEM; + break; + case 1: + type = SSL_FILETYPE_ASN1; + break; + } + + if (!type) { + luaL_argerror(L, index, lua_pushfstring(L, "invalid option %s", luaL_checkstring(L, index))); + } + + return type; +} static _Bool rawgeti(lua_State *L, int index, int n) { lua_rawgeti(L, index, n); @@ -3256,12 +3275,6 @@ static const auxL_IntegerReg openssl_integers[] = { { NULL, 0 }, }; -static const auxL_IntegerReg openssl_filetypes[] = { - {"PEM", SSL_FILETYPE_PEM}, - {"ASN1", SSL_FILETYPE_ASN1}, - {NULL, 0} -}; - EXPORT int luaopen__openssl(lua_State *L) { size_t i; @@ -3285,12 +3298,6 @@ EXPORT int luaopen__openssl(lua_State *L) { lua_pushstring(L, SHLIB_VERSION_NUMBER); lua_setfield(L, -2, "SHLIB_VERSION_NUMBER"); - - lua_newtable(L); - auxL_setintegers(L, openssl_filetypes); - - lua_setfield(L, -2, "filetypes"); - return 1; } /* luaopen__openssl() */ @@ -9556,9 +9563,9 @@ static int sx_setPrivateKey(lua_State *L) { static int sx_setPrivateKeyFromFile(lua_State* L) { SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS); const char* filepath = luaL_checkstring(L, 2); - int typ = luaL_optinteger(L, 3, SSL_FILETYPE_PEM); + int type = optfiletype(L, 3, "PEM"); - if (!SSL_CTX_use_PrivateKey_file(ctx, filepath, typ)) + if (!SSL_CTX_use_PrivateKey_file(ctx, filepath, type)) return auxL_error(L, auxL_EOPENSSL, "ssl.context:setPrivateKeyFromFile"); lua_pushboolean(L, 1); @@ -10896,9 +10903,9 @@ static int ssl_setPrivateKey(lua_State *L) { static int ssl_setPrivateKeyFromFile(lua_State* L) { SSL *ssl = checksimple(L, 1, SSL_CLASS); const char* filepath = luaL_checkstring(L, 2); - int typ = luaL_optinteger(L, 3, SSL_FILETYPE_PEM); + int type = optfiletype(L, 3, "PEM"); - if (!SSL_use_PrivateKey_file(ssl, filepath, typ)) + if (!SSL_use_PrivateKey_file(ssl, filepath, type)) return auxL_error(L, auxL_EOPENSSL, "ssl:setPrivateKeyFromFile"); lua_pushboolean(L, 1);