diff options
| author | William Ahern <william@25thandclement.com> | 2016-10-29 13:27:26 -0700 |
|---|---|---|
| committer | William Ahern <william@25thandclement.com> | 2016-10-29 13:27:26 -0700 |
| commit | 17622cab611b7a4c89bb8c7024ad6770a92e9a27 (patch) | |
| tree | 16c4cc4fc8f770a4f71fb886fc52a5145677280b /src | |
| parent | 2c0e26b55ecc1f052fa7907ca513c277b6363329 (diff) | |
| download | luaossl-17622cab611b7a4c89bb8c7024ad6770a92e9a27.tar.gz luaossl-17622cab611b7a4c89bb8c7024ad6770a92e9a27.tar.bz2 luaossl-17622cab611b7a4c89bb8c7024ad6770a92e9a27.zip | |
more OpenSSL 1.1 work
Diffstat (limited to 'src')
| -rw-r--r-- | src/openssl.c | 152 |
1 files changed, 127 insertions, 25 deletions
diff --git a/src/openssl.c b/src/openssl.c index 78d79cc..8208f78 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
| @@ -83,52 +83,88 @@ | |||
| 83 | #define LIBRESSL_PREREQ(M, m, p) \ | 83 | #define LIBRESSL_PREREQ(M, m, p) \ |
| 84 | (LIBRESSL_VERSION_NUMBER >= (((M) << 28) | ((m) << 20) | ((p) << 12))) | 84 | (LIBRESSL_VERSION_NUMBER >= (((M) << 28) | ((m) << 20) | ((p) << 12))) |
| 85 | 85 | ||
| 86 | #ifndef HAVE_ASN1_STRING_GET0_DATA | ||
| 87 | #define HAVE_ASN1_STRING_GET0_DATA OPENSSL_PREREQ(1,1,0) | ||
| 88 | #endif | ||
| 89 | |||
| 86 | #ifndef HAVE_DH_GET0_KEY | 90 | #ifndef HAVE_DH_GET0_KEY |
| 87 | #define HAVE_DH_GET0_KEY 0 | 91 | #define HAVE_DH_GET0_KEY OPENSSL_PREREQ(1,1,0) |
| 88 | #endif | 92 | #endif |
| 89 | 93 | ||
| 90 | #ifndef HAVE_DH_GET0_PQG | 94 | #ifndef HAVE_DH_GET0_PQG |
| 91 | #define HAVE_DH_GET0_PQG 0 | 95 | #define HAVE_DH_GET0_PQG OPENSSL_PREREQ(1,1,0) |
| 96 | #endif | ||
| 97 | |||
| 98 | #ifndef HAVE_DH_SET0_KEY | ||
| 99 | #define HAVE_DH_SET0_KEY OPENSSL_PREREQ(1,1,0) | ||
| 100 | #endif | ||
| 101 | |||
| 102 | #ifndef HAVE_DH_SET0_PQG | ||
| 103 | #define HAVE_DH_SET0_PQG OPENSSL_PREREQ(1,1,0) | ||
| 92 | #endif | 104 | #endif |
| 93 | 105 | ||
| 94 | #ifndef HAVE_DSA_GET0_KEY | 106 | #ifndef HAVE_DSA_GET0_KEY |
| 95 | #define HAVE_DSA_GET0_KEY 0 | 107 | #define HAVE_DSA_GET0_KEY OPENSSL_PREREQ(1,1,0) |
| 96 | #endif | 108 | #endif |
| 97 | 109 | ||
| 98 | #ifndef HAVE_DSA_GET0_PQG | 110 | #ifndef HAVE_DSA_GET0_PQG |
| 99 | #define HAVE_DSA_GET0_PQG 0 | 111 | #define HAVE_DSA_GET0_PQG OPENSSL_PREREQ(1,1,0) |
| 112 | #endif | ||
| 113 | |||
| 114 | #ifndef HAVE_DSA_SET0_KEY | ||
| 115 | #define HAVE_DSA_SET0_KEY OPENSSL_PREREQ(1,1,0) | ||
| 116 | #endif | ||
| 117 | |||
| 118 | #ifndef HAVE_DSA_SET0_PQG | ||
| 119 | #define HAVE_DSA_SET0_PQG OPENSSL_PREREQ(1,1,0) | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #ifndef HAVE_EVP_PKEY_BASE_ID | ||
| 123 | #define HAVE_EVP_PKEY_BASE_ID OPENSSL_PREREQ(1,1,0) | ||
| 124 | #endif | ||
| 125 | |||
| 126 | #ifndef HAVE_EVP_PKEY_GET0 | ||
| 127 | #define HAVE_EVP_PKEY_GET0 OPENSSL_PREREQ(1,1,0) | ||
| 100 | #endif | 128 | #endif |
| 101 | 129 | ||
| 102 | #ifndef HAVE_EVP_PKEY_ID | 130 | #ifndef HAVE_EVP_PKEY_ID |
| 103 | #define HAVE_EVP_PKEY_ID 0 | 131 | #define HAVE_EVP_PKEY_ID OPENSSL_PREREQ(1,1,0) |
| 132 | #endif | ||
| 133 | |||
| 134 | #ifndef HAVE_GENERAL_NAME_GET0_VALUE | ||
| 135 | #define HAVE_GENERAL_NAME_GET0_VALUE OPENSSL_PREREQ(1,1,0) | ||
| 136 | #endif | ||
| 137 | |||
| 138 | #ifndef HAVE_GENERAL_NAME_SET0_VALUE | ||
| 139 | #define HAVE_GENERAL_NAME_SET0_VALUE OPENSSL_PREREQ(1,1,0) | ||
| 104 | #endif | 140 | #endif |
| 105 | 141 | ||
| 106 | #ifndef HAVE_RSA_GET0_CRT_PARAMS | 142 | #ifndef HAVE_RSA_GET0_CRT_PARAMS |
| 107 | #define HAVE_RSA_GET0_CRT_PARAMS 0 | 143 | #define HAVE_RSA_GET0_CRT_PARAMS OPENSSL_PREREQ(1,1,0) |
| 108 | #endif | 144 | #endif |
| 109 | 145 | ||
| 110 | #ifndef HAVE_RSA_GET0_FACTORS | 146 | #ifndef HAVE_RSA_GET0_FACTORS |
| 111 | #define HAVE_RSA_GET0_FACTORS 0 | 147 | #define HAVE_RSA_GET0_FACTORS OPENSSL_PREREQ(1,1,0) |
| 112 | #endif | 148 | #endif |
| 113 | 149 | ||
| 114 | #ifndef HAVE_RSA_GET0_KEY | 150 | #ifndef HAVE_RSA_GET0_KEY |
| 115 | #define HAVE_RSA_GET0_KEY 0 | 151 | #define HAVE_RSA_GET0_KEY OPENSSL_PREREQ(1,1,0) |
| 116 | #endif | 152 | #endif |
| 117 | 153 | ||
| 118 | #ifndef HAVE_RSA_SET0_CRT_PARAMS | 154 | #ifndef HAVE_RSA_SET0_CRT_PARAMS |
| 119 | #define HAVE_RSA_SET0_CRT_PARAMS 0 | 155 | #define HAVE_RSA_SET0_CRT_PARAMS OPENSSL_PREREQ(1,1,0) |
| 120 | #endif | 156 | #endif |
| 121 | 157 | ||
| 122 | #ifndef HAVE_RSA_SET0_FACTORS | 158 | #ifndef HAVE_RSA_SET0_FACTORS |
| 123 | #define HAVE_RSA_SET0_FACTORS 0 | 159 | #define HAVE_RSA_SET0_FACTORS OPENSSL_PREREQ(1,1,0) |
| 124 | #endif | 160 | #endif |
| 125 | 161 | ||
| 126 | #ifndef HAVE_RSA_SET0_KEY | 162 | #ifndef HAVE_RSA_SET0_KEY |
| 127 | #define HAVE_RSA_SET0_KEY 0 | 163 | #define HAVE_RSA_SET0_KEY OPENSSL_PREREQ(1,1,0) |
| 128 | #endif | 164 | #endif |
| 129 | 165 | ||
| 130 | #ifndef HAVE_SSL_CTX_SET_ALPN_PROTOS | 166 | #ifndef HAVE_SSL_CTX_SET_ALPN_PROTOS |
| 131 | #define HAVE_SSL_CTX_SET_ALPN_PROTOS (OPENSSL_PREREQ(1, 0, 2) || LIBRESSL_PREREQ(2, 1, 3)) | 167 | #define HAVE_SSL_CTX_SET_ALPN_PROTOS (OPENSSL_PREREQ(1,0,2) || LIBRESSL_PREREQ(2,1,3)) |
| 132 | #endif | 168 | #endif |
| 133 | 169 | ||
| 134 | #ifndef HAVE_SSL_CTX_SET_ALPN_SELECT_CB | 170 | #ifndef HAVE_SSL_CTX_SET_ALPN_SELECT_CB |
| @@ -140,7 +176,7 @@ | |||
| 140 | #endif | 176 | #endif |
| 141 | 177 | ||
| 142 | #ifndef HAVE_SSL_CTX_CERT_STORE | 178 | #ifndef HAVE_SSL_CTX_CERT_STORE |
| 143 | #define HAVE_SSL_CTX_CERT_STORE 1 | 179 | #define HAVE_SSL_CTX_CERT_STORE (!OPENSSL_PREREQ(1,1,0)) |
| 144 | #endif | 180 | #endif |
| 145 | 181 | ||
| 146 | #ifndef HAVE_SSL_SET_ALPN_PROTOS | 182 | #ifndef HAVE_SSL_SET_ALPN_PROTOS |
| @@ -160,7 +196,7 @@ | |||
| 160 | #endif | 196 | #endif |
| 161 | 197 | ||
| 162 | #ifndef HAVE_DTLS_CLIENT_METHOD | 198 | #ifndef HAVE_DTLS_CLIENT_METHOD |
| 163 | #define HAVE_DTLS_CLIENT_METHOD (OPENSSL_PREREQ(1, 0, 2) && !defined OPENSSL_NO_DTLS1) | 199 | #define HAVE_DTLS_CLIENT_METHOD (OPENSSL_PREREQ(1,0,2) && !defined OPENSSL_NO_DTLS1) |
| 164 | #endif | 200 | #endif |
| 165 | 201 | ||
| 166 | #ifndef HAVE_DTLS_SERVER_METHOD | 202 | #ifndef HAVE_DTLS_SERVER_METHOD |
| @@ -168,7 +204,7 @@ | |||
| 168 | #endif | 204 | #endif |
| 169 | 205 | ||
| 170 | #ifndef HAVE_DTLSV1_2_CLIENT_METHOD | 206 | #ifndef HAVE_DTLSV1_2_CLIENT_METHOD |
| 171 | #define HAVE_DTLSV1_2_CLIENT_METHOD (OPENSSL_PREREQ(1, 0, 2) && !defined OPENSSL_NO_DTLS1) | 207 | #define HAVE_DTLSV1_2_CLIENT_METHOD (OPENSSL_PREREQ(1,0,2) && !defined OPENSSL_NO_DTLS1) |
| 172 | #endif | 208 | #endif |
| 173 | 209 | ||
| 174 | #ifndef HAVE_DTLSV1_2_SERVER_METHOD | 210 | #ifndef HAVE_DTLSV1_2_SERVER_METHOD |
| @@ -176,7 +212,7 @@ | |||
| 176 | #endif | 212 | #endif |
| 177 | 213 | ||
| 178 | #ifndef HAVE_X509_STORE_REFERENCES | 214 | #ifndef HAVE_X509_STORE_REFERENCES |
| 179 | #define HAVE_X509_STORE_REFERENCES 1 | 215 | #define HAVE_X509_STORE_REFERENCES (!OPENSSL_PREREQ(1,1,0)) |
| 180 | #endif | 216 | #endif |
| 181 | 217 | ||
| 182 | #ifndef STRERROR_R_CHAR_P | 218 | #ifndef STRERROR_R_CHAR_P |
| @@ -1084,6 +1120,10 @@ static struct { | |||
| 1084 | .X509_STORE_free = &X509_STORE_free, | 1120 | .X509_STORE_free = &X509_STORE_free, |
| 1085 | }; | 1121 | }; |
| 1086 | 1122 | ||
| 1123 | #if !HAVE_ASN1_STRING_GET0_DATA | ||
| 1124 | #define ASN1_STRING_get0_data(s) ASN1_STRING_data((s)) | ||
| 1125 | #endif | ||
| 1126 | |||
| 1087 | #if !HAVE_DH_GET0_KEY | 1127 | #if !HAVE_DH_GET0_KEY |
| 1088 | #define DH_get0_key(...) compat_DH_get0_key(__VA_ARGS__) | 1128 | #define DH_get0_key(...) compat_DH_get0_key(__VA_ARGS__) |
| 1089 | 1129 | ||
| @@ -1228,6 +1268,68 @@ static void *compat_EVP_PKEY_get0(EVP_PKEY *key) { | |||
| 1228 | } /* compat_EVP_PKEY_get0() */ | 1268 | } /* compat_EVP_PKEY_get0() */ |
| 1229 | #endif | 1269 | #endif |
| 1230 | 1270 | ||
| 1271 | #if !HAVE_GENERAL_NAME_GET0_VALUE | ||
| 1272 | #define GENERAL_NAME_get0_value(...) \ | ||
| 1273 | compat_GENERAL_NAME_get0_value(__VA_ARGS__) | ||
| 1274 | |||
| 1275 | static void *GENERAL_NAME_get0_value(GENERAL_NAME *name, int *type) { | ||
| 1276 | if (type) | ||
| 1277 | *type = name->type; | ||
| 1278 | switch (name->type) { | ||
| 1279 | case GEN_X400: | ||
| 1280 | case GEN_EDIPARTY: | ||
| 1281 | return name->d.other; | ||
| 1282 | case GEN_OTHERNAME: | ||
| 1283 | return name->d.otherName; | ||
| 1284 | case GEN_EMAIL: | ||
| 1285 | case GEN_DNS: | ||
| 1286 | case GEN_URI: | ||
| 1287 | return name->d.ia5; | ||
| 1288 | case GEN_DIRNAME: | ||
| 1289 | return name->d.dirn; | ||
| 1290 | case GEN_IPADD: | ||
| 1291 | return name->d.ip; | ||
| 1292 | case GEN_RID: | ||
| 1293 | return name->d.rid; | ||
| 1294 | default: | ||
| 1295 | return NULL; | ||
| 1296 | } | ||
| 1297 | } /* compat_GENERAL_NAME_get0_value() */ | ||
| 1298 | #endif | ||
| 1299 | |||
| 1300 | #if !HAVE_GENERAL_NAME_SET0_VALUE | ||
| 1301 | #define GENERAL_NAME_set0_value(...) \ | ||
| 1302 | compat_GENERAL_NAME_set0_value(__VA_ARGS__) | ||
| 1303 | |||
| 1304 | static void GENERAL_NAME_set0_value(GENERAL_NAME *name, int type, void *value) { | ||
| 1305 | switch ((name->type = type)) { | ||
| 1306 | case GEN_X400: | ||
| 1307 | case GEN_EDIPARTY: | ||
| 1308 | name->d.other = value; | ||
| 1309 | break; | ||
| 1310 | case GEN_OTHERNAME: | ||
| 1311 | name->d.otherName = value; | ||
| 1312 | break; | ||
| 1313 | case GEN_EMAIL: | ||
| 1314 | case GEN_DNS: | ||
| 1315 | case GEN_URI: | ||
| 1316 | name->d.ia5 = value; | ||
| 1317 | break; | ||
| 1318 | case GEN_DIRNAME: | ||
| 1319 | name->d.dirn = value; | ||
| 1320 | break; | ||
| 1321 | case GEN_IPADD: | ||
| 1322 | name->d.ip = value; | ||
| 1323 | break; | ||
| 1324 | case GEN_RID: | ||
| 1325 | name->d.rid = value; | ||
| 1326 | break; | ||
| 1327 | default: | ||
| 1328 | break; | ||
| 1329 | } | ||
| 1330 | } /* compat_GENERAL_NAME_set0_value() */ | ||
| 1331 | #endif | ||
| 1332 | |||
| 1231 | #if !HAVE_RSA_GET0_CRT_PARAMS | 1333 | #if !HAVE_RSA_GET0_CRT_PARAMS |
| 1232 | #define RSA_get0_crt_params(...) compat_RSA_get0_crt_params(__VA_ARGS__) | 1334 | #define RSA_get0_crt_params(...) compat_RSA_get0_crt_params(__VA_ARGS__) |
| 1233 | 1335 | ||
| @@ -4020,7 +4122,7 @@ static int xn_all(lua_State *L) { | |||
| 4020 | lua_setfield(L, -2, "id"); | 4122 | lua_setfield(L, -2, "id"); |
| 4021 | 4123 | ||
| 4022 | len = ASN1_STRING_length(X509_NAME_ENTRY_get_data(entry)); | 4124 | len = ASN1_STRING_length(X509_NAME_ENTRY_get_data(entry)); |
| 4023 | lua_pushlstring(L, (char *)ASN1_STRING_data(X509_NAME_ENTRY_get_data(entry)), len); | 4125 | lua_pushlstring(L, (char *)ASN1_STRING_get0_data(X509_NAME_ENTRY_get_data(entry)), len); |
| 4024 | 4126 | ||
| 4025 | lua_setfield(L, -2, "blob"); | 4127 | lua_setfield(L, -2, "blob"); |
| 4026 | 4128 | ||
| @@ -4054,7 +4156,7 @@ static int xn__next(lua_State *L) { | |||
| 4054 | lua_pushlstring(L, txt, len); | 4156 | lua_pushlstring(L, txt, len); |
| 4055 | 4157 | ||
| 4056 | len = ASN1_STRING_length(X509_NAME_ENTRY_get_data(entry)); | 4158 | len = ASN1_STRING_length(X509_NAME_ENTRY_get_data(entry)); |
| 4057 | lua_pushlstring(L, (char *)ASN1_STRING_data(X509_NAME_ENTRY_get_data(entry)), len); | 4159 | lua_pushlstring(L, (char *)ASN1_STRING_get0_data(X509_NAME_ENTRY_get_data(entry)), len); |
| 4058 | 4160 | ||
| 4059 | break; | 4161 | break; |
| 4060 | } | 4162 | } |
| @@ -4232,7 +4334,7 @@ text: | |||
| 4232 | 4334 | ||
| 4233 | gen->type = type; | 4335 | gen->type = type; |
| 4234 | 4336 | ||
| 4235 | if (!(gen->d.ia5 = M_ASN1_IA5STRING_new())) | 4337 | if (!(gen->d.ia5 = ASN1_STRING_type_new(V_ASN1_IA5STRING))) |
| 4236 | goto error; | 4338 | goto error; |
| 4237 | 4339 | ||
| 4238 | if (!ASN1_STRING_set(gen->d.ia5, (unsigned char *)txt, len)) | 4340 | if (!ASN1_STRING_set(gen->d.ia5, (unsigned char *)txt, len)) |
| @@ -4253,7 +4355,7 @@ error: | |||
| 4253 | 4355 | ||
| 4254 | 4356 | ||
| 4255 | #define GN_PUSHSTRING(L, o) \ | 4357 | #define GN_PUSHSTRING(L, o) \ |
| 4256 | lua_pushlstring((L), (char *)M_ASN1_STRING_data((o)), M_ASN1_STRING_length((o))) | 4358 | lua_pushlstring((L), (char *)ASN1_STRING_get0_data((o)), ASN1_STRING_length((o))) |
| 4257 | 4359 | ||
| 4258 | static int gn__next(lua_State *L) { | 4360 | static int gn__next(lua_State *L) { |
| 4259 | GENERAL_NAMES *gens = checksimple(L, lua_upvalueindex(1), X509_GENS_CLASS); | 4361 | GENERAL_NAMES *gens = checksimple(L, lua_upvalueindex(1), X509_GENS_CLASS); |
| @@ -4290,8 +4392,8 @@ static int gn__next(lua_State *L) { | |||
| 4290 | 4392 | ||
| 4291 | break; | 4393 | break; |
| 4292 | case GEN_IPADD: | 4394 | case GEN_IPADD: |
| 4293 | txt = (char *)M_ASN1_STRING_data(name->d.iPAddress); | 4395 | txt = (char *)ASN1_STRING_get0_data(name->d.iPAddress); |
| 4294 | len = M_ASN1_STRING_length(name->d.iPAddress); | 4396 | len = ASN1_STRING_length(name->d.iPAddress); |
| 4295 | 4397 | ||
| 4296 | switch (len) { | 4398 | switch (len) { |
| 4297 | case 16: | 4399 | case 16: |
| @@ -4536,7 +4638,7 @@ static int xe_getLongName(lua_State *L) { | |||
| 4536 | static int xe_getData(lua_State *L) { | 4638 | static int xe_getData(lua_State *L) { |
| 4537 | ASN1_STRING *data = X509_EXTENSION_get0_data(checksimple(L, 1, X509_EXT_CLASS)); | 4639 | ASN1_STRING *data = X509_EXTENSION_get0_data(checksimple(L, 1, X509_EXT_CLASS)); |
| 4538 | 4640 | ||
| 4539 | lua_pushlstring(L, (char *)ASN1_STRING_data(data), ASN1_STRING_length(data)); | 4641 | lua_pushlstring(L, (char *)ASN1_STRING_get0_data(data), ASN1_STRING_length(data)); |
| 4540 | 4642 | ||
| 4541 | return 1; | 4643 | return 1; |
| 4542 | } /* xe_getData() */ | 4644 | } /* xe_getData() */ |
| @@ -4866,7 +4968,7 @@ static double timeutc(ASN1_TIME *time) { | |||
| 4866 | if (!ASN1_TIME_check(time)) | 4968 | if (!ASN1_TIME_check(time)) |
| 4867 | return 0; | 4969 | return 0; |
| 4868 | 4970 | ||
| 4869 | cp = strncpy(buf, (const char *)ASN1_STRING_data((ASN1_STRING *)time), sizeof buf - 1); | 4971 | cp = strncpy(buf, (const char *)ASN1_STRING_get0_data((ASN1_STRING *)time), sizeof buf - 1); |
| 4870 | 4972 | ||
| 4871 | if (ASN1_STRING_type(time) == V_ASN1_GENERALIZEDTIME) { | 4973 | if (ASN1_STRING_type(time) == V_ASN1_GENERALIZEDTIME) { |
| 4872 | if (!scan(&year, &cp, 4, 1)) | 4974 | if (!scan(&year, &cp, 4, 1)) |
| @@ -5270,7 +5372,7 @@ static int xc_setBasicConstraint(lua_State *L) { | |||
| 5270 | if (pathLen >= 0) { | 5372 | if (pathLen >= 0) { |
| 5271 | ASN1_INTEGER_free(bs->pathlen); | 5373 | ASN1_INTEGER_free(bs->pathlen); |
| 5272 | 5374 | ||
| 5273 | if (!(bs->pathlen = M_ASN1_INTEGER_new())) | 5375 | if (!(bs->pathlen = ASN1_STRING_type_new(V_ASN1_INTEGER))) |
| 5274 | goto error; | 5376 | goto error; |
| 5275 | 5377 | ||
| 5276 | if (!ASN1_INTEGER_set(bs->pathlen, pathLen)) | 5378 | if (!ASN1_INTEGER_set(bs->pathlen, pathLen)) |
