diff options
author | William Ahern <william@25thandclement.com> | 2016-10-29 13:48:07 -0700 |
---|---|---|
committer | William Ahern <william@25thandclement.com> | 2016-10-29 13:48:07 -0700 |
commit | 2391a59e43de4ccc685b7790d84a9a4705750dd3 (patch) | |
tree | c37d9ec27483f87006eb4fb9861cd7087842c4b4 /src/openssl.c | |
parent | 17622cab611b7a4c89bb8c7024ad6770a92e9a27 (diff) | |
download | luaossl-2391a59e43de4ccc685b7790d84a9a4705750dd3.tar.gz luaossl-2391a59e43de4ccc685b7790d84a9a4705750dd3.tar.bz2 luaossl-2391a59e43de4ccc685b7790d84a9a4705750dd3.zip |
use EVP_PKEY_get_default_digest_nid to determine the default signature, and emulate for OpenSSL 0.9.8 using our old code from xc_signature
Diffstat (limited to 'src/openssl.c')
-rw-r--r-- | src/openssl.c | 52 |
1 files changed, 41 insertions, 11 deletions
diff --git a/src/openssl.c b/src/openssl.c index 8208f78..f5d9343 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
@@ -119,6 +119,10 @@ | |||
119 | #define HAVE_DSA_SET0_PQG OPENSSL_PREREQ(1,1,0) | 119 | #define HAVE_DSA_SET0_PQG OPENSSL_PREREQ(1,1,0) |
120 | #endif | 120 | #endif |
121 | 121 | ||
122 | #ifndef HAVE_EVP_PKEY_GET_DEFAULT_DIGEST_NID | ||
123 | #define HAVE_EVP_PKEY_GET_DEFAULT_DIGEST_NID OPENSSL_PREREQ(0,9,9) | ||
124 | #endif | ||
125 | |||
122 | #ifndef HAVE_EVP_PKEY_BASE_ID | 126 | #ifndef HAVE_EVP_PKEY_BASE_ID |
123 | #define HAVE_EVP_PKEY_BASE_ID OPENSSL_PREREQ(1,1,0) | 127 | #define HAVE_EVP_PKEY_BASE_ID OPENSSL_PREREQ(1,1,0) |
124 | #endif | 128 | #endif |
@@ -1232,6 +1236,29 @@ static int compat_EVP_PKEY_base_id(EVP_PKEY *key) { | |||
1232 | } /* compat_EVP_PKEY_base_id() */ | 1236 | } /* compat_EVP_PKEY_base_id() */ |
1233 | #endif | 1237 | #endif |
1234 | 1238 | ||
1239 | #if !HAVE_EVP_PKEY_GET_DEFAULT_DIGEST_NID | ||
1240 | #define EVP_PKEY_get_default_digest_nid(...) \ | ||
1241 | compat_EVP_PKEY_get_default_digest_nid(__VA_ARGS__) | ||
1242 | |||
1243 | static int compat_EVP_PKEY_get_default_digest_nid(EVP_PKEY *key, int *nid) { | ||
1244 | switch (EVP_PKEY_base_id(key)) { | ||
1245 | case EVP_PKEY_RSA: | ||
1246 | *nid = EVP_MD_nid(EVP_sha1()); | ||
1247 | break; | ||
1248 | case EVP_PKEY_DSA: | ||
1249 | *nid = EVP_MD_nid(EVP_dss1()); | ||
1250 | break; | ||
1251 | case EVP_PKEY_EC: | ||
1252 | *nid = EVP_MD_nid(EVP_ecdsa()); | ||
1253 | break; | ||
1254 | default: | ||
1255 | *nid = EVP_MD_nid(EVP_md_null()); | ||
1256 | break; | ||
1257 | } | ||
1258 | |||
1259 | return 1; | ||
1260 | } /* compat_EVP_PKEY_get_default_digest_nid() */ | ||
1261 | #endif | ||
1235 | 1262 | ||
1236 | #if !HAVE_EVP_PKEY_GET0 | 1263 | #if !HAVE_EVP_PKEY_GET0 |
1237 | #define EVP_PKEY_get0(key) compat_EVP_PKEY_get0((key)) | 1264 | #define EVP_PKEY_get0(key) compat_EVP_PKEY_get0((key)) |
@@ -5559,20 +5586,23 @@ static int xc_getPublicKeyDigest(lua_State *L) { | |||
5559 | static const EVP_MD *xc_signature(lua_State *L, int index, EVP_PKEY *key) { | 5586 | static const EVP_MD *xc_signature(lua_State *L, int index, EVP_PKEY *key) { |
5560 | const char *id; | 5587 | const char *id; |
5561 | const EVP_MD *md; | 5588 | const EVP_MD *md; |
5589 | int nid; | ||
5562 | 5590 | ||
5563 | if ((id = luaL_optstring(L, index, NULL))) | 5591 | if ((id = luaL_optstring(L, index, NULL))) { |
5564 | return ((md = EVP_get_digestbyname(id)))? md : EVP_md_null(); | 5592 | if (!(md = EVP_get_digestbyname(id))) |
5593 | goto unknown; | ||
5565 | 5594 | ||
5566 | switch (EVP_PKEY_base_id(key)) { | 5595 | return md; |
5567 | case EVP_PKEY_RSA: | ||
5568 | return EVP_sha1(); | ||
5569 | case EVP_PKEY_DSA: | ||
5570 | return EVP_dss1(); | ||
5571 | case EVP_PKEY_EC: | ||
5572 | return EVP_ecdsa(); | ||
5573 | default: | ||
5574 | return EVP_md_null(); | ||
5575 | } | 5596 | } |
5597 | |||
5598 | if (!(EVP_PKEY_get_default_digest_nid(key, &nid) > 0)) | ||
5599 | goto unknown; | ||
5600 | if (!(md = EVP_get_digestbynid(nid))) | ||
5601 | goto unknown; | ||
5602 | |||
5603 | return md; | ||
5604 | unknown: | ||
5605 | return EVP_md_null(); | ||
5576 | } /* xc_signature() */ | 5606 | } /* xc_signature() */ |
5577 | 5607 | ||
5578 | static int xc_sign(lua_State *L) { | 5608 | static int xc_sign(lua_State *L) { |