zig_example 0.3.0 → 0.3.1

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