diff options
| author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2015-05-14 15:24:05 +0300 |
|---|---|---|
| committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2015-05-18 01:04:55 +0300 |
| commit | 615d4aa6b5a42df259e41a041768b2a1ec07da35 (patch) | |
| tree | 8d78746f2621528598c266f30b4b9701a09ce88f | |
| parent | 057aefa60887b4599edba7f32b9bcd83d926c3af (diff) | |
| download | luaossl-615d4aa6b5a42df259e41a041768b2a1ec07da35.tar.gz luaossl-615d4aa6b5a42df259e41a041768b2a1ec07da35.tar.bz2 luaossl-615d4aa6b5a42df259e41a041768b2a1ec07da35.zip | |
initialize extension data in DER format without intermediate hex encoding
| -rw-r--r-- | src/openssl.c | 27 |
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) { | |||
| 2841 | const char *name = luaL_checkstring(L, 1); | 2841 | const char *name = luaL_checkstring(L, 1); |
| 2842 | const char *value = luaL_checkstring(L, 2); | 2842 | const char *value = luaL_checkstring(L, 2); |
| 2843 | 2843 | ||
| 2844 | ASN1_OBJECT *obj = NULL; | ||
| 2845 | ASN1_STRING *oct = NULL; | ||
| 2844 | CONF *conf = NULL; | 2846 | CONF *conf = NULL; |
| 2845 | X509V3_CTX cbuf = { 0 }, *ctx = NULL; | 2847 | X509V3_CTX cbuf = { 0 }, *ctx = NULL; |
| 2846 | X509_EXTENSION *ext = NULL; | 2848 | X509_EXTENSION *ext = NULL; |
| 2847 | 2849 | ||
| 2848 | if (!lua_isnil(L, 3)) { | 2850 | if (!lua_isnil(L, 3)) { |
| 2849 | const char *cdata = luaL_checkstring(L, 3); | 2851 | size_t len; |
| 2852 | const char *cdata = luaL_checklstring(L, 3, &len); | ||
| 2853 | int crit = !strcmp(value, "critical,DER"); | ||
| 2854 | |||
| 2855 | if (crit || !strcmp(value, "DER")) { | ||
| 2856 | if (!(obj = OBJ_txt2obj(name, 0))) | ||
| 2857 | goto error; | ||
| 2858 | if (!(oct = ASN1_STRING_new())) | ||
| 2859 | goto error; | ||
| 2860 | if (!ASN1_STRING_set(oct, cdata, len)) | ||
| 2861 | goto error; | ||
| 2862 | if (!(*ud = X509_EXTENSION_create_by_OBJ(NULL, obj, crit, oct))) | ||
| 2863 | goto error; | ||
| 2864 | ASN1_OBJECT_free(obj); | ||
| 2865 | ASN1_STRING_free(oct); | ||
| 2866 | return 1; | ||
| 2867 | } | ||
| 2868 | |||
| 2850 | BIO *bio = getbio(L); | 2869 | BIO *bio = getbio(L); |
| 2851 | if (BIO_puts(bio, cdata) < 0) | 2870 | if (BIO_puts(bio, cdata) < 0) |
| 2852 | goto error; | 2871 | goto error; |
| @@ -2877,6 +2896,12 @@ static int xe_new(lua_State *L) { | |||
| 2877 | 2896 | ||
| 2878 | return 1; | 2897 | return 1; |
| 2879 | error: | 2898 | error: |
| 2899 | if (obj) | ||
| 2900 | ASN1_OBJECT_free(obj); | ||
| 2901 | |||
| 2902 | if (oct) | ||
| 2903 | ASN1_STRING_free(oct); | ||
| 2904 | |||
| 2880 | if (conf) | 2905 | if (conf) |
| 2881 | NCONF_free(conf); | 2906 | NCONF_free(conf); |
| 2882 | 2907 | ||
