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.
Files changed (74) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +5 -6
  3. data/ext/rubysl/openssl/.gitignore +3 -0
  4. data/ext/rubysl/openssl/deprecation.rb +21 -0
  5. data/ext/rubysl/openssl/extconf.rb +45 -32
  6. data/ext/rubysl/openssl/openssl_missing.c +20 -7
  7. data/ext/rubysl/openssl/openssl_missing.h +22 -15
  8. data/ext/rubysl/openssl/ossl.c +610 -61
  9. data/ext/rubysl/openssl/ossl.h +31 -17
  10. data/ext/rubysl/openssl/ossl_asn1.c +974 -183
  11. data/ext/rubysl/openssl/ossl_asn1.h +3 -3
  12. data/ext/rubysl/openssl/ossl_bio.c +4 -3
  13. data/ext/rubysl/openssl/ossl_bio.h +1 -1
  14. data/ext/rubysl/openssl/ossl_bn.c +32 -28
  15. data/ext/rubysl/openssl/ossl_bn.h +1 -1
  16. data/ext/rubysl/openssl/ossl_cipher.c +494 -93
  17. data/ext/rubysl/openssl/ossl_cipher.h +1 -1
  18. data/ext/rubysl/openssl/ossl_config.c +4 -5
  19. data/ext/rubysl/openssl/ossl_config.h +1 -1
  20. data/ext/rubysl/openssl/ossl_digest.c +206 -24
  21. data/ext/rubysl/openssl/ossl_digest.h +1 -1
  22. data/ext/rubysl/openssl/ossl_engine.c +48 -26
  23. data/ext/rubysl/openssl/ossl_engine.h +1 -1
  24. data/ext/rubysl/openssl/ossl_hmac.c +40 -38
  25. data/ext/rubysl/openssl/ossl_hmac.h +1 -1
  26. data/ext/rubysl/openssl/ossl_ns_spki.c +157 -25
  27. data/ext/rubysl/openssl/ossl_ns_spki.h +1 -1
  28. data/ext/rubysl/openssl/ossl_ocsp.c +57 -40
  29. data/ext/rubysl/openssl/ossl_ocsp.h +1 -1
  30. data/ext/rubysl/openssl/ossl_pkcs12.c +15 -13
  31. data/ext/rubysl/openssl/ossl_pkcs12.h +1 -1
  32. data/ext/rubysl/openssl/ossl_pkcs5.c +108 -18
  33. data/ext/rubysl/openssl/ossl_pkcs7.c +44 -37
  34. data/ext/rubysl/openssl/ossl_pkcs7.h +1 -1
  35. data/ext/rubysl/openssl/ossl_pkey.c +211 -15
  36. data/ext/rubysl/openssl/ossl_pkey.h +19 -9
  37. data/ext/rubysl/openssl/ossl_pkey_dh.c +180 -47
  38. data/ext/rubysl/openssl/ossl_pkey_dsa.c +184 -47
  39. data/ext/rubysl/openssl/ossl_pkey_ec.c +177 -93
  40. data/ext/rubysl/openssl/ossl_pkey_rsa.c +209 -102
  41. data/ext/rubysl/openssl/ossl_rand.c +15 -15
  42. data/ext/rubysl/openssl/ossl_rand.h +1 -1
  43. data/ext/rubysl/openssl/ossl_ssl.c +939 -192
  44. data/ext/rubysl/openssl/ossl_ssl.h +6 -6
  45. data/ext/rubysl/openssl/ossl_ssl_session.c +78 -62
  46. data/ext/rubysl/openssl/ossl_version.h +2 -2
  47. data/ext/rubysl/openssl/ossl_x509.c +1 -1
  48. data/ext/rubysl/openssl/ossl_x509.h +1 -1
  49. data/ext/rubysl/openssl/ossl_x509attr.c +20 -19
  50. data/ext/rubysl/openssl/ossl_x509cert.c +169 -67
  51. data/ext/rubysl/openssl/ossl_x509crl.c +41 -39
  52. data/ext/rubysl/openssl/ossl_x509ext.c +51 -38
  53. data/ext/rubysl/openssl/ossl_x509name.c +139 -29
  54. data/ext/rubysl/openssl/ossl_x509req.c +42 -40
  55. data/ext/rubysl/openssl/ossl_x509revoked.c +20 -20
  56. data/ext/rubysl/openssl/ossl_x509store.c +99 -47
  57. data/ext/rubysl/openssl/ruby_missing.h +3 -16
  58. data/lib/openssl/bn.rb +19 -19
  59. data/lib/openssl/buffering.rb +222 -14
  60. data/lib/openssl/cipher.rb +20 -20
  61. data/lib/openssl/config.rb +1 -4
  62. data/lib/openssl/digest.rb +47 -19
  63. data/lib/openssl/ssl.rb +197 -1
  64. data/lib/openssl/x509.rb +162 -1
  65. data/lib/rubysl/openssl.rb +4 -8
  66. data/lib/rubysl/openssl/version.rb +1 -1
  67. data/rubysl-openssl.gemspec +1 -2
  68. metadata +16 -34
  69. data/ext/rubysl/openssl/extconf.h +0 -50
  70. data/lib/openssl/net/ftptls.rb +0 -53
  71. data/lib/openssl/net/telnets.rb +0 -251
  72. data/lib/openssl/pkcs7.rb +0 -25
  73. data/lib/openssl/ssl-internal.rb +0 -187
  74. data/lib/openssl/x509-internal.rb +0 -153
@@ -1,5 +1,5 @@
1
1
  /*
2
- * $Id: ossl_cipher.h 12496 2007-06-08 15:02:04Z technorama $
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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * $Id: ossl_config.c 29856 2010-11-22 07:21:45Z shyouhei $
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.
@@ -17,12 +17,10 @@
17
17
  VALUE cConfig;
18
18
  VALUE eConfigError;
19
19
 
20
- /*
21
- * Public
20
+ /*
21
+ * Public
22
22
  */
23
23
 
24
- static CONF *parse_config(VALUE, CONF*);
25
-
26
24
  /*
27
25
  * GetConfigPtr is a public C-level function for getting OpenSSL CONF struct
28
26
  * from an OpenSSL::Config(eConfig) instance. We decided to implement
@@ -57,6 +55,7 @@ GetConfigPtr(VALUE obj)
57
55
  return conf;
58
56
  }
59
57
 
58
+
60
59
  /*
61
60
  * INIT
62
61
  */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * $Id: ossl_config.h 11708 2007-02-12 23:01:19Z shyouhei $
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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * $Id: ossl_digest.c 15600 2008-02-25 08:48:57Z technorama $
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,14 +11,14 @@
11
11
  #include "ossl.h"
12
12
 
13
13
  #define GetDigest(obj, ctx) do { \
14
- Data_Get_Struct(obj, EVP_MD_CTX, ctx); \
15
- if (!ctx) { \
14
+ Data_Get_Struct((obj), EVP_MD_CTX, (ctx)); \
15
+ if (!(ctx)) { \
16
16
  ossl_raise(rb_eRuntimeError, "Digest CTX wasn't initialized!"); \
17
17
  } \
18
18
  } while (0)
19
19
  #define SafeGetDigest(obj, ctx) do { \
20
- OSSL_Check_Kind(obj, cDigest); \
21
- GetDigest(obj, ctx); \
20
+ OSSL_Check_Kind((obj), cDigest); \
21
+ GetDigest((obj), (ctx)); \
22
22
  } while (0)
23
23
 
24
24
  /*
@@ -36,12 +36,18 @@ const EVP_MD *
36
36
  GetDigestPtr(VALUE obj)
37
37
  {
38
38
  const EVP_MD *md;
39
+ ASN1_OBJECT *oid = NULL;
39
40
 
40
41
  if (TYPE(obj) == T_STRING) {
41
- const char *name = STR2CSTR(obj);
42
-
43
- md = EVP_get_digestbyname(name);
44
- if (!md)
42
+ const char *name = StringValueCStr(obj);
43
+
44
+ md = EVP_get_digestbyname(name);
45
+ if (!md) {
46
+ oid = OBJ_txt2obj(name, 0);
47
+ md = EVP_get_digestbyobj(oid);
48
+ ASN1_OBJECT_free(oid);
49
+ }
50
+ if(!md)
45
51
  ossl_raise(rb_eRuntimeError, "Unsupported digest algorithm (%s).", name);
46
52
  } else {
47
53
  EVP_MD_CTX *ctx;
@@ -56,14 +62,16 @@ GetDigestPtr(VALUE obj)
56
62
 
57
63
  VALUE
58
64
  ossl_digest_new(const EVP_MD *md)
59
- {
65
+ {
60
66
  VALUE ret;
61
67
  EVP_MD_CTX *ctx;
62
68
 
63
69
  ret = ossl_digest_alloc(cDigest);
64
70
  GetDigest(ret, ctx);
65
- EVP_DigestInit_ex(ctx, md, NULL);
66
-
71
+ if (EVP_DigestInit_ex(ctx, md, NULL) != 1) {
72
+ ossl_raise(eDigestError, "Digest initialization failed.");
73
+ }
74
+
67
75
  return ret;
68
76
  }
69
77
 
@@ -88,7 +96,20 @@ VALUE ossl_digest_update(VALUE, VALUE);
88
96
 
89
97
  /*
90
98
  * call-seq:
91
- * Digest.new(string) -> digest
99
+ * Digest.new(string [, data]) -> Digest
100
+ *
101
+ * Creates a Digest instance based on +string+, which is either the ln
102
+ * (long name) or sn (short name) of a supported digest algorithm.
103
+ * If +data+ (a +String+) is given, it is used as the initial input to the
104
+ * Digest instance, i.e.
105
+ * digest = OpenSSL::Digest.new('sha256', 'digestdata')
106
+ * is equal to
107
+ * digest = OpenSSL::Digest.new('sha256')
108
+ * digest.update('digestdata')
109
+ *
110
+ * === Example
111
+ * digest = OpenSSL::Digest.new('sha1')
112
+ *
92
113
  *
93
114
  */
94
115
  static VALUE
@@ -96,7 +117,6 @@ ossl_digest_initialize(int argc, VALUE *argv, VALUE self)
96
117
  {
97
118
  EVP_MD_CTX *ctx;
98
119
  const EVP_MD *md;
99
- char *name;
100
120
  VALUE type, data;
101
121
 
102
122
  rb_scan_args(argc, argv, "11", &type, &data);
@@ -104,8 +124,10 @@ ossl_digest_initialize(int argc, VALUE *argv, VALUE self)
104
124
  if (!NIL_P(data)) StringValue(data);
105
125
 
106
126
  GetDigest(self, ctx);
107
- EVP_DigestInit_ex(ctx, md, NULL);
108
-
127
+ if (EVP_DigestInit_ex(ctx, md, NULL) != 1) {
128
+ ossl_raise(eDigestError, "Digest initialization failed.");
129
+ }
130
+
109
131
  if (!NIL_P(data)) return ossl_digest_update(self, data);
110
132
  return self;
111
133
  }
@@ -114,7 +136,7 @@ static VALUE
114
136
  ossl_digest_copy(VALUE self, VALUE other)
115
137
  {
116
138
  EVP_MD_CTX *ctx1, *ctx2;
117
-
139
+
118
140
  rb_check_frozen(self);
119
141
  if (self == other) return self;
120
142
 
@@ -131,6 +153,9 @@ ossl_digest_copy(VALUE self, VALUE other)
131
153
  * call-seq:
132
154
  * digest.reset -> self
133
155
  *
156
+ * Resets the Digest in the sense that any Digest#update that has been
157
+ * performed is abandoned and the Digest is set to its initial state again.
158
+ *
134
159
  */
135
160
  static VALUE
136
161
  ossl_digest_reset(VALUE self)
@@ -138,7 +163,9 @@ ossl_digest_reset(VALUE self)
138
163
  EVP_MD_CTX *ctx;
139
164
 
140
165
  GetDigest(self, ctx);
141
- EVP_DigestInit_ex(ctx, EVP_MD_CTX_md(ctx), NULL);
166
+ if (EVP_DigestInit_ex(ctx, EVP_MD_CTX_md(ctx), NULL) != 1) {
167
+ ossl_raise(eDigestError, "Digest initialization failed.");
168
+ }
142
169
 
143
170
  return self;
144
171
  }
@@ -147,6 +174,16 @@ ossl_digest_reset(VALUE self)
147
174
  * call-seq:
148
175
  * digest.update(string) -> aString
149
176
  *
177
+ * Not every message digest can be computed in one single pass. If a message
178
+ * digest is to be computed from several subsequent sources, then each may
179
+ * be passed individually to the Digest instance.
180
+ *
181
+ * === Example
182
+ * digest = OpenSSL::Digest::SHA256.new
183
+ * digest.update('First input')
184
+ * digest << 'Second input' # equivalent to digest.update('Second input')
185
+ * result = digest.digest
186
+ *
150
187
  */
151
188
  VALUE
152
189
  ossl_digest_update(VALUE self, VALUE data)
@@ -182,7 +219,7 @@ ossl_digest_finish(int argc, VALUE *argv, VALUE self)
182
219
  rb_str_resize(str, EVP_MD_CTX_size(ctx));
183
220
  }
184
221
 
185
- EVP_DigestFinal_ex(ctx, RSTRING_PTR(str), NULL);
222
+ EVP_DigestFinal_ex(ctx, (unsigned char *)RSTRING_PTR(str), NULL);
186
223
 
187
224
  return str;
188
225
  }
@@ -191,6 +228,12 @@ ossl_digest_finish(int argc, VALUE *argv, VALUE self)
191
228
  * call-seq:
192
229
  * digest.name -> string
193
230
  *
231
+ * Returns the sn of this Digest instance.
232
+ *
233
+ * === Example
234
+ * digest = OpenSSL::Digest::SHA512.new
235
+ * puts digest.name # => SHA512
236
+ *
194
237
  */
195
238
  static VALUE
196
239
  ossl_digest_name(VALUE self)
@@ -204,9 +247,15 @@ ossl_digest_name(VALUE self)
204
247
 
205
248
  /*
206
249
  * call-seq:
207
- * digest.digest_size -> integer
250
+ * digest.digest_length -> integer
251
+ *
252
+ * Returns the output size of the digest, i.e. the length in bytes of the
253
+ * final message digest result.
254
+ *
255
+ * === Example
256
+ * digest = OpenSSL::Digest::SHA1.new
257
+ * puts digest.digest_length # => 20
208
258
  *
209
- * Returns the output size of the digest.
210
259
  */
211
260
  static VALUE
212
261
  ossl_digest_size(VALUE self)
@@ -218,6 +267,19 @@ ossl_digest_size(VALUE self)
218
267
  return INT2NUM(EVP_MD_CTX_size(ctx));
219
268
  }
220
269
 
270
+ /*
271
+ * call-seq:
272
+ * digest.block_length -> integer
273
+ *
274
+ * Returns the block length of the digest algorithm, i.e. the length in bytes
275
+ * of an individual block. Most modern algorithms partition a message to be
276
+ * digested into a sequence of fix-sized blocks that are processed
277
+ * consecutively.
278
+ *
279
+ * === Example
280
+ * digest = OpenSSL::Digest::SHA1.new
281
+ * puts digest.block_length # => 64
282
+ */
221
283
  static VALUE
222
284
  ossl_digest_block_length(VALUE self)
223
285
  {
@@ -234,13 +296,133 @@ ossl_digest_block_length(VALUE self)
234
296
  void
235
297
  Init_ossl_digest()
236
298
  {
237
- #if 0 /* let rdoc know about mOSSL */
238
- mOSSL = rb_define_module("OpenSSL");
299
+ rb_require("digest");
300
+
301
+ #if 0
302
+ mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL */
239
303
  #endif
240
304
 
305
+ /* Document-class: OpenSSL::Digest
306
+ *
307
+ * OpenSSL::Digest allows you to compute message digests (sometimes
308
+ * interchangeably called "hashes") of arbitrary data that are
309
+ * cryptographically secure, i.e. a Digest implements a secure one-way
310
+ * function.
311
+ *
312
+ * One-way functions offer some useful properties. E.g. given two
313
+ * distinct inputs the probability that both yield the same output
314
+ * is highly unlikely. Combined with the fact that every message digest
315
+ * algorithm has a fixed-length output of just a few bytes, digests are
316
+ * often used to create unique identifiers for arbitrary data. A common
317
+ * example is the creation of a unique id for binary documents that are
318
+ * stored in a database.
319
+ *
320
+ * Another useful characteristic of one-way functions (and thus the name)
321
+ * is that given a digest there is no indication about the original
322
+ * data that produced it, i.e. the only way to identify the original input
323
+ * is to "brute-force" through every possible combination of inputs.
324
+ *
325
+ * These characteristics make one-way functions also ideal companions
326
+ * for public key signature algorithms: instead of signing an entire
327
+ * document, first a hash of the document is produced with a considerably
328
+ * faster message digest algorithm and only the few bytes of its output
329
+ * need to be signed using the slower public key algorithm. To validate
330
+ * the integrity of a signed document, it suffices to re-compute the hash
331
+ * and verify that it is equal to that in the signature.
332
+ *
333
+ * Among the supported message digest algorithms are:
334
+ * * SHA, SHA1, SHA224, SHA256, SHA384 and SHA512
335
+ * * MD2, MD4, MDC2 and MD5
336
+ * * RIPEMD160
337
+ * * DSS, DSS1 (Pseudo algorithms to be used for DSA signatures. DSS is
338
+ * equal to SHA and DSS1 is equal to SHA1)
339
+ *
340
+ * For each of these algorithms, there is a sub-class of Digest that
341
+ * can be instantiated as simply as e.g.
342
+ *
343
+ * digest = OpenSSL::Digest::SHA1.new
344
+ *
345
+ * === Mapping between Digest class and sn/ln
346
+ *
347
+ * The sn (short names) and ln (long names) are defined in
348
+ * <openssl/object.h> and <openssl/obj_mac.h>. They are textual
349
+ * representations of ASN.1 OBJECT IDENTIFIERs. Each supported digest
350
+ * algorithm has an OBJECT IDENTIFIER associated to it and those again
351
+ * have short/long names assigned to them.
352
+ * E.g. the OBJECT IDENTIFIER for SHA-1 is 1.3.14.3.2.26 and its
353
+ * sn is "SHA1" and its ln is "sha1".
354
+ * ==== MD2
355
+ * * sn: MD2
356
+ * * ln: md2
357
+ * ==== MD4
358
+ * * sn: MD4
359
+ * * ln: md4
360
+ * ==== MD5
361
+ * * sn: MD5
362
+ * * ln: md5
363
+ * ==== SHA
364
+ * * sn: SHA
365
+ * * ln: SHA
366
+ * ==== SHA-1
367
+ * * sn: SHA1
368
+ * * ln: sha1
369
+ * ==== SHA-224
370
+ * * sn: SHA224
371
+ * * ln: sha224
372
+ * ==== SHA-256
373
+ * * sn: SHA256
374
+ * * ln: sha256
375
+ * ==== SHA-384
376
+ * * sn: SHA384
377
+ * * ln: sha384
378
+ * ==== SHA-512
379
+ * * sn: SHA512
380
+ * * ln: sha512
381
+ *
382
+ * "Breaking" a message digest algorithm means defying its one-way
383
+ * function characteristics, i.e. producing a collision or finding a way
384
+ * to get to the original data by means that are more efficient than
385
+ * brute-forcing etc. Most of the supported digest algorithms can be
386
+ * considered broken in this sense, even the very popular MD5 and SHA1
387
+ * algorithms. Should security be your highest concern, then you should
388
+ * probably rely on SHA224, SHA256, SHA384 or SHA512.
389
+ *
390
+ * === Hashing a file
391
+ *
392
+ * data = File.read('document')
393
+ * sha256 = OpenSSL::Digest::SHA256.new
394
+ * digest = sha256.digest(data)
395
+ *
396
+ * === Hashing several pieces of data at once
397
+ *
398
+ * data1 = File.read('file1')
399
+ * data2 = File.read('file2')
400
+ * data3 = File.read('file3')
401
+ * sha256 = OpenSSL::Digest::SHA256.new
402
+ * sha256 << data1
403
+ * sha256 << data2
404
+ * sha256 << data3
405
+ * digest = sha256.digest
406
+ *
407
+ * === Reuse a Digest instance
408
+ *
409
+ * data1 = File.read('file1')
410
+ * sha256 = OpenSSL::Digest::SHA256.new
411
+ * digest1 = sha256.digest(data1)
412
+ *
413
+ * data2 = File.read('file2')
414
+ * sha256.reset
415
+ * digest2 = sha256.digest(data2)
416
+ *
417
+ */
241
418
  cDigest = rb_define_class_under(mOSSL, "Digest", rb_path2class("Digest::Class"));
419
+ /* Document-class: OpenSSL::Digest::DigestError
420
+ *
421
+ * Generic Exception class that is raised if an error occurs during a
422
+ * Digest operation.
423
+ */
242
424
  eDigestError = rb_define_class_under(cDigest, "DigestError", eOSSLError);
243
-
425
+
244
426
  rb_define_alloc_func(cDigest, ossl_digest_alloc);
245
427
 
246
428
  rb_define_method(cDigest, "initialize", ossl_digest_initialize, -1);
@@ -1,5 +1,5 @@
1
1
  /*
2
- * $Id: ossl_digest.h 12496 2007-06-08 15:02:04Z technorama $
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.
@@ -13,23 +13,23 @@
13
13
  #if defined(OSSL_ENGINE_ENABLED)
14
14
 
15
15
  #define WrapEngine(klass, obj, engine) do { \
16
- if (!engine) { \
16
+ if (!(engine)) { \
17
17
  ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
18
18
  } \
19
- obj = Data_Wrap_Struct(klass, 0, ENGINE_free, engine); \
19
+ (obj) = Data_Wrap_Struct((klass), 0, ENGINE_free, (engine)); \
20
20
  } while(0)
21
21
  #define GetEngine(obj, engine) do { \
22
- Data_Get_Struct(obj, ENGINE, engine); \
23
- if (!engine) { \
22
+ Data_Get_Struct((obj), ENGINE, (engine)); \
23
+ if (!(engine)) { \
24
24
  ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
25
25
  } \
26
26
  } while (0)
27
27
  #define SafeGetEngine(obj, engine) do { \
28
- OSSL_Check_Kind(obj, cEngine); \
29
- GetPKCS7(obj, engine); \
28
+ OSSL_Check_Kind((obj), cEngine); \
29
+ GetPKCS7((obj), (engine)); \
30
30
  } while (0)
31
31
 
32
- /*
32
+ /*
33
33
  * Classes
34
34
  */
35
35
  VALUE cEngine;
@@ -64,29 +64,47 @@ ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
64
64
  #if HAVE_ENGINE_LOAD_DYNAMIC
65
65
  OSSL_ENGINE_LOAD_IF_MATCH(dynamic);
66
66
  #endif
67
- #if HAVE_ENGINE_LOAD_CSWIFT
68
- OSSL_ENGINE_LOAD_IF_MATCH(cswift);
67
+ #if HAVE_ENGINE_LOAD_4758CCA
68
+ OSSL_ENGINE_LOAD_IF_MATCH(4758cca);
69
69
  #endif
70
- #if HAVE_ENGINE_LOAD_CHIL
71
- OSSL_ENGINE_LOAD_IF_MATCH(chil);
70
+ #if HAVE_ENGINE_LOAD_AEP
71
+ OSSL_ENGINE_LOAD_IF_MATCH(aep);
72
72
  #endif
73
73
  #if HAVE_ENGINE_LOAD_ATALLA
74
74
  OSSL_ENGINE_LOAD_IF_MATCH(atalla);
75
75
  #endif
76
+ #if HAVE_ENGINE_LOAD_CHIL
77
+ OSSL_ENGINE_LOAD_IF_MATCH(chil);
78
+ #endif
79
+ #if HAVE_ENGINE_LOAD_CSWIFT
80
+ OSSL_ENGINE_LOAD_IF_MATCH(cswift);
81
+ #endif
76
82
  #if HAVE_ENGINE_LOAD_NURON
77
83
  OSSL_ENGINE_LOAD_IF_MATCH(nuron);
78
84
  #endif
85
+ #if HAVE_ENGINE_LOAD_SUREWARE
86
+ OSSL_ENGINE_LOAD_IF_MATCH(sureware);
87
+ #endif
79
88
  #if HAVE_ENGINE_LOAD_UBSEC
80
89
  OSSL_ENGINE_LOAD_IF_MATCH(ubsec);
81
90
  #endif
82
- #if HAVE_ENGINE_LOAD_AEP
83
- OSSL_ENGINE_LOAD_IF_MATCH(aep);
91
+ #if HAVE_ENGINE_LOAD_PADLOCK
92
+ OSSL_ENGINE_LOAD_IF_MATCH(padlock);
84
93
  #endif
85
- #if HAVE_ENGINE_LOAD_SUREWARE
86
- OSSL_ENGINE_LOAD_IF_MATCH(sureware);
94
+ #if HAVE_ENGINE_LOAD_CAPI
95
+ OSSL_ENGINE_LOAD_IF_MATCH(capi);
87
96
  #endif
88
- #if HAVE_ENGINE_LOAD_4758CCA
89
- OSSL_ENGINE_LOAD_IF_MATCH(4758cca);
97
+ #if HAVE_ENGINE_LOAD_GMP
98
+ OSSL_ENGINE_LOAD_IF_MATCH(gmp);
99
+ #endif
100
+ #if HAVE_ENGINE_LOAD_GOST
101
+ OSSL_ENGINE_LOAD_IF_MATCH(gost);
102
+ #endif
103
+ #if HAVE_ENGINE_LOAD_CRYPTODEV
104
+ OSSL_ENGINE_LOAD_IF_MATCH(cryptodev);
105
+ #endif
106
+ #if HAVE_ENGINE_LOAD_AESNI
107
+ OSSL_ENGINE_LOAD_IF_MATCH(aesni);
90
108
  #endif
91
109
  #endif
92
110
  #ifdef HAVE_ENGINE_LOAD_OPENBSD_DEV_CRYPTO
@@ -115,7 +133,11 @@ ossl_engine_s_engines(VALUE klass)
115
133
 
116
134
  ary = rb_ary_new();
117
135
  for(e = ENGINE_get_first(); e; e = ENGINE_get_next(e)){
118
- WrapEngine(klass, obj, e);
136
+ /* Need a ref count of two here because of ENGINE_free being
137
+ * called internally by OpenSSL when moving to the next ENGINE
138
+ * and by us when releasing the ENGINE reference */
139
+ ENGINE_up_ref(e);
140
+ WrapEngine(klass, obj, e);
119
141
  rb_ary_push(ary, obj);
120
142
  }
121
143
 
@@ -137,7 +159,7 @@ ossl_engine_s_by_id(VALUE klass, VALUE id)
137
159
  if(!ENGINE_init(e))
138
160
  ossl_raise(eEngineError, NULL);
139
161
  ENGINE_ctrl(e, ENGINE_CTRL_SET_PASSWORD_CALLBACK,
140
- 0, NULL, (void(*)(void))ossl_pem_passwd_cb);
162
+ 0, NULL, (void(*)(void))ossl_pem_passwd_cb);
141
163
  ERR_clear_error();
142
164
 
143
165
  return obj;
@@ -184,10 +206,10 @@ ossl_engine_finish(VALUE self)
184
206
  return Qnil;
185
207
  }
186
208
 
209
+ #if defined(HAVE_ENGINE_GET_CIPHER)
187
210
  static VALUE
188
211
  ossl_engine_get_cipher(VALUE self, VALUE name)
189
212
  {
190
- #if defined(HAVE_ENGINE_GET_CIPHER)
191
213
  ENGINE *e;
192
214
  const EVP_CIPHER *ciph, *tmp;
193
215
  char *s;
@@ -202,15 +224,15 @@ ossl_engine_get_cipher(VALUE self, VALUE name)
202
224
  if(!ciph) ossl_raise(eEngineError, NULL);
203
225
 
204
226
  return ossl_cipher_new(ciph);
227
+ }
205
228
  #else
206
- rb_notimplement();
229
+ #define ossl_engine_get_cipher rb_f_notimplement
207
230
  #endif
208
- }
209
231
 
232
+ #if defined(HAVE_ENGINE_GET_DIGEST)
210
233
  static VALUE
211
234
  ossl_engine_get_digest(VALUE self, VALUE name)
212
235
  {
213
- #if defined(HAVE_ENGINE_GET_DIGEST)
214
236
  ENGINE *e;
215
237
  const EVP_MD *md, *tmp;
216
238
  char *s;
@@ -225,10 +247,10 @@ ossl_engine_get_digest(VALUE self, VALUE name)
225
247
  if(!md) ossl_raise(eEngineError, NULL);
226
248
 
227
249
  return ossl_digest_new(md);
250
+ }
228
251
  #else
229
- rb_notimplement();
252
+ #define ossl_engine_get_digest rb_f_notimplement
230
253
  #endif
231
- }
232
254
 
233
255
  static VALUE
234
256
  ossl_engine_load_privkey(int argc, VALUE *argv, VALUE self)
@@ -345,7 +367,7 @@ ossl_engine_inspect(VALUE self)
345
367
  {
346
368
  VALUE str;
347
369
  const char *cname = rb_class2name(rb_obj_class(self));
348
-
370
+
349
371
  str = rb_str_new2("#<");
350
372
  rb_str_cat2(str, cname);
351
373
  rb_str_cat2(str, " id=\"");