aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatarLibravatar Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> 2015-05-14 15:24:05 +0300
committerLibravatarLibravatar Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> 2015-05-18 01:04:55 +0300
commit615d4aa6b5a42df259e41a041768b2a1ec07da35 (patch)
tree8d78746f2621528598c266f30b4b9701a09ce88f /src
parent057aefa60887b4599edba7f32b9bcd83d926c3af (diff)
downloadluaossl-615d4aa6b5a42df259e41a041768b2a1ec07da35.tar.gz
luaossl-615d4aa6b5a42df259e41a041768b2a1ec07da35.tar.bz2
luaossl-615d4aa6b5a42df259e41a041768b2a1ec07da35.zip
initialize extension data in DER format without intermediate hex encoding
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c27
1 files changed, 26 insertions, 1 deletions
diff --git a/src/openssl.c b/src/openssl.c
index c3b9145..3b75e63 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -2841,12 +2841,31 @@ static int xe_new(lua_State *L) {
const char *name = luaL_checkstring(L, 1);
const char *value = luaL_checkstring(L, 2);
+ ASN1_OBJECT *obj = NULL;
+ ASN1_STRING *oct = NULL;
CONF *conf = NULL;
X509V3_CTX cbuf = { 0 }, *ctx = NULL;
X509_EXTENSION *ext = NULL;
if (!lua_isnil(L, 3)) {
- const char *cdata = luaL_checkstring(L, 3);
+ size_t len;
+ const char *cdata = luaL_checklstring(L, 3, &len);
+ int crit = !strcmp(value, "critical,DER");
+
+ if (crit || !strcmp(value, "DER")) {
+ if (!(obj = OBJ_txt2obj(name, 0)))
+ goto error;
+ if (!(oct = ASN1_STRING_new()))
+ goto error;
+ if (!ASN1_STRING_set(oct, cdata, len))
+ goto error;
+ if (!(*ud = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct)))
+ goto error;
+ ASN1_OBJECT_free(obj);
+ ASN1_STRING_free(oct);
+ return 1;
+ }
+
BIO *bio = getbio(L);
if (BIO_puts(bio, cdata) < 0)
goto error;
@@ -2877,6 +2896,12 @@ static int xe_new(lua_State *L) {
return 1;
error:
+ if (obj)
+ ASN1_OBJECT_free(obj);
+
+ if (oct)
+ ASN1_STRING_free(oct);
+
if (conf)
NCONF_free(conf);