aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatarLibravatar Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> 2015-05-14 11:44:14 +0300
committerLibravatarLibravatar Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> 2015-05-14 18:10:39 +0300
commit919cf75aa17ff885382a4dd234fc7a168c4e0972 (patch)
treebd4f83864ff6d5d590ced46a9d047ab959cf7d96 /src
parent91eb47726cb3b8d487f21a17b3c2b8c5e9fb1024 (diff)
downloadluaossl-919cf75aa17ff885382a4dd234fc7a168c4e0972.tar.gz
luaossl-919cf75aa17ff885382a4dd234fc7a168c4e0972.tar.bz2
luaossl-919cf75aa17ff885382a4dd234fc7a168c4e0972.zip
get digest for certificate's public key
The digest may be used in key identifier extensions. See RFC 5280 ยง4.2.1.2.
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 99a1ec0..34f893a 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 },