diff options
| author | william <william@25tandclement.com> | 2014-07-15 20:53:49 -0700 |
|---|---|---|
| committer | william <william@25tandclement.com> | 2014-07-15 20:53:49 -0700 |
| commit | 9cb3637d37cbc41032284a31f751ee03c6b199f9 (patch) | |
| tree | 09b25d5f7da8358574d980386cfdabf2878375e6 /src | |
| parent | 2a8831f0edfb9404c2c7e10628033ff0ac0fff81 (diff) | |
| parent | ab27845444a153c8a9c402fab947e8997fc9d2da (diff) | |
| download | luaossl-9cb3637d37cbc41032284a31f751ee03c6b199f9.tar.gz luaossl-9cb3637d37cbc41032284a31f751ee03c6b199f9.tar.bz2 luaossl-9cb3637d37cbc41032284a31f751ee03c6b199f9.zip | |
Merge branch 'text' of https://github.com/kunkku/luaossl into kunkku-text
Diffstat (limited to 'src')
| -rw-r--r-- | src/openssl.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c index c16c0d8..e1c3b8d 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
| @@ -2590,6 +2590,66 @@ static int xc_sign(lua_State *L) { | |||
| 2590 | } /* xc_sign() */ | 2590 | } /* xc_sign() */ |
| 2591 | 2591 | ||
| 2592 | 2592 | ||
| 2593 | static int xc_text(lua_State *L) { | ||
| 2594 | static const struct { const char *kw; unsigned int flag; } map[] = { | ||
| 2595 | { "no_header", X509_FLAG_NO_HEADER }, | ||
| 2596 | { "no_version", X509_FLAG_NO_VERSION }, | ||
| 2597 | { "no_serial", X509_FLAG_NO_SERIAL }, | ||
| 2598 | { "no_signame", X509_FLAG_NO_SIGNAME }, | ||
| 2599 | { "no_validity", X509_FLAG_NO_VALIDITY }, | ||
| 2600 | { "no_subject", X509_FLAG_NO_SUBJECT }, | ||
| 2601 | { "no_issuer", X509_FLAG_NO_ISSUER }, | ||
| 2602 | { "no_pubkey", X509_FLAG_NO_PUBKEY }, | ||
| 2603 | { "no_extensions", X509_FLAG_NO_EXTENSIONS }, | ||
| 2604 | { "no_sigdump", X509_FLAG_NO_SIGDUMP }, | ||
| 2605 | { "no_aux", X509_FLAG_NO_AUX }, | ||
| 2606 | { "no_attributes", X509_FLAG_NO_ATTRIBUTES }, | ||
| 2607 | { "ext_default", X509V3_EXT_DEFAULT }, | ||
| 2608 | { "ext_error", X509V3_EXT_ERROR_UNKNOWN }, | ||
| 2609 | { "ext_parse", X509V3_EXT_PARSE_UNKNOWN }, | ||
| 2610 | { "ext_dump", X509V3_EXT_DUMP_UNKNOWN } | ||
| 2611 | }; | ||
| 2612 | |||
| 2613 | lua_settop(L, 2); | ||
| 2614 | |||
| 2615 | X509 *crt = checksimple(L, 1, X509_CERT_CLASS); | ||
| 2616 | |||
| 2617 | unsigned int flags = 0; | ||
| 2618 | const char *kw; | ||
| 2619 | int found; | ||
| 2620 | unsigned int i; | ||
| 2621 | |||
| 2622 | BIO *bio = getbio(L); | ||
| 2623 | char *data; | ||
| 2624 | long len; | ||
| 2625 | |||
| 2626 | if (!lua_isnil(L, 2)) { | ||
| 2627 | lua_pushnil(L); | ||
| 2628 | while (lua_next(L, 2)) { | ||
| 2629 | kw = luaL_checkstring(L, -1); | ||
| 2630 | found = 0; | ||
| 2631 | for (i = 0; i < countof(map); i++) | ||
| 2632 | if (!strcmp(kw, map[i].kw)) { | ||
| 2633 | flags |= map[i].flag; | ||
| 2634 | found = 1; | ||
| 2635 | } | ||
| 2636 | if (!found) | ||
| 2637 | luaL_argerror(L, 2, lua_pushfstring(L, "invalid flag: %s", kw)); | ||
| 2638 | lua_pop(L, 1); | ||
| 2639 | } | ||
| 2640 | } | ||
| 2641 | |||
| 2642 | if (!X509_print_ex(bio, crt, 0, flags)) | ||
| 2643 | return throwssl(L, "x509.cert:text"); | ||
| 2644 | |||
| 2645 | len = BIO_get_mem_data(bio, &data); | ||
| 2646 | |||
| 2647 | lua_pushlstring(L, data, len); | ||
| 2648 | |||
| 2649 | return 1; | ||
| 2650 | } /* xc_text() */ | ||
| 2651 | |||
| 2652 | |||
| 2593 | static int xc__tostring(lua_State *L) { | 2653 | static int xc__tostring(lua_State *L) { |
| 2594 | X509 *crt = checksimple(L, 1, X509_CERT_CLASS); | 2654 | X509 *crt = checksimple(L, 1, X509_CERT_CLASS); |
| 2595 | int type = optencoding(L, 2, "pem", X509_PEM|X509_DER); | 2655 | int type = optencoding(L, 2, "pem", X509_PEM|X509_DER); |
| @@ -2656,6 +2716,7 @@ static const luaL_Reg xc_methods[] = { | |||
| 2656 | { "getPublicKey", &xc_getPublicKey }, | 2716 | { "getPublicKey", &xc_getPublicKey }, |
| 2657 | { "setPublicKey", &xc_setPublicKey }, | 2717 | { "setPublicKey", &xc_setPublicKey }, |
| 2658 | { "sign", &xc_sign }, | 2718 | { "sign", &xc_sign }, |
| 2719 | { "text", &xc_text }, | ||
| 2659 | { "tostring", &xc__tostring }, | 2720 | { "tostring", &xc__tostring }, |
| 2660 | { NULL, NULL }, | 2721 | { NULL, NULL }, |
| 2661 | }; | 2722 | }; |
| @@ -3104,6 +3165,24 @@ static int xx_sign(lua_State *L) { | |||
| 3104 | } /* xx_sign() */ | 3165 | } /* xx_sign() */ |
| 3105 | 3166 | ||
| 3106 | 3167 | ||
| 3168 | static int xx_text(lua_State *L) { | ||
| 3169 | X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS); | ||
| 3170 | |||
| 3171 | BIO *bio = getbio(L); | ||
| 3172 | char *data; | ||
| 3173 | long len; | ||
| 3174 | |||
| 3175 | if (!X509_CRL_print(bio, crl)) | ||
| 3176 | return throwssl(L, "x509.crl:text"); | ||
| 3177 | |||
| 3178 | len = BIO_get_mem_data(bio, &data); | ||
| 3179 | |||
| 3180 | lua_pushlstring(L, data, len); | ||
| 3181 | |||
| 3182 | return 1; | ||
| 3183 | } /* xx_text() */ | ||
| 3184 | |||
| 3185 | |||
| 3107 | static int xx__tostring(lua_State *L) { | 3186 | static int xx__tostring(lua_State *L) { |
| 3108 | X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS); | 3187 | X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS); |
| 3109 | int type = optencoding(L, 2, "pem", X509_PEM|X509_DER); | 3188 | int type = optencoding(L, 2, "pem", X509_PEM|X509_DER); |
| @@ -3150,6 +3229,7 @@ static const luaL_Reg xx_methods[] = { | |||
| 3150 | { "setIssuer", &xx_setIssuer }, | 3229 | { "setIssuer", &xx_setIssuer }, |
| 3151 | { "add", &xx_add }, | 3230 | { "add", &xx_add }, |
| 3152 | { "sign", &xx_sign }, | 3231 | { "sign", &xx_sign }, |
| 3232 | { "text", &xx_text }, | ||
| 3153 | { "tostring", &xx__tostring }, | 3233 | { "tostring", &xx__tostring }, |
| 3154 | { NULL, NULL }, | 3234 | { NULL, NULL }, |
| 3155 | }; | 3235 | }; |
