rubysl-openssl 1.0.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +5 -6
- data/ext/rubysl/openssl/.gitignore +3 -0
- data/ext/rubysl/openssl/deprecation.rb +21 -0
- data/ext/rubysl/openssl/extconf.rb +45 -32
- data/ext/rubysl/openssl/openssl_missing.c +20 -7
- data/ext/rubysl/openssl/openssl_missing.h +22 -15
- data/ext/rubysl/openssl/ossl.c +610 -61
- data/ext/rubysl/openssl/ossl.h +31 -17
- data/ext/rubysl/openssl/ossl_asn1.c +974 -183
- data/ext/rubysl/openssl/ossl_asn1.h +3 -3
- data/ext/rubysl/openssl/ossl_bio.c +4 -3
- data/ext/rubysl/openssl/ossl_bio.h +1 -1
- data/ext/rubysl/openssl/ossl_bn.c +32 -28
- data/ext/rubysl/openssl/ossl_bn.h +1 -1
- data/ext/rubysl/openssl/ossl_cipher.c +494 -93
- data/ext/rubysl/openssl/ossl_cipher.h +1 -1
- data/ext/rubysl/openssl/ossl_config.c +4 -5
- data/ext/rubysl/openssl/ossl_config.h +1 -1
- data/ext/rubysl/openssl/ossl_digest.c +206 -24
- data/ext/rubysl/openssl/ossl_digest.h +1 -1
- data/ext/rubysl/openssl/ossl_engine.c +48 -26
- data/ext/rubysl/openssl/ossl_engine.h +1 -1
- data/ext/rubysl/openssl/ossl_hmac.c +40 -38
- data/ext/rubysl/openssl/ossl_hmac.h +1 -1
- data/ext/rubysl/openssl/ossl_ns_spki.c +157 -25
- data/ext/rubysl/openssl/ossl_ns_spki.h +1 -1
- data/ext/rubysl/openssl/ossl_ocsp.c +57 -40
- data/ext/rubysl/openssl/ossl_ocsp.h +1 -1
- data/ext/rubysl/openssl/ossl_pkcs12.c +15 -13
- data/ext/rubysl/openssl/ossl_pkcs12.h +1 -1
- data/ext/rubysl/openssl/ossl_pkcs5.c +108 -18
- data/ext/rubysl/openssl/ossl_pkcs7.c +44 -37
- data/ext/rubysl/openssl/ossl_pkcs7.h +1 -1
- data/ext/rubysl/openssl/ossl_pkey.c +211 -15
- data/ext/rubysl/openssl/ossl_pkey.h +19 -9
- data/ext/rubysl/openssl/ossl_pkey_dh.c +180 -47
- data/ext/rubysl/openssl/ossl_pkey_dsa.c +184 -47
- data/ext/rubysl/openssl/ossl_pkey_ec.c +177 -93
- data/ext/rubysl/openssl/ossl_pkey_rsa.c +209 -102
- data/ext/rubysl/openssl/ossl_rand.c +15 -15
- data/ext/rubysl/openssl/ossl_rand.h +1 -1
- data/ext/rubysl/openssl/ossl_ssl.c +939 -192
- data/ext/rubysl/openssl/ossl_ssl.h +6 -6
- data/ext/rubysl/openssl/ossl_ssl_session.c +78 -62
- data/ext/rubysl/openssl/ossl_version.h +2 -2
- data/ext/rubysl/openssl/ossl_x509.c +1 -1
- data/ext/rubysl/openssl/ossl_x509.h +1 -1
- data/ext/rubysl/openssl/ossl_x509attr.c +20 -19
- data/ext/rubysl/openssl/ossl_x509cert.c +169 -67
- data/ext/rubysl/openssl/ossl_x509crl.c +41 -39
- data/ext/rubysl/openssl/ossl_x509ext.c +51 -38
- data/ext/rubysl/openssl/ossl_x509name.c +139 -29
- data/ext/rubysl/openssl/ossl_x509req.c +42 -40
- data/ext/rubysl/openssl/ossl_x509revoked.c +20 -20
- data/ext/rubysl/openssl/ossl_x509store.c +99 -47
- data/ext/rubysl/openssl/ruby_missing.h +3 -16
- data/lib/openssl/bn.rb +19 -19
- data/lib/openssl/buffering.rb +222 -14
- data/lib/openssl/cipher.rb +20 -20
- data/lib/openssl/config.rb +1 -4
- data/lib/openssl/digest.rb +47 -19
- data/lib/openssl/ssl.rb +197 -1
- data/lib/openssl/x509.rb +162 -1
- data/lib/rubysl/openssl.rb +4 -8
- data/lib/rubysl/openssl/version.rb +1 -1
- data/rubysl-openssl.gemspec +1 -2
- metadata +16 -34
- data/ext/rubysl/openssl/extconf.h +0 -50
- data/lib/openssl/net/ftptls.rb +0 -53
- data/lib/openssl/net/telnets.rb +0 -251
- data/lib/openssl/pkcs7.rb +0 -25
- data/lib/openssl/ssl-internal.rb +0 -187
- data/lib/openssl/x509-internal.rb +0 -153
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* $Id
|
2
|
+
* $Id$
|
3
3
|
* 'OpenSSL for Ruby' project
|
4
4
|
* Copyright (C) 2001 Michal Rokos <m.rokos@sh.cvut.cz>
|
5
5
|
* All rights reserved.
|
@@ -11,20 +11,20 @@
|
|
11
11
|
#include "ossl.h"
|
12
12
|
|
13
13
|
#define WrapX509Name(klass, obj, name) do { \
|
14
|
-
if (!name) { \
|
14
|
+
if (!(name)) { \
|
15
15
|
ossl_raise(rb_eRuntimeError, "Name wasn't initialized."); \
|
16
16
|
} \
|
17
|
-
obj = Data_Wrap_Struct(klass, 0, X509_NAME_free, name); \
|
17
|
+
(obj) = Data_Wrap_Struct((klass), 0, X509_NAME_free, (name)); \
|
18
18
|
} while (0)
|
19
19
|
#define GetX509Name(obj, name) do { \
|
20
|
-
Data_Get_Struct(obj, X509_NAME, name); \
|
21
|
-
if (!name) { \
|
20
|
+
Data_Get_Struct((obj), X509_NAME, (name)); \
|
21
|
+
if (!(name)) { \
|
22
22
|
ossl_raise(rb_eRuntimeError, "Name wasn't initialized."); \
|
23
23
|
} \
|
24
24
|
} while (0)
|
25
25
|
#define SafeGetX509Name(obj, name) do { \
|
26
|
-
OSSL_Check_Kind(obj, cX509Name); \
|
27
|
-
GetX509Name(obj, name); \
|
26
|
+
OSSL_Check_Kind((obj), cX509Name); \
|
27
|
+
GetX509Name((obj), (name)); \
|
28
28
|
} while (0)
|
29
29
|
|
30
30
|
#define OBJECT_TYPE_TEMPLATE \
|
@@ -41,7 +41,7 @@ VALUE eX509NameError;
|
|
41
41
|
/*
|
42
42
|
* Public
|
43
43
|
*/
|
44
|
-
VALUE
|
44
|
+
VALUE
|
45
45
|
ossl_x509name_new(X509_NAME *name)
|
46
46
|
{
|
47
47
|
X509_NAME *new;
|
@@ -56,7 +56,7 @@ ossl_x509name_new(X509_NAME *name)
|
|
56
56
|
ossl_raise(eX509NameError, NULL);
|
57
57
|
}
|
58
58
|
WrapX509Name(cX509Name, obj, new);
|
59
|
-
|
59
|
+
|
60
60
|
return obj;
|
61
61
|
}
|
62
62
|
|
@@ -78,7 +78,7 @@ ossl_x509name_alloc(VALUE klass)
|
|
78
78
|
{
|
79
79
|
X509_NAME *name;
|
80
80
|
VALUE obj;
|
81
|
-
|
81
|
+
|
82
82
|
if (!(name = X509_NAME_new())) {
|
83
83
|
ossl_raise(eX509NameError, NULL);
|
84
84
|
}
|
@@ -87,9 +87,9 @@ ossl_x509name_alloc(VALUE klass)
|
|
87
87
|
return obj;
|
88
88
|
}
|
89
89
|
|
90
|
-
static
|
90
|
+
static ID id_aref;
|
91
91
|
static VALUE ossl_x509name_add_entry(int, VALUE*, VALUE);
|
92
|
-
#define rb_aref(obj, key) rb_funcall(obj, id_aref, 1, key)
|
92
|
+
#define rb_aref(obj, key) rb_funcall((obj), id_aref, 1, (key))
|
93
93
|
|
94
94
|
static VALUE
|
95
95
|
ossl_x509name_init_i(VALUE i, VALUE args)
|
@@ -111,10 +111,23 @@ ossl_x509name_init_i(VALUE i, VALUE args)
|
|
111
111
|
|
112
112
|
/*
|
113
113
|
* call-seq:
|
114
|
-
* X509::Name.new
|
115
|
-
* X509::Name.new(
|
116
|
-
* X509::Name.new(
|
117
|
-
* X509::Name.new(
|
114
|
+
* X509::Name.new => name
|
115
|
+
* X509::Name.new(der) => name
|
116
|
+
* X509::Name.new(distinguished_name) => name
|
117
|
+
* X509::Name.new(distinguished_name, template) => name
|
118
|
+
*
|
119
|
+
* Creates a new Name.
|
120
|
+
*
|
121
|
+
* A name may be created from a DER encoded string +der+, an Array
|
122
|
+
* representing a +distinguished_name+ or a +distinguished_name+ along with a
|
123
|
+
* +template+.
|
124
|
+
*
|
125
|
+
* name = OpenSSL::X509::Name.new [['CN', 'nobody'], ['DC', 'example']]
|
126
|
+
*
|
127
|
+
* name = OpenSSL::X509::Name.new name.to_der
|
128
|
+
*
|
129
|
+
* See add_entry for a description of the +distinguished_name+ Array's
|
130
|
+
* contents
|
118
131
|
*/
|
119
132
|
static VALUE
|
120
133
|
ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
|
@@ -154,6 +167,16 @@ ossl_x509name_initialize(int argc, VALUE *argv, VALUE self)
|
|
154
167
|
/*
|
155
168
|
* call-seq:
|
156
169
|
* name.add_entry(oid, value [, type]) => self
|
170
|
+
*
|
171
|
+
* Adds a new entry with the given +oid+ and +value+ to this name. The +oid+
|
172
|
+
* is an object identifier defined in ASN.1. Some common OIDs are:
|
173
|
+
*
|
174
|
+
* C:: Country Name
|
175
|
+
* CN:: Common Name
|
176
|
+
* DC:: Domain Component
|
177
|
+
* O:: Organization Name
|
178
|
+
* OU:: Organizational Unit Name
|
179
|
+
* ST:: State or Province Name
|
157
180
|
*/
|
158
181
|
static
|
159
182
|
VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
|
@@ -167,7 +190,7 @@ VALUE ossl_x509name_add_entry(int argc, VALUE *argv, VALUE self)
|
|
167
190
|
if(NIL_P(type)) type = rb_aref(OBJECT_TYPE_TEMPLATE, oid);
|
168
191
|
GetX509Name(self, name);
|
169
192
|
if (!X509_NAME_add_entry_by_txt(name, RSTRING_PTR(oid), NUM2INT(type),
|
170
|
-
RSTRING_PTR(value),
|
193
|
+
(const unsigned char *)RSTRING_PTR(value), RSTRING_LENINT(value), -1, 0)) {
|
171
194
|
ossl_raise(eX509NameError, NULL);
|
172
195
|
}
|
173
196
|
|
@@ -192,7 +215,14 @@ ossl_x509name_to_s_old(VALUE self)
|
|
192
215
|
/*
|
193
216
|
* call-seq:
|
194
217
|
* name.to_s => string
|
195
|
-
* name.to_s(
|
218
|
+
* name.to_s(flags) => string
|
219
|
+
*
|
220
|
+
* Returns this name as a Distinguished Name string. +flags+ may be one of:
|
221
|
+
*
|
222
|
+
* * OpenSSL::X509::Name::COMPAT
|
223
|
+
* * OpenSSL::X509::Name::RFC2253
|
224
|
+
* * OpenSSL::X509::Name::ONELINE
|
225
|
+
* * OpenSSL::X509::Name::MULTILINE
|
196
226
|
*/
|
197
227
|
static VALUE
|
198
228
|
ossl_x509name_to_s(int argc, VALUE *argv, VALUE self)
|
@@ -221,17 +251,20 @@ ossl_x509name_to_s(int argc, VALUE *argv, VALUE self)
|
|
221
251
|
/*
|
222
252
|
* call-seq:
|
223
253
|
* name.to_a => [[name, data, type], ...]
|
254
|
+
*
|
255
|
+
* Returns an Array representation of the distinguished name suitable for
|
256
|
+
* passing to ::new
|
224
257
|
*/
|
225
|
-
static VALUE
|
258
|
+
static VALUE
|
226
259
|
ossl_x509name_to_a(VALUE self)
|
227
260
|
{
|
228
261
|
X509_NAME *name;
|
229
262
|
X509_NAME_ENTRY *entry;
|
230
|
-
int i,entries;
|
263
|
+
int i,entries,nid;
|
231
264
|
char long_name[512];
|
232
265
|
const char *short_name;
|
233
|
-
VALUE ary, ret;
|
234
|
-
|
266
|
+
VALUE ary, vname, ret;
|
267
|
+
|
235
268
|
GetX509Name(self, name);
|
236
269
|
entries = X509_NAME_entry_count(name);
|
237
270
|
if (entries < 0) {
|
@@ -246,9 +279,16 @@ ossl_x509name_to_a(VALUE self)
|
|
246
279
|
if (!i2t_ASN1_OBJECT(long_name, sizeof(long_name), entry->object)) {
|
247
280
|
ossl_raise(eX509NameError, NULL);
|
248
281
|
}
|
249
|
-
|
250
|
-
|
251
|
-
|
282
|
+
nid = OBJ_ln2nid(long_name);
|
283
|
+
if (nid == NID_undef) {
|
284
|
+
vname = rb_str_new2((const char *) &long_name);
|
285
|
+
} else {
|
286
|
+
short_name = OBJ_nid2sn(nid);
|
287
|
+
vname = rb_str_new2(short_name); /*do not free*/
|
288
|
+
}
|
289
|
+
ary = rb_ary_new3(3,
|
290
|
+
vname,
|
291
|
+
rb_str_new((const char *)entry->value->data, entry->value->length),
|
252
292
|
INT2FIX(entry->value->type));
|
253
293
|
rb_ary_push(ret, ary);
|
254
294
|
}
|
@@ -266,6 +306,14 @@ ossl_x509name_cmp0(VALUE self, VALUE other)
|
|
266
306
|
return X509_NAME_cmp(name1, name2);
|
267
307
|
}
|
268
308
|
|
309
|
+
/*
|
310
|
+
* call-seq:
|
311
|
+
* name.cmp other => integer
|
312
|
+
* name.<=> other => integer
|
313
|
+
*
|
314
|
+
* Compares this Name with +other+ and returns 0 if they are the same and -1 or
|
315
|
+
* +1 if they are greater or less than each other respectively.
|
316
|
+
*/
|
269
317
|
static VALUE
|
270
318
|
ossl_x509name_cmp(VALUE self, VALUE other)
|
271
319
|
{
|
@@ -278,6 +326,12 @@ ossl_x509name_cmp(VALUE self, VALUE other)
|
|
278
326
|
return INT2FIX(0);
|
279
327
|
}
|
280
328
|
|
329
|
+
/*
|
330
|
+
* call-seq:
|
331
|
+
* name.eql? other => boolean
|
332
|
+
*
|
333
|
+
* Returns true if +name+ and +other+ refer to the same hash key.
|
334
|
+
*/
|
281
335
|
static VALUE
|
282
336
|
ossl_x509name_eql(VALUE self, VALUE other)
|
283
337
|
{
|
@@ -292,6 +346,9 @@ ossl_x509name_eql(VALUE self, VALUE other)
|
|
292
346
|
/*
|
293
347
|
* call-seq:
|
294
348
|
* name.hash => integer
|
349
|
+
*
|
350
|
+
* The hash value returned is suitable for use as a certificate's filename in
|
351
|
+
* a CA path.
|
295
352
|
*/
|
296
353
|
static VALUE
|
297
354
|
ossl_x509name_hash(VALUE self)
|
@@ -311,7 +368,7 @@ ossl_x509name_hash(VALUE self)
|
|
311
368
|
* call-seq:
|
312
369
|
* name.hash_old => integer
|
313
370
|
*
|
314
|
-
*
|
371
|
+
* Returns an MD5 based hash used in OpenSSL 0.9.X.
|
315
372
|
*/
|
316
373
|
static VALUE
|
317
374
|
ossl_x509name_hash_old(VALUE self)
|
@@ -330,6 +387,8 @@ ossl_x509name_hash_old(VALUE self)
|
|
330
387
|
/*
|
331
388
|
* call-seq:
|
332
389
|
* name.to_der => string
|
390
|
+
*
|
391
|
+
* Converts the name to DER encoding
|
333
392
|
*/
|
334
393
|
static VALUE
|
335
394
|
ossl_x509name_to_der(VALUE self)
|
@@ -343,7 +402,7 @@ ossl_x509name_to_der(VALUE self)
|
|
343
402
|
if((len = i2d_X509_NAME(name, NULL)) <= 0)
|
344
403
|
ossl_raise(eX509NameError, NULL);
|
345
404
|
str = rb_str_new(0, len);
|
346
|
-
p = RSTRING_PTR(str);
|
405
|
+
p = (unsigned char *)RSTRING_PTR(str);
|
347
406
|
if(i2d_X509_NAME(name, &p) <= 0)
|
348
407
|
ossl_raise(eX509NameError, NULL);
|
349
408
|
ossl_str_adjust(str, p);
|
@@ -352,9 +411,20 @@ ossl_x509name_to_der(VALUE self)
|
|
352
411
|
}
|
353
412
|
|
354
413
|
/*
|
355
|
-
*
|
414
|
+
* Document-class: OpenSSL::X509::Name
|
415
|
+
*
|
416
|
+
* An X.509 name represents a hostname, email address or other entity
|
417
|
+
* associated with a public key.
|
418
|
+
*
|
419
|
+
* You can create a Name by parsing a distinguished name String or by
|
420
|
+
* supplying the distinguished name as an Array.
|
421
|
+
*
|
422
|
+
* name = OpenSSL::X509::Name.parse 'CN=nobody/DC=example'
|
423
|
+
*
|
424
|
+
* name = OpenSSL::X509::Name.new [['CN', 'nobody'], ['DC', 'example']]
|
356
425
|
*/
|
357
|
-
|
426
|
+
|
427
|
+
void
|
358
428
|
Init_ossl_x509name()
|
359
429
|
{
|
360
430
|
VALUE utf8str, ptrstr, ia5str, hash;
|
@@ -363,6 +433,8 @@ Init_ossl_x509name()
|
|
363
433
|
eX509NameError = rb_define_class_under(mX509, "NameError", eOSSLError);
|
364
434
|
cX509Name = rb_define_class_under(mX509, "Name", rb_cObject);
|
365
435
|
|
436
|
+
rb_include_module(cX509Name, rb_mComparable);
|
437
|
+
|
366
438
|
rb_define_alloc_func(cX509Name, ossl_x509name_alloc);
|
367
439
|
rb_define_method(cX509Name, "initialize", ossl_x509name_initialize, -1);
|
368
440
|
rb_define_method(cX509Name, "add_entry", ossl_x509name_add_entry, -1);
|
@@ -380,6 +452,11 @@ Init_ossl_x509name()
|
|
380
452
|
utf8str = INT2NUM(V_ASN1_UTF8STRING);
|
381
453
|
ptrstr = INT2NUM(V_ASN1_PRINTABLESTRING);
|
382
454
|
ia5str = INT2NUM(V_ASN1_IA5STRING);
|
455
|
+
|
456
|
+
/* Document-const: DEFAULT_OBJECT_TYPE
|
457
|
+
*
|
458
|
+
* The default object type for name entries.
|
459
|
+
*/
|
383
460
|
rb_define_const(cX509Name, "DEFAULT_OBJECT_TYPE", utf8str);
|
384
461
|
hash = rb_hash_new();
|
385
462
|
rb_funcall(hash, rb_intern("default="), 1, utf8str);
|
@@ -390,10 +467,43 @@ Init_ossl_x509name()
|
|
390
467
|
rb_hash_aset(hash, rb_str_new2("DC"), ia5str);
|
391
468
|
rb_hash_aset(hash, rb_str_new2("domainComponent"), ia5str);
|
392
469
|
rb_hash_aset(hash, rb_str_new2("emailAddress"), ia5str);
|
470
|
+
|
471
|
+
/* Document-const: OBJECT_TYPE_TEMPLATE
|
472
|
+
*
|
473
|
+
* The default object type template for name entries.
|
474
|
+
*/
|
393
475
|
rb_define_const(cX509Name, "OBJECT_TYPE_TEMPLATE", hash);
|
394
476
|
|
477
|
+
/* Document-const: COMPAT
|
478
|
+
*
|
479
|
+
* A flag for #to_s.
|
480
|
+
*
|
481
|
+
* Breaks the name returned into multiple lines if longer than 80
|
482
|
+
* characters.
|
483
|
+
*/
|
395
484
|
rb_define_const(cX509Name, "COMPAT", ULONG2NUM(XN_FLAG_COMPAT));
|
485
|
+
|
486
|
+
/* Document-const: RFC2253
|
487
|
+
*
|
488
|
+
* A flag for #to_s.
|
489
|
+
*
|
490
|
+
* Returns an RFC2253 format name.
|
491
|
+
*/
|
396
492
|
rb_define_const(cX509Name, "RFC2253", ULONG2NUM(XN_FLAG_RFC2253));
|
493
|
+
|
494
|
+
/* Document-const: ONELINE
|
495
|
+
*
|
496
|
+
* A flag for #to_s.
|
497
|
+
*
|
498
|
+
* Returns a more readable format than RFC2253.
|
499
|
+
*/
|
397
500
|
rb_define_const(cX509Name, "ONELINE", ULONG2NUM(XN_FLAG_ONELINE));
|
501
|
+
|
502
|
+
/* Document-const: MULTILINE
|
503
|
+
*
|
504
|
+
* A flag for #to_s.
|
505
|
+
*
|
506
|
+
* Returns a multiline format.
|
507
|
+
*/
|
398
508
|
rb_define_const(cX509Name, "MULTILINE", ULONG2NUM(XN_FLAG_MULTILINE));
|
399
509
|
}
|
@@ -1,5 +1,5 @@
|
|
1
1
|
/*
|
2
|
-
* $Id
|
2
|
+
* $Id$
|
3
3
|
* 'OpenSSL for Ruby' project
|
4
4
|
* Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
|
5
5
|
* All rights reserved.
|
@@ -11,20 +11,20 @@
|
|
11
11
|
#include "ossl.h"
|
12
12
|
|
13
13
|
#define WrapX509Req(klass, obj, req) do { \
|
14
|
-
if (!req) { \
|
14
|
+
if (!(req)) { \
|
15
15
|
ossl_raise(rb_eRuntimeError, "Req wasn't initialized!"); \
|
16
16
|
} \
|
17
|
-
obj = Data_Wrap_Struct(klass, 0, X509_REQ_free, req); \
|
17
|
+
(obj) = Data_Wrap_Struct((klass), 0, X509_REQ_free, (req)); \
|
18
18
|
} while (0)
|
19
19
|
#define GetX509Req(obj, req) do { \
|
20
|
-
Data_Get_Struct(obj, X509_REQ, req); \
|
21
|
-
if (!req) { \
|
20
|
+
Data_Get_Struct((obj), X509_REQ, (req)); \
|
21
|
+
if (!(req)) { \
|
22
22
|
ossl_raise(rb_eRuntimeError, "Req wasn't initialized!"); \
|
23
23
|
} \
|
24
24
|
} while (0)
|
25
25
|
#define SafeGetX509Req(obj, req) do { \
|
26
|
-
OSSL_Check_Kind(obj, cX509Req); \
|
27
|
-
GetX509Req(obj, req); \
|
26
|
+
OSSL_Check_Kind((obj), cX509Req); \
|
27
|
+
GetX509Req((obj), (req)); \
|
28
28
|
} while (0)
|
29
29
|
|
30
30
|
/*
|
@@ -81,7 +81,7 @@ DupX509ReqPtr(VALUE obj)
|
|
81
81
|
/*
|
82
82
|
* Private functions
|
83
83
|
*/
|
84
|
-
static VALUE
|
84
|
+
static VALUE
|
85
85
|
ossl_x509req_alloc(VALUE klass)
|
86
86
|
{
|
87
87
|
X509_REQ *req;
|
@@ -95,11 +95,11 @@ ossl_x509req_alloc(VALUE klass)
|
|
95
95
|
return obj;
|
96
96
|
}
|
97
97
|
|
98
|
-
static VALUE
|
98
|
+
static VALUE
|
99
99
|
ossl_x509req_initialize(int argc, VALUE *argv, VALUE self)
|
100
100
|
{
|
101
101
|
BIO *in;
|
102
|
-
X509_REQ *req;
|
102
|
+
X509_REQ *req, *x = DATA_PTR(self);
|
103
103
|
VALUE arg;
|
104
104
|
|
105
105
|
if (rb_scan_args(argc, argv, "01", &arg) == 0) {
|
@@ -107,10 +107,12 @@ ossl_x509req_initialize(int argc, VALUE *argv, VALUE self)
|
|
107
107
|
}
|
108
108
|
arg = ossl_to_der_if_possible(arg);
|
109
109
|
in = ossl_obj2bio(arg);
|
110
|
-
req = PEM_read_bio_X509_REQ(in,
|
110
|
+
req = PEM_read_bio_X509_REQ(in, &x, NULL, NULL);
|
111
|
+
DATA_PTR(self) = x;
|
111
112
|
if (!req) {
|
112
|
-
|
113
|
-
req = d2i_X509_REQ_bio(in,
|
113
|
+
OSSL_BIO_reset(in);
|
114
|
+
req = d2i_X509_REQ_bio(in, &x);
|
115
|
+
DATA_PTR(self) = x;
|
114
116
|
}
|
115
117
|
BIO_free(in);
|
116
118
|
if (!req) ossl_raise(eX509ReqError, NULL);
|
@@ -122,7 +124,7 @@ static VALUE
|
|
122
124
|
ossl_x509req_copy(VALUE self, VALUE other)
|
123
125
|
{
|
124
126
|
X509_REQ *a, *b, *req;
|
125
|
-
|
127
|
+
|
126
128
|
rb_check_frozen(self);
|
127
129
|
if (self == other) return self;
|
128
130
|
GetX509Req(self, a);
|
@@ -136,14 +138,14 @@ ossl_x509req_copy(VALUE self, VALUE other)
|
|
136
138
|
return self;
|
137
139
|
}
|
138
140
|
|
139
|
-
static VALUE
|
141
|
+
static VALUE
|
140
142
|
ossl_x509req_to_pem(VALUE self)
|
141
143
|
{
|
142
144
|
X509_REQ *req;
|
143
145
|
BIO *out;
|
144
146
|
BUF_MEM *buf;
|
145
147
|
VALUE str;
|
146
|
-
|
148
|
+
|
147
149
|
GetX509Req(self, req);
|
148
150
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
149
151
|
ossl_raise(eX509ReqError, NULL);
|
@@ -169,9 +171,9 @@ ossl_x509req_to_der(VALUE self)
|
|
169
171
|
|
170
172
|
GetX509Req(self, req);
|
171
173
|
if ((len = i2d_X509_REQ(req, NULL)) <= 0)
|
172
|
-
ossl_raise(
|
174
|
+
ossl_raise(eX509ReqError, NULL);
|
173
175
|
str = rb_str_new(0, len);
|
174
|
-
p = RSTRING_PTR(str);
|
176
|
+
p = (unsigned char *)RSTRING_PTR(str);
|
175
177
|
if (i2d_X509_REQ(req, &p) <= 0)
|
176
178
|
ossl_raise(eX509ReqError, NULL);
|
177
179
|
ossl_str_adjust(str, p);
|
@@ -179,7 +181,7 @@ ossl_x509req_to_der(VALUE self)
|
|
179
181
|
return str;
|
180
182
|
}
|
181
183
|
|
182
|
-
static VALUE
|
184
|
+
static VALUE
|
183
185
|
ossl_x509req_to_text(VALUE self)
|
184
186
|
{
|
185
187
|
X509_REQ *req;
|
@@ -206,12 +208,12 @@ ossl_x509req_to_text(VALUE self)
|
|
206
208
|
/*
|
207
209
|
* Makes X509 from X509_REQuest
|
208
210
|
*/
|
209
|
-
static VALUE
|
211
|
+
static VALUE
|
210
212
|
ossl_x509req_to_x509(VALUE self, VALUE days, VALUE key)
|
211
213
|
{
|
212
214
|
X509_REQ *req;
|
213
215
|
X509 *x509;
|
214
|
-
|
216
|
+
|
215
217
|
GetX509Req(self, req);
|
216
218
|
...
|
217
219
|
if (!(x509 = X509_REQ_to_X509(req, d, pkey))) {
|
@@ -222,7 +224,7 @@ ossl_x509req_to_x509(VALUE self, VALUE days, VALUE key)
|
|
222
224
|
}
|
223
225
|
#endif
|
224
226
|
|
225
|
-
static VALUE
|
227
|
+
static VALUE
|
226
228
|
ossl_x509req_get_version(VALUE self)
|
227
229
|
{
|
228
230
|
X509_REQ *req;
|
@@ -234,7 +236,7 @@ ossl_x509req_get_version(VALUE self)
|
|
234
236
|
return LONG2FIX(version);
|
235
237
|
}
|
236
238
|
|
237
|
-
static VALUE
|
239
|
+
static VALUE
|
238
240
|
ossl_x509req_set_version(VALUE self, VALUE version)
|
239
241
|
{
|
240
242
|
X509_REQ *req;
|
@@ -251,7 +253,7 @@ ossl_x509req_set_version(VALUE self, VALUE version)
|
|
251
253
|
return version;
|
252
254
|
}
|
253
255
|
|
254
|
-
static VALUE
|
256
|
+
static VALUE
|
255
257
|
ossl_x509req_get_subject(VALUE self)
|
256
258
|
{
|
257
259
|
X509_REQ *req;
|
@@ -265,11 +267,11 @@ ossl_x509req_get_subject(VALUE self)
|
|
265
267
|
return ossl_x509name_new(name);
|
266
268
|
}
|
267
269
|
|
268
|
-
static VALUE
|
270
|
+
static VALUE
|
269
271
|
ossl_x509req_set_subject(VALUE self, VALUE subject)
|
270
272
|
{
|
271
273
|
X509_REQ *req;
|
272
|
-
|
274
|
+
|
273
275
|
GetX509Req(self, req);
|
274
276
|
/* DUPs name */
|
275
277
|
if (!X509_REQ_set_subject_name(req, GetX509NamePtr(subject))) {
|
@@ -279,7 +281,7 @@ ossl_x509req_set_subject(VALUE self, VALUE subject)
|
|
279
281
|
return subject;
|
280
282
|
}
|
281
283
|
|
282
|
-
static VALUE
|
284
|
+
static VALUE
|
283
285
|
ossl_x509req_get_signature_algorithm(VALUE self)
|
284
286
|
{
|
285
287
|
X509_REQ *req;
|
@@ -288,7 +290,7 @@ ossl_x509req_get_signature_algorithm(VALUE self)
|
|
288
290
|
VALUE str;
|
289
291
|
|
290
292
|
GetX509Req(self, req);
|
291
|
-
|
293
|
+
|
292
294
|
if (!(out = BIO_new(BIO_s_mem()))) {
|
293
295
|
ossl_raise(eX509ReqError, NULL);
|
294
296
|
}
|
@@ -302,7 +304,7 @@ ossl_x509req_get_signature_algorithm(VALUE self)
|
|
302
304
|
return str;
|
303
305
|
}
|
304
306
|
|
305
|
-
static VALUE
|
307
|
+
static VALUE
|
306
308
|
ossl_x509req_get_public_key(VALUE self)
|
307
309
|
{
|
308
310
|
X509_REQ *req;
|
@@ -316,7 +318,7 @@ ossl_x509req_get_public_key(VALUE self)
|
|
316
318
|
return ossl_pkey_new(pkey); /* NO DUP - OK */
|
317
319
|
}
|
318
320
|
|
319
|
-
static VALUE
|
321
|
+
static VALUE
|
320
322
|
ossl_x509req_set_public_key(VALUE self, VALUE key)
|
321
323
|
{
|
322
324
|
X509_REQ *req;
|
@@ -331,7 +333,7 @@ ossl_x509req_set_public_key(VALUE self, VALUE key)
|
|
331
333
|
return key;
|
332
334
|
}
|
333
335
|
|
334
|
-
static VALUE
|
336
|
+
static VALUE
|
335
337
|
ossl_x509req_sign(VALUE self, VALUE key, VALUE digest)
|
336
338
|
{
|
337
339
|
X509_REQ *req;
|
@@ -351,7 +353,7 @@ ossl_x509req_sign(VALUE self, VALUE key, VALUE digest)
|
|
351
353
|
/*
|
352
354
|
* Checks that cert signature is made with PRIVversion of this PUBLIC 'key'
|
353
355
|
*/
|
354
|
-
static VALUE
|
356
|
+
static VALUE
|
355
357
|
ossl_x509req_verify(VALUE self, VALUE key)
|
356
358
|
{
|
357
359
|
X509_REQ *req;
|
@@ -370,14 +372,14 @@ ossl_x509req_verify(VALUE self, VALUE key)
|
|
370
372
|
return Qfalse;
|
371
373
|
}
|
372
374
|
|
373
|
-
static VALUE
|
375
|
+
static VALUE
|
374
376
|
ossl_x509req_get_attributes(VALUE self)
|
375
377
|
{
|
376
378
|
X509_REQ *req;
|
377
379
|
int count, i;
|
378
380
|
X509_ATTRIBUTE *attr;
|
379
381
|
VALUE ary;
|
380
|
-
|
382
|
+
|
381
383
|
GetX509Req(self, req);
|
382
384
|
|
383
385
|
count = X509_REQ_get_attr_count(req);
|
@@ -394,7 +396,7 @@ ossl_x509req_get_attributes(VALUE self)
|
|
394
396
|
return ary;
|
395
397
|
}
|
396
398
|
|
397
|
-
static VALUE
|
399
|
+
static VALUE
|
398
400
|
ossl_x509req_set_attributes(VALUE self, VALUE ary)
|
399
401
|
{
|
400
402
|
X509_REQ *req;
|
@@ -419,7 +421,7 @@ ossl_x509req_set_attributes(VALUE self, VALUE ary)
|
|
419
421
|
return ary;
|
420
422
|
}
|
421
423
|
|
422
|
-
static VALUE
|
424
|
+
static VALUE
|
423
425
|
ossl_x509req_add_attribute(VALUE self, VALUE attr)
|
424
426
|
{
|
425
427
|
X509_REQ *req;
|
@@ -435,17 +437,17 @@ ossl_x509req_add_attribute(VALUE self, VALUE attr)
|
|
435
437
|
/*
|
436
438
|
* X509_REQUEST init
|
437
439
|
*/
|
438
|
-
void
|
440
|
+
void
|
439
441
|
Init_ossl_x509req()
|
440
442
|
{
|
441
443
|
eX509ReqError = rb_define_class_under(mX509, "RequestError", eOSSLError);
|
442
|
-
|
444
|
+
|
443
445
|
cX509Req = rb_define_class_under(mX509, "Request", rb_cObject);
|
444
|
-
|
446
|
+
|
445
447
|
rb_define_alloc_func(cX509Req, ossl_x509req_alloc);
|
446
448
|
rb_define_method(cX509Req, "initialize", ossl_x509req_initialize, -1);
|
447
449
|
rb_define_copy_func(cX509Req, ossl_x509req_copy);
|
448
|
-
|
450
|
+
|
449
451
|
rb_define_method(cX509Req, "to_pem", ossl_x509req_to_pem, 0);
|
450
452
|
rb_define_method(cX509Req, "to_der", ossl_x509req_to_der, 0);
|
451
453
|
rb_define_alias(cX509Req, "to_s", "to_pem");
|