openssl 2.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of openssl might be problematic. Click here for more details.

Files changed (71) hide show
  1. checksums.yaml +7 -0
  2. data/BSDL +22 -0
  3. data/CONTRIBUTING.md +130 -0
  4. data/History.md +118 -0
  5. data/LICENSE.txt +56 -0
  6. data/README.md +70 -0
  7. data/ext/openssl/deprecation.rb +26 -0
  8. data/ext/openssl/extconf.rb +158 -0
  9. data/ext/openssl/openssl_missing.c +173 -0
  10. data/ext/openssl/openssl_missing.h +244 -0
  11. data/ext/openssl/ossl.c +1201 -0
  12. data/ext/openssl/ossl.h +222 -0
  13. data/ext/openssl/ossl_asn1.c +1992 -0
  14. data/ext/openssl/ossl_asn1.h +66 -0
  15. data/ext/openssl/ossl_bio.c +87 -0
  16. data/ext/openssl/ossl_bio.h +19 -0
  17. data/ext/openssl/ossl_bn.c +1153 -0
  18. data/ext/openssl/ossl_bn.h +23 -0
  19. data/ext/openssl/ossl_cipher.c +1085 -0
  20. data/ext/openssl/ossl_cipher.h +20 -0
  21. data/ext/openssl/ossl_config.c +89 -0
  22. data/ext/openssl/ossl_config.h +19 -0
  23. data/ext/openssl/ossl_digest.c +453 -0
  24. data/ext/openssl/ossl_digest.h +20 -0
  25. data/ext/openssl/ossl_engine.c +580 -0
  26. data/ext/openssl/ossl_engine.h +19 -0
  27. data/ext/openssl/ossl_hmac.c +398 -0
  28. data/ext/openssl/ossl_hmac.h +18 -0
  29. data/ext/openssl/ossl_ns_spki.c +406 -0
  30. data/ext/openssl/ossl_ns_spki.h +19 -0
  31. data/ext/openssl/ossl_ocsp.c +2013 -0
  32. data/ext/openssl/ossl_ocsp.h +23 -0
  33. data/ext/openssl/ossl_pkcs12.c +259 -0
  34. data/ext/openssl/ossl_pkcs12.h +13 -0
  35. data/ext/openssl/ossl_pkcs5.c +180 -0
  36. data/ext/openssl/ossl_pkcs5.h +6 -0
  37. data/ext/openssl/ossl_pkcs7.c +1125 -0
  38. data/ext/openssl/ossl_pkcs7.h +20 -0
  39. data/ext/openssl/ossl_pkey.c +435 -0
  40. data/ext/openssl/ossl_pkey.h +245 -0
  41. data/ext/openssl/ossl_pkey_dh.c +650 -0
  42. data/ext/openssl/ossl_pkey_dsa.c +672 -0
  43. data/ext/openssl/ossl_pkey_ec.c +1899 -0
  44. data/ext/openssl/ossl_pkey_rsa.c +768 -0
  45. data/ext/openssl/ossl_rand.c +238 -0
  46. data/ext/openssl/ossl_rand.h +18 -0
  47. data/ext/openssl/ossl_ssl.c +2679 -0
  48. data/ext/openssl/ossl_ssl.h +41 -0
  49. data/ext/openssl/ossl_ssl_session.c +352 -0
  50. data/ext/openssl/ossl_version.h +15 -0
  51. data/ext/openssl/ossl_x509.c +186 -0
  52. data/ext/openssl/ossl_x509.h +119 -0
  53. data/ext/openssl/ossl_x509attr.c +328 -0
  54. data/ext/openssl/ossl_x509cert.c +860 -0
  55. data/ext/openssl/ossl_x509crl.c +565 -0
  56. data/ext/openssl/ossl_x509ext.c +480 -0
  57. data/ext/openssl/ossl_x509name.c +547 -0
  58. data/ext/openssl/ossl_x509req.c +492 -0
  59. data/ext/openssl/ossl_x509revoked.c +279 -0
  60. data/ext/openssl/ossl_x509store.c +846 -0
  61. data/ext/openssl/ruby_missing.h +32 -0
  62. data/lib/openssl.rb +21 -0
  63. data/lib/openssl/bn.rb +39 -0
  64. data/lib/openssl/buffering.rb +451 -0
  65. data/lib/openssl/cipher.rb +67 -0
  66. data/lib/openssl/config.rb +473 -0
  67. data/lib/openssl/digest.rb +78 -0
  68. data/lib/openssl/pkey.rb +44 -0
  69. data/lib/openssl/ssl.rb +416 -0
  70. data/lib/openssl/x509.rb +176 -0
  71. metadata +178 -0
@@ -0,0 +1,20 @@
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
+ #if !defined(_OSSL_DIGEST_H_)
11
+ #define _OSSL_DIGEST_H_
12
+
13
+ extern VALUE cDigest;
14
+ extern VALUE eDigestError;
15
+
16
+ const EVP_MD *GetDigestPtr(VALUE);
17
+ VALUE ossl_digest_new(const EVP_MD *);
18
+ void Init_ossl_digest(void);
19
+
20
+ #endif /* _OSSL_DIGEST_H_ */
@@ -0,0 +1,580 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
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
+ #if !defined(OPENSSL_NO_ENGINE)
13
+
14
+ #define NewEngine(klass) \
15
+ TypedData_Wrap_Struct((klass), &ossl_engine_type, 0)
16
+ #define SetEngine(obj, engine) do { \
17
+ if (!(engine)) { \
18
+ ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
19
+ } \
20
+ RTYPEDDATA_DATA(obj) = (engine); \
21
+ } while(0)
22
+ #define GetEngine(obj, engine) do { \
23
+ TypedData_Get_Struct((obj), ENGINE, &ossl_engine_type, (engine)); \
24
+ if (!(engine)) { \
25
+ ossl_raise(rb_eRuntimeError, "ENGINE wasn't initialized."); \
26
+ } \
27
+ } while (0)
28
+ #define SafeGetEngine(obj, engine) do { \
29
+ OSSL_Check_Kind((obj), cEngine); \
30
+ GetPKCS7((obj), (engine)); \
31
+ } while (0)
32
+
33
+ /*
34
+ * Classes
35
+ */
36
+ /* Document-class: OpenSSL::Engine
37
+ *
38
+ * This class is the access to openssl's ENGINE cryptographic module
39
+ * implementation.
40
+ *
41
+ * See also, https://www.openssl.org/docs/crypto/engine.html
42
+ */
43
+ VALUE cEngine;
44
+ /* Document-class: OpenSSL::Engine::EngineError
45
+ *
46
+ * This is the generic exception for OpenSSL::Engine related errors
47
+ */
48
+ VALUE eEngineError;
49
+
50
+ /*
51
+ * Private
52
+ */
53
+ #define OSSL_ENGINE_LOAD_IF_MATCH(x) \
54
+ do{\
55
+ if(!strcmp(#x, RSTRING_PTR(name))){\
56
+ ENGINE_load_##x();\
57
+ return Qtrue;\
58
+ }\
59
+ }while(0)
60
+
61
+ static void
62
+ ossl_engine_free(void *engine)
63
+ {
64
+ ENGINE_free(engine);
65
+ }
66
+
67
+ static const rb_data_type_t ossl_engine_type = {
68
+ "OpenSSL/Engine",
69
+ {
70
+ 0, ossl_engine_free,
71
+ },
72
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
73
+ };
74
+
75
+ /* Document-method: OpenSSL::Engine.load
76
+ *
77
+ * call-seq:
78
+ * load(enginename = nil)
79
+ *
80
+ * This method loads engines. If +name+ is nil, then all builtin engines are
81
+ * loaded. Otherwise, the given +name+, as a string, is loaded if available to
82
+ * your runtime, and returns true. If +name+ is not found, then nil is
83
+ * returned.
84
+ *
85
+ */
86
+ static VALUE
87
+ ossl_engine_s_load(int argc, VALUE *argv, VALUE klass)
88
+ {
89
+ #if !defined(HAVE_ENGINE_LOAD_BUILTIN_ENGINES)
90
+ return Qnil;
91
+ #else
92
+ VALUE name;
93
+
94
+ rb_scan_args(argc, argv, "01", &name);
95
+ if(NIL_P(name)){
96
+ ENGINE_load_builtin_engines();
97
+ return Qtrue;
98
+ }
99
+ StringValueCStr(name);
100
+ #ifndef OPENSSL_NO_STATIC_ENGINE
101
+ #if HAVE_ENGINE_LOAD_DYNAMIC
102
+ OSSL_ENGINE_LOAD_IF_MATCH(dynamic);
103
+ #endif
104
+ #if HAVE_ENGINE_LOAD_4758CCA
105
+ OSSL_ENGINE_LOAD_IF_MATCH(4758cca);
106
+ #endif
107
+ #if HAVE_ENGINE_LOAD_AEP
108
+ OSSL_ENGINE_LOAD_IF_MATCH(aep);
109
+ #endif
110
+ #if HAVE_ENGINE_LOAD_ATALLA
111
+ OSSL_ENGINE_LOAD_IF_MATCH(atalla);
112
+ #endif
113
+ #if HAVE_ENGINE_LOAD_CHIL
114
+ OSSL_ENGINE_LOAD_IF_MATCH(chil);
115
+ #endif
116
+ #if HAVE_ENGINE_LOAD_CSWIFT
117
+ OSSL_ENGINE_LOAD_IF_MATCH(cswift);
118
+ #endif
119
+ #if HAVE_ENGINE_LOAD_NURON
120
+ OSSL_ENGINE_LOAD_IF_MATCH(nuron);
121
+ #endif
122
+ #if HAVE_ENGINE_LOAD_SUREWARE
123
+ OSSL_ENGINE_LOAD_IF_MATCH(sureware);
124
+ #endif
125
+ #if HAVE_ENGINE_LOAD_UBSEC
126
+ OSSL_ENGINE_LOAD_IF_MATCH(ubsec);
127
+ #endif
128
+ #if HAVE_ENGINE_LOAD_PADLOCK
129
+ OSSL_ENGINE_LOAD_IF_MATCH(padlock);
130
+ #endif
131
+ #if HAVE_ENGINE_LOAD_CAPI
132
+ OSSL_ENGINE_LOAD_IF_MATCH(capi);
133
+ #endif
134
+ #if HAVE_ENGINE_LOAD_GMP
135
+ OSSL_ENGINE_LOAD_IF_MATCH(gmp);
136
+ #endif
137
+ #if HAVE_ENGINE_LOAD_GOST
138
+ OSSL_ENGINE_LOAD_IF_MATCH(gost);
139
+ #endif
140
+ #if HAVE_ENGINE_LOAD_CRYPTODEV
141
+ OSSL_ENGINE_LOAD_IF_MATCH(cryptodev);
142
+ #endif
143
+ #if HAVE_ENGINE_LOAD_AESNI
144
+ OSSL_ENGINE_LOAD_IF_MATCH(aesni);
145
+ #endif
146
+ #endif
147
+ #ifdef HAVE_ENGINE_LOAD_OPENBSD_DEV_CRYPTO
148
+ OSSL_ENGINE_LOAD_IF_MATCH(openbsd_dev_crypto);
149
+ #endif
150
+ OSSL_ENGINE_LOAD_IF_MATCH(openssl);
151
+ rb_warning("no such builtin loader for `%"PRIsVALUE"'", name);
152
+ return Qnil;
153
+ #endif /* HAVE_ENGINE_LOAD_BUILTIN_ENGINES */
154
+ }
155
+
156
+ /* Document-method: OpenSSL::Engine.cleanup
157
+ * call-seq:
158
+ * OpenSSL::Engine.cleanup
159
+ *
160
+ * It is only necessary to run cleanup when engines are loaded via
161
+ * OpenSSL::Engine.load. However, running cleanup before exit is recommended.
162
+ *
163
+ * Note that this is needed and works only in OpenSSL < 1.1.0.
164
+ */
165
+ static VALUE
166
+ ossl_engine_s_cleanup(VALUE self)
167
+ {
168
+ ENGINE_cleanup();
169
+ return Qnil;
170
+ }
171
+
172
+ /* Document-method: OpenSSL::Engine.engines
173
+ *
174
+ * Returns an array of currently loaded engines.
175
+ */
176
+ static VALUE
177
+ ossl_engine_s_engines(VALUE klass)
178
+ {
179
+ ENGINE *e;
180
+ VALUE ary, obj;
181
+
182
+ ary = rb_ary_new();
183
+ for(e = ENGINE_get_first(); e; e = ENGINE_get_next(e)){
184
+ obj = NewEngine(klass);
185
+ /* Need a ref count of two here because of ENGINE_free being
186
+ * called internally by OpenSSL when moving to the next ENGINE
187
+ * and by us when releasing the ENGINE reference */
188
+ ENGINE_up_ref(e);
189
+ SetEngine(obj, e);
190
+ rb_ary_push(ary, obj);
191
+ }
192
+
193
+ return ary;
194
+ }
195
+
196
+ /* Document-method: OpenSSL::Engine.by_id
197
+ *
198
+ * call-seq:
199
+ * by_id(name) -> engine
200
+ *
201
+ * Fetch the engine as specified by the +id+ String
202
+ *
203
+ * OpenSSL::Engine.by_id("openssl")
204
+ * => #<OpenSSL::Engine id="openssl" name="Software engine support">
205
+ *
206
+ * See OpenSSL::Engine.engines for the currently loaded engines
207
+ */
208
+ static VALUE
209
+ ossl_engine_s_by_id(VALUE klass, VALUE id)
210
+ {
211
+ ENGINE *e;
212
+ VALUE obj;
213
+
214
+ StringValueCStr(id);
215
+ ossl_engine_s_load(1, &id, klass);
216
+ obj = NewEngine(klass);
217
+ if(!(e = ENGINE_by_id(RSTRING_PTR(id))))
218
+ ossl_raise(eEngineError, NULL);
219
+ SetEngine(obj, e);
220
+ if(rb_block_given_p()) rb_yield(obj);
221
+ if(!ENGINE_init(e))
222
+ ossl_raise(eEngineError, NULL);
223
+ ENGINE_ctrl(e, ENGINE_CTRL_SET_PASSWORD_CALLBACK,
224
+ 0, NULL, (void(*)(void))ossl_pem_passwd_cb);
225
+ ossl_clear_error();
226
+
227
+ return obj;
228
+ }
229
+
230
+ static VALUE
231
+ ossl_engine_s_alloc(VALUE klass)
232
+ {
233
+ ENGINE *e;
234
+ VALUE obj;
235
+
236
+ obj = NewEngine(klass);
237
+ if (!(e = ENGINE_new())) {
238
+ ossl_raise(eEngineError, NULL);
239
+ }
240
+ SetEngine(obj, e);
241
+
242
+ return obj;
243
+ }
244
+
245
+ /* Document-method: OpenSSL::Engine#id
246
+ *
247
+ * Get the id for this engine
248
+ *
249
+ * OpenSSL::Engine.load
250
+ * OpenSSL::Engine.engines #=> [#<OpenSSL::Engine#>, ...]
251
+ * OpenSSL::Engine.engines.first.id
252
+ * #=> "rsax"
253
+ */
254
+ static VALUE
255
+ ossl_engine_get_id(VALUE self)
256
+ {
257
+ ENGINE *e;
258
+ GetEngine(self, e);
259
+ return rb_str_new2(ENGINE_get_id(e));
260
+ }
261
+
262
+ /* Document-method: OpenSSL::Engine#name
263
+ *
264
+ * Get the descriptive name for this engine
265
+ *
266
+ * OpenSSL::Engine.load
267
+ * OpenSSL::Engine.engines #=> [#<OpenSSL::Engine#>, ...]
268
+ * OpenSSL::Engine.engines.first.name
269
+ * #=> "RSAX engine support"
270
+ *
271
+ */
272
+ static VALUE
273
+ ossl_engine_get_name(VALUE self)
274
+ {
275
+ ENGINE *e;
276
+ GetEngine(self, e);
277
+ return rb_str_new2(ENGINE_get_name(e));
278
+ }
279
+
280
+ /* Document-method: OpenSSL::Engine#finish
281
+ *
282
+ * Releases all internal structural references for this engine.
283
+ *
284
+ * May raise an EngineError if the engine is unavailable
285
+ */
286
+ static VALUE
287
+ ossl_engine_finish(VALUE self)
288
+ {
289
+ ENGINE *e;
290
+
291
+ GetEngine(self, e);
292
+ if(!ENGINE_finish(e)) ossl_raise(eEngineError, NULL);
293
+
294
+ return Qnil;
295
+ }
296
+
297
+ /* Document-method: OpenSSL::Engine#cipher
298
+ *
299
+ * call-seq:
300
+ * engine.cipher(name) -> OpenSSL::Cipher
301
+ *
302
+ * This returns an OpenSSL::Cipher by +name+, if it is available in this
303
+ * engine.
304
+ *
305
+ * A EngineError will be raised if the cipher is unavailable.
306
+ *
307
+ * e = OpenSSL::Engine.by_id("openssl")
308
+ * => #<OpenSSL::Engine id="openssl" name="Software engine support">
309
+ * e.cipher("RC4")
310
+ * => #<OpenSSL::Cipher:0x007fc5cacc3048>
311
+ *
312
+ */
313
+ static VALUE
314
+ ossl_engine_get_cipher(VALUE self, VALUE name)
315
+ {
316
+ ENGINE *e;
317
+ const EVP_CIPHER *ciph, *tmp;
318
+ int nid;
319
+
320
+ tmp = EVP_get_cipherbyname(StringValueCStr(name));
321
+ if(!tmp) ossl_raise(eEngineError, "no such cipher `%"PRIsVALUE"'", name);
322
+ nid = EVP_CIPHER_nid(tmp);
323
+ GetEngine(self, e);
324
+ ciph = ENGINE_get_cipher(e, nid);
325
+ if(!ciph) ossl_raise(eEngineError, NULL);
326
+
327
+ return ossl_cipher_new(ciph);
328
+ }
329
+
330
+ /* Document-method: OpenSSL::Engine#digest
331
+ *
332
+ * call-seq:
333
+ * engine.digest(name) -> OpenSSL::Digest
334
+ *
335
+ * This returns an OpenSSL::Digest by +name+.
336
+ *
337
+ * Will raise an EngineError if the digest is unavailable.
338
+ *
339
+ * e = OpenSSL::Engine.by_id("openssl")
340
+ * #=> #<OpenSSL::Engine id="openssl" name="Software engine support">
341
+ * e.digest("SHA1")
342
+ * #=> #<OpenSSL::Digest: da39a3ee5e6b4b0d3255bfef95601890afd80709>
343
+ * e.digest("zomg")
344
+ * #=> OpenSSL::Engine::EngineError: no such digest `zomg'
345
+ */
346
+ static VALUE
347
+ ossl_engine_get_digest(VALUE self, VALUE name)
348
+ {
349
+ ENGINE *e;
350
+ const EVP_MD *md, *tmp;
351
+ int nid;
352
+
353
+ tmp = EVP_get_digestbyname(StringValueCStr(name));
354
+ if(!tmp) ossl_raise(eEngineError, "no such digest `%"PRIsVALUE"'", name);
355
+ nid = EVP_MD_nid(tmp);
356
+ GetEngine(self, e);
357
+ md = ENGINE_get_digest(e, nid);
358
+ if(!md) ossl_raise(eEngineError, NULL);
359
+
360
+ return ossl_digest_new(md);
361
+ }
362
+
363
+ /* Document-method: OpenSSL::Engine#load_private_key
364
+ *
365
+ * call-seq:
366
+ * engine.load_private_key(id = nil, data = nil) -> OpenSSL::PKey
367
+ *
368
+ * Loads the given private key by +id+ and +data+.
369
+ *
370
+ * An EngineError is raised of the OpenSSL::PKey is unavailable.
371
+ *
372
+ */
373
+ static VALUE
374
+ ossl_engine_load_privkey(int argc, VALUE *argv, VALUE self)
375
+ {
376
+ ENGINE *e;
377
+ EVP_PKEY *pkey;
378
+ VALUE id, data, obj;
379
+ char *sid, *sdata;
380
+
381
+ rb_scan_args(argc, argv, "02", &id, &data);
382
+ sid = NIL_P(id) ? NULL : StringValueCStr(id);
383
+ sdata = NIL_P(data) ? NULL : StringValueCStr(data);
384
+ GetEngine(self, e);
385
+ pkey = ENGINE_load_private_key(e, sid, NULL, sdata);
386
+ if (!pkey) ossl_raise(eEngineError, NULL);
387
+ obj = ossl_pkey_new(pkey);
388
+ OSSL_PKEY_SET_PRIVATE(obj);
389
+
390
+ return obj;
391
+ }
392
+
393
+ /* Document-method: OpenSSL::Engine#load_public_key
394
+ *
395
+ * call-seq:
396
+ * engine.load_public_key(id = nil, data = nil) -> OpenSSL::PKey
397
+ *
398
+ * Loads the given private key by +id+ and +data+.
399
+ *
400
+ * An EngineError is raised of the OpenSSL::PKey is unavailable.
401
+ *
402
+ */
403
+ static VALUE
404
+ ossl_engine_load_pubkey(int argc, VALUE *argv, VALUE self)
405
+ {
406
+ ENGINE *e;
407
+ EVP_PKEY *pkey;
408
+ VALUE id, data;
409
+ char *sid, *sdata;
410
+
411
+ rb_scan_args(argc, argv, "02", &id, &data);
412
+ sid = NIL_P(id) ? NULL : StringValueCStr(id);
413
+ sdata = NIL_P(data) ? NULL : StringValueCStr(data);
414
+ GetEngine(self, e);
415
+ pkey = ENGINE_load_public_key(e, sid, NULL, sdata);
416
+ if (!pkey) ossl_raise(eEngineError, NULL);
417
+
418
+ return ossl_pkey_new(pkey);
419
+ }
420
+
421
+ /* Document-method: OpenSSL::Engine#set_default
422
+ *
423
+ * call-seq:
424
+ * engine.set_default(flag)
425
+ *
426
+ * Set the defaults for this engine with the given +flag+.
427
+ *
428
+ * These flags are used to control combinations of algorithm methods.
429
+ *
430
+ * +flag+ can be one of the following, other flags are available depending on
431
+ * your OS.
432
+ *
433
+ * [All flags] 0xFFFF
434
+ * [No flags] 0x0000
435
+ *
436
+ * See also <openssl/engine.h>
437
+ */
438
+ static VALUE
439
+ ossl_engine_set_default(VALUE self, VALUE flag)
440
+ {
441
+ ENGINE *e;
442
+ int f = NUM2INT(flag);
443
+
444
+ GetEngine(self, e);
445
+ ENGINE_set_default(e, f);
446
+
447
+ return Qtrue;
448
+ }
449
+
450
+ /* Document-method: OpenSSL::Engine#ctrl_cmd
451
+ *
452
+ * call-seq:
453
+ * engine.ctrl_cmd(command, value = nil) -> engine
454
+ *
455
+ * Send the given +command+ to this engine.
456
+ *
457
+ * Raises an EngineError if the +command+ fails.
458
+ */
459
+ static VALUE
460
+ ossl_engine_ctrl_cmd(int argc, VALUE *argv, VALUE self)
461
+ {
462
+ ENGINE *e;
463
+ VALUE cmd, val;
464
+ int ret;
465
+
466
+ GetEngine(self, e);
467
+ rb_scan_args(argc, argv, "11", &cmd, &val);
468
+ ret = ENGINE_ctrl_cmd_string(e, StringValueCStr(cmd),
469
+ NIL_P(val) ? NULL : StringValueCStr(val), 0);
470
+ if (!ret) ossl_raise(eEngineError, NULL);
471
+
472
+ return self;
473
+ }
474
+
475
+ static VALUE
476
+ ossl_engine_cmd_flag_to_name(int flag)
477
+ {
478
+ switch(flag){
479
+ case ENGINE_CMD_FLAG_NUMERIC: return rb_str_new2("NUMERIC");
480
+ case ENGINE_CMD_FLAG_STRING: return rb_str_new2("STRING");
481
+ case ENGINE_CMD_FLAG_NO_INPUT: return rb_str_new2("NO_INPUT");
482
+ case ENGINE_CMD_FLAG_INTERNAL: return rb_str_new2("INTERNAL");
483
+ default: return rb_str_new2("UNKNOWN");
484
+ }
485
+ }
486
+
487
+ /* Document-method: OpenSSL::Engine#cmds
488
+ *
489
+ * Returns an array of command definitions for the current engine
490
+ */
491
+ static VALUE
492
+ ossl_engine_get_cmds(VALUE self)
493
+ {
494
+ ENGINE *e;
495
+ const ENGINE_CMD_DEFN *defn, *p;
496
+ VALUE ary, tmp;
497
+
498
+ GetEngine(self, e);
499
+ ary = rb_ary_new();
500
+ if ((defn = ENGINE_get_cmd_defns(e)) != NULL){
501
+ for (p = defn; p->cmd_num > 0; p++){
502
+ tmp = rb_ary_new();
503
+ rb_ary_push(tmp, rb_str_new2(p->cmd_name));
504
+ rb_ary_push(tmp, rb_str_new2(p->cmd_desc));
505
+ rb_ary_push(tmp, ossl_engine_cmd_flag_to_name(p->cmd_flags));
506
+ rb_ary_push(ary, tmp);
507
+ }
508
+ }
509
+
510
+ return ary;
511
+ }
512
+
513
+ /* Document-method: OpenSSL::Engine#inspect
514
+ *
515
+ * Pretty print this engine
516
+ */
517
+ static VALUE
518
+ ossl_engine_inspect(VALUE self)
519
+ {
520
+ ENGINE *e;
521
+
522
+ GetEngine(self, e);
523
+ return rb_sprintf("#<%"PRIsVALUE" id=\"%s\" name=\"%s\">",
524
+ rb_obj_class(self), ENGINE_get_id(e), ENGINE_get_name(e));
525
+ }
526
+
527
+ #define DefEngineConst(x) rb_define_const(cEngine, #x, INT2NUM(ENGINE_##x))
528
+
529
+ void
530
+ Init_ossl_engine(void)
531
+ {
532
+ #if 0
533
+ mOSSL = rb_define_module("OpenSSL");
534
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
535
+ #endif
536
+
537
+ cEngine = rb_define_class_under(mOSSL, "Engine", rb_cObject);
538
+ eEngineError = rb_define_class_under(cEngine, "EngineError", eOSSLError);
539
+
540
+ rb_define_alloc_func(cEngine, ossl_engine_s_alloc);
541
+ rb_define_singleton_method(cEngine, "load", ossl_engine_s_load, -1);
542
+ rb_define_singleton_method(cEngine, "cleanup", ossl_engine_s_cleanup, 0);
543
+ rb_define_singleton_method(cEngine, "engines", ossl_engine_s_engines, 0);
544
+ rb_define_singleton_method(cEngine, "by_id", ossl_engine_s_by_id, 1);
545
+ rb_undef_method(CLASS_OF(cEngine), "new");
546
+ rb_undef_method(cEngine, "initialize_copy");
547
+
548
+ rb_define_method(cEngine, "id", ossl_engine_get_id, 0);
549
+ rb_define_method(cEngine, "name", ossl_engine_get_name, 0);
550
+ rb_define_method(cEngine, "finish", ossl_engine_finish, 0);
551
+ rb_define_method(cEngine, "cipher", ossl_engine_get_cipher, 1);
552
+ rb_define_method(cEngine, "digest", ossl_engine_get_digest, 1);
553
+ rb_define_method(cEngine, "load_private_key", ossl_engine_load_privkey, -1);
554
+ rb_define_method(cEngine, "load_public_key", ossl_engine_load_pubkey, -1);
555
+ rb_define_method(cEngine, "set_default", ossl_engine_set_default, 1);
556
+ rb_define_method(cEngine, "ctrl_cmd", ossl_engine_ctrl_cmd, -1);
557
+ rb_define_method(cEngine, "cmds", ossl_engine_get_cmds, 0);
558
+ rb_define_method(cEngine, "inspect", ossl_engine_inspect, 0);
559
+
560
+ DefEngineConst(METHOD_RSA);
561
+ DefEngineConst(METHOD_DSA);
562
+ DefEngineConst(METHOD_DH);
563
+ DefEngineConst(METHOD_RAND);
564
+ #ifdef ENGINE_METHOD_BN_MOD_EXP
565
+ DefEngineConst(METHOD_BN_MOD_EXP);
566
+ #endif
567
+ #ifdef ENGINE_METHOD_BN_MOD_EXP_CRT
568
+ DefEngineConst(METHOD_BN_MOD_EXP_CRT);
569
+ #endif
570
+ DefEngineConst(METHOD_CIPHERS);
571
+ DefEngineConst(METHOD_DIGESTS);
572
+ DefEngineConst(METHOD_ALL);
573
+ DefEngineConst(METHOD_NONE);
574
+ }
575
+ #else
576
+ void
577
+ Init_ossl_engine(void)
578
+ {
579
+ }
580
+ #endif