summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c83
1 files changed, 82 insertions, 1 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 2ac14f1..b183524 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -27,6 +27,7 @@
27#define LUAOSSL_H 27#define LUAOSSL_H
28 28
29#include <limits.h> /* INT_MAX INT_MIN */ 29#include <limits.h> /* INT_MAX INT_MIN */
30#include <stdint.h> /* uintptr_t */
30#include <string.h> /* memset(3) strerror_r(3) */ 31#include <string.h> /* memset(3) strerror_r(3) */
31#include <strings.h> /* strcasecmp(3) */ 32#include <strings.h> /* strcasecmp(3) */
32#include <math.h> /* INFINITY fabs(3) floor(3) frexp(3) fmod(3) round(3) isfinite(3) */ 33#include <math.h> /* INFINITY fabs(3) floor(3) frexp(3) fmod(3) round(3) isfinite(3) */
@@ -2603,6 +2604,66 @@ static int xc_sign(lua_State *L) {
2603} /* xc_sign() */ 2604} /* xc_sign() */
2604 2605
2605 2606
2607static int xc_text(lua_State *L) {
2608 static const struct { const char *kw; unsigned int flag; } map[] = {
2609 { "no_header", X509_FLAG_NO_HEADER },
2610 { "no_version", X509_FLAG_NO_VERSION },
2611 { "no_serial", X509_FLAG_NO_SERIAL },
2612 { "no_signame", X509_FLAG_NO_SIGNAME },
2613 { "no_validity", X509_FLAG_NO_VALIDITY },
2614 { "no_subject", X509_FLAG_NO_SUBJECT },
2615 { "no_issuer", X509_FLAG_NO_ISSUER },
2616 { "no_pubkey", X509_FLAG_NO_PUBKEY },
2617 { "no_extensions", X509_FLAG_NO_EXTENSIONS },
2618 { "no_sigdump", X509_FLAG_NO_SIGDUMP },
2619 { "no_aux", X509_FLAG_NO_AUX },
2620 { "no_attributes", X509_FLAG_NO_ATTRIBUTES },
2621 { "ext_default", X509V3_EXT_DEFAULT },
2622 { "ext_error", X509V3_EXT_ERROR_UNKNOWN },
2623 { "ext_parse", X509V3_EXT_PARSE_UNKNOWN },
2624 { "ext_dump", X509V3_EXT_DUMP_UNKNOWN }
2625 };
2626
2627 lua_settop(L, 2);
2628
2629 X509 *crt = checksimple(L, 1, X509_CERT_CLASS);
2630
2631 unsigned int flags = 0;
2632 const char *kw;
2633 int found;
2634 unsigned int i;
2635
2636 BIO *bio = getbio(L);
2637 char *data;
2638 long len;
2639
2640 if (!lua_isnil(L, 2)) {
2641 lua_pushnil(L);
2642 while (lua_next(L, 2)) {
2643 kw = luaL_checkstring(L, -1);
2644 found = 0;
2645 for (i = 0; i < countof(map); i++)
2646 if (!strcmp(kw, map[i].kw)) {
2647 flags |= map[i].flag;
2648 found = 1;
2649 }
2650 if (!found)
2651 luaL_argerror(L, 2, lua_pushfstring(L, "invalid flag: %s", kw));
2652 lua_pop(L, 1);
2653 }
2654 }
2655
2656 if (!X509_print_ex(bio, crt, 0, flags))
2657 return throwssl(L, "x509.cert:text");
2658
2659 len = BIO_get_mem_data(bio, &data);
2660
2661 lua_pushlstring(L, data, len);
2662
2663 return 1;
2664} /* xc_text() */
2665
2666
2606static int xc__tostring(lua_State *L) { 2667static int xc__tostring(lua_State *L) {
2607 X509 *crt = checksimple(L, 1, X509_CERT_CLASS); 2668 X509 *crt = checksimple(L, 1, X509_CERT_CLASS);
2608 int type = optencoding(L, 2, "pem", X509_PEM|X509_DER); 2669 int type = optencoding(L, 2, "pem", X509_PEM|X509_DER);
@@ -2669,6 +2730,7 @@ static const luaL_Reg xc_methods[] = {
2669 { "getPublicKey", &xc_getPublicKey }, 2730 { "getPublicKey", &xc_getPublicKey },
2670 { "setPublicKey", &xc_setPublicKey }, 2731 { "setPublicKey", &xc_setPublicKey },
2671 { "sign", &xc_sign }, 2732 { "sign", &xc_sign },
2733 { "text", &xc_text },
2672 { "tostring", &xc__tostring }, 2734 { "tostring", &xc__tostring },
2673 { NULL, NULL }, 2735 { NULL, NULL },
2674}; 2736};
@@ -2956,7 +3018,7 @@ static int xx_getLastUpdate(lua_State *L) {
2956 updated = timeutc(time); 3018 updated = timeutc(time);
2957 3019
2958 if (isfinite(updated)) 3020 if (isfinite(updated))
2959 lua_pushnumber(L, 1); 3021 lua_pushnumber(L, updated);
2960 else 3022 else
2961 lua_pushnil(L); 3023 lua_pushnil(L);
2962 3024
@@ -3117,6 +3179,24 @@ static int xx_sign(lua_State *L) {
3117} /* xx_sign() */ 3179} /* xx_sign() */
3118 3180
3119 3181
3182static int xx_text(lua_State *L) {
3183 X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS);
3184
3185 BIO *bio = getbio(L);
3186 char *data;
3187 long len;
3188
3189 if (!X509_CRL_print(bio, crl))
3190 return throwssl(L, "x509.crl:text");
3191
3192 len = BIO_get_mem_data(bio, &data);
3193
3194 lua_pushlstring(L, data, len);
3195
3196 return 1;
3197} /* xx_text() */
3198
3199
3120static int xx__tostring(lua_State *L) { 3200static int xx__tostring(lua_State *L) {
3121 X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS); 3201 X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS);
3122 int type = optencoding(L, 2, "pem", X509_PEM|X509_DER); 3202 int type = optencoding(L, 2, "pem", X509_PEM|X509_DER);
@@ -3163,6 +3243,7 @@ static const luaL_Reg xx_methods[] = {
3163 { "setIssuer", &xx_setIssuer }, 3243 { "setIssuer", &xx_setIssuer },
3164 { "add", &xx_add }, 3244 { "add", &xx_add },
3165 { "sign", &xx_sign }, 3245 { "sign", &xx_sign },
3246 { "text", &xx_text },
3166 { "tostring", &xx__tostring }, 3247 { "tostring", &xx__tostring },
3167 { NULL, NULL }, 3248 { NULL, NULL },
3168}; 3249};