-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support SSL_CTX_use_certificate_chain_file and SSL_CTX_use_private_key_file #194
Open
Mehgugs
wants to merge
2
commits into
wahern:master
Choose a base branch
from
Mehgugs:use_certificate_chain_file
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -501,6 +501,10 @@ | |
#define HAVE_SSL_SET1_CHAIN OPENSSL_PREREQ(1,0,2) | ||
#endif | ||
|
||
#ifndef HAVE_SSL_USE_CHAIN_FILE | ||
#define HAVE_SSL_USE_CHAIN_FILE (OPENSSL_PREREQ(1,1,0) || LIBRESSL_PREREQ(3,3,3)) | ||
#endif | ||
|
||
#ifndef HAVE_SSL_SET1_PARAM | ||
#define HAVE_SSL_SET1_PARAM (OPENSSL_PREREQ(1,0,2) || LIBRESSL_PREREQ(2,5,1)) | ||
#endif | ||
|
@@ -613,6 +617,10 @@ | |
#define HMAC_INIT_EX_INT OPENSSL_PREREQ(1,0,0) | ||
#endif | ||
|
||
#ifndef HAVE_USE_CERTIFICATE_CHAIN_FILE | ||
#define HAVE_USE_CERTIFICATE_CHAIN_FILE (OPENSSL_PREREQ(0,9,4) || LIBRESSL_PREREQ(2,0,0)) | ||
#endif | ||
|
||
#if HAVE_EVP_PKEY_CTX_KDF || HAVE_EVP_KDF_CTX | ||
#include <openssl/kdf.h> | ||
#endif | ||
|
@@ -3248,6 +3256,12 @@ 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; | ||
|
||
|
@@ -3271,6 +3285,12 @@ 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() */ | ||
|
||
|
@@ -9482,6 +9502,20 @@ static int sx_setCertificateChain(lua_State *L) { | |
#endif | ||
|
||
|
||
#if HAVE_USE_CERTIFICATE_CHAIN_FILE | ||
static int sx_setCertificateChainFromFile(lua_State* L) { | ||
SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS); | ||
const char *filepath = luaL_checkstring(L, 2); | ||
|
||
if (!SSL_CTX_use_certificate_chain_file(ctx, filepath)) | ||
return auxL_error(L, auxL_EOPENSSL, "ssl.context:setCertificateChainFromFile"); | ||
|
||
lua_pushboolean(L, 1); | ||
return 1; | ||
} /* sx_setCertificateChainFromFile() */ | ||
#endif | ||
|
||
|
||
#if HAVE_SSL_CTX_GET0_CHAIN_CERTS | ||
static int sx_getCertificateChain(lua_State *L) { | ||
SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS); | ||
|
@@ -9519,6 +9553,20 @@ static int sx_setPrivateKey(lua_State *L) { | |
} /* sx_setPrivateKey() */ | ||
|
||
|
||
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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should probably take a string rather than an integer option? ( |
||
|
||
if (!SSL_CTX_use_PrivateKey_file(ctx, filepath, typ)) | ||
return auxL_error(L, auxL_EOPENSSL, "ssl.context:setPrivateKeyFromFile"); | ||
|
||
lua_pushboolean(L, 1); | ||
|
||
return 1; | ||
} /* sx_setPrivateKeyFromFile() */ | ||
|
||
|
||
static int sx_setCipherList(lua_State *L) { | ||
SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS); | ||
const char *ciphers = luaL_checkstring(L, 2); | ||
|
@@ -10270,7 +10318,6 @@ static int sx__gc(lua_State *L) { | |
return 0; | ||
} /* sx__gc() */ | ||
|
||
|
||
Mehgugs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
static const auxL_Reg sx_methods[] = { | ||
{ "setOptions", &sx_setOptions }, | ||
{ "getOptions", &sx_getOptions }, | ||
|
@@ -10293,8 +10340,12 @@ static const auxL_Reg sx_methods[] = { | |
#if HAVE_SSL_CTX_GET0_CHAIN_CERTS | ||
{ "getCertificateChain", &sx_getCertificateChain }, | ||
#endif | ||
{ "setPrivateKey", &sx_setPrivateKey }, | ||
{ "setCipherList", &sx_setCipherList }, | ||
#if HAVE_USE_CERTIFICATE_CHAIN_FILE | ||
{ "setCertificateChainFromFile", &sx_setCertificateChainFromFile }, | ||
#endif | ||
{ "setPrivateKey", &sx_setPrivateKey }, | ||
{ "setPrivateKeyFromFile", &sx_setPrivateKeyFromFile }, | ||
{ "setCipherList", &sx_setCipherList }, | ||
#if HAVE_SSL_CTX_SET_CIPHERSUITES | ||
{ "setCipherSuites", &sx_setCipherSuites }, | ||
#endif | ||
|
@@ -10791,6 +10842,21 @@ static int ssl_setCertificateChain(lua_State *L) { | |
#endif | ||
|
||
|
||
#if HAVE_SSL_USE_CHAIN_FILE | ||
static int ssl_setCertificateChainFromFile(lua_State *L) { | ||
SSL *ssl = checksimple(L, 1, SSL_CLASS); | ||
const char *filepath = luaL_checkstring(L, 2); | ||
|
||
if (!SSL_use_certificate_chain_file(ssl, filepath)) | ||
return auxL_error(L, auxL_EOPENSSL, "ssl:setCertificateChainFromFile"); | ||
|
||
lua_pushboolean(L, 1); | ||
|
||
return 1; | ||
} /* ssl_setCertificateChainFromFile() */ | ||
#endif | ||
|
||
|
||
#if HAVE_SSL_GET0_CHAIN_CERTS | ||
static int ssl_getCertificateChain(lua_State *L) { | ||
SSL *ssl = checksimple(L, 1, SSL_CLASS); | ||
|
@@ -10827,6 +10893,21 @@ static int ssl_setPrivateKey(lua_State *L) { | |
} /* ssl_setPrivateKey() */ | ||
|
||
|
||
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); | ||
|
||
if (!SSL_use_PrivateKey_file(ssl, filepath, typ)) | ||
return auxL_error(L, auxL_EOPENSSL, "ssl:setPrivateKeyFromFile"); | ||
|
||
lua_pushboolean(L, 1); | ||
|
||
return 1; | ||
} /* ssl_setPrivateKeyFromFile() */ | ||
|
||
|
||
|
||
static int ssl_getCertificate(lua_State *L) { | ||
SSL *ssl = checksimple(L, 1, SSL_CLASS); | ||
X509 *x509; | ||
|
@@ -11219,15 +11300,19 @@ static const auxL_Reg ssl_methods[] = { | |
#if HAVE_SSL_SET1_CHAIN | ||
{ "setCertificateChain", &ssl_setCertificateChain }, | ||
#endif | ||
#if HAVE_SSL_USE_CHAIN_FILE | ||
{ "setCertificateChainFromFile", &ssl_setCertificateChainFromFile}, | ||
#endif | ||
#if HAVE_SSL_GET0_CHAIN_CERTS | ||
{ "getCertificateChain", &ssl_getCertificateChain }, | ||
#endif | ||
{ "setPrivateKey", &ssl_setPrivateKey }, | ||
{ "getCertificate", &ssl_getCertificate }, | ||
{ "getPeerCertificate", &ssl_getPeerCertificate }, | ||
{ "getPeerChain", &ssl_getPeerChain }, | ||
{ "getCipherInfo", &ssl_getCipherInfo }, | ||
{ "setCipherList", &ssl_setCipherList }, | ||
{ "setPrivateKey", &ssl_setPrivateKey }, | ||
{ "setPrivateKeyFromFile", &ssl_setPrivateKeyFromFile }, | ||
{ "getCertificate", &ssl_getCertificate }, | ||
{ "getPeerCertificate", &ssl_getPeerCertificate }, | ||
{ "getPeerChain", &ssl_getPeerChain }, | ||
{ "getCipherInfo", &ssl_getCipherInfo }, | ||
{ "setCipherList", &ssl_setCipherList }, | ||
#if HAVE_SSL_SET_CIPHERSUITES | ||
{ "setCipherSuites", &ssl_setCipherSuites }, | ||
#endif | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is old enough we can likely count on it