summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/openssl.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c
index e902edf..2b363d5 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -297,6 +297,10 @@
297#define HAVE_SSL_SET1_PARAM OPENSSL_PREREQ(1,0,2) 297#define HAVE_SSL_SET1_PARAM OPENSSL_PREREQ(1,0,2)
298#endif 298#endif
299 299
300#ifndef HAVE_SSL_GET_CLIENT_RANDOM
301#define HAVE_SSL_GET_CLIENT_RANDOM OPENSSL_PREREQ(1,1,0)
302#endif
303
300#ifndef HAVE_SSL_GET_TLSEXT_STATUS_TYPE 304#ifndef HAVE_SSL_GET_TLSEXT_STATUS_TYPE
301#define HAVE_SSL_GET_TLSEXT_STATUS_TYPE OPENSSL_PREREQ(1,1,0) 305#define HAVE_SSL_GET_TLSEXT_STATUS_TYPE OPENSSL_PREREQ(1,1,0)
302#endif 306#endif
@@ -1576,6 +1580,18 @@ static void compat_RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) {
1576} /* compat_RSA_set0_key() */ 1580} /* compat_RSA_set0_key() */
1577#endif 1581#endif
1578 1582
1583#if !HAVE_SSL_GET_CLIENT_RANDOM
1584#define SSL_get_client_random(...) compat_SSL_get_client_random(__VA_ARGS__)
1585static size_t compat_SSL_get_client_random(const SSL *ssl, unsigned char *out, size_t outlen) {
1586 if (outlen == 0)
1587 return sizeof(ssl->s3->client_random);
1588 if (outlen > sizeof(ssl->s3->client_random))
1589 outlen = sizeof(ssl->s3->client_random);
1590 memcpy(out, ssl->s3->client_random, outlen);
1591 return outlen;
1592}
1593#endif
1594
1579#if !HAVE_SSL_CLIENT_VERSION 1595#if !HAVE_SSL_CLIENT_VERSION
1580#define SSL_client_version(...) compat_SSL_client_version(__VA_ARGS__) 1596#define SSL_client_version(...) compat_SSL_client_version(__VA_ARGS__)
1581 1597
@@ -8474,6 +8490,31 @@ static int ssl_getVersion(lua_State *L) {
8474} /* ssl_getVersion() */ 8490} /* ssl_getVersion() */
8475 8491
8476 8492
8493static int ssl_getClientRandom(lua_State *L) {
8494 SSL *ssl = checksimple(L, 1, SSL_CLASS);
8495 luaL_Buffer B;
8496 size_t len;
8497 unsigned char *out;
8498
8499 len = SSL_get_client_random(ssl, NULL, 0);
8500#if LUA_VERSION_NUM < 502
8501 if (LUAL_BUFFERSIZE < len)
8502 luaL_error(L, "ssl:getClientRandom: LUAL_BUFFERSIZE(%d) < SSL_get_client_random(ssl, NULL, 0)", (int)LUAL_BUFFERSIZE, (int)len);
8503 luaL_buffinit(L, &B);
8504 out = luaL_prepbuffer(&B);
8505 len = SSL_get_client_random(ssl, out, len);
8506 luaL_addsize(&B, len);
8507 luaL_pushresult(&B);
8508#else
8509 out = luaL_buffinitsize(L, &B, len);
8510 len = SSL_get_client_random(ssl, out, len);
8511 luaL_pushresultsize(&B, len);
8512#endif
8513
8514 return 1;
8515} /* ssl_getClientRandom() */
8516
8517
8477static int ssl_getClientVersion(lua_State *L) { 8518static int ssl_getClientVersion(lua_State *L) {
8478 SSL *ssl = checksimple(L, 1, SSL_CLASS); 8519 SSL *ssl = checksimple(L, 1, SSL_CLASS);
8479 int format = luaL_checkoption(L, 2, "d", (const char *[]){ "d", ".", "f", NULL }); 8520 int format = luaL_checkoption(L, 2, "d", (const char *[]){ "d", ".", "f", NULL });
@@ -8650,6 +8691,7 @@ static const auxL_Reg ssl_methods[] = {
8650 { "getHostName", &ssl_getHostName }, 8691 { "getHostName", &ssl_getHostName },
8651 { "setHostName", &ssl_setHostName }, 8692 { "setHostName", &ssl_setHostName },
8652 { "getVersion", &ssl_getVersion }, 8693 { "getVersion", &ssl_getVersion },
8694 { "getClientRandom", &ssl_getClientRandom },
8653 { "getClientVersion", &ssl_getClientVersion }, 8695 { "getClientVersion", &ssl_getClientVersion },
8654#if HAVE_SSL_GET0_ALPN_SELECTED 8696#if HAVE_SSL_GET0_ALPN_SELECTED
8655 { "getAlpnSelected", &ssl_getAlpnSelected }, 8697 { "getAlpnSelected", &ssl_getAlpnSelected },