1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
From 85d74658b5ad93a3e2788639dff5ffb210b0e04b Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Thu, 14 May 2015 11:44:14 +0300
Subject: [PATCH 1/5] get digest for certificate's public key
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The digest may be used in key identifier extensions. See RFC 5280
§4.2.1.2.
---
src/openssl.c | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/src/openssl.c b/src/openssl.c
index aa01cbc..4f89859 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -3693,6 +3693,21 @@ static int xc_setPublicKey(lua_State *L) {
} /* xc_setPublicKey() */
+static int xc_getPublicKeyDigest(lua_State *L) {
+ ASN1_BIT_STRING *pk = ((X509 *) checksimple(L, 1, X509_CERT_CLASS))->cert_info->key->public_key;
+
+ unsigned char digest[EVP_MAX_MD_SIZE];
+ unsigned int len;
+
+ if (!EVP_Digest(pk->data, pk->length, digest, &len, EVP_sha1(), NULL))
+ return auxL_error(L, auxL_EOPENSSL, "x509.cert:getPublicKeyDigest");
+
+ lua_pushlstring(L, (char *) digest, len);
+
+ return 1;
+} /* xc_setPublicKeyDigest() */
+
+
static const EVP_MD *xc_signature(lua_State *L, int index, EVP_PKEY *key) {
const char *id;
const EVP_MD *md;
@@ -3853,6 +3868,7 @@ static const luaL_Reg xc_methods[] = {
{ "isIssuedBy", &xc_isIssuedBy },
{ "getPublicKey", &xc_getPublicKey },
{ "setPublicKey", &xc_setPublicKey },
+ { "getPublicKeyDigest", &xc_getPublicKeyDigest },
{ "sign", &xc_sign },
{ "text", &xc_text },
{ "tostring", &xc__tostring },
--
2.1.0
|