|
279 | 279 | #define HAVE_SSL_CTX_ADD_CUSTOM_EXT OPENSSL_PREREQ(1,1,1) |
280 | 280 | #endif |
281 | 281 |
|
| 282 | +#ifndef HAVE_SSL_CTX_GET0_CHAIN_CERTS |
| 283 | +#define HAVE_SSL_CTX_GET0_CHAIN_CERTS OPENSSL_PREREQ(1,0,2) |
| 284 | +#endif |
| 285 | + |
282 | 286 | #ifndef HAVE_SSL_CTX_GET0_PARAM |
283 | 287 | #define HAVE_SSL_CTX_GET0_PARAM (OPENSSL_PREREQ(1,0,2) || LIBRESSL_PREREQ(2,7,0)) |
284 | 288 | #endif |
|
315 | 319 | #define HAVE_SSL_CTX_SET1_CERT_STORE (HAVE_SSL_CTX_set1_cert_store || OPENSSL_PREREQ(1,1,1)) /* backwards compatible with old macro name */ |
316 | 320 | #endif |
317 | 321 |
|
| 322 | +#ifndef HAVE_SSL_CTX_SET1_CHAIN |
| 323 | +#define HAVE_SSL_CTX_SET1_CHAIN OPENSSL_PREREQ(1,0,2) |
| 324 | +#endif |
| 325 | + |
318 | 326 | #ifndef HAVE_SSL_CTX_SET1_PARAM |
319 | 327 | #define HAVE_SSL_CTX_SET1_PARAM (OPENSSL_PREREQ(1,0,2) || LIBRESSL_PREREQ(2,1,0)) |
320 | 328 | #endif |
|
363 | 371 | #define HAVE_SSL_GET0_ALPN_SELECTED HAVE_SSL_CTX_SET_ALPN_PROTOS |
364 | 372 | #endif |
365 | 373 |
|
| 374 | +#ifndef HAVE_SSL_GET0_CHAIN_CERTS |
| 375 | +#define HAVE_SSL_GET0_CHAIN_CERTS OPENSSL_PREREQ(1,0,2) |
| 376 | +#endif |
| 377 | + |
366 | 378 | #ifndef HAVE_SSL_GET0_PARAM |
367 | 379 | #define HAVE_SSL_GET0_PARAM (OPENSSL_PREREQ(1,0,2) || LIBRESSL_PREREQ(2,7,0)) |
368 | 380 | #endif |
|
387 | 399 | #define HAVE_SSL_SET_CURVES_LIST (OPENSSL_PREREQ(1,0,2) || LIBRESSL_PREREQ(2,5,1)) |
388 | 400 | #endif |
389 | 401 |
|
| 402 | +#ifndef HAVE_SSL_SET1_CHAIN |
| 403 | +#define HAVE_SSL_SET1_CHAIN OPENSSL_PREREQ(1,0,2) |
| 404 | +#endif |
| 405 | + |
390 | 406 | #ifndef HAVE_SSL_SET1_PARAM |
391 | 407 | #define HAVE_SSL_SET1_PARAM (OPENSSL_PREREQ(1,0,2) || LIBRESSL_PREREQ(2,5,1)) |
392 | 408 | #endif |
@@ -8758,6 +8774,36 @@ static int sx_getCertificate(lua_State *L) { |
8758 | 8774 | #endif |
8759 | 8775 |
|
8760 | 8776 |
|
| 8777 | +#if HAVE_SSL_CTX_SET1_CHAIN |
| 8778 | +static int sx_setCertificateChain(lua_State *L) { |
| 8779 | + SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS); |
| 8780 | + STACK_OF(X509) *certs = checksimple(L, 2, X509_CHAIN_CLASS); |
| 8781 | + |
| 8782 | + if (!SSL_CTX_set1_chain(ctx, certs)) |
| 8783 | + return auxL_error(L, auxL_EOPENSSL, "ssl.context:setCertificateChain"); |
| 8784 | + |
| 8785 | + lua_pushboolean(L, 1); |
| 8786 | + |
| 8787 | + return 1; |
| 8788 | +} /* sx_setCertificateChain() */ |
| 8789 | +#endif |
| 8790 | + |
| 8791 | + |
| 8792 | +#if HAVE_SSL_CTX_GET0_CHAIN_CERTS |
| 8793 | +static int sx_getCertificateChain(lua_State *L) { |
| 8794 | + SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS); |
| 8795 | + STACK_OF(X509) *certs; |
| 8796 | + |
| 8797 | + if (!SSL_CTX_get0_chain_certs(ctx, &certs)) |
| 8798 | + return auxL_error(L, auxL_EOPENSSL, "ssl.context:getCertificateChain"); |
| 8799 | + |
| 8800 | + xl_dup(L, certs, 1); |
| 8801 | + |
| 8802 | + return 1; |
| 8803 | +} /* sx_getCertificateChain() */ |
| 8804 | +#endif |
| 8805 | + |
| 8806 | + |
8761 | 8807 | static int sx_setPrivateKey(lua_State *L) { |
8762 | 8808 | SSL_CTX *ctx = checksimple(L, 1, SSL_CTX_CLASS); |
8763 | 8809 | EVP_PKEY *key = checksimple(L, 2, PKEY_CLASS); |
@@ -9499,6 +9545,12 @@ static const auxL_Reg sx_methods[] = { |
9499 | 9545 | { "setCertificate", &sx_setCertificate }, |
9500 | 9546 | #if HAVE_SSL_CTX_GET0_CERTIFICATE |
9501 | 9547 | { "getCertificate", &sx_getCertificate }, |
| 9548 | +#endif |
| 9549 | +#if HAVE_SSL_CTX_SET1_CHAIN |
| 9550 | + { "setCertificateChain", &sx_setCertificateChain }, |
| 9551 | +#endif |
| 9552 | +#if HAVE_SSL_CTX_GET0_CHAIN_CERTS |
| 9553 | + { "getCertificateChain", &sx_getCertificateChain }, |
9502 | 9554 | #endif |
9503 | 9555 | { "setPrivateKey", &sx_setPrivateKey }, |
9504 | 9556 | { "setCipherList", &sx_setCipherList }, |
@@ -9982,6 +10034,36 @@ static int ssl_setCertificate(lua_State *L) { |
9982 | 10034 | } /* ssl_setCertificate() */ |
9983 | 10035 |
|
9984 | 10036 |
|
| 10037 | +#if HAVE_SSL_SET1_CHAIN |
| 10038 | +static int ssl_setCertificateChain(lua_State *L) { |
| 10039 | + SSL *ssl = checksimple(L, 1, SSL_CLASS); |
| 10040 | + STACK_OF(X509) *certs = checksimple(L, 2, X509_CHAIN_CLASS); |
| 10041 | + |
| 10042 | + if (!SSL_set1_chain(ssl, certs)) |
| 10043 | + return auxL_error(L, auxL_EOPENSSL, "ssl:setCertificateChain"); |
| 10044 | + |
| 10045 | + lua_pushboolean(L, 1); |
| 10046 | + |
| 10047 | + return 1; |
| 10048 | +} /* ssl_setCertificateChain() */ |
| 10049 | +#endif |
| 10050 | + |
| 10051 | + |
| 10052 | +#if HAVE_SSL_GET0_CHAIN_CERTS |
| 10053 | +static int ssl_getCertificateChain(lua_State *L) { |
| 10054 | + SSL *ssl = checksimple(L, 1, SSL_CLASS); |
| 10055 | + STACK_OF(X509) *certs; |
| 10056 | + |
| 10057 | + if (!SSL_get0_chain_certs(ssl, &certs)) |
| 10058 | + return auxL_error(L, auxL_EOPENSSL, "ssl:getCertificateChain"); |
| 10059 | + |
| 10060 | + xl_dup(L, X509_chain_up_ref(certs), 1); |
| 10061 | + |
| 10062 | + return 1; |
| 10063 | +} /* ssl_getCertificateChain() */ |
| 10064 | +#endif |
| 10065 | + |
| 10066 | + |
9985 | 10067 | static int ssl_setPrivateKey(lua_State *L) { |
9986 | 10068 | SSL *ssl = checksimple(L, 1, SSL_CLASS); |
9987 | 10069 | EVP_PKEY *key = checksimple(L, 2, PKEY_CLASS); |
@@ -10392,6 +10474,12 @@ static const auxL_Reg ssl_methods[] = { |
10392 | 10474 | { "getVerify", &ssl_getVerify }, |
10393 | 10475 | { "getVerifyResult", &ssl_getVerifyResult }, |
10394 | 10476 | { "setCertificate", &ssl_setCertificate }, |
| 10477 | +#if HAVE_SSL_SET1_CHAIN |
| 10478 | + { "setCertificateChain", &ssl_setCertificateChain }, |
| 10479 | +#endif |
| 10480 | +#if HAVE_SSL_GET0_CHAIN_CERTS |
| 10481 | + { "getCertificateChain", &ssl_getCertificateChain }, |
| 10482 | +#endif |
10395 | 10483 | { "setPrivateKey", &ssl_setPrivateKey }, |
10396 | 10484 | { "getCertificate", &ssl_getCertificate }, |
10397 | 10485 | { "getPeerCertificate", &ssl_getPeerCertificate }, |
|
0 commit comments