openssl-custom 2.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/BSDL +22 -0
  3. data/CONTRIBUTING.md +132 -0
  4. data/History.md +485 -0
  5. data/LICENSE.txt +56 -0
  6. data/README.md +66 -0
  7. data/ext/openssl/extconf.rb +190 -0
  8. data/ext/openssl/openssl_missing.c +106 -0
  9. data/ext/openssl/openssl_missing.h +257 -0
  10. data/ext/openssl/ossl.c +1282 -0
  11. data/ext/openssl/ossl.h +181 -0
  12. data/ext/openssl/ossl_asn1.c +1878 -0
  13. data/ext/openssl/ossl_asn1.h +62 -0
  14. data/ext/openssl/ossl_bio.c +42 -0
  15. data/ext/openssl/ossl_bio.h +16 -0
  16. data/ext/openssl/ossl_bn.c +1270 -0
  17. data/ext/openssl/ossl_bn.h +26 -0
  18. data/ext/openssl/ossl_cipher.c +1075 -0
  19. data/ext/openssl/ossl_cipher.h +20 -0
  20. data/ext/openssl/ossl_config.c +89 -0
  21. data/ext/openssl/ossl_config.h +19 -0
  22. data/ext/openssl/ossl_digest.c +425 -0
  23. data/ext/openssl/ossl_digest.h +20 -0
  24. data/ext/openssl/ossl_engine.c +567 -0
  25. data/ext/openssl/ossl_engine.h +19 -0
  26. data/ext/openssl/ossl_hmac.c +389 -0
  27. data/ext/openssl/ossl_hmac.h +18 -0
  28. data/ext/openssl/ossl_kdf.c +303 -0
  29. data/ext/openssl/ossl_kdf.h +6 -0
  30. data/ext/openssl/ossl_ns_spki.c +405 -0
  31. data/ext/openssl/ossl_ns_spki.h +19 -0
  32. data/ext/openssl/ossl_ocsp.c +2013 -0
  33. data/ext/openssl/ossl_ocsp.h +23 -0
  34. data/ext/openssl/ossl_pkcs12.c +257 -0
  35. data/ext/openssl/ossl_pkcs12.h +13 -0
  36. data/ext/openssl/ossl_pkcs7.c +1098 -0
  37. data/ext/openssl/ossl_pkcs7.h +36 -0
  38. data/ext/openssl/ossl_pkey.c +673 -0
  39. data/ext/openssl/ossl_pkey.h +241 -0
  40. data/ext/openssl/ossl_pkey_dh.c +650 -0
  41. data/ext/openssl/ossl_pkey_dsa.c +664 -0
  42. data/ext/openssl/ossl_pkey_ec.c +1827 -0
  43. data/ext/openssl/ossl_pkey_rsa.c +966 -0
  44. data/ext/openssl/ossl_rand.c +200 -0
  45. data/ext/openssl/ossl_rand.h +18 -0
  46. data/ext/openssl/ossl_ssl.c +3080 -0
  47. data/ext/openssl/ossl_ssl.h +36 -0
  48. data/ext/openssl/ossl_ssl_session.c +332 -0
  49. data/ext/openssl/ossl_ts.c +1524 -0
  50. data/ext/openssl/ossl_ts.h +16 -0
  51. data/ext/openssl/ossl_x509.c +262 -0
  52. data/ext/openssl/ossl_x509.h +115 -0
  53. data/ext/openssl/ossl_x509attr.c +324 -0
  54. data/ext/openssl/ossl_x509cert.c +846 -0
  55. data/ext/openssl/ossl_x509crl.c +542 -0
  56. data/ext/openssl/ossl_x509ext.c +491 -0
  57. data/ext/openssl/ossl_x509name.c +590 -0
  58. data/ext/openssl/ossl_x509req.c +441 -0
  59. data/ext/openssl/ossl_x509revoked.c +300 -0
  60. data/ext/openssl/ossl_x509store.c +902 -0
  61. data/ext/openssl/ruby_missing.h +24 -0
  62. data/lib/openssl/bn.rb +40 -0
  63. data/lib/openssl/buffering.rb +478 -0
  64. data/lib/openssl/cipher.rb +67 -0
  65. data/lib/openssl/config.rb +501 -0
  66. data/lib/openssl/digest.rb +73 -0
  67. data/lib/openssl/hmac.rb +13 -0
  68. data/lib/openssl/marshal.rb +30 -0
  69. data/lib/openssl/pkcs5.rb +22 -0
  70. data/lib/openssl/pkey.rb +42 -0
  71. data/lib/openssl/ssl.rb +542 -0
  72. data/lib/openssl/version.rb +5 -0
  73. data/lib/openssl/x509.rb +369 -0
  74. data/lib/openssl.rb +38 -0
  75. metadata +196 -0
@@ -0,0 +1,200 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2001-2002 Michal Rokos <m.rokos@sh.cvut.cz>
4
+ *
5
+ * All rights reserved.
6
+ *
7
+ * This program is licensed under the same licence as Ruby.
8
+ * (See the file 'LICENCE'.)
9
+ */
10
+ #include "ossl.h"
11
+
12
+ VALUE mRandom;
13
+ VALUE eRandomError;
14
+
15
+ /*
16
+ * call-seq:
17
+ * seed(str) -> str
18
+ *
19
+ * ::seed is equivalent to ::add where _entropy_ is length of _str_.
20
+ */
21
+ static VALUE
22
+ ossl_rand_seed(VALUE self, VALUE str)
23
+ {
24
+ StringValue(str);
25
+ RAND_seed(RSTRING_PTR(str), RSTRING_LENINT(str));
26
+
27
+ return str;
28
+ }
29
+
30
+ /*
31
+ * call-seq:
32
+ * add(str, entropy) -> self
33
+ *
34
+ * Mixes the bytes from _str_ into the Pseudo Random Number Generator(PRNG)
35
+ * state.
36
+ *
37
+ * Thus, if the data from _str_ are unpredictable to an adversary, this
38
+ * increases the uncertainty about the state and makes the PRNG output less
39
+ * predictable.
40
+ *
41
+ * The _entropy_ argument is (the lower bound of) an estimate of how much
42
+ * randomness is contained in _str_, measured in bytes.
43
+ *
44
+ * === Example
45
+ *
46
+ * pid = $$
47
+ * now = Time.now
48
+ * ary = [now.to_i, now.nsec, 1000, pid]
49
+ * OpenSSL::Random.add(ary.join, 0.0)
50
+ * OpenSSL::Random.seed(ary.join)
51
+ */
52
+ static VALUE
53
+ ossl_rand_add(VALUE self, VALUE str, VALUE entropy)
54
+ {
55
+ StringValue(str);
56
+ RAND_add(RSTRING_PTR(str), RSTRING_LENINT(str), NUM2DBL(entropy));
57
+
58
+ return self;
59
+ }
60
+
61
+ /*
62
+ * call-seq:
63
+ * load_random_file(filename) -> true
64
+ *
65
+ * Reads bytes from _filename_ and adds them to the PRNG.
66
+ */
67
+ static VALUE
68
+ ossl_rand_load_file(VALUE self, VALUE filename)
69
+ {
70
+ if(!RAND_load_file(StringValueCStr(filename), -1)) {
71
+ ossl_raise(eRandomError, NULL);
72
+ }
73
+ return Qtrue;
74
+ }
75
+
76
+ /*
77
+ * call-seq:
78
+ * write_random_file(filename) -> true
79
+ *
80
+ * Writes a number of random generated bytes (currently 1024) to _filename_
81
+ * which can be used to initialize the PRNG by calling ::load_random_file in a
82
+ * later session.
83
+ */
84
+ static VALUE
85
+ ossl_rand_write_file(VALUE self, VALUE filename)
86
+ {
87
+ if (RAND_write_file(StringValueCStr(filename)) == -1) {
88
+ ossl_raise(eRandomError, NULL);
89
+ }
90
+ return Qtrue;
91
+ }
92
+
93
+ /*
94
+ * call-seq:
95
+ * random_bytes(length) -> string
96
+ *
97
+ * Generates a String with _length_ number of cryptographically strong
98
+ * pseudo-random bytes.
99
+ *
100
+ * === Example
101
+ *
102
+ * OpenSSL::Random.random_bytes(12)
103
+ * #=> "..."
104
+ */
105
+ static VALUE
106
+ ossl_rand_bytes(VALUE self, VALUE len)
107
+ {
108
+ VALUE str;
109
+ int n = NUM2INT(len);
110
+ int ret;
111
+
112
+ str = rb_str_new(0, n);
113
+ ret = RAND_bytes((unsigned char *)RSTRING_PTR(str), n);
114
+ if (ret == 0) {
115
+ ossl_raise(eRandomError, "RAND_bytes");
116
+ } else if (ret == -1) {
117
+ ossl_raise(eRandomError, "RAND_bytes is not supported");
118
+ }
119
+
120
+ return str;
121
+ }
122
+
123
+ #ifdef HAVE_RAND_EGD
124
+ /*
125
+ * call-seq:
126
+ * egd(filename) -> true
127
+ *
128
+ * Same as ::egd_bytes but queries 255 bytes by default.
129
+ */
130
+ static VALUE
131
+ ossl_rand_egd(VALUE self, VALUE filename)
132
+ {
133
+ if (RAND_egd(StringValueCStr(filename)) == -1) {
134
+ ossl_raise(eRandomError, NULL);
135
+ }
136
+ return Qtrue;
137
+ }
138
+
139
+ /*
140
+ * call-seq:
141
+ * egd_bytes(filename, length) -> true
142
+ *
143
+ * Queries the entropy gathering daemon EGD on socket path given by _filename_.
144
+ *
145
+ * Fetches _length_ number of bytes and uses ::add to seed the OpenSSL built-in
146
+ * PRNG.
147
+ */
148
+ static VALUE
149
+ ossl_rand_egd_bytes(VALUE self, VALUE filename, VALUE len)
150
+ {
151
+ int n = NUM2INT(len);
152
+
153
+ if (RAND_egd_bytes(StringValueCStr(filename), n) == -1) {
154
+ ossl_raise(eRandomError, NULL);
155
+ }
156
+ return Qtrue;
157
+ }
158
+ #endif /* HAVE_RAND_EGD */
159
+
160
+ /*
161
+ * call-seq:
162
+ * status? => true | false
163
+ *
164
+ * Return +true+ if the PRNG has been seeded with enough data, +false+ otherwise.
165
+ */
166
+ static VALUE
167
+ ossl_rand_status(VALUE self)
168
+ {
169
+ return RAND_status() ? Qtrue : Qfalse;
170
+ }
171
+
172
+ /*
173
+ * INIT
174
+ */
175
+ void
176
+ Init_ossl_rand(void)
177
+ {
178
+ #if 0
179
+ mOSSL = rb_define_module("OpenSSL");
180
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
181
+ #endif
182
+
183
+ mRandom = rb_define_module_under(mOSSL, "Random");
184
+
185
+ eRandomError = rb_define_class_under(mRandom, "RandomError", eOSSLError);
186
+
187
+ rb_define_module_function(mRandom, "seed", ossl_rand_seed, 1);
188
+ rb_define_module_function(mRandom, "random_add", ossl_rand_add, 2);
189
+ rb_define_module_function(mRandom, "load_random_file", ossl_rand_load_file, 1);
190
+ rb_define_module_function(mRandom, "write_random_file", ossl_rand_write_file, 1);
191
+ rb_define_module_function(mRandom, "random_bytes", ossl_rand_bytes, 1);
192
+ #if OPENSSL_VERSION_NUMBER < 0x10101000 || defined(LIBRESSL_VERSION_NUMBER)
193
+ rb_define_alias(rb_singleton_class(mRandom), "pseudo_bytes", "random_bytes");
194
+ #endif
195
+ #ifdef HAVE_RAND_EGD
196
+ rb_define_module_function(mRandom, "egd", ossl_rand_egd, 1);
197
+ rb_define_module_function(mRandom, "egd_bytes", ossl_rand_egd_bytes, 2);
198
+ #endif /* HAVE_RAND_EGD */
199
+ rb_define_module_function(mRandom, "status?", ossl_rand_status, 0);
200
+ }
@@ -0,0 +1,18 @@
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_RAND_H_)
11
+ #define _OSSL_RAND_H_
12
+
13
+ extern VALUE mRandom;
14
+ extern VALUE eRandomError;
15
+
16
+ void Init_ossl_rand(void);
17
+
18
+ #endif /* _OSSL_RAND_H_ */