zig_example 0.3.2 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/mkmf.rb +5 -2
- data/lib/zig_example/version.rb +1 -1
- metadata +3 -56
- data/ext/openssl/openssl_missing.c +0 -40
- data/ext/openssl/openssl_missing.h +0 -238
- data/ext/openssl/ossl.c +0 -1295
- data/ext/openssl/ossl.h +0 -201
- data/ext/openssl/ossl_asn1.c +0 -1891
- data/ext/openssl/ossl_asn1.h +0 -62
- data/ext/openssl/ossl_bio.c +0 -42
- data/ext/openssl/ossl_bio.h +0 -16
- data/ext/openssl/ossl_bn.c +0 -1344
- data/ext/openssl/ossl_bn.h +0 -26
- data/ext/openssl/ossl_cipher.c +0 -1074
- data/ext/openssl/ossl_cipher.h +0 -20
- data/ext/openssl/ossl_config.c +0 -460
- data/ext/openssl/ossl_config.h +0 -16
- data/ext/openssl/ossl_digest.c +0 -425
- data/ext/openssl/ossl_digest.h +0 -20
- data/ext/openssl/ossl_engine.c +0 -568
- data/ext/openssl/ossl_engine.h +0 -19
- data/ext/openssl/ossl_hmac.c +0 -310
- data/ext/openssl/ossl_hmac.h +0 -18
- data/ext/openssl/ossl_kdf.c +0 -311
- data/ext/openssl/ossl_kdf.h +0 -6
- data/ext/openssl/ossl_ns_spki.c +0 -405
- data/ext/openssl/ossl_ns_spki.h +0 -19
- data/ext/openssl/ossl_ocsp.c +0 -1965
- data/ext/openssl/ossl_ocsp.h +0 -23
- data/ext/openssl/ossl_pkcs12.c +0 -275
- data/ext/openssl/ossl_pkcs12.h +0 -13
- data/ext/openssl/ossl_pkcs7.c +0 -1081
- data/ext/openssl/ossl_pkcs7.h +0 -36
- data/ext/openssl/ossl_pkey.c +0 -1624
- data/ext/openssl/ossl_pkey.h +0 -204
- data/ext/openssl/ossl_pkey_dh.c +0 -440
- data/ext/openssl/ossl_pkey_dsa.c +0 -359
- data/ext/openssl/ossl_pkey_ec.c +0 -1655
- data/ext/openssl/ossl_pkey_rsa.c +0 -579
- data/ext/openssl/ossl_rand.c +0 -200
- data/ext/openssl/ossl_rand.h +0 -18
- data/ext/openssl/ossl_ssl.c +0 -3142
- data/ext/openssl/ossl_ssl.h +0 -36
- data/ext/openssl/ossl_ssl_session.c +0 -331
- data/ext/openssl/ossl_ts.c +0 -1539
- data/ext/openssl/ossl_ts.h +0 -16
- data/ext/openssl/ossl_x509.c +0 -256
- data/ext/openssl/ossl_x509.h +0 -115
- data/ext/openssl/ossl_x509attr.c +0 -324
- data/ext/openssl/ossl_x509cert.c +0 -1002
- data/ext/openssl/ossl_x509crl.c +0 -545
- data/ext/openssl/ossl_x509ext.c +0 -490
- data/ext/openssl/ossl_x509name.c +0 -597
- data/ext/openssl/ossl_x509req.c +0 -444
- data/ext/openssl/ossl_x509revoked.c +0 -300
- data/ext/openssl/ossl_x509store.c +0 -986
data/ext/openssl/ossl_pkcs7.c
DELETED
@@ -1,1081 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* 'OpenSSL for Ruby' project
|
3
|
-
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
4
|
-
* All rights reserved.
|
5
|
-
*/
|
6
|
-
/*
|
7
|
-
* This program is licensed under the same licence as Ruby.
|
8
|
-
* (See the file 'LICENCE'.)
|
9
|
-
*/
|
10
|
-
#include "ossl.h"
|
11
|
-
|
12
|
-
#define NewPKCS7si(klass) \
|
13
|
-
TypedData_Wrap_Struct((klass), &ossl_pkcs7_signer_info_type, 0)
|
14
|
-
#define SetPKCS7si(obj, p7si) do { \
|
15
|
-
if (!(p7si)) { \
|
16
|
-
ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \
|
17
|
-
} \
|
18
|
-
RTYPEDDATA_DATA(obj) = (p7si); \
|
19
|
-
} while (0)
|
20
|
-
#define GetPKCS7si(obj, p7si) do { \
|
21
|
-
TypedData_Get_Struct((obj), PKCS7_SIGNER_INFO, &ossl_pkcs7_signer_info_type, (p7si)); \
|
22
|
-
if (!(p7si)) { \
|
23
|
-
ossl_raise(rb_eRuntimeError, "PKCS7si wasn't initialized."); \
|
24
|
-
} \
|
25
|
-
} while (0)
|
26
|
-
|
27
|
-
#define NewPKCS7ri(klass) \
|
28
|
-
TypedData_Wrap_Struct((klass), &ossl_pkcs7_recip_info_type, 0)
|
29
|
-
#define SetPKCS7ri(obj, p7ri) do { \
|
30
|
-
if (!(p7ri)) { \
|
31
|
-
ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \
|
32
|
-
} \
|
33
|
-
RTYPEDDATA_DATA(obj) = (p7ri); \
|
34
|
-
} while (0)
|
35
|
-
#define GetPKCS7ri(obj, p7ri) do { \
|
36
|
-
TypedData_Get_Struct((obj), PKCS7_RECIP_INFO, &ossl_pkcs7_recip_info_type, (p7ri)); \
|
37
|
-
if (!(p7ri)) { \
|
38
|
-
ossl_raise(rb_eRuntimeError, "PKCS7ri wasn't initialized."); \
|
39
|
-
} \
|
40
|
-
} while (0)
|
41
|
-
|
42
|
-
#define numberof(ary) (int)(sizeof(ary)/sizeof((ary)[0]))
|
43
|
-
|
44
|
-
#define ossl_pkcs7_set_data(o,v) rb_iv_set((o), "@data", (v))
|
45
|
-
#define ossl_pkcs7_get_data(o) rb_iv_get((o), "@data")
|
46
|
-
#define ossl_pkcs7_set_err_string(o,v) rb_iv_set((o), "@error_string", (v))
|
47
|
-
#define ossl_pkcs7_get_err_string(o) rb_iv_get((o), "@error_string")
|
48
|
-
|
49
|
-
/*
|
50
|
-
* Classes
|
51
|
-
*/
|
52
|
-
VALUE cPKCS7;
|
53
|
-
VALUE cPKCS7Signer;
|
54
|
-
VALUE cPKCS7Recipient;
|
55
|
-
VALUE ePKCS7Error;
|
56
|
-
|
57
|
-
static void
|
58
|
-
ossl_pkcs7_free(void *ptr)
|
59
|
-
{
|
60
|
-
PKCS7_free(ptr);
|
61
|
-
}
|
62
|
-
|
63
|
-
const rb_data_type_t ossl_pkcs7_type = {
|
64
|
-
"OpenSSL/PKCS7",
|
65
|
-
{
|
66
|
-
0, ossl_pkcs7_free,
|
67
|
-
},
|
68
|
-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
69
|
-
};
|
70
|
-
|
71
|
-
static void
|
72
|
-
ossl_pkcs7_signer_info_free(void *ptr)
|
73
|
-
{
|
74
|
-
PKCS7_SIGNER_INFO_free(ptr);
|
75
|
-
}
|
76
|
-
|
77
|
-
static const rb_data_type_t ossl_pkcs7_signer_info_type = {
|
78
|
-
"OpenSSL/PKCS7/SIGNER_INFO",
|
79
|
-
{
|
80
|
-
0, ossl_pkcs7_signer_info_free,
|
81
|
-
},
|
82
|
-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
83
|
-
};
|
84
|
-
|
85
|
-
static void
|
86
|
-
ossl_pkcs7_recip_info_free(void *ptr)
|
87
|
-
{
|
88
|
-
PKCS7_RECIP_INFO_free(ptr);
|
89
|
-
}
|
90
|
-
|
91
|
-
static const rb_data_type_t ossl_pkcs7_recip_info_type = {
|
92
|
-
"OpenSSL/PKCS7/RECIP_INFO",
|
93
|
-
{
|
94
|
-
0, ossl_pkcs7_recip_info_free,
|
95
|
-
},
|
96
|
-
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
97
|
-
};
|
98
|
-
|
99
|
-
/*
|
100
|
-
* Public
|
101
|
-
* (MADE PRIVATE UNTIL SOMEBODY WILL NEED THEM)
|
102
|
-
*/
|
103
|
-
static PKCS7_SIGNER_INFO *
|
104
|
-
ossl_PKCS7_SIGNER_INFO_dup(PKCS7_SIGNER_INFO *si)
|
105
|
-
{
|
106
|
-
PKCS7_SIGNER_INFO *si_new = ASN1_dup((i2d_of_void *)i2d_PKCS7_SIGNER_INFO,
|
107
|
-
(d2i_of_void *)d2i_PKCS7_SIGNER_INFO,
|
108
|
-
si);
|
109
|
-
if (si_new && si->pkey) {
|
110
|
-
EVP_PKEY_up_ref(si->pkey);
|
111
|
-
si_new->pkey = si->pkey;
|
112
|
-
}
|
113
|
-
return si_new;
|
114
|
-
}
|
115
|
-
|
116
|
-
static PKCS7_RECIP_INFO *
|
117
|
-
ossl_PKCS7_RECIP_INFO_dup(PKCS7_RECIP_INFO *si)
|
118
|
-
{
|
119
|
-
return ASN1_dup((i2d_of_void *)i2d_PKCS7_RECIP_INFO,
|
120
|
-
(d2i_of_void *)d2i_PKCS7_RECIP_INFO,
|
121
|
-
si);
|
122
|
-
}
|
123
|
-
|
124
|
-
static VALUE
|
125
|
-
ossl_pkcs7si_new(PKCS7_SIGNER_INFO *p7si)
|
126
|
-
{
|
127
|
-
PKCS7_SIGNER_INFO *pkcs7;
|
128
|
-
VALUE obj;
|
129
|
-
|
130
|
-
obj = NewPKCS7si(cPKCS7Signer);
|
131
|
-
pkcs7 = p7si ? ossl_PKCS7_SIGNER_INFO_dup(p7si) : PKCS7_SIGNER_INFO_new();
|
132
|
-
if (!pkcs7) ossl_raise(ePKCS7Error, NULL);
|
133
|
-
SetPKCS7si(obj, pkcs7);
|
134
|
-
|
135
|
-
return obj;
|
136
|
-
}
|
137
|
-
|
138
|
-
static VALUE
|
139
|
-
ossl_pkcs7ri_new(PKCS7_RECIP_INFO *p7ri)
|
140
|
-
{
|
141
|
-
PKCS7_RECIP_INFO *pkcs7;
|
142
|
-
VALUE obj;
|
143
|
-
|
144
|
-
obj = NewPKCS7ri(cPKCS7Recipient);
|
145
|
-
pkcs7 = p7ri ? ossl_PKCS7_RECIP_INFO_dup(p7ri) : PKCS7_RECIP_INFO_new();
|
146
|
-
if (!pkcs7) ossl_raise(ePKCS7Error, NULL);
|
147
|
-
SetPKCS7ri(obj, pkcs7);
|
148
|
-
|
149
|
-
return obj;
|
150
|
-
}
|
151
|
-
|
152
|
-
/*
|
153
|
-
* call-seq:
|
154
|
-
* PKCS7.read_smime(string) => pkcs7
|
155
|
-
*/
|
156
|
-
static VALUE
|
157
|
-
ossl_pkcs7_s_read_smime(VALUE klass, VALUE arg)
|
158
|
-
{
|
159
|
-
BIO *in, *out;
|
160
|
-
PKCS7 *pkcs7;
|
161
|
-
VALUE ret, data;
|
162
|
-
|
163
|
-
ret = NewPKCS7(cPKCS7);
|
164
|
-
in = ossl_obj2bio(&arg);
|
165
|
-
out = NULL;
|
166
|
-
pkcs7 = SMIME_read_PKCS7(in, &out);
|
167
|
-
BIO_free(in);
|
168
|
-
if(!pkcs7) ossl_raise(ePKCS7Error, NULL);
|
169
|
-
data = out ? ossl_membio2str(out) : Qnil;
|
170
|
-
SetPKCS7(ret, pkcs7);
|
171
|
-
ossl_pkcs7_set_data(ret, data);
|
172
|
-
ossl_pkcs7_set_err_string(ret, Qnil);
|
173
|
-
|
174
|
-
return ret;
|
175
|
-
}
|
176
|
-
|
177
|
-
/*
|
178
|
-
* call-seq:
|
179
|
-
* PKCS7.write_smime(pkcs7 [, data [, flags]]) => string
|
180
|
-
*/
|
181
|
-
static VALUE
|
182
|
-
ossl_pkcs7_s_write_smime(int argc, VALUE *argv, VALUE klass)
|
183
|
-
{
|
184
|
-
VALUE pkcs7, data, flags;
|
185
|
-
BIO *out, *in;
|
186
|
-
PKCS7 *p7;
|
187
|
-
VALUE str;
|
188
|
-
int flg;
|
189
|
-
|
190
|
-
rb_scan_args(argc, argv, "12", &pkcs7, &data, &flags);
|
191
|
-
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
|
192
|
-
if(NIL_P(data)) data = ossl_pkcs7_get_data(pkcs7);
|
193
|
-
GetPKCS7(pkcs7, p7);
|
194
|
-
if(!NIL_P(data) && PKCS7_is_detached(p7))
|
195
|
-
flg |= PKCS7_DETACHED;
|
196
|
-
in = NIL_P(data) ? NULL : ossl_obj2bio(&data);
|
197
|
-
if(!(out = BIO_new(BIO_s_mem()))){
|
198
|
-
BIO_free(in);
|
199
|
-
ossl_raise(ePKCS7Error, NULL);
|
200
|
-
}
|
201
|
-
if(!SMIME_write_PKCS7(out, p7, in, flg)){
|
202
|
-
BIO_free(out);
|
203
|
-
BIO_free(in);
|
204
|
-
ossl_raise(ePKCS7Error, NULL);
|
205
|
-
}
|
206
|
-
BIO_free(in);
|
207
|
-
str = ossl_membio2str(out);
|
208
|
-
|
209
|
-
return str;
|
210
|
-
}
|
211
|
-
|
212
|
-
/*
|
213
|
-
* call-seq:
|
214
|
-
* PKCS7.sign(cert, key, data, [, certs [, flags]]) => pkcs7
|
215
|
-
*/
|
216
|
-
static VALUE
|
217
|
-
ossl_pkcs7_s_sign(int argc, VALUE *argv, VALUE klass)
|
218
|
-
{
|
219
|
-
VALUE cert, key, data, certs, flags;
|
220
|
-
X509 *x509;
|
221
|
-
EVP_PKEY *pkey;
|
222
|
-
BIO *in;
|
223
|
-
STACK_OF(X509) *x509s;
|
224
|
-
int flg, status = 0;
|
225
|
-
PKCS7 *pkcs7;
|
226
|
-
VALUE ret;
|
227
|
-
|
228
|
-
rb_scan_args(argc, argv, "32", &cert, &key, &data, &certs, &flags);
|
229
|
-
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
|
230
|
-
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
|
231
|
-
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
|
232
|
-
ret = NewPKCS7(cPKCS7);
|
233
|
-
in = ossl_obj2bio(&data);
|
234
|
-
if(NIL_P(certs)) x509s = NULL;
|
235
|
-
else{
|
236
|
-
x509s = ossl_protect_x509_ary2sk(certs, &status);
|
237
|
-
if(status){
|
238
|
-
BIO_free(in);
|
239
|
-
rb_jump_tag(status);
|
240
|
-
}
|
241
|
-
}
|
242
|
-
if(!(pkcs7 = PKCS7_sign(x509, pkey, x509s, in, flg))){
|
243
|
-
BIO_free(in);
|
244
|
-
sk_X509_pop_free(x509s, X509_free);
|
245
|
-
ossl_raise(ePKCS7Error, NULL);
|
246
|
-
}
|
247
|
-
SetPKCS7(ret, pkcs7);
|
248
|
-
ossl_pkcs7_set_data(ret, data);
|
249
|
-
ossl_pkcs7_set_err_string(ret, Qnil);
|
250
|
-
BIO_free(in);
|
251
|
-
sk_X509_pop_free(x509s, X509_free);
|
252
|
-
|
253
|
-
return ret;
|
254
|
-
}
|
255
|
-
|
256
|
-
/*
|
257
|
-
* call-seq:
|
258
|
-
* PKCS7.encrypt(certs, data, [, cipher [, flags]]) => pkcs7
|
259
|
-
*/
|
260
|
-
static VALUE
|
261
|
-
ossl_pkcs7_s_encrypt(int argc, VALUE *argv, VALUE klass)
|
262
|
-
{
|
263
|
-
VALUE certs, data, cipher, flags;
|
264
|
-
STACK_OF(X509) *x509s;
|
265
|
-
BIO *in;
|
266
|
-
const EVP_CIPHER *ciph;
|
267
|
-
int flg, status = 0;
|
268
|
-
VALUE ret;
|
269
|
-
PKCS7 *p7;
|
270
|
-
|
271
|
-
rb_scan_args(argc, argv, "22", &certs, &data, &cipher, &flags);
|
272
|
-
if(NIL_P(cipher)){
|
273
|
-
#if !defined(OPENSSL_NO_RC2)
|
274
|
-
ciph = EVP_rc2_40_cbc();
|
275
|
-
#elif !defined(OPENSSL_NO_DES)
|
276
|
-
ciph = EVP_des_ede3_cbc();
|
277
|
-
#elif !defined(OPENSSL_NO_RC2)
|
278
|
-
ciph = EVP_rc2_40_cbc();
|
279
|
-
#elif !defined(OPENSSL_NO_AES)
|
280
|
-
ciph = EVP_EVP_aes_128_cbc();
|
281
|
-
#else
|
282
|
-
ossl_raise(ePKCS7Error, "Must specify cipher");
|
283
|
-
#endif
|
284
|
-
|
285
|
-
}
|
286
|
-
else ciph = ossl_evp_get_cipherbyname(cipher);
|
287
|
-
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
|
288
|
-
ret = NewPKCS7(cPKCS7);
|
289
|
-
in = ossl_obj2bio(&data);
|
290
|
-
x509s = ossl_protect_x509_ary2sk(certs, &status);
|
291
|
-
if(status){
|
292
|
-
BIO_free(in);
|
293
|
-
rb_jump_tag(status);
|
294
|
-
}
|
295
|
-
if(!(p7 = PKCS7_encrypt(x509s, in, (EVP_CIPHER*)ciph, flg))){
|
296
|
-
BIO_free(in);
|
297
|
-
sk_X509_pop_free(x509s, X509_free);
|
298
|
-
ossl_raise(ePKCS7Error, NULL);
|
299
|
-
}
|
300
|
-
BIO_free(in);
|
301
|
-
SetPKCS7(ret, p7);
|
302
|
-
ossl_pkcs7_set_data(ret, data);
|
303
|
-
sk_X509_pop_free(x509s, X509_free);
|
304
|
-
|
305
|
-
return ret;
|
306
|
-
}
|
307
|
-
|
308
|
-
static VALUE
|
309
|
-
ossl_pkcs7_alloc(VALUE klass)
|
310
|
-
{
|
311
|
-
PKCS7 *pkcs7;
|
312
|
-
VALUE obj;
|
313
|
-
|
314
|
-
obj = NewPKCS7(klass);
|
315
|
-
if (!(pkcs7 = PKCS7_new())) {
|
316
|
-
ossl_raise(ePKCS7Error, NULL);
|
317
|
-
}
|
318
|
-
SetPKCS7(obj, pkcs7);
|
319
|
-
|
320
|
-
return obj;
|
321
|
-
}
|
322
|
-
|
323
|
-
/*
|
324
|
-
* call-seq:
|
325
|
-
* PKCS7.new => pkcs7
|
326
|
-
* PKCS7.new(string) => pkcs7
|
327
|
-
*
|
328
|
-
* Many methods in this class aren't documented.
|
329
|
-
*/
|
330
|
-
static VALUE
|
331
|
-
ossl_pkcs7_initialize(int argc, VALUE *argv, VALUE self)
|
332
|
-
{
|
333
|
-
PKCS7 *p7, *p7_orig = RTYPEDDATA_DATA(self);
|
334
|
-
BIO *in;
|
335
|
-
VALUE arg;
|
336
|
-
|
337
|
-
if(rb_scan_args(argc, argv, "01", &arg) == 0)
|
338
|
-
return self;
|
339
|
-
arg = ossl_to_der_if_possible(arg);
|
340
|
-
in = ossl_obj2bio(&arg);
|
341
|
-
p7 = d2i_PKCS7_bio(in, NULL);
|
342
|
-
if (!p7) {
|
343
|
-
OSSL_BIO_reset(in);
|
344
|
-
p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL);
|
345
|
-
}
|
346
|
-
BIO_free(in);
|
347
|
-
if (!p7)
|
348
|
-
ossl_raise(rb_eArgError, "Could not parse the PKCS7");
|
349
|
-
|
350
|
-
RTYPEDDATA_DATA(self) = p7;
|
351
|
-
PKCS7_free(p7_orig);
|
352
|
-
ossl_pkcs7_set_data(self, Qnil);
|
353
|
-
ossl_pkcs7_set_err_string(self, Qnil);
|
354
|
-
|
355
|
-
return self;
|
356
|
-
}
|
357
|
-
|
358
|
-
static VALUE
|
359
|
-
ossl_pkcs7_copy(VALUE self, VALUE other)
|
360
|
-
{
|
361
|
-
PKCS7 *a, *b, *pkcs7;
|
362
|
-
|
363
|
-
rb_check_frozen(self);
|
364
|
-
if (self == other) return self;
|
365
|
-
|
366
|
-
GetPKCS7(self, a);
|
367
|
-
GetPKCS7(other, b);
|
368
|
-
|
369
|
-
pkcs7 = PKCS7_dup(b);
|
370
|
-
if (!pkcs7) {
|
371
|
-
ossl_raise(ePKCS7Error, NULL);
|
372
|
-
}
|
373
|
-
DATA_PTR(self) = pkcs7;
|
374
|
-
PKCS7_free(a);
|
375
|
-
|
376
|
-
return self;
|
377
|
-
}
|
378
|
-
|
379
|
-
static int
|
380
|
-
ossl_pkcs7_sym2typeid(VALUE sym)
|
381
|
-
{
|
382
|
-
int i, ret = Qnil;
|
383
|
-
const char *s;
|
384
|
-
size_t l;
|
385
|
-
|
386
|
-
static const struct {
|
387
|
-
char name[20];
|
388
|
-
int nid;
|
389
|
-
} p7_type_tab[] = {
|
390
|
-
{ "signed", NID_pkcs7_signed },
|
391
|
-
{ "data", NID_pkcs7_data },
|
392
|
-
{ "signedAndEnveloped", NID_pkcs7_signedAndEnveloped },
|
393
|
-
{ "enveloped", NID_pkcs7_enveloped },
|
394
|
-
{ "encrypted", NID_pkcs7_encrypted },
|
395
|
-
{ "digest", NID_pkcs7_digest },
|
396
|
-
};
|
397
|
-
|
398
|
-
if (SYMBOL_P(sym)) sym = rb_sym2str(sym);
|
399
|
-
else StringValue(sym);
|
400
|
-
RSTRING_GETMEM(sym, s, l);
|
401
|
-
|
402
|
-
for(i = 0; ; i++){
|
403
|
-
if(i == numberof(p7_type_tab))
|
404
|
-
ossl_raise(ePKCS7Error, "unknown type \"%"PRIsVALUE"\"", sym);
|
405
|
-
if(strlen(p7_type_tab[i].name) != l) continue;
|
406
|
-
if(strcmp(p7_type_tab[i].name, s) == 0){
|
407
|
-
ret = p7_type_tab[i].nid;
|
408
|
-
break;
|
409
|
-
}
|
410
|
-
}
|
411
|
-
|
412
|
-
return ret;
|
413
|
-
}
|
414
|
-
|
415
|
-
/*
|
416
|
-
* call-seq:
|
417
|
-
* pkcs7.type = type => type
|
418
|
-
*/
|
419
|
-
static VALUE
|
420
|
-
ossl_pkcs7_set_type(VALUE self, VALUE type)
|
421
|
-
{
|
422
|
-
PKCS7 *p7;
|
423
|
-
|
424
|
-
GetPKCS7(self, p7);
|
425
|
-
if(!PKCS7_set_type(p7, ossl_pkcs7_sym2typeid(type)))
|
426
|
-
ossl_raise(ePKCS7Error, NULL);
|
427
|
-
|
428
|
-
return type;
|
429
|
-
}
|
430
|
-
|
431
|
-
/*
|
432
|
-
* call-seq:
|
433
|
-
* pkcs7.type => string or nil
|
434
|
-
*/
|
435
|
-
static VALUE
|
436
|
-
ossl_pkcs7_get_type(VALUE self)
|
437
|
-
{
|
438
|
-
PKCS7 *p7;
|
439
|
-
|
440
|
-
GetPKCS7(self, p7);
|
441
|
-
if(PKCS7_type_is_signed(p7))
|
442
|
-
return ID2SYM(rb_intern("signed"));
|
443
|
-
if(PKCS7_type_is_encrypted(p7))
|
444
|
-
return ID2SYM(rb_intern("encrypted"));
|
445
|
-
if(PKCS7_type_is_enveloped(p7))
|
446
|
-
return ID2SYM(rb_intern("enveloped"));
|
447
|
-
if(PKCS7_type_is_signedAndEnveloped(p7))
|
448
|
-
return ID2SYM(rb_intern("signedAndEnveloped"));
|
449
|
-
if(PKCS7_type_is_data(p7))
|
450
|
-
return ID2SYM(rb_intern("data"));
|
451
|
-
return Qnil;
|
452
|
-
}
|
453
|
-
|
454
|
-
static VALUE
|
455
|
-
ossl_pkcs7_set_detached(VALUE self, VALUE flag)
|
456
|
-
{
|
457
|
-
PKCS7 *p7;
|
458
|
-
|
459
|
-
GetPKCS7(self, p7);
|
460
|
-
if(flag != Qtrue && flag != Qfalse)
|
461
|
-
ossl_raise(ePKCS7Error, "must specify a boolean");
|
462
|
-
if(!PKCS7_set_detached(p7, flag == Qtrue ? 1 : 0))
|
463
|
-
ossl_raise(ePKCS7Error, NULL);
|
464
|
-
|
465
|
-
return flag;
|
466
|
-
}
|
467
|
-
|
468
|
-
static VALUE
|
469
|
-
ossl_pkcs7_get_detached(VALUE self)
|
470
|
-
{
|
471
|
-
PKCS7 *p7;
|
472
|
-
GetPKCS7(self, p7);
|
473
|
-
return PKCS7_get_detached(p7) ? Qtrue : Qfalse;
|
474
|
-
}
|
475
|
-
|
476
|
-
static VALUE
|
477
|
-
ossl_pkcs7_detached_p(VALUE self)
|
478
|
-
{
|
479
|
-
PKCS7 *p7;
|
480
|
-
GetPKCS7(self, p7);
|
481
|
-
return PKCS7_is_detached(p7) ? Qtrue : Qfalse;
|
482
|
-
}
|
483
|
-
|
484
|
-
static VALUE
|
485
|
-
ossl_pkcs7_set_cipher(VALUE self, VALUE cipher)
|
486
|
-
{
|
487
|
-
PKCS7 *pkcs7;
|
488
|
-
|
489
|
-
GetPKCS7(self, pkcs7);
|
490
|
-
if (!PKCS7_set_cipher(pkcs7, ossl_evp_get_cipherbyname(cipher))) {
|
491
|
-
ossl_raise(ePKCS7Error, NULL);
|
492
|
-
}
|
493
|
-
|
494
|
-
return cipher;
|
495
|
-
}
|
496
|
-
|
497
|
-
static VALUE
|
498
|
-
ossl_pkcs7_add_signer(VALUE self, VALUE signer)
|
499
|
-
{
|
500
|
-
PKCS7 *pkcs7;
|
501
|
-
PKCS7_SIGNER_INFO *si, *si_new;
|
502
|
-
|
503
|
-
GetPKCS7(self, pkcs7);
|
504
|
-
GetPKCS7si(signer, si);
|
505
|
-
|
506
|
-
si_new = ossl_PKCS7_SIGNER_INFO_dup(si);
|
507
|
-
if (!si_new)
|
508
|
-
ossl_raise(ePKCS7Error, "PKCS7_SIGNER_INFO_dup");
|
509
|
-
|
510
|
-
if (PKCS7_add_signer(pkcs7, si_new) != 1) {
|
511
|
-
PKCS7_SIGNER_INFO_free(si_new);
|
512
|
-
ossl_raise(ePKCS7Error, "PKCS7_add_signer");
|
513
|
-
}
|
514
|
-
|
515
|
-
return self;
|
516
|
-
}
|
517
|
-
|
518
|
-
static VALUE
|
519
|
-
ossl_pkcs7_get_signer(VALUE self)
|
520
|
-
{
|
521
|
-
PKCS7 *pkcs7;
|
522
|
-
STACK_OF(PKCS7_SIGNER_INFO) *sk;
|
523
|
-
PKCS7_SIGNER_INFO *si;
|
524
|
-
int num, i;
|
525
|
-
VALUE ary;
|
526
|
-
|
527
|
-
GetPKCS7(self, pkcs7);
|
528
|
-
if (!(sk = PKCS7_get_signer_info(pkcs7))) {
|
529
|
-
OSSL_Debug("OpenSSL::PKCS7#get_signer_info == NULL!");
|
530
|
-
return rb_ary_new();
|
531
|
-
}
|
532
|
-
if ((num = sk_PKCS7_SIGNER_INFO_num(sk)) < 0) {
|
533
|
-
ossl_raise(ePKCS7Error, "Negative number of signers!");
|
534
|
-
}
|
535
|
-
ary = rb_ary_new2(num);
|
536
|
-
for (i=0; i<num; i++) {
|
537
|
-
si = sk_PKCS7_SIGNER_INFO_value(sk, i);
|
538
|
-
rb_ary_push(ary, ossl_pkcs7si_new(si));
|
539
|
-
}
|
540
|
-
|
541
|
-
return ary;
|
542
|
-
}
|
543
|
-
|
544
|
-
static VALUE
|
545
|
-
ossl_pkcs7_add_recipient(VALUE self, VALUE recip)
|
546
|
-
{
|
547
|
-
PKCS7 *pkcs7;
|
548
|
-
PKCS7_RECIP_INFO *ri, *ri_new;
|
549
|
-
|
550
|
-
GetPKCS7(self, pkcs7);
|
551
|
-
GetPKCS7ri(recip, ri);
|
552
|
-
|
553
|
-
ri_new = ossl_PKCS7_RECIP_INFO_dup(ri);
|
554
|
-
if (!ri_new)
|
555
|
-
ossl_raise(ePKCS7Error, "PKCS7_RECIP_INFO_dup");
|
556
|
-
|
557
|
-
if (PKCS7_add_recipient_info(pkcs7, ri_new) != 1) {
|
558
|
-
PKCS7_RECIP_INFO_free(ri_new);
|
559
|
-
ossl_raise(ePKCS7Error, "PKCS7_add_recipient_info");
|
560
|
-
}
|
561
|
-
|
562
|
-
return self;
|
563
|
-
}
|
564
|
-
|
565
|
-
static VALUE
|
566
|
-
ossl_pkcs7_get_recipient(VALUE self)
|
567
|
-
{
|
568
|
-
PKCS7 *pkcs7;
|
569
|
-
STACK_OF(PKCS7_RECIP_INFO) *sk;
|
570
|
-
PKCS7_RECIP_INFO *si;
|
571
|
-
int num, i;
|
572
|
-
VALUE ary;
|
573
|
-
|
574
|
-
GetPKCS7(self, pkcs7);
|
575
|
-
if (PKCS7_type_is_enveloped(pkcs7))
|
576
|
-
sk = pkcs7->d.enveloped->recipientinfo;
|
577
|
-
else if (PKCS7_type_is_signedAndEnveloped(pkcs7))
|
578
|
-
sk = pkcs7->d.signed_and_enveloped->recipientinfo;
|
579
|
-
else sk = NULL;
|
580
|
-
if (!sk) return rb_ary_new();
|
581
|
-
if ((num = sk_PKCS7_RECIP_INFO_num(sk)) < 0) {
|
582
|
-
ossl_raise(ePKCS7Error, "Negative number of recipient!");
|
583
|
-
}
|
584
|
-
ary = rb_ary_new2(num);
|
585
|
-
for (i=0; i<num; i++) {
|
586
|
-
si = sk_PKCS7_RECIP_INFO_value(sk, i);
|
587
|
-
rb_ary_push(ary, ossl_pkcs7ri_new(si));
|
588
|
-
}
|
589
|
-
|
590
|
-
return ary;
|
591
|
-
}
|
592
|
-
|
593
|
-
static VALUE
|
594
|
-
ossl_pkcs7_add_certificate(VALUE self, VALUE cert)
|
595
|
-
{
|
596
|
-
PKCS7 *pkcs7;
|
597
|
-
X509 *x509;
|
598
|
-
|
599
|
-
GetPKCS7(self, pkcs7);
|
600
|
-
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
|
601
|
-
if (!PKCS7_add_certificate(pkcs7, x509)){
|
602
|
-
ossl_raise(ePKCS7Error, NULL);
|
603
|
-
}
|
604
|
-
|
605
|
-
return self;
|
606
|
-
}
|
607
|
-
|
608
|
-
static STACK_OF(X509) *
|
609
|
-
pkcs7_get_certs(VALUE self)
|
610
|
-
{
|
611
|
-
PKCS7 *pkcs7;
|
612
|
-
STACK_OF(X509) *certs;
|
613
|
-
int i;
|
614
|
-
|
615
|
-
GetPKCS7(self, pkcs7);
|
616
|
-
i = OBJ_obj2nid(pkcs7->type);
|
617
|
-
switch(i){
|
618
|
-
case NID_pkcs7_signed:
|
619
|
-
certs = pkcs7->d.sign->cert;
|
620
|
-
break;
|
621
|
-
case NID_pkcs7_signedAndEnveloped:
|
622
|
-
certs = pkcs7->d.signed_and_enveloped->cert;
|
623
|
-
break;
|
624
|
-
default:
|
625
|
-
certs = NULL;
|
626
|
-
}
|
627
|
-
|
628
|
-
return certs;
|
629
|
-
}
|
630
|
-
|
631
|
-
static STACK_OF(X509_CRL) *
|
632
|
-
pkcs7_get_crls(VALUE self)
|
633
|
-
{
|
634
|
-
PKCS7 *pkcs7;
|
635
|
-
STACK_OF(X509_CRL) *crls;
|
636
|
-
int i;
|
637
|
-
|
638
|
-
GetPKCS7(self, pkcs7);
|
639
|
-
i = OBJ_obj2nid(pkcs7->type);
|
640
|
-
switch(i){
|
641
|
-
case NID_pkcs7_signed:
|
642
|
-
crls = pkcs7->d.sign->crl;
|
643
|
-
break;
|
644
|
-
case NID_pkcs7_signedAndEnveloped:
|
645
|
-
crls = pkcs7->d.signed_and_enveloped->crl;
|
646
|
-
break;
|
647
|
-
default:
|
648
|
-
crls = NULL;
|
649
|
-
}
|
650
|
-
|
651
|
-
return crls;
|
652
|
-
}
|
653
|
-
|
654
|
-
static VALUE
|
655
|
-
ossl_pkcs7_set_certs_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
|
656
|
-
{
|
657
|
-
return ossl_pkcs7_add_certificate(arg, i);
|
658
|
-
}
|
659
|
-
|
660
|
-
static VALUE
|
661
|
-
ossl_pkcs7_set_certificates(VALUE self, VALUE ary)
|
662
|
-
{
|
663
|
-
STACK_OF(X509) *certs;
|
664
|
-
X509 *cert;
|
665
|
-
|
666
|
-
certs = pkcs7_get_certs(self);
|
667
|
-
while((cert = sk_X509_pop(certs))) X509_free(cert);
|
668
|
-
rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_certs_i, self);
|
669
|
-
|
670
|
-
return ary;
|
671
|
-
}
|
672
|
-
|
673
|
-
static VALUE
|
674
|
-
ossl_pkcs7_get_certificates(VALUE self)
|
675
|
-
{
|
676
|
-
return ossl_x509_sk2ary(pkcs7_get_certs(self));
|
677
|
-
}
|
678
|
-
|
679
|
-
static VALUE
|
680
|
-
ossl_pkcs7_add_crl(VALUE self, VALUE crl)
|
681
|
-
{
|
682
|
-
PKCS7 *pkcs7;
|
683
|
-
X509_CRL *x509crl;
|
684
|
-
|
685
|
-
GetPKCS7(self, pkcs7); /* NO DUP needed! */
|
686
|
-
x509crl = GetX509CRLPtr(crl);
|
687
|
-
if (!PKCS7_add_crl(pkcs7, x509crl)) {
|
688
|
-
ossl_raise(ePKCS7Error, NULL);
|
689
|
-
}
|
690
|
-
|
691
|
-
return self;
|
692
|
-
}
|
693
|
-
|
694
|
-
static VALUE
|
695
|
-
ossl_pkcs7_set_crls_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, arg))
|
696
|
-
{
|
697
|
-
return ossl_pkcs7_add_crl(arg, i);
|
698
|
-
}
|
699
|
-
|
700
|
-
static VALUE
|
701
|
-
ossl_pkcs7_set_crls(VALUE self, VALUE ary)
|
702
|
-
{
|
703
|
-
STACK_OF(X509_CRL) *crls;
|
704
|
-
X509_CRL *crl;
|
705
|
-
|
706
|
-
crls = pkcs7_get_crls(self);
|
707
|
-
while((crl = sk_X509_CRL_pop(crls))) X509_CRL_free(crl);
|
708
|
-
rb_block_call(ary, rb_intern("each"), 0, 0, ossl_pkcs7_set_crls_i, self);
|
709
|
-
|
710
|
-
return ary;
|
711
|
-
}
|
712
|
-
|
713
|
-
static VALUE
|
714
|
-
ossl_pkcs7_get_crls(VALUE self)
|
715
|
-
{
|
716
|
-
return ossl_x509crl_sk2ary(pkcs7_get_crls(self));
|
717
|
-
}
|
718
|
-
|
719
|
-
static VALUE
|
720
|
-
ossl_pkcs7_verify(int argc, VALUE *argv, VALUE self)
|
721
|
-
{
|
722
|
-
VALUE certs, store, indata, flags;
|
723
|
-
STACK_OF(X509) *x509s;
|
724
|
-
X509_STORE *x509st;
|
725
|
-
int flg, ok, status = 0;
|
726
|
-
BIO *in, *out;
|
727
|
-
PKCS7 *p7;
|
728
|
-
VALUE data;
|
729
|
-
const char *msg;
|
730
|
-
|
731
|
-
GetPKCS7(self, p7);
|
732
|
-
rb_scan_args(argc, argv, "22", &certs, &store, &indata, &flags);
|
733
|
-
x509st = GetX509StorePtr(store);
|
734
|
-
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
|
735
|
-
if(NIL_P(indata)) indata = ossl_pkcs7_get_data(self);
|
736
|
-
in = NIL_P(indata) ? NULL : ossl_obj2bio(&indata);
|
737
|
-
if(NIL_P(certs)) x509s = NULL;
|
738
|
-
else{
|
739
|
-
x509s = ossl_protect_x509_ary2sk(certs, &status);
|
740
|
-
if(status){
|
741
|
-
BIO_free(in);
|
742
|
-
rb_jump_tag(status);
|
743
|
-
}
|
744
|
-
}
|
745
|
-
if(!(out = BIO_new(BIO_s_mem()))){
|
746
|
-
BIO_free(in);
|
747
|
-
sk_X509_pop_free(x509s, X509_free);
|
748
|
-
ossl_raise(ePKCS7Error, NULL);
|
749
|
-
}
|
750
|
-
ok = PKCS7_verify(p7, x509s, x509st, in, out, flg);
|
751
|
-
BIO_free(in);
|
752
|
-
sk_X509_pop_free(x509s, X509_free);
|
753
|
-
if (ok < 0) ossl_raise(ePKCS7Error, "PKCS7_verify");
|
754
|
-
msg = ERR_reason_error_string(ERR_peek_error());
|
755
|
-
ossl_pkcs7_set_err_string(self, msg ? rb_str_new2(msg) : Qnil);
|
756
|
-
ossl_clear_error();
|
757
|
-
data = ossl_membio2str(out);
|
758
|
-
ossl_pkcs7_set_data(self, data);
|
759
|
-
|
760
|
-
return (ok == 1) ? Qtrue : Qfalse;
|
761
|
-
}
|
762
|
-
|
763
|
-
static VALUE
|
764
|
-
ossl_pkcs7_decrypt(int argc, VALUE *argv, VALUE self)
|
765
|
-
{
|
766
|
-
VALUE pkey, cert, flags;
|
767
|
-
EVP_PKEY *key;
|
768
|
-
X509 *x509;
|
769
|
-
int flg;
|
770
|
-
PKCS7 *p7;
|
771
|
-
BIO *out;
|
772
|
-
VALUE str;
|
773
|
-
|
774
|
-
rb_scan_args(argc, argv, "12", &pkey, &cert, &flags);
|
775
|
-
key = GetPrivPKeyPtr(pkey); /* NO NEED TO DUP */
|
776
|
-
x509 = NIL_P(cert) ? NULL : GetX509CertPtr(cert); /* NO NEED TO DUP */
|
777
|
-
flg = NIL_P(flags) ? 0 : NUM2INT(flags);
|
778
|
-
GetPKCS7(self, p7);
|
779
|
-
if(!(out = BIO_new(BIO_s_mem())))
|
780
|
-
ossl_raise(ePKCS7Error, NULL);
|
781
|
-
if(!PKCS7_decrypt(p7, key, x509, out, flg)){
|
782
|
-
BIO_free(out);
|
783
|
-
ossl_raise(ePKCS7Error, NULL);
|
784
|
-
}
|
785
|
-
str = ossl_membio2str(out); /* out will be free */
|
786
|
-
|
787
|
-
return str;
|
788
|
-
}
|
789
|
-
|
790
|
-
static VALUE
|
791
|
-
ossl_pkcs7_add_data(VALUE self, VALUE data)
|
792
|
-
{
|
793
|
-
PKCS7 *pkcs7;
|
794
|
-
BIO *out, *in;
|
795
|
-
char buf[4096];
|
796
|
-
int len;
|
797
|
-
|
798
|
-
GetPKCS7(self, pkcs7);
|
799
|
-
if(PKCS7_type_is_signed(pkcs7)){
|
800
|
-
if(!PKCS7_content_new(pkcs7, NID_pkcs7_data))
|
801
|
-
ossl_raise(ePKCS7Error, NULL);
|
802
|
-
}
|
803
|
-
in = ossl_obj2bio(&data);
|
804
|
-
if(!(out = PKCS7_dataInit(pkcs7, NULL))) goto err;
|
805
|
-
for(;;){
|
806
|
-
if((len = BIO_read(in, buf, sizeof(buf))) <= 0)
|
807
|
-
break;
|
808
|
-
if(BIO_write(out, buf, len) != len)
|
809
|
-
goto err;
|
810
|
-
}
|
811
|
-
if(!PKCS7_dataFinal(pkcs7, out)) goto err;
|
812
|
-
ossl_pkcs7_set_data(self, Qnil);
|
813
|
-
|
814
|
-
err:
|
815
|
-
BIO_free_all(out);
|
816
|
-
BIO_free(in);
|
817
|
-
if(ERR_peek_error()){
|
818
|
-
ossl_raise(ePKCS7Error, NULL);
|
819
|
-
}
|
820
|
-
|
821
|
-
return data;
|
822
|
-
}
|
823
|
-
|
824
|
-
static VALUE
|
825
|
-
ossl_pkcs7_to_der(VALUE self)
|
826
|
-
{
|
827
|
-
PKCS7 *pkcs7;
|
828
|
-
VALUE str;
|
829
|
-
long len;
|
830
|
-
unsigned char *p;
|
831
|
-
|
832
|
-
GetPKCS7(self, pkcs7);
|
833
|
-
if((len = i2d_PKCS7(pkcs7, NULL)) <= 0)
|
834
|
-
ossl_raise(ePKCS7Error, NULL);
|
835
|
-
str = rb_str_new(0, len);
|
836
|
-
p = (unsigned char *)RSTRING_PTR(str);
|
837
|
-
if(i2d_PKCS7(pkcs7, &p) <= 0)
|
838
|
-
ossl_raise(ePKCS7Error, NULL);
|
839
|
-
ossl_str_adjust(str, p);
|
840
|
-
|
841
|
-
return str;
|
842
|
-
}
|
843
|
-
|
844
|
-
static VALUE
|
845
|
-
ossl_pkcs7_to_pem(VALUE self)
|
846
|
-
{
|
847
|
-
PKCS7 *pkcs7;
|
848
|
-
BIO *out;
|
849
|
-
VALUE str;
|
850
|
-
|
851
|
-
GetPKCS7(self, pkcs7);
|
852
|
-
if (!(out = BIO_new(BIO_s_mem()))) {
|
853
|
-
ossl_raise(ePKCS7Error, NULL);
|
854
|
-
}
|
855
|
-
if (!PEM_write_bio_PKCS7(out, pkcs7)) {
|
856
|
-
BIO_free(out);
|
857
|
-
ossl_raise(ePKCS7Error, NULL);
|
858
|
-
}
|
859
|
-
str = ossl_membio2str(out);
|
860
|
-
|
861
|
-
return str;
|
862
|
-
}
|
863
|
-
|
864
|
-
/*
|
865
|
-
* SIGNER INFO
|
866
|
-
*/
|
867
|
-
static VALUE
|
868
|
-
ossl_pkcs7si_alloc(VALUE klass)
|
869
|
-
{
|
870
|
-
PKCS7_SIGNER_INFO *p7si;
|
871
|
-
VALUE obj;
|
872
|
-
|
873
|
-
obj = NewPKCS7si(klass);
|
874
|
-
if (!(p7si = PKCS7_SIGNER_INFO_new())) {
|
875
|
-
ossl_raise(ePKCS7Error, NULL);
|
876
|
-
}
|
877
|
-
SetPKCS7si(obj, p7si);
|
878
|
-
|
879
|
-
return obj;
|
880
|
-
}
|
881
|
-
|
882
|
-
static VALUE
|
883
|
-
ossl_pkcs7si_initialize(VALUE self, VALUE cert, VALUE key, VALUE digest)
|
884
|
-
{
|
885
|
-
PKCS7_SIGNER_INFO *p7si;
|
886
|
-
EVP_PKEY *pkey;
|
887
|
-
X509 *x509;
|
888
|
-
const EVP_MD *md;
|
889
|
-
|
890
|
-
pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
|
891
|
-
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
|
892
|
-
md = ossl_evp_get_digestbyname(digest);
|
893
|
-
GetPKCS7si(self, p7si);
|
894
|
-
if (!(PKCS7_SIGNER_INFO_set(p7si, x509, pkey, (EVP_MD*)md))) {
|
895
|
-
ossl_raise(ePKCS7Error, NULL);
|
896
|
-
}
|
897
|
-
|
898
|
-
return self;
|
899
|
-
}
|
900
|
-
|
901
|
-
static VALUE
|
902
|
-
ossl_pkcs7si_get_issuer(VALUE self)
|
903
|
-
{
|
904
|
-
PKCS7_SIGNER_INFO *p7si;
|
905
|
-
|
906
|
-
GetPKCS7si(self, p7si);
|
907
|
-
|
908
|
-
return ossl_x509name_new(p7si->issuer_and_serial->issuer);
|
909
|
-
}
|
910
|
-
|
911
|
-
static VALUE
|
912
|
-
ossl_pkcs7si_get_serial(VALUE self)
|
913
|
-
{
|
914
|
-
PKCS7_SIGNER_INFO *p7si;
|
915
|
-
|
916
|
-
GetPKCS7si(self, p7si);
|
917
|
-
|
918
|
-
return asn1integer_to_num(p7si->issuer_and_serial->serial);
|
919
|
-
}
|
920
|
-
|
921
|
-
static VALUE
|
922
|
-
ossl_pkcs7si_get_signed_time(VALUE self)
|
923
|
-
{
|
924
|
-
PKCS7_SIGNER_INFO *p7si;
|
925
|
-
ASN1_TYPE *asn1obj;
|
926
|
-
|
927
|
-
GetPKCS7si(self, p7si);
|
928
|
-
|
929
|
-
if (!(asn1obj = PKCS7_get_signed_attribute(p7si, NID_pkcs9_signingTime))) {
|
930
|
-
ossl_raise(ePKCS7Error, NULL);
|
931
|
-
}
|
932
|
-
if (asn1obj->type == V_ASN1_UTCTIME) {
|
933
|
-
return asn1time_to_time(asn1obj->value.utctime);
|
934
|
-
}
|
935
|
-
/*
|
936
|
-
* OR
|
937
|
-
* ossl_raise(ePKCS7Error, "...");
|
938
|
-
* ?
|
939
|
-
*/
|
940
|
-
|
941
|
-
return Qnil;
|
942
|
-
}
|
943
|
-
|
944
|
-
/*
|
945
|
-
* RECIPIENT INFO
|
946
|
-
*/
|
947
|
-
static VALUE
|
948
|
-
ossl_pkcs7ri_alloc(VALUE klass)
|
949
|
-
{
|
950
|
-
PKCS7_RECIP_INFO *p7ri;
|
951
|
-
VALUE obj;
|
952
|
-
|
953
|
-
obj = NewPKCS7ri(klass);
|
954
|
-
if (!(p7ri = PKCS7_RECIP_INFO_new())) {
|
955
|
-
ossl_raise(ePKCS7Error, NULL);
|
956
|
-
}
|
957
|
-
SetPKCS7ri(obj, p7ri);
|
958
|
-
|
959
|
-
return obj;
|
960
|
-
}
|
961
|
-
|
962
|
-
static VALUE
|
963
|
-
ossl_pkcs7ri_initialize(VALUE self, VALUE cert)
|
964
|
-
{
|
965
|
-
PKCS7_RECIP_INFO *p7ri;
|
966
|
-
X509 *x509;
|
967
|
-
|
968
|
-
x509 = GetX509CertPtr(cert); /* NO NEED TO DUP */
|
969
|
-
GetPKCS7ri(self, p7ri);
|
970
|
-
if (!PKCS7_RECIP_INFO_set(p7ri, x509)) {
|
971
|
-
ossl_raise(ePKCS7Error, NULL);
|
972
|
-
}
|
973
|
-
|
974
|
-
return self;
|
975
|
-
}
|
976
|
-
|
977
|
-
static VALUE
|
978
|
-
ossl_pkcs7ri_get_issuer(VALUE self)
|
979
|
-
{
|
980
|
-
PKCS7_RECIP_INFO *p7ri;
|
981
|
-
|
982
|
-
GetPKCS7ri(self, p7ri);
|
983
|
-
|
984
|
-
return ossl_x509name_new(p7ri->issuer_and_serial->issuer);
|
985
|
-
}
|
986
|
-
|
987
|
-
static VALUE
|
988
|
-
ossl_pkcs7ri_get_serial(VALUE self)
|
989
|
-
{
|
990
|
-
PKCS7_RECIP_INFO *p7ri;
|
991
|
-
|
992
|
-
GetPKCS7ri(self, p7ri);
|
993
|
-
|
994
|
-
return asn1integer_to_num(p7ri->issuer_and_serial->serial);
|
995
|
-
}
|
996
|
-
|
997
|
-
static VALUE
|
998
|
-
ossl_pkcs7ri_get_enc_key(VALUE self)
|
999
|
-
{
|
1000
|
-
PKCS7_RECIP_INFO *p7ri;
|
1001
|
-
|
1002
|
-
GetPKCS7ri(self, p7ri);
|
1003
|
-
|
1004
|
-
return asn1str_to_str(p7ri->enc_key);
|
1005
|
-
}
|
1006
|
-
|
1007
|
-
/*
|
1008
|
-
* INIT
|
1009
|
-
*/
|
1010
|
-
void
|
1011
|
-
Init_ossl_pkcs7(void)
|
1012
|
-
{
|
1013
|
-
#undef rb_intern
|
1014
|
-
#if 0
|
1015
|
-
mOSSL = rb_define_module("OpenSSL");
|
1016
|
-
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
1017
|
-
#endif
|
1018
|
-
|
1019
|
-
cPKCS7 = rb_define_class_under(mOSSL, "PKCS7", rb_cObject);
|
1020
|
-
ePKCS7Error = rb_define_class_under(cPKCS7, "PKCS7Error", eOSSLError);
|
1021
|
-
rb_define_singleton_method(cPKCS7, "read_smime", ossl_pkcs7_s_read_smime, 1);
|
1022
|
-
rb_define_singleton_method(cPKCS7, "write_smime", ossl_pkcs7_s_write_smime, -1);
|
1023
|
-
rb_define_singleton_method(cPKCS7, "sign", ossl_pkcs7_s_sign, -1);
|
1024
|
-
rb_define_singleton_method(cPKCS7, "encrypt", ossl_pkcs7_s_encrypt, -1);
|
1025
|
-
rb_attr(cPKCS7, rb_intern("data"), 1, 0, Qfalse);
|
1026
|
-
rb_attr(cPKCS7, rb_intern("error_string"), 1, 1, Qfalse);
|
1027
|
-
rb_define_alloc_func(cPKCS7, ossl_pkcs7_alloc);
|
1028
|
-
rb_define_method(cPKCS7, "initialize_copy", ossl_pkcs7_copy, 1);
|
1029
|
-
rb_define_method(cPKCS7, "initialize", ossl_pkcs7_initialize, -1);
|
1030
|
-
rb_define_method(cPKCS7, "type=", ossl_pkcs7_set_type, 1);
|
1031
|
-
rb_define_method(cPKCS7, "type", ossl_pkcs7_get_type, 0);
|
1032
|
-
rb_define_method(cPKCS7, "detached=", ossl_pkcs7_set_detached, 1);
|
1033
|
-
rb_define_method(cPKCS7, "detached", ossl_pkcs7_get_detached, 0);
|
1034
|
-
rb_define_method(cPKCS7, "detached?", ossl_pkcs7_detached_p, 0);
|
1035
|
-
rb_define_method(cPKCS7, "cipher=", ossl_pkcs7_set_cipher, 1);
|
1036
|
-
rb_define_method(cPKCS7, "add_signer", ossl_pkcs7_add_signer, 1);
|
1037
|
-
rb_define_method(cPKCS7, "signers", ossl_pkcs7_get_signer, 0);
|
1038
|
-
rb_define_method(cPKCS7, "add_recipient", ossl_pkcs7_add_recipient, 1);
|
1039
|
-
rb_define_method(cPKCS7, "recipients", ossl_pkcs7_get_recipient, 0);
|
1040
|
-
rb_define_method(cPKCS7, "add_certificate", ossl_pkcs7_add_certificate, 1);
|
1041
|
-
rb_define_method(cPKCS7, "certificates=", ossl_pkcs7_set_certificates, 1);
|
1042
|
-
rb_define_method(cPKCS7, "certificates", ossl_pkcs7_get_certificates, 0);
|
1043
|
-
rb_define_method(cPKCS7, "add_crl", ossl_pkcs7_add_crl, 1);
|
1044
|
-
rb_define_method(cPKCS7, "crls=", ossl_pkcs7_set_crls, 1);
|
1045
|
-
rb_define_method(cPKCS7, "crls", ossl_pkcs7_get_crls, 0);
|
1046
|
-
rb_define_method(cPKCS7, "add_data", ossl_pkcs7_add_data, 1);
|
1047
|
-
rb_define_alias(cPKCS7, "data=", "add_data");
|
1048
|
-
rb_define_method(cPKCS7, "verify", ossl_pkcs7_verify, -1);
|
1049
|
-
rb_define_method(cPKCS7, "decrypt", ossl_pkcs7_decrypt, -1);
|
1050
|
-
rb_define_method(cPKCS7, "to_pem", ossl_pkcs7_to_pem, 0);
|
1051
|
-
rb_define_alias(cPKCS7, "to_s", "to_pem");
|
1052
|
-
rb_define_method(cPKCS7, "to_der", ossl_pkcs7_to_der, 0);
|
1053
|
-
|
1054
|
-
cPKCS7Signer = rb_define_class_under(cPKCS7, "SignerInfo", rb_cObject);
|
1055
|
-
rb_define_const(cPKCS7, "Signer", cPKCS7Signer);
|
1056
|
-
rb_define_alloc_func(cPKCS7Signer, ossl_pkcs7si_alloc);
|
1057
|
-
rb_define_method(cPKCS7Signer, "initialize", ossl_pkcs7si_initialize,3);
|
1058
|
-
rb_define_method(cPKCS7Signer, "issuer", ossl_pkcs7si_get_issuer, 0);
|
1059
|
-
rb_define_method(cPKCS7Signer, "serial", ossl_pkcs7si_get_serial,0);
|
1060
|
-
rb_define_method(cPKCS7Signer,"signed_time",ossl_pkcs7si_get_signed_time,0);
|
1061
|
-
|
1062
|
-
cPKCS7Recipient = rb_define_class_under(cPKCS7,"RecipientInfo",rb_cObject);
|
1063
|
-
rb_define_alloc_func(cPKCS7Recipient, ossl_pkcs7ri_alloc);
|
1064
|
-
rb_define_method(cPKCS7Recipient, "initialize", ossl_pkcs7ri_initialize,1);
|
1065
|
-
rb_define_method(cPKCS7Recipient, "issuer", ossl_pkcs7ri_get_issuer,0);
|
1066
|
-
rb_define_method(cPKCS7Recipient, "serial", ossl_pkcs7ri_get_serial,0);
|
1067
|
-
rb_define_method(cPKCS7Recipient, "enc_key", ossl_pkcs7ri_get_enc_key,0);
|
1068
|
-
|
1069
|
-
#define DefPKCS7Const(x) rb_define_const(cPKCS7, #x, INT2NUM(PKCS7_##x))
|
1070
|
-
|
1071
|
-
DefPKCS7Const(TEXT);
|
1072
|
-
DefPKCS7Const(NOCERTS);
|
1073
|
-
DefPKCS7Const(NOSIGS);
|
1074
|
-
DefPKCS7Const(NOCHAIN);
|
1075
|
-
DefPKCS7Const(NOINTERN);
|
1076
|
-
DefPKCS7Const(NOVERIFY);
|
1077
|
-
DefPKCS7Const(DETACHED);
|
1078
|
-
DefPKCS7Const(BINARY);
|
1079
|
-
DefPKCS7Const(NOATTR);
|
1080
|
-
DefPKCS7Const(NOSMIMECAP);
|
1081
|
-
}
|