1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
From fd6efb22e98d51b441b9b4d9e440c099ba07ca4a Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Fri, 5 Sep 2014 10:38:43 +0300
Subject: [PATCH] parse CRLs from PEM and DER formats
---
src/openssl.c | 33 ++++++++++++++++++++++++++++++---
1 file 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) {
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static int xx_new(lua_State *L) {
+ const char *data;
+ size_t len;
X509_CRL **ud;
+ lua_settop(L, 2);
+
ud = prepsimple(L, X509_CRL_CLASS);
- if (!(*ud = X509_CRL_new()))
- return throwssl(L, "x509.crl.new");
+ if ((data = luaL_optlstring(L, 1, NULL, &len))) {
+ int type = optencoding(L, 2, "*", X509_ANY|X509_PEM|X509_DER);
+ BIO *tmp;
+ int ok = 0;
+
+ if (!(tmp = BIO_new_mem_buf((char *)data, len)))
+ return throwssl(L, "x509.crl.new");
+
+ if (type == X509_PEM || type == X509_ANY) {
+ ok = !!(*ud = PEM_read_bio_X509_CRL(tmp, NULL, 0, "")); /* no password */
+ }
+
+ if (!ok && (type == X509_DER || type == X509_ANY)) {
+ ok = !!(*ud = d2i_X509_CRL_bio(tmp, NULL));
+ }
- X509_gmtime_adj(X509_CRL_get_lastUpdate(*ud), 0);
+ BIO_free(tmp);
+
+ if (!ok)
+ return throwssl(L, "x509.crl.new");
+ }
+ else {
+ if (!(*ud = X509_CRL_new()))
+ return throwssl(L, "x509.crl.new");
+
+ X509_gmtime_adj(X509_CRL_get_lastUpdate(*ud), 0);
+ }
return 1;
} /* xx_new() */
--
1.8.3.1
|