aboutsummaryrefslogtreecommitdiffstats
path: root/src/openssl.c
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-05-29 11:59:54 +1000
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2018-05-29 13:47:51 +1000
commitc2505e13f50232c561b156ff0b1e14db8d616b73 (patch)
tree7fa9e56fb865d0039a65183b7a95e2cb77aab4b7 /src/openssl.c
parent6aaf6adfe40e629ead457f2696fa3d8139b59883 (diff)
downloadluaossl-c2505e13f50232c561b156ff0b1e14db8d616b73.tar.gz
luaossl-c2505e13f50232c561b156ff0b1e14db8d616b73.tar.bz2
luaossl-c2505e13f50232c561b156ff0b1e14db8d616b73.zip
src/openssl.c: Add ssl:getCertificate()
It uses X509_dup to match :setCertificate(). Note that this differs from ssl:getPeerCertificate() which does *not* dup().
Diffstat (limited to 'src/openssl.c')
-rw-r--r--src/openssl.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 8efe6f7..860b8a0 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -9186,6 +9186,19 @@ static int ssl_setPrivateKey(lua_State *L) {
} /* ssl_setPrivateKey() */
+static int ssl_getCertificate(lua_State *L) {
+ SSL *ssl = checksimple(L, 1, SSL_CLASS);
+ X509 *x509;
+
+ if (!(x509 = SSL_get_certificate(ssl)))
+ return 0;
+
+ xc_dup(L, x509);
+
+ return 1;
+} /* ssl_getCertificate() */
+
+
static int ssl_getPeerCertificate(lua_State *L) {
SSL *ssl = checksimple(L, 1, SSL_CLASS);
X509 **x509 = prepsimple(L, X509_CERT_CLASS);
@@ -9520,6 +9533,7 @@ static const auxL_Reg ssl_methods[] = {
{ "getVerifyResult", &ssl_getVerifyResult },
{ "setCertificate", &ssl_setCertificate },
{ "setPrivateKey", &ssl_setPrivateKey },
+ { "getCertificate", &ssl_getCertificate },
{ "getPeerCertificate", &ssl_getPeerCertificate },
{ "getPeerChain", &ssl_getPeerChain },
{ "getCipherInfo", &ssl_getCipherInfo },