openssl-custom 2.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/BSDL +22 -0
- data/CONTRIBUTING.md +132 -0
- data/History.md +485 -0
- data/LICENSE.txt +56 -0
- data/README.md +66 -0
- data/ext/openssl/extconf.rb +190 -0
- data/ext/openssl/openssl_missing.c +106 -0
- data/ext/openssl/openssl_missing.h +257 -0
- data/ext/openssl/ossl.c +1282 -0
- data/ext/openssl/ossl.h +181 -0
- data/ext/openssl/ossl_asn1.c +1878 -0
- data/ext/openssl/ossl_asn1.h +62 -0
- data/ext/openssl/ossl_bio.c +42 -0
- data/ext/openssl/ossl_bio.h +16 -0
- data/ext/openssl/ossl_bn.c +1270 -0
- data/ext/openssl/ossl_bn.h +26 -0
- data/ext/openssl/ossl_cipher.c +1075 -0
- data/ext/openssl/ossl_cipher.h +20 -0
- data/ext/openssl/ossl_config.c +89 -0
- data/ext/openssl/ossl_config.h +19 -0
- data/ext/openssl/ossl_digest.c +425 -0
- data/ext/openssl/ossl_digest.h +20 -0
- data/ext/openssl/ossl_engine.c +567 -0
- data/ext/openssl/ossl_engine.h +19 -0
- data/ext/openssl/ossl_hmac.c +389 -0
- data/ext/openssl/ossl_hmac.h +18 -0
- data/ext/openssl/ossl_kdf.c +303 -0
- data/ext/openssl/ossl_kdf.h +6 -0
- data/ext/openssl/ossl_ns_spki.c +405 -0
- data/ext/openssl/ossl_ns_spki.h +19 -0
- data/ext/openssl/ossl_ocsp.c +2013 -0
- data/ext/openssl/ossl_ocsp.h +23 -0
- data/ext/openssl/ossl_pkcs12.c +257 -0
- data/ext/openssl/ossl_pkcs12.h +13 -0
- data/ext/openssl/ossl_pkcs7.c +1098 -0
- data/ext/openssl/ossl_pkcs7.h +36 -0
- data/ext/openssl/ossl_pkey.c +673 -0
- data/ext/openssl/ossl_pkey.h +241 -0
- data/ext/openssl/ossl_pkey_dh.c +650 -0
- data/ext/openssl/ossl_pkey_dsa.c +664 -0
- data/ext/openssl/ossl_pkey_ec.c +1827 -0
- data/ext/openssl/ossl_pkey_rsa.c +966 -0
- data/ext/openssl/ossl_rand.c +200 -0
- data/ext/openssl/ossl_rand.h +18 -0
- data/ext/openssl/ossl_ssl.c +3080 -0
- data/ext/openssl/ossl_ssl.h +36 -0
- data/ext/openssl/ossl_ssl_session.c +332 -0
- data/ext/openssl/ossl_ts.c +1524 -0
- data/ext/openssl/ossl_ts.h +16 -0
- data/ext/openssl/ossl_x509.c +262 -0
- data/ext/openssl/ossl_x509.h +115 -0
- data/ext/openssl/ossl_x509attr.c +324 -0
- data/ext/openssl/ossl_x509cert.c +846 -0
- data/ext/openssl/ossl_x509crl.c +542 -0
- data/ext/openssl/ossl_x509ext.c +491 -0
- data/ext/openssl/ossl_x509name.c +590 -0
- data/ext/openssl/ossl_x509req.c +441 -0
- data/ext/openssl/ossl_x509revoked.c +300 -0
- data/ext/openssl/ossl_x509store.c +902 -0
- data/ext/openssl/ruby_missing.h +24 -0
- data/lib/openssl/bn.rb +40 -0
- data/lib/openssl/buffering.rb +478 -0
- data/lib/openssl/cipher.rb +67 -0
- data/lib/openssl/config.rb +501 -0
- data/lib/openssl/digest.rb +73 -0
- data/lib/openssl/hmac.rb +13 -0
- data/lib/openssl/marshal.rb +30 -0
- data/lib/openssl/pkcs5.rb +22 -0
- data/lib/openssl/pkey.rb +42 -0
- data/lib/openssl/ssl.rb +542 -0
- data/lib/openssl/version.rb +5 -0
- data/lib/openssl/x509.rb +369 -0
- data/lib/openssl.rb +38 -0
- metadata +196 -0
@@ -0,0 +1,36 @@
|
|
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_SSL_H_)
|
11
|
+
#define _OSSL_SSL_H_
|
12
|
+
|
13
|
+
#define GetSSL(obj, ssl) do { \
|
14
|
+
TypedData_Get_Struct((obj), SSL, &ossl_ssl_type, (ssl)); \
|
15
|
+
if (!(ssl)) { \
|
16
|
+
ossl_raise(rb_eRuntimeError, "SSL is not initialized"); \
|
17
|
+
} \
|
18
|
+
} while (0)
|
19
|
+
|
20
|
+
#define GetSSLSession(obj, sess) do { \
|
21
|
+
TypedData_Get_Struct((obj), SSL_SESSION, &ossl_ssl_session_type, (sess)); \
|
22
|
+
if (!(sess)) { \
|
23
|
+
ossl_raise(rb_eRuntimeError, "SSL Session wasn't initialized."); \
|
24
|
+
} \
|
25
|
+
} while (0)
|
26
|
+
|
27
|
+
extern const rb_data_type_t ossl_ssl_type;
|
28
|
+
extern const rb_data_type_t ossl_ssl_session_type;
|
29
|
+
extern VALUE mSSL;
|
30
|
+
extern VALUE cSSLSocket;
|
31
|
+
extern VALUE cSSLSession;
|
32
|
+
|
33
|
+
void Init_ossl_ssl(void);
|
34
|
+
void Init_ossl_ssl_session(void);
|
35
|
+
|
36
|
+
#endif /* _OSSL_SSL_H_ */
|
@@ -0,0 +1,332 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (C) 2004-2007 Technorama Ltd. <oss-ruby@technorama.net>
|
3
|
+
*/
|
4
|
+
|
5
|
+
#include "ossl.h"
|
6
|
+
|
7
|
+
VALUE cSSLSession;
|
8
|
+
static VALUE eSSLSession;
|
9
|
+
|
10
|
+
static void
|
11
|
+
ossl_ssl_session_free(void *ptr)
|
12
|
+
{
|
13
|
+
SSL_SESSION_free(ptr);
|
14
|
+
}
|
15
|
+
|
16
|
+
const rb_data_type_t ossl_ssl_session_type = {
|
17
|
+
"OpenSSL/SSL/Session",
|
18
|
+
{
|
19
|
+
0, ossl_ssl_session_free,
|
20
|
+
},
|
21
|
+
0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
|
22
|
+
};
|
23
|
+
|
24
|
+
static VALUE ossl_ssl_session_alloc(VALUE klass)
|
25
|
+
{
|
26
|
+
return TypedData_Wrap_Struct(klass, &ossl_ssl_session_type, NULL);
|
27
|
+
}
|
28
|
+
|
29
|
+
/*
|
30
|
+
* call-seq:
|
31
|
+
* Session.new(ssl_socket) -> Session
|
32
|
+
* Session.new(string) -> Session
|
33
|
+
*
|
34
|
+
* Creates a new Session object from an instance of SSLSocket or DER/PEM encoded
|
35
|
+
* String.
|
36
|
+
*/
|
37
|
+
static VALUE ossl_ssl_session_initialize(VALUE self, VALUE arg1)
|
38
|
+
{
|
39
|
+
SSL_SESSION *ctx = NULL;
|
40
|
+
|
41
|
+
if (RDATA(self)->data)
|
42
|
+
ossl_raise(eSSLSession, "SSL Session already initialized");
|
43
|
+
|
44
|
+
if (rb_obj_is_instance_of(arg1, cSSLSocket)) {
|
45
|
+
SSL *ssl;
|
46
|
+
|
47
|
+
GetSSL(arg1, ssl);
|
48
|
+
|
49
|
+
if ((ctx = SSL_get1_session(ssl)) == NULL)
|
50
|
+
ossl_raise(eSSLSession, "no session available");
|
51
|
+
} else {
|
52
|
+
BIO *in = ossl_obj2bio(&arg1);
|
53
|
+
|
54
|
+
ctx = PEM_read_bio_SSL_SESSION(in, NULL, NULL, NULL);
|
55
|
+
|
56
|
+
if (!ctx) {
|
57
|
+
OSSL_BIO_reset(in);
|
58
|
+
ctx = d2i_SSL_SESSION_bio(in, NULL);
|
59
|
+
}
|
60
|
+
|
61
|
+
BIO_free(in);
|
62
|
+
|
63
|
+
if (!ctx)
|
64
|
+
ossl_raise(rb_eArgError, "unknown type");
|
65
|
+
}
|
66
|
+
|
67
|
+
/* should not happen */
|
68
|
+
if (ctx == NULL)
|
69
|
+
ossl_raise(eSSLSession, "ctx not set - internal error");
|
70
|
+
|
71
|
+
RDATA(self)->data = ctx;
|
72
|
+
|
73
|
+
return self;
|
74
|
+
}
|
75
|
+
|
76
|
+
static VALUE
|
77
|
+
ossl_ssl_session_initialize_copy(VALUE self, VALUE other)
|
78
|
+
{
|
79
|
+
SSL_SESSION *sess, *sess_other, *sess_new;
|
80
|
+
|
81
|
+
rb_check_frozen(self);
|
82
|
+
sess = RTYPEDDATA_DATA(self); /* XXX */
|
83
|
+
GetSSLSession(other, sess_other);
|
84
|
+
|
85
|
+
sess_new = ASN1_dup((i2d_of_void *)i2d_SSL_SESSION, (d2i_of_void *)d2i_SSL_SESSION,
|
86
|
+
(char *)sess_other);
|
87
|
+
if (!sess_new)
|
88
|
+
ossl_raise(eSSLSession, "ASN1_dup");
|
89
|
+
|
90
|
+
RTYPEDDATA_DATA(self) = sess_new;
|
91
|
+
SSL_SESSION_free(sess);
|
92
|
+
|
93
|
+
return self;
|
94
|
+
}
|
95
|
+
|
96
|
+
static int
|
97
|
+
ossl_SSL_SESSION_cmp(const SSL_SESSION *a, const SSL_SESSION *b)
|
98
|
+
{
|
99
|
+
unsigned int a_len;
|
100
|
+
const unsigned char *a_sid = SSL_SESSION_get_id(a, &a_len);
|
101
|
+
unsigned int b_len;
|
102
|
+
const unsigned char *b_sid = SSL_SESSION_get_id(b, &b_len);
|
103
|
+
|
104
|
+
if (SSL_SESSION_get_protocol_version(a) != SSL_SESSION_get_protocol_version(b))
|
105
|
+
return 1;
|
106
|
+
if (a_len != b_len)
|
107
|
+
return 1;
|
108
|
+
|
109
|
+
return CRYPTO_memcmp(a_sid, b_sid, a_len);
|
110
|
+
}
|
111
|
+
|
112
|
+
/*
|
113
|
+
* call-seq:
|
114
|
+
* session1 == session2 -> boolean
|
115
|
+
*
|
116
|
+
* Returns +true+ if the two Session is the same, +false+ if not.
|
117
|
+
*/
|
118
|
+
static VALUE ossl_ssl_session_eq(VALUE val1, VALUE val2)
|
119
|
+
{
|
120
|
+
SSL_SESSION *ctx1, *ctx2;
|
121
|
+
|
122
|
+
GetSSLSession(val1, ctx1);
|
123
|
+
GetSSLSession(val2, ctx2);
|
124
|
+
|
125
|
+
switch (ossl_SSL_SESSION_cmp(ctx1, ctx2)) {
|
126
|
+
case 0: return Qtrue;
|
127
|
+
default: return Qfalse;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
/*
|
132
|
+
* call-seq:
|
133
|
+
* session.time -> Time
|
134
|
+
*
|
135
|
+
* Returns the time at which the session was established.
|
136
|
+
*/
|
137
|
+
static VALUE
|
138
|
+
ossl_ssl_session_get_time(VALUE self)
|
139
|
+
{
|
140
|
+
SSL_SESSION *ctx;
|
141
|
+
long t;
|
142
|
+
|
143
|
+
GetSSLSession(self, ctx);
|
144
|
+
t = SSL_SESSION_get_time(ctx);
|
145
|
+
if (t == 0)
|
146
|
+
return Qnil;
|
147
|
+
|
148
|
+
return rb_funcall(rb_cTime, rb_intern("at"), 1, LONG2NUM(t));
|
149
|
+
}
|
150
|
+
|
151
|
+
/*
|
152
|
+
* call-seq:
|
153
|
+
* session.timeout -> Integer
|
154
|
+
*
|
155
|
+
* Returns the timeout value set for the session, in seconds from the
|
156
|
+
* established time.
|
157
|
+
*
|
158
|
+
*/
|
159
|
+
static VALUE
|
160
|
+
ossl_ssl_session_get_timeout(VALUE self)
|
161
|
+
{
|
162
|
+
SSL_SESSION *ctx;
|
163
|
+
long t;
|
164
|
+
|
165
|
+
GetSSLSession(self, ctx);
|
166
|
+
t = SSL_SESSION_get_timeout(ctx);
|
167
|
+
|
168
|
+
return LONG2NUM(t);
|
169
|
+
}
|
170
|
+
|
171
|
+
/*
|
172
|
+
* call-seq:
|
173
|
+
* session.time = time
|
174
|
+
* session.time = integer
|
175
|
+
*
|
176
|
+
* Sets start time of the session. Time resolution is in seconds.
|
177
|
+
*
|
178
|
+
*/
|
179
|
+
static VALUE ossl_ssl_session_set_time(VALUE self, VALUE time_v)
|
180
|
+
{
|
181
|
+
SSL_SESSION *ctx;
|
182
|
+
long t;
|
183
|
+
|
184
|
+
GetSSLSession(self, ctx);
|
185
|
+
if (rb_obj_is_instance_of(time_v, rb_cTime)) {
|
186
|
+
time_v = rb_funcall(time_v, rb_intern("to_i"), 0);
|
187
|
+
}
|
188
|
+
t = NUM2LONG(time_v);
|
189
|
+
SSL_SESSION_set_time(ctx, t);
|
190
|
+
return ossl_ssl_session_get_time(self);
|
191
|
+
}
|
192
|
+
|
193
|
+
/*
|
194
|
+
* call-seq:
|
195
|
+
* session.timeout = integer
|
196
|
+
*
|
197
|
+
* Sets how long until the session expires in seconds.
|
198
|
+
*/
|
199
|
+
static VALUE ossl_ssl_session_set_timeout(VALUE self, VALUE time_v)
|
200
|
+
{
|
201
|
+
SSL_SESSION *ctx;
|
202
|
+
long t;
|
203
|
+
|
204
|
+
GetSSLSession(self, ctx);
|
205
|
+
t = NUM2LONG(time_v);
|
206
|
+
SSL_SESSION_set_timeout(ctx, t);
|
207
|
+
return ossl_ssl_session_get_timeout(self);
|
208
|
+
}
|
209
|
+
|
210
|
+
/*
|
211
|
+
* call-seq:
|
212
|
+
* session.id -> String
|
213
|
+
*
|
214
|
+
* Returns the Session ID.
|
215
|
+
*/
|
216
|
+
static VALUE ossl_ssl_session_get_id(VALUE self)
|
217
|
+
{
|
218
|
+
SSL_SESSION *ctx;
|
219
|
+
const unsigned char *p = NULL;
|
220
|
+
unsigned int i = 0;
|
221
|
+
|
222
|
+
GetSSLSession(self, ctx);
|
223
|
+
|
224
|
+
p = SSL_SESSION_get_id(ctx, &i);
|
225
|
+
|
226
|
+
return rb_str_new((const char *) p, i);
|
227
|
+
}
|
228
|
+
|
229
|
+
/*
|
230
|
+
* call-seq:
|
231
|
+
* session.to_der -> String
|
232
|
+
*
|
233
|
+
* Returns an ASN1 encoded String that contains the Session object.
|
234
|
+
*/
|
235
|
+
static VALUE ossl_ssl_session_to_der(VALUE self)
|
236
|
+
{
|
237
|
+
SSL_SESSION *ctx;
|
238
|
+
unsigned char *p;
|
239
|
+
int len;
|
240
|
+
VALUE str;
|
241
|
+
|
242
|
+
GetSSLSession(self, ctx);
|
243
|
+
len = i2d_SSL_SESSION(ctx, NULL);
|
244
|
+
if (len <= 0) {
|
245
|
+
ossl_raise(eSSLSession, "i2d_SSL_SESSION");
|
246
|
+
}
|
247
|
+
|
248
|
+
str = rb_str_new(0, len);
|
249
|
+
p = (unsigned char *)RSTRING_PTR(str);
|
250
|
+
i2d_SSL_SESSION(ctx, &p);
|
251
|
+
ossl_str_adjust(str, p);
|
252
|
+
return str;
|
253
|
+
}
|
254
|
+
|
255
|
+
/*
|
256
|
+
* call-seq:
|
257
|
+
* session.to_pem -> String
|
258
|
+
*
|
259
|
+
* Returns a PEM encoded String that contains the Session object.
|
260
|
+
*/
|
261
|
+
static VALUE ossl_ssl_session_to_pem(VALUE self)
|
262
|
+
{
|
263
|
+
SSL_SESSION *ctx;
|
264
|
+
BIO *out;
|
265
|
+
|
266
|
+
GetSSLSession(self, ctx);
|
267
|
+
|
268
|
+
if (!(out = BIO_new(BIO_s_mem()))) {
|
269
|
+
ossl_raise(eSSLSession, "BIO_s_mem()");
|
270
|
+
}
|
271
|
+
|
272
|
+
if (!PEM_write_bio_SSL_SESSION(out, ctx)) {
|
273
|
+
BIO_free(out);
|
274
|
+
ossl_raise(eSSLSession, "SSL_SESSION_print()");
|
275
|
+
}
|
276
|
+
|
277
|
+
|
278
|
+
return ossl_membio2str(out);
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
/*
|
283
|
+
* call-seq:
|
284
|
+
* session.to_text -> String
|
285
|
+
*
|
286
|
+
* Shows everything in the Session object. This is for diagnostic purposes.
|
287
|
+
*/
|
288
|
+
static VALUE ossl_ssl_session_to_text(VALUE self)
|
289
|
+
{
|
290
|
+
SSL_SESSION *ctx;
|
291
|
+
BIO *out;
|
292
|
+
|
293
|
+
GetSSLSession(self, ctx);
|
294
|
+
|
295
|
+
if (!(out = BIO_new(BIO_s_mem()))) {
|
296
|
+
ossl_raise(eSSLSession, "BIO_s_mem()");
|
297
|
+
}
|
298
|
+
|
299
|
+
if (!SSL_SESSION_print(out, ctx)) {
|
300
|
+
BIO_free(out);
|
301
|
+
ossl_raise(eSSLSession, "SSL_SESSION_print()");
|
302
|
+
}
|
303
|
+
|
304
|
+
return ossl_membio2str(out);
|
305
|
+
}
|
306
|
+
|
307
|
+
|
308
|
+
void Init_ossl_ssl_session(void)
|
309
|
+
{
|
310
|
+
#if 0
|
311
|
+
mOSSL = rb_define_module("OpenSSL");
|
312
|
+
mSSL = rb_define_module_under(mOSSL, "SSL");
|
313
|
+
eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
|
314
|
+
#endif
|
315
|
+
cSSLSession = rb_define_class_under(mSSL, "Session", rb_cObject);
|
316
|
+
eSSLSession = rb_define_class_under(cSSLSession, "SessionError", eOSSLError);
|
317
|
+
|
318
|
+
rb_define_alloc_func(cSSLSession, ossl_ssl_session_alloc);
|
319
|
+
rb_define_method(cSSLSession, "initialize", ossl_ssl_session_initialize, 1);
|
320
|
+
rb_define_method(cSSLSession, "initialize_copy", ossl_ssl_session_initialize_copy, 1);
|
321
|
+
|
322
|
+
rb_define_method(cSSLSession, "==", ossl_ssl_session_eq, 1);
|
323
|
+
|
324
|
+
rb_define_method(cSSLSession, "time", ossl_ssl_session_get_time, 0);
|
325
|
+
rb_define_method(cSSLSession, "time=", ossl_ssl_session_set_time, 1);
|
326
|
+
rb_define_method(cSSLSession, "timeout", ossl_ssl_session_get_timeout, 0);
|
327
|
+
rb_define_method(cSSLSession, "timeout=", ossl_ssl_session_set_timeout, 1);
|
328
|
+
rb_define_method(cSSLSession, "id", ossl_ssl_session_get_id, 0);
|
329
|
+
rb_define_method(cSSLSession, "to_der", ossl_ssl_session_to_der, 0);
|
330
|
+
rb_define_method(cSSLSession, "to_pem", ossl_ssl_session_to_pem, 0);
|
331
|
+
rb_define_method(cSSLSession, "to_text", ossl_ssl_session_to_text, 0);
|
332
|
+
}
|