diff options
author | william <william@25tandclement.com> | 2014-05-10 18:12:56 -0700 |
---|---|---|
committer | william <william@25tandclement.com> | 2014-05-10 18:12:56 -0700 |
commit | 9ae361069c9c0528a563a1eecdda12d36af97cfe (patch) | |
tree | f9e35d5e089ef06c7e73befd6d0d2f0997b5b2b7 /src | |
parent | 74a0cb8873f5760f12c9e96e03dee26c126a84c2 (diff) | |
download | luaossl-9ae361069c9c0528a563a1eecdda12d36af97cfe.tar.gz luaossl-9ae361069c9c0528a563a1eecdda12d36af97cfe.tar.bz2 luaossl-9ae361069c9c0528a563a1eecdda12d36af97cfe.zip |
refactor xx_add to be more linear
Diffstat (limited to 'src')
-rw-r--r-- | src/openssl.c | 62 |
1 files changed, 38 insertions, 24 deletions
diff --git a/src/openssl.c b/src/openssl.c index f2166f5..6079bee 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
@@ -30,7 +30,7 @@ | |||
30 | #include <string.h> /* memset(3) strerror_r(3) */ | 30 | #include <string.h> /* memset(3) strerror_r(3) */ |
31 | #include <strings.h> /* strcasecmp(3) */ | 31 | #include <strings.h> /* strcasecmp(3) */ |
32 | #include <math.h> /* INFINITY fabs(3) floor(3) frexp(3) fmod(3) round(3) isfinite(3) */ | 32 | #include <math.h> /* INFINITY fabs(3) floor(3) frexp(3) fmod(3) round(3) isfinite(3) */ |
33 | #include <time.h> /* struct tm time_t strptime(3) */ | 33 | #include <time.h> /* struct tm time_t strptime(3) time(2) */ |
34 | #include <ctype.h> /* tolower(3) */ | 34 | #include <ctype.h> /* tolower(3) */ |
35 | #include <errno.h> /* errno */ | 35 | #include <errno.h> /* errno */ |
36 | 36 | ||
@@ -3039,40 +3039,53 @@ static int xx_setIssuer(lua_State *L) { | |||
3039 | 3039 | ||
3040 | 3040 | ||
3041 | static int xx_add(lua_State *L) { | 3041 | static int xx_add(lua_State *L) { |
3042 | int ok = 1; | ||
3043 | |||
3044 | lua_settop(L, 3); | ||
3045 | X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS); | 3042 | X509_CRL *crl = checksimple(L, 1, X509_CRL_CLASS); |
3046 | BIGNUM *serial = checkbig(L, 2); | 3043 | BIGNUM *bn = checkbig(L, 2); |
3047 | 3044 | double ut = luaL_optnumber(L, 3, time(NULL)); | |
3048 | X509_REVOKED *rev = NULL; | 3045 | X509_REVOKED *rev = NULL; |
3049 | ASN1_INTEGER *aserial = NULL; | 3046 | ASN1_INTEGER *serial = NULL; |
3050 | ASN1_TIME *date = NULL; | 3047 | ASN1_TIME *date = NULL; |
3051 | 3048 | ||
3052 | if (!(rev = X509_REVOKED_new())) goto error; | 3049 | if (!(rev = X509_REVOKED_new())) |
3050 | goto error; | ||
3053 | 3051 | ||
3054 | if (!(aserial = BN_to_ASN1_INTEGER(serial, NULL))) goto error; | 3052 | if (!(serial = BN_to_ASN1_INTEGER(bn, NULL))) |
3055 | if (!X509_REVOKED_set_serialNumber(rev, aserial)) goto error; | 3053 | goto error; |
3056 | 3054 | ||
3057 | if (!(date = ASN1_TIME_new())) goto error; | 3055 | if (!X509_REVOKED_set_serialNumber(rev, serial)) /* duplicates serial */ |
3058 | if (lua_isnil(L, 3)) X509_gmtime_adj(date, 0); | 3056 | goto error; |
3059 | else if (!ASN1_TIME_set(date, luaL_checknumber(L, 3))) goto error; | ||
3060 | if (!X509_REVOKED_set_revocationDate(rev, date)) goto error; | ||
3061 | 3057 | ||
3062 | if (!X509_CRL_add0_revoked(crl, rev)) goto error; | 3058 | ASN1_INTEGER_free(serial); |
3059 | serial = NULL; | ||
3063 | 3060 | ||
3064 | goto done; | 3061 | if (!(date = ASN1_TIME_new())) |
3062 | goto error; | ||
3065 | 3063 | ||
3066 | error: | 3064 | if (!ASN1_TIME_set(date, ut)) |
3067 | ok = 0; | 3065 | goto error; |
3068 | 3066 | ||
3069 | done: | 3067 | if (!X509_REVOKED_set_revocationDate(rev, date)) /* duplicates date */ |
3070 | if (date) ASN1_TIME_free(date); | 3068 | goto error; |
3071 | if (serial) ASN1_INTEGER_free(aserial); | ||
3072 | if (!ok && rev) X509_REVOKED_free(rev); | ||
3073 | 3069 | ||
3074 | return ok ? 0 : throwssl(L, "x509.crl:add"); | 3070 | ASN1_TIME_free(date); |
3075 | } /* xx_setIssuer() */ | 3071 | date = NULL; |
3072 | |||
3073 | if (!X509_CRL_add0_revoked(crl, rev)) /* takes ownership of rev */ | ||
3074 | goto error; | ||
3075 | |||
3076 | lua_pushboolean(L, 1); | ||
3077 | |||
3078 | return 1; | ||
3079 | error: | ||
3080 | if (date) | ||
3081 | ASN1_TIME_free(date); | ||
3082 | if (serial) | ||
3083 | ASN1_INTEGER_free(serial); | ||
3084 | if (rev) | ||
3085 | X509_REVOKED_free(rev); | ||
3086 | |||
3087 | return throwssl(L, "x509.crl:add"); | ||
3088 | } /* xx_add() */ | ||
3076 | 3089 | ||
3077 | 3090 | ||
3078 | static int xx_sign(lua_State *L) { | 3091 | static int xx_sign(lua_State *L) { |
@@ -3134,6 +3147,7 @@ static const luaL_Reg xx_methods[] = { | |||
3134 | { "setIssuer", &xx_setIssuer }, | 3147 | { "setIssuer", &xx_setIssuer }, |
3135 | { "add", &xx_add }, | 3148 | { "add", &xx_add }, |
3136 | { "sign", &xx_sign }, | 3149 | { "sign", &xx_sign }, |
3150 | { "tostring", &xx__tostring }, | ||
3137 | { NULL, NULL }, | 3151 | { NULL, NULL }, |
3138 | }; | 3152 | }; |
3139 | 3153 | ||