501501#define HAVE_SSL_SET1_CHAIN OPENSSL_PREREQ(1,0,2)
502502#endif
503503
504+ #ifndef HAVE_SSL_USE_CHAIN_FILE
505+ #define HAVE_SSL_USE_CHAIN_FILE (OPENSSL_PREREQ(1,1,0) || LIBRESSL_PREREQ(3,3,3))
506+ #endif
507+
504508#ifndef HAVE_SSL_SET1_PARAM
505509#define HAVE_SSL_SET1_PARAM (OPENSSL_PREREQ(1,0,2) || LIBRESSL_PREREQ(2,5,1))
506510#endif
@@ -9497,8 +9501,9 @@ static int sx_setCertificateChain(lua_State *L) {
94979501} /* sx_setCertificateChain() */
94989502#endif
94999503
9504+
95009505#if HAVE_USE_CERTIFICATE_CHAIN_FILE
9501- static int sx_useCertificateChainFile (lua_State * L ) {
9506+ static int sx_setCertificateChainFromFile (lua_State * L ) {
95029507 SSL_CTX * ctx = checksimple (L , 1 , SSL_CTX_CLASS );
95039508 const char * filepath = luaL_checkstring (L , 2 );
95049509
@@ -9507,9 +9512,10 @@ static int sx_useCertificateChainFile(lua_State* L) {
95079512
95089513 lua_pushboolean (L , 1 );
95099514 return 1 ;
9510- }
9515+ } /* sx_setCertificateChainFromFile() */
95119516#endif
95129517
9518+
95139519#if HAVE_SSL_CTX_GET0_CHAIN_CERTS
95149520static int sx_getCertificateChain (lua_State * L ) {
95159521 SSL_CTX * ctx = checksimple (L , 1 , SSL_CTX_CLASS );
@@ -9524,6 +9530,7 @@ static int sx_getCertificateChain(lua_State *L) {
95249530} /* sx_getCertificateChain() */
95259531#endif
95269532
9533+
95279534static int sx_setPrivateKey (lua_State * L ) {
95289535 SSL_CTX * ctx = checksimple (L , 1 , SSL_CTX_CLASS );
95299536 EVP_PKEY * key = checksimple (L , 2 , PKEY_CLASS );
@@ -9546,7 +9553,7 @@ static int sx_setPrivateKey(lua_State *L) {
95469553} /* sx_setPrivateKey() */
95479554
95489555
9549- static int sx_usePrivateKeyFile (lua_State * L ) {
9556+ static int sx_setPrivateKeyFromFile (lua_State * L ) {
95509557 SSL_CTX * ctx = checksimple (L , 1 , SSL_CTX_CLASS );
95519558 const char * filepath = luaL_checkstring (L , 2 );
95529559 int typ = luaL_optinteger (L , 3 , SSL_FILETYPE_PEM );
@@ -9557,7 +9564,8 @@ static int sx_usePrivateKeyFile(lua_State* L) {
95579564 lua_pushboolean (L , 1 );
95589565
95599566 return 1 ;
9560- }
9567+ } /* sx_setPrivateKeyFromFile() */
9568+
95619569
95629570static int sx_setCipherList (lua_State * L ) {
95639571 SSL_CTX * ctx = checksimple (L , 1 , SSL_CTX_CLASS );
@@ -10333,11 +10341,11 @@ static const auxL_Reg sx_methods[] = {
1033310341 { "getCertificateChain" , & sx_getCertificateChain },
1033410342#endif
1033510343#if HAVE_USE_CERTIFICATE_CHAIN_FILE
10336- {"setCertificateChainFromFile" , & sx_useCertificateChainFile },
10344+ { "setCertificateChainFromFile" , & sx_setCertificateChainFromFile },
1033710345#endif
10338- { "setPrivateKey" , & sx_setPrivateKey },
10339- { "setPrivateKeyFromFile" , & sx_usePrivateKeyFile },
10340- { "setCipherList" , & sx_setCipherList },
10346+ { "setPrivateKey" , & sx_setPrivateKey },
10347+ { "setPrivateKeyFromFile" , & sx_setPrivateKeyFromFile },
10348+ { "setCipherList" , & sx_setCipherList },
1034110349#if HAVE_SSL_CTX_SET_CIPHERSUITES
1034210350 { "setCipherSuites" , & sx_setCipherSuites },
1034310351#endif
@@ -10834,6 +10842,21 @@ static int ssl_setCertificateChain(lua_State *L) {
1083410842#endif
1083510843
1083610844
10845+ #if HAVE_SSL_USE_CHAIN_FILE
10846+ static int ssl_setCertificateChainFromFile (lua_State * L ) {
10847+ SSL * ssl = checksimple (L , 1 , SSL_CLASS );
10848+ const char * filepath = luaL_checkstring (L , 2 );
10849+
10850+ if (!SSL_use_certificate_chain_file (ssl , filepath ))
10851+ return auxL_error (L , auxL_EOPENSSL , "ssl:setCertificateChainFromFile" );
10852+
10853+ lua_pushboolean (L , 1 );
10854+
10855+ return 1 ;
10856+ } /* ssl_setCertificateChainFromFile() */
10857+ #endif
10858+
10859+
1083710860#if HAVE_SSL_GET0_CHAIN_CERTS
1083810861static int ssl_getCertificateChain (lua_State * L ) {
1083910862 SSL * ssl = checksimple (L , 1 , SSL_CLASS );
@@ -10870,6 +10893,21 @@ static int ssl_setPrivateKey(lua_State *L) {
1087010893} /* ssl_setPrivateKey() */
1087110894
1087210895
10896+ static int ssl_setPrivateKeyFromFile (lua_State * L ) {
10897+ SSL * ssl = checksimple (L , 1 , SSL_CLASS );
10898+ const char * filepath = luaL_checkstring (L , 2 );
10899+ int typ = luaL_optinteger (L , 3 , SSL_FILETYPE_PEM );
10900+
10901+ if (!SSL_use_PrivateKey_file (ssl , filepath , typ ))
10902+ return auxL_error (L , auxL_EOPENSSL , "ssl:setPrivateKeyFromFile" );
10903+
10904+ lua_pushboolean (L , 1 );
10905+
10906+ return 1 ;
10907+ } /* ssl_setPrivateKeyFromFile() */
10908+
10909+
10910+
1087310911static int ssl_getCertificate (lua_State * L ) {
1087410912 SSL * ssl = checksimple (L , 1 , SSL_CLASS );
1087510913 X509 * x509 ;
@@ -11262,15 +11300,19 @@ static const auxL_Reg ssl_methods[] = {
1126211300#if HAVE_SSL_SET1_CHAIN
1126311301 { "setCertificateChain" , & ssl_setCertificateChain },
1126411302#endif
11303+ #if HAVE_SSL_USE_CHAIN_FILE
11304+ { "setCertificateChainFromFile" , & ssl_setCertificateChainFromFile },
11305+ #endif
1126511306#if HAVE_SSL_GET0_CHAIN_CERTS
1126611307 { "getCertificateChain" , & ssl_getCertificateChain },
1126711308#endif
11268- { "setPrivateKey" , & ssl_setPrivateKey },
11269- { "getCertificate" , & ssl_getCertificate },
11270- { "getPeerCertificate" , & ssl_getPeerCertificate },
11271- { "getPeerChain" , & ssl_getPeerChain },
11272- { "getCipherInfo" , & ssl_getCipherInfo },
11273- { "setCipherList" , & ssl_setCipherList },
11309+ { "setPrivateKey" , & ssl_setPrivateKey },
11310+ { "setPrivateKeyFromFile" , & ssl_setPrivateKeyFromFile },
11311+ { "getCertificate" , & ssl_getCertificate },
11312+ { "getPeerCertificate" , & ssl_getPeerCertificate },
11313+ { "getPeerChain" , & ssl_getPeerChain },
11314+ { "getCipherInfo" , & ssl_getCipherInfo },
11315+ { "setCipherList" , & ssl_setCipherList },
1127411316#if HAVE_SSL_SET_CIPHERSUITES
1127511317 { "setCipherSuites" , & ssl_setCipherSuites },
1127611318#endif
0 commit comments