summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2015-05-14 14:28:00 +0300
committerKaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>2015-05-18 01:04:55 +0300
commit4ca7cbf40e85f79f4864d462d7defd5469d282e5 (patch)
tree6fe9d07797187b90cdd7fa58d956cc89b989de65
parentbfd750138c8c970cade9ad40dd525acd1ca88276 (diff)
downloadluaossl-4ca7cbf40e85f79f4864d462d7defd5469d282e5.tar.gz
luaossl-4ca7cbf40e85f79f4864d462d7defd5469d282e5.tar.bz2
luaossl-4ca7cbf40e85f79f4864d462d7defd5469d282e5.zip
get named extension from certificate
-rw-r--r--src/openssl.c32
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) {
3632} /* xc_addExtension() */ 3632} /* xc_addExtension() */
3633 3633
3634 3634
3635static int xc_getExtension(lua_State *L) {
3636 X509 *crt = checksimple(L, 1, X509_CERT_CLASS);
3637 const char *name = luaL_checkstring(L, 2);
3638
3639 X509_EXTENSION *ext, **ud;
3640 ASN1_OBJECT *obj = NULL;
3641
3642 if (!(obj = OBJ_txt2obj(name, 0)))
3643 goto error;
3644
3645 int i = X509_get_ext_by_OBJ(crt, obj, -1);
3646 if (i > -1) {
3647 ud = prepsimple(L, X509_EXT_CLASS);
3648 if (!(ext = X509_get_ext(crt, i)))
3649 goto error;
3650 if (!(*ud = X509_EXTENSION_dup(ext)))
3651 goto error;
3652 }
3653 else lua_pushnil(L);
3654
3655 ASN1_OBJECT_free(obj);
3656 return 1;
3657
3658error:
3659 if (obj)
3660 ASN1_OBJECT_free(obj);
3661
3662 return auxL_error(L, auxL_EOPENSSL, "x509.cert:getExtension");
3663} /* xc_getExtension() */
3664
3665
3635static int xc_isIssuedBy(lua_State *L) { 3666static int xc_isIssuedBy(lua_State *L) {
3636 X509 *crt = checksimple(L, 1, X509_CERT_CLASS); 3667 X509 *crt = checksimple(L, 1, X509_CERT_CLASS);
3637 X509 *issuer = checksimple(L, 2, X509_CERT_CLASS); 3668 X509 *issuer = checksimple(L, 2, X509_CERT_CLASS);
@@ -3850,6 +3881,7 @@ static const luaL_Reg xc_methods[] = {
3850 { "getBasicConstraintsCritical", &xc_getBasicConstraintsCritical }, 3881 { "getBasicConstraintsCritical", &xc_getBasicConstraintsCritical },
3851 { "setBasicConstraintsCritical", &xc_setBasicConstraintsCritical }, 3882 { "setBasicConstraintsCritical", &xc_setBasicConstraintsCritical },
3852 { "addExtension", &xc_addExtension }, 3883 { "addExtension", &xc_addExtension },
3884 { "getExtension", &xc_getExtension },
3853 { "isIssuedBy", &xc_isIssuedBy }, 3885 { "isIssuedBy", &xc_isIssuedBy },
3854 { "getPublicKey", &xc_getPublicKey }, 3886 { "getPublicKey", &xc_getPublicKey },
3855 { "setPublicKey", &xc_setPublicKey }, 3887 { "setPublicKey", &xc_setPublicKey },