diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2015-05-14 14:28:00 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2015-05-18 01:04:55 +0300 |
commit | 4ca7cbf40e85f79f4864d462d7defd5469d282e5 (patch) | |
tree | 6fe9d07797187b90cdd7fa58d956cc89b989de65 /src | |
parent | bfd750138c8c970cade9ad40dd525acd1ca88276 (diff) | |
download | luaossl-4ca7cbf40e85f79f4864d462d7defd5469d282e5.tar.gz luaossl-4ca7cbf40e85f79f4864d462d7defd5469d282e5.tar.bz2 luaossl-4ca7cbf40e85f79f4864d462d7defd5469d282e5.zip |
get named extension from certificate
Diffstat (limited to 'src')
-rw-r--r-- | src/openssl.c | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c index 086b4fa..1c0dfbd 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -3632,6 +3632,37 @@ static int xc_addExtension(lua_State *L) { } /* xc_addExtension() */ +static int xc_getExtension(lua_State *L) { + X509 *crt = checksimple(L, 1, X509_CERT_CLASS); + const char *name = luaL_checkstring(L, 2); + + X509_EXTENSION *ext, **ud; + ASN1_OBJECT *obj = NULL; + + if (!(obj = OBJ_txt2obj(name, 0))) + goto error; + + int i = X509_get_ext_by_OBJ(crt, obj, -1); + if (i > -1) { + ud = prepsimple(L, X509_EXT_CLASS); + if (!(ext = X509_get_ext(crt, i))) + goto error; + if (!(*ud = X509_EXTENSION_dup(ext))) + goto error; + } + else lua_pushnil(L); + + ASN1_OBJECT_free(obj); + return 1; + +error: + if (obj) + ASN1_OBJECT_free(obj); + + return auxL_error(L, auxL_EOPENSSL, "x509.cert:getExtension"); +} /* xc_getExtension() */ + + static int xc_isIssuedBy(lua_State *L) { X509 *crt = checksimple(L, 1, X509_CERT_CLASS); X509 *issuer = checksimple(L, 2, X509_CERT_CLASS); @@ -3850,6 +3881,7 @@ static const luaL_Reg xc_methods[] = { { "getBasicConstraintsCritical", &xc_getBasicConstraintsCritical }, { "setBasicConstraintsCritical", &xc_setBasicConstraintsCritical }, { "addExtension", &xc_addExtension }, + { "getExtension", &xc_getExtension }, { "isIssuedBy", &xc_isIssuedBy }, { "getPublicKey", &xc_getPublicKey }, { "setPublicKey", &xc_setPublicKey }, |