Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified doc/luaossl.pdf
Binary file not shown.
22 changes: 21 additions & 1 deletion doc/luaossl.tex
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down Expand Up @@ -1286,20 +1294,32 @@ \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.
See \fn{openssl.ssl.context:setCertificateChain}.

\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.
Expand Down
39 changes: 23 additions & 16 deletions src/openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;

Expand All @@ -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() */

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down