diff options
| author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-09-05 10:38:43 +0300 |
|---|---|---|
| committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2014-09-05 10:38:43 +0300 |
| commit | fd6efb22e98d51b441b9b4d9e440c099ba07ca4a (patch) | |
| tree | 63edeb1b201738e481c7b072eb1acf586bfa7980 | |
| parent | 0588f3ad4981ea5282d4b423654e87c0170c941e (diff) | |
| download | luaossl-fd6efb22e98d51b441b9b4d9e440c099ba07ca4a.tar.gz luaossl-fd6efb22e98d51b441b9b4d9e440c099ba07ca4a.tar.bz2 luaossl-fd6efb22e98d51b441b9b4d9e440c099ba07ca4a.zip | |
parse CRLs from PEM and DER formats
| -rw-r--r-- | src/openssl.c | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/openssl.c b/src/openssl.c index 757bbf0..9845bcc 100644 --- a/src/openssl.c +++ b/src/openssl.c | |||
| @@ -3070,14 +3070,41 @@ int luaopen__openssl_x509_csr(lua_State *L) { | |||
| 3070 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ | 3070 | * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ |
| 3071 | 3071 | ||
| 3072 | static int xx_new(lua_State *L) { | 3072 | static int xx_new(lua_State *L) { |
| 3073 | const char *data; | ||
| 3074 | size_t len; | ||
| 3073 | X509_CRL **ud; | 3075 | X509_CRL **ud; |
| 3074 | 3076 | ||
| 3077 | lua_settop(L, 2); | ||
| 3078 | |||
| 3075 | ud = prepsimple(L, X509_CRL_CLASS); | 3079 | ud = prepsimple(L, X509_CRL_CLASS); |
| 3076 | 3080 | ||
| 3077 | if (!(*ud = X509_CRL_new())) | 3081 | if ((data = luaL_optlstring(L, 1, NULL, &len))) { |
| 3078 | return throwssl(L, "x509.crl.new"); | 3082 | int type = optencoding(L, 2, "*", X509_ANY|X509_PEM|X509_DER); |
| 3083 | BIO *tmp; | ||
| 3084 | int ok = 0; | ||
| 3085 | |||
| 3086 | if (!(tmp = BIO_new_mem_buf((char *)data, len))) | ||
| 3087 | return throwssl(L, "x509.crl.new"); | ||
| 3088 | |||
| 3089 | if (type == X509_PEM || type == X509_ANY) { | ||
| 3090 | ok = !!(*ud = PEM_read_bio_X509_CRL(tmp, NULL, 0, "")); /* no password */ | ||
| 3091 | } | ||
| 3092 | |||
| 3093 | if (!ok && (type == X509_DER || type == X509_ANY)) { | ||
| 3094 | ok = !!(*ud = d2i_X509_CRL_bio(tmp, NULL)); | ||
| 3095 | } | ||
| 3079 | 3096 | ||
| 3080 | X509_gmtime_adj(X509_CRL_get_lastUpdate(*ud), 0); | 3097 | BIO_free(tmp); |
| 3098 | |||
| 3099 | if (!ok) | ||
| 3100 | return throwssl(L, "x509.crl.new"); | ||
| 3101 | } | ||
| 3102 | else { | ||
| 3103 | if (!(*ud = X509_CRL_new())) | ||
| 3104 | return throwssl(L, "x509.crl.new"); | ||
| 3105 | |||
| 3106 | X509_gmtime_adj(X509_CRL_get_lastUpdate(*ud), 0); | ||
| 3107 | } | ||
| 3081 | 3108 | ||
| 3082 | return 1; | 3109 | return 1; |
| 3083 | } /* xx_new() */ | 3110 | } /* xx_new() */ |
