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,23 @@
1
+ /*
2
+ * 'OpenSSL for Ruby' project
3
+ * Copyright (C) 2003 Michal Rokos <m.rokos@sh.cvut.cz>
4
+ * Copyright (C) 2003 GOTOU Yuuzou <gotoyuzo@notwork.org>
5
+ * All rights reserved.
6
+ */
7
+ /*
8
+ * This program is licensed under the same licence as Ruby.
9
+ * (See the file 'LICENCE'.)
10
+ */
11
+ #if !defined(_OSSL_OCSP_H_)
12
+ #define _OSSL_OCSP_H_
13
+
14
+ #if !defined(OPENSSL_NO_OCSP)
15
+ extern VALUE mOCSP;
16
+ extern VALUE cOCSPReq;
17
+ extern VALUE cOCSPRes;
18
+ extern VALUE cOCSPBasicRes;
19
+ #endif
20
+
21
+ void Init_ossl_ocsp(void);
22
+
23
+ #endif /* _OSSL_OCSP_H_ */
@@ -0,0 +1,257 @@
1
+ /*
2
+ * This program is licensed under the same licence as Ruby.
3
+ * (See the file 'LICENCE'.)
4
+ */
5
+ #include "ossl.h"
6
+
7
+ #define NewPKCS12(klass) \
8
+ TypedData_Wrap_Struct((klass), &ossl_pkcs12_type, 0)
9
+
10
+ #define SetPKCS12(obj, p12) do { \
11
+ if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \
12
+ RTYPEDDATA_DATA(obj) = (p12); \
13
+ } while (0)
14
+
15
+ #define GetPKCS12(obj, p12) do { \
16
+ TypedData_Get_Struct((obj), PKCS12, &ossl_pkcs12_type, (p12)); \
17
+ if(!(p12)) ossl_raise(rb_eRuntimeError, "PKCS12 wasn't initialized."); \
18
+ } while (0)
19
+
20
+ #define ossl_pkcs12_set_key(o,v) rb_iv_set((o), "@key", (v))
21
+ #define ossl_pkcs12_set_cert(o,v) rb_iv_set((o), "@certificate", (v))
22
+ #define ossl_pkcs12_set_ca_certs(o,v) rb_iv_set((o), "@ca_certs", (v))
23
+ #define ossl_pkcs12_get_key(o) rb_iv_get((o), "@key")
24
+ #define ossl_pkcs12_get_cert(o) rb_iv_get((o), "@certificate")
25
+ #define ossl_pkcs12_get_ca_certs(o) rb_iv_get((o), "@ca_certs")
26
+
27
+ /*
28
+ * Classes
29
+ */
30
+ VALUE cPKCS12;
31
+ VALUE ePKCS12Error;
32
+
33
+ /*
34
+ * Private
35
+ */
36
+ static void
37
+ ossl_pkcs12_free(void *ptr)
38
+ {
39
+ PKCS12_free(ptr);
40
+ }
41
+
42
+ static const rb_data_type_t ossl_pkcs12_type = {
43
+ "OpenSSL/PKCS12",
44
+ {
45
+ 0, ossl_pkcs12_free,
46
+ },
47
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
48
+ };
49
+
50
+ static VALUE
51
+ ossl_pkcs12_s_allocate(VALUE klass)
52
+ {
53
+ PKCS12 *p12;
54
+ VALUE obj;
55
+
56
+ obj = NewPKCS12(klass);
57
+ if(!(p12 = PKCS12_new())) ossl_raise(ePKCS12Error, NULL);
58
+ SetPKCS12(obj, p12);
59
+
60
+ return obj;
61
+ }
62
+
63
+ static VALUE
64
+ ossl_pkcs12_initialize_copy(VALUE self, VALUE other)
65
+ {
66
+ PKCS12 *p12, *p12_old, *p12_new;
67
+
68
+ rb_check_frozen(self);
69
+ GetPKCS12(self, p12_old);
70
+ GetPKCS12(other, p12);
71
+
72
+ p12_new = ASN1_dup((i2d_of_void *)i2d_PKCS12, (d2i_of_void *)d2i_PKCS12, (char *)p12);
73
+ if (!p12_new)
74
+ ossl_raise(ePKCS12Error, "ASN1_dup");
75
+
76
+ SetPKCS12(self, p12_new);
77
+ PKCS12_free(p12_old);
78
+
79
+ return self;
80
+ }
81
+
82
+ /*
83
+ * call-seq:
84
+ * PKCS12.create(pass, name, key, cert [, ca, [, key_pbe [, cert_pbe [, key_iter [, mac_iter [, keytype]]]]]])
85
+ *
86
+ * === Parameters
87
+ * * _pass_ - string
88
+ * * _name_ - A string describing the key.
89
+ * * _key_ - Any PKey.
90
+ * * _cert_ - A X509::Certificate.
91
+ * * The public_key portion of the certificate must contain a valid public key.
92
+ * * The not_before and not_after fields must be filled in.
93
+ * * _ca_ - An optional array of X509::Certificate's.
94
+ * * _key_pbe_ - string
95
+ * * _cert_pbe_ - string
96
+ * * _key_iter_ - integer
97
+ * * _mac_iter_ - integer
98
+ * * _keytype_ - An integer representing an MSIE specific extension.
99
+ *
100
+ * Any optional arguments may be supplied as +nil+ to preserve the OpenSSL defaults.
101
+ *
102
+ * See the OpenSSL documentation for PKCS12_create().
103
+ */
104
+ static VALUE
105
+ ossl_pkcs12_s_create(int argc, VALUE *argv, VALUE self)
106
+ {
107
+ VALUE pass, name, pkey, cert, ca, key_nid, cert_nid, key_iter, mac_iter, keytype;
108
+ VALUE obj;
109
+ char *passphrase, *friendlyname;
110
+ EVP_PKEY *key;
111
+ X509 *x509;
112
+ STACK_OF(X509) *x509s;
113
+ int nkey = 0, ncert = 0, kiter = 0, miter = 0, ktype = 0;
114
+ PKCS12 *p12;
115
+
116
+ rb_scan_args(argc, argv, "46", &pass, &name, &pkey, &cert, &ca, &key_nid, &cert_nid, &key_iter, &mac_iter, &keytype);
117
+ passphrase = NIL_P(pass) ? NULL : StringValueCStr(pass);
118
+ friendlyname = NIL_P(name) ? NULL : StringValueCStr(name);
119
+ key = GetPKeyPtr(pkey);
120
+ x509 = GetX509CertPtr(cert);
121
+ /* TODO: make a VALUE to nid function */
122
+ if (!NIL_P(key_nid)) {
123
+ if ((nkey = OBJ_txt2nid(StringValueCStr(key_nid))) == NID_undef)
124
+ ossl_raise(rb_eArgError, "Unknown PBE algorithm %"PRIsVALUE, key_nid);
125
+ }
126
+ if (!NIL_P(cert_nid)) {
127
+ if ((ncert = OBJ_txt2nid(StringValueCStr(cert_nid))) == NID_undef)
128
+ ossl_raise(rb_eArgError, "Unknown PBE algorithm %"PRIsVALUE, cert_nid);
129
+ }
130
+ if (!NIL_P(key_iter))
131
+ kiter = NUM2INT(key_iter);
132
+ if (!NIL_P(mac_iter))
133
+ miter = NUM2INT(mac_iter);
134
+ if (!NIL_P(keytype))
135
+ ktype = NUM2INT(keytype);
136
+
137
+ obj = NewPKCS12(cPKCS12);
138
+ x509s = NIL_P(ca) ? NULL : ossl_x509_ary2sk(ca);
139
+ p12 = PKCS12_create(passphrase, friendlyname, key, x509, x509s,
140
+ nkey, ncert, kiter, miter, ktype);
141
+ sk_X509_pop_free(x509s, X509_free);
142
+ if(!p12) ossl_raise(ePKCS12Error, NULL);
143
+ SetPKCS12(obj, p12);
144
+
145
+ ossl_pkcs12_set_key(obj, pkey);
146
+ ossl_pkcs12_set_cert(obj, cert);
147
+ ossl_pkcs12_set_ca_certs(obj, ca);
148
+
149
+ return obj;
150
+ }
151
+
152
+ /*
153
+ * call-seq:
154
+ * PKCS12.new -> pkcs12
155
+ * PKCS12.new(str) -> pkcs12
156
+ * PKCS12.new(str, pass) -> pkcs12
157
+ *
158
+ * === Parameters
159
+ * * _str_ - Must be a DER encoded PKCS12 string.
160
+ * * _pass_ - string
161
+ */
162
+ static VALUE
163
+ ossl_pkcs12_initialize(int argc, VALUE *argv, VALUE self)
164
+ {
165
+ BIO *in;
166
+ VALUE arg, pass, pkey, cert, ca;
167
+ char *passphrase;
168
+ EVP_PKEY *key;
169
+ X509 *x509;
170
+ STACK_OF(X509) *x509s = NULL;
171
+ int st = 0;
172
+ PKCS12 *pkcs = DATA_PTR(self);
173
+
174
+ if(rb_scan_args(argc, argv, "02", &arg, &pass) == 0) return self;
175
+ passphrase = NIL_P(pass) ? NULL : StringValueCStr(pass);
176
+ in = ossl_obj2bio(&arg);
177
+ d2i_PKCS12_bio(in, &pkcs);
178
+ DATA_PTR(self) = pkcs;
179
+ BIO_free(in);
180
+
181
+ pkey = cert = ca = Qnil;
182
+ /* OpenSSL's bug; PKCS12_parse() puts errors even if it succeeds.
183
+ * Fixed in OpenSSL 1.0.0t, 1.0.1p, 1.0.2d */
184
+ ERR_set_mark();
185
+ if(!PKCS12_parse(pkcs, passphrase, &key, &x509, &x509s))
186
+ ossl_raise(ePKCS12Error, "PKCS12_parse");
187
+ ERR_pop_to_mark();
188
+ if (key) {
189
+ pkey = rb_protect((VALUE (*)(VALUE))ossl_pkey_new, (VALUE)key, &st);
190
+ if (st) goto err;
191
+ }
192
+ if (x509) {
193
+ cert = rb_protect((VALUE (*)(VALUE))ossl_x509_new, (VALUE)x509, &st);
194
+ if (st) goto err;
195
+ }
196
+ if (x509s) {
197
+ ca = rb_protect((VALUE (*)(VALUE))ossl_x509_sk2ary, (VALUE)x509s, &st);
198
+ if (st) goto err;
199
+ }
200
+
201
+ err:
202
+ X509_free(x509);
203
+ sk_X509_pop_free(x509s, X509_free);
204
+ ossl_pkcs12_set_key(self, pkey);
205
+ ossl_pkcs12_set_cert(self, cert);
206
+ ossl_pkcs12_set_ca_certs(self, ca);
207
+ if(st) rb_jump_tag(st);
208
+
209
+ return self;
210
+ }
211
+
212
+ static VALUE
213
+ ossl_pkcs12_to_der(VALUE self)
214
+ {
215
+ PKCS12 *p12;
216
+ VALUE str;
217
+ long len;
218
+ unsigned char *p;
219
+
220
+ GetPKCS12(self, p12);
221
+ if((len = i2d_PKCS12(p12, NULL)) <= 0)
222
+ ossl_raise(ePKCS12Error, NULL);
223
+ str = rb_str_new(0, len);
224
+ p = (unsigned char *)RSTRING_PTR(str);
225
+ if(i2d_PKCS12(p12, &p) <= 0)
226
+ ossl_raise(ePKCS12Error, NULL);
227
+ ossl_str_adjust(str, p);
228
+
229
+ return str;
230
+ }
231
+
232
+ void
233
+ Init_ossl_pkcs12(void)
234
+ {
235
+ #undef rb_intern
236
+ #if 0
237
+ mOSSL = rb_define_module("OpenSSL");
238
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
239
+ #endif
240
+
241
+ /*
242
+ * Defines a file format commonly used to store private keys with
243
+ * accompanying public key certificates, protected with a password-based
244
+ * symmetric key.
245
+ */
246
+ cPKCS12 = rb_define_class_under(mOSSL, "PKCS12", rb_cObject);
247
+ ePKCS12Error = rb_define_class_under(cPKCS12, "PKCS12Error", eOSSLError);
248
+ rb_define_singleton_method(cPKCS12, "create", ossl_pkcs12_s_create, -1);
249
+
250
+ rb_define_alloc_func(cPKCS12, ossl_pkcs12_s_allocate);
251
+ rb_define_method(cPKCS12, "initialize_copy", ossl_pkcs12_initialize_copy, 1);
252
+ rb_attr(cPKCS12, rb_intern("key"), 1, 0, Qfalse);
253
+ rb_attr(cPKCS12, rb_intern("certificate"), 1, 0, Qfalse);
254
+ rb_attr(cPKCS12, rb_intern("ca_certs"), 1, 0, Qfalse);
255
+ rb_define_method(cPKCS12, "initialize", ossl_pkcs12_initialize, -1);
256
+ rb_define_method(cPKCS12, "to_der", ossl_pkcs12_to_der, 0);
257
+ }
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This program is licensed under the same licence as Ruby.
3
+ * (See the file 'LICENCE'.)
4
+ */
5
+ #if !defined(_OSSL_PKCS12_H_)
6
+ #define _OSSL_PKCS12_H_
7
+
8
+ extern VALUE cPKCS12;
9
+ extern VALUE ePKCS12Error;
10
+
11
+ void Init_ossl_pkcs12(void);
12
+
13
+ #endif /* _OSSL_PKCS12_H_ */