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,444 @@
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
+ #include "ossl.h"
11
+
12
+ #define NewX509Req(klass) \
13
+ TypedData_Wrap_Struct((klass), &ossl_x509req_type, 0)
14
+ #define SetX509Req(obj, req) do { \
15
+ if (!(req)) { \
16
+ ossl_raise(rb_eRuntimeError, "Req wasn't initialized!"); \
17
+ } \
18
+ RTYPEDDATA_DATA(obj) = (req); \
19
+ } while (0)
20
+ #define GetX509Req(obj, req) do { \
21
+ TypedData_Get_Struct((obj), X509_REQ, &ossl_x509req_type, (req)); \
22
+ if (!(req)) { \
23
+ ossl_raise(rb_eRuntimeError, "Req wasn't initialized!"); \
24
+ } \
25
+ } while (0)
26
+
27
+ /*
28
+ * Classes
29
+ */
30
+ VALUE cX509Req;
31
+ VALUE eX509ReqError;
32
+
33
+ static void
34
+ ossl_x509req_free(void *ptr)
35
+ {
36
+ X509_REQ_free(ptr);
37
+ }
38
+
39
+ static const rb_data_type_t ossl_x509req_type = {
40
+ "OpenSSL/X509/REQ",
41
+ {
42
+ 0, ossl_x509req_free,
43
+ },
44
+ 0, 0, RUBY_TYPED_FREE_IMMEDIATELY,
45
+ };
46
+
47
+ /*
48
+ * Public functions
49
+ */
50
+ X509_REQ *
51
+ GetX509ReqPtr(VALUE obj)
52
+ {
53
+ X509_REQ *req;
54
+
55
+ GetX509Req(obj, req);
56
+
57
+ return req;
58
+ }
59
+
60
+ /*
61
+ * Private functions
62
+ */
63
+ static VALUE
64
+ ossl_x509req_alloc(VALUE klass)
65
+ {
66
+ X509_REQ *req;
67
+ VALUE obj;
68
+
69
+ obj = NewX509Req(klass);
70
+ if (!(req = X509_REQ_new())) {
71
+ ossl_raise(eX509ReqError, NULL);
72
+ }
73
+ SetX509Req(obj, req);
74
+
75
+ return obj;
76
+ }
77
+
78
+ static VALUE
79
+ ossl_x509req_initialize(int argc, VALUE *argv, VALUE self)
80
+ {
81
+ BIO *in;
82
+ X509_REQ *req, *req_orig = RTYPEDDATA_DATA(self);
83
+ VALUE arg;
84
+
85
+ rb_check_frozen(self);
86
+ if (rb_scan_args(argc, argv, "01", &arg) == 0) {
87
+ return self;
88
+ }
89
+ arg = ossl_to_der_if_possible(arg);
90
+ in = ossl_obj2bio(&arg);
91
+ req = d2i_X509_REQ_bio(in, NULL);
92
+ if (!req) {
93
+ OSSL_BIO_reset(in);
94
+ req = PEM_read_bio_X509_REQ(in, NULL, NULL, NULL);
95
+ }
96
+ BIO_free(in);
97
+ if (!req)
98
+ ossl_raise(eX509ReqError, "PEM_read_bio_X509_REQ");
99
+
100
+ RTYPEDDATA_DATA(self) = req;
101
+ X509_REQ_free(req_orig);
102
+
103
+ return self;
104
+ }
105
+
106
+ static VALUE
107
+ ossl_x509req_copy(VALUE self, VALUE other)
108
+ {
109
+ X509_REQ *a, *b, *req;
110
+
111
+ rb_check_frozen(self);
112
+ if (self == other) return self;
113
+ GetX509Req(self, a);
114
+ GetX509Req(other, b);
115
+ if (!(req = X509_REQ_dup(b))) {
116
+ ossl_raise(eX509ReqError, NULL);
117
+ }
118
+ X509_REQ_free(a);
119
+ DATA_PTR(self) = req;
120
+
121
+ return self;
122
+ }
123
+
124
+ static VALUE
125
+ ossl_x509req_to_pem(VALUE self)
126
+ {
127
+ X509_REQ *req;
128
+ BIO *out;
129
+
130
+ GetX509Req(self, req);
131
+ if (!(out = BIO_new(BIO_s_mem()))) {
132
+ ossl_raise(eX509ReqError, NULL);
133
+ }
134
+ if (!PEM_write_bio_X509_REQ(out, req)) {
135
+ BIO_free(out);
136
+ ossl_raise(eX509ReqError, NULL);
137
+ }
138
+
139
+ return ossl_membio2str(out);
140
+ }
141
+
142
+ static VALUE
143
+ ossl_x509req_to_der(VALUE self)
144
+ {
145
+ X509_REQ *req;
146
+ VALUE str;
147
+ long len;
148
+ unsigned char *p;
149
+
150
+ GetX509Req(self, req);
151
+ if ((len = i2d_X509_REQ(req, NULL)) <= 0)
152
+ ossl_raise(eX509ReqError, NULL);
153
+ str = rb_str_new(0, len);
154
+ p = (unsigned char *)RSTRING_PTR(str);
155
+ if (i2d_X509_REQ(req, &p) <= 0)
156
+ ossl_raise(eX509ReqError, NULL);
157
+ ossl_str_adjust(str, p);
158
+
159
+ return str;
160
+ }
161
+
162
+ static VALUE
163
+ ossl_x509req_to_text(VALUE self)
164
+ {
165
+ X509_REQ *req;
166
+ BIO *out;
167
+
168
+ GetX509Req(self, req);
169
+ if (!(out = BIO_new(BIO_s_mem()))) {
170
+ ossl_raise(eX509ReqError, NULL);
171
+ }
172
+ if (!X509_REQ_print(out, req)) {
173
+ BIO_free(out);
174
+ ossl_raise(eX509ReqError, NULL);
175
+ }
176
+
177
+ return ossl_membio2str(out);
178
+ }
179
+
180
+ #if 0
181
+ /*
182
+ * Makes X509 from X509_REQuest
183
+ */
184
+ static VALUE
185
+ ossl_x509req_to_x509(VALUE self, VALUE days, VALUE key)
186
+ {
187
+ X509_REQ *req;
188
+ X509 *x509;
189
+
190
+ GetX509Req(self, req);
191
+ ...
192
+ if (!(x509 = X509_REQ_to_X509(req, d, pkey))) {
193
+ ossl_raise(eX509ReqError, NULL);
194
+ }
195
+
196
+ return ossl_x509_new(x509);
197
+ }
198
+ #endif
199
+
200
+ static VALUE
201
+ ossl_x509req_get_version(VALUE self)
202
+ {
203
+ X509_REQ *req;
204
+ long version;
205
+
206
+ GetX509Req(self, req);
207
+ version = X509_REQ_get_version(req);
208
+
209
+ return LONG2NUM(version);
210
+ }
211
+
212
+ static VALUE
213
+ ossl_x509req_set_version(VALUE self, VALUE version)
214
+ {
215
+ X509_REQ *req;
216
+ long ver;
217
+
218
+ if ((ver = NUM2LONG(version)) < 0) {
219
+ ossl_raise(eX509ReqError, "version must be >= 0!");
220
+ }
221
+ GetX509Req(self, req);
222
+ if (!X509_REQ_set_version(req, ver)) {
223
+ ossl_raise(eX509ReqError, "X509_REQ_set_version");
224
+ }
225
+
226
+ return version;
227
+ }
228
+
229
+ static VALUE
230
+ ossl_x509req_get_subject(VALUE self)
231
+ {
232
+ X509_REQ *req;
233
+ X509_NAME *name;
234
+
235
+ GetX509Req(self, req);
236
+ if (!(name = X509_REQ_get_subject_name(req))) { /* NO DUP - don't free */
237
+ ossl_raise(eX509ReqError, NULL);
238
+ }
239
+
240
+ return ossl_x509name_new(name);
241
+ }
242
+
243
+ static VALUE
244
+ ossl_x509req_set_subject(VALUE self, VALUE subject)
245
+ {
246
+ X509_REQ *req;
247
+
248
+ GetX509Req(self, req);
249
+ /* DUPs name */
250
+ if (!X509_REQ_set_subject_name(req, GetX509NamePtr(subject))) {
251
+ ossl_raise(eX509ReqError, NULL);
252
+ }
253
+
254
+ return subject;
255
+ }
256
+
257
+ static VALUE
258
+ ossl_x509req_get_signature_algorithm(VALUE self)
259
+ {
260
+ X509_REQ *req;
261
+ const X509_ALGOR *alg;
262
+ BIO *out;
263
+
264
+ GetX509Req(self, req);
265
+
266
+ if (!(out = BIO_new(BIO_s_mem()))) {
267
+ ossl_raise(eX509ReqError, NULL);
268
+ }
269
+ X509_REQ_get0_signature(req, NULL, &alg);
270
+ if (!i2a_ASN1_OBJECT(out, alg->algorithm)) {
271
+ BIO_free(out);
272
+ ossl_raise(eX509ReqError, NULL);
273
+ }
274
+
275
+ return ossl_membio2str(out);
276
+ }
277
+
278
+ static VALUE
279
+ ossl_x509req_get_public_key(VALUE self)
280
+ {
281
+ X509_REQ *req;
282
+ EVP_PKEY *pkey;
283
+
284
+ GetX509Req(self, req);
285
+ if (!(pkey = X509_REQ_get_pubkey(req))) { /* adds reference */
286
+ ossl_raise(eX509ReqError, NULL);
287
+ }
288
+
289
+ return ossl_pkey_new(pkey); /* NO DUP - OK */
290
+ }
291
+
292
+ static VALUE
293
+ ossl_x509req_set_public_key(VALUE self, VALUE key)
294
+ {
295
+ X509_REQ *req;
296
+ EVP_PKEY *pkey;
297
+
298
+ GetX509Req(self, req);
299
+ pkey = GetPKeyPtr(key);
300
+ ossl_pkey_check_public_key(pkey);
301
+ if (!X509_REQ_set_pubkey(req, pkey))
302
+ ossl_raise(eX509ReqError, "X509_REQ_set_pubkey");
303
+ return key;
304
+ }
305
+
306
+ static VALUE
307
+ ossl_x509req_sign(VALUE self, VALUE key, VALUE digest)
308
+ {
309
+ X509_REQ *req;
310
+ EVP_PKEY *pkey;
311
+ const EVP_MD *md;
312
+
313
+ GetX509Req(self, req);
314
+ pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
315
+ md = ossl_evp_get_digestbyname(digest);
316
+ if (!X509_REQ_sign(req, pkey, md)) {
317
+ ossl_raise(eX509ReqError, NULL);
318
+ }
319
+
320
+ return self;
321
+ }
322
+
323
+ /*
324
+ * Checks that cert signature is made with PRIVversion of this PUBLIC 'key'
325
+ */
326
+ static VALUE
327
+ ossl_x509req_verify(VALUE self, VALUE key)
328
+ {
329
+ X509_REQ *req;
330
+ EVP_PKEY *pkey;
331
+
332
+ GetX509Req(self, req);
333
+ pkey = GetPKeyPtr(key);
334
+ ossl_pkey_check_public_key(pkey);
335
+ switch (X509_REQ_verify(req, pkey)) {
336
+ case 1:
337
+ return Qtrue;
338
+ case 0:
339
+ ossl_clear_error();
340
+ return Qfalse;
341
+ default:
342
+ ossl_raise(eX509ReqError, NULL);
343
+ }
344
+ }
345
+
346
+ static VALUE
347
+ ossl_x509req_get_attributes(VALUE self)
348
+ {
349
+ X509_REQ *req;
350
+ int count, i;
351
+ X509_ATTRIBUTE *attr;
352
+ VALUE ary;
353
+
354
+ GetX509Req(self, req);
355
+
356
+ count = X509_REQ_get_attr_count(req);
357
+ if (count < 0) {
358
+ OSSL_Debug("count < 0???");
359
+ return rb_ary_new();
360
+ }
361
+ ary = rb_ary_new2(count);
362
+ for (i=0; i<count; i++) {
363
+ attr = X509_REQ_get_attr(req, i);
364
+ rb_ary_push(ary, ossl_x509attr_new(attr));
365
+ }
366
+
367
+ return ary;
368
+ }
369
+
370
+ static VALUE
371
+ ossl_x509req_set_attributes(VALUE self, VALUE ary)
372
+ {
373
+ X509_REQ *req;
374
+ X509_ATTRIBUTE *attr;
375
+ long i;
376
+ VALUE item;
377
+
378
+ Check_Type(ary, T_ARRAY);
379
+ for (i=0;i<RARRAY_LEN(ary); i++) {
380
+ OSSL_Check_Kind(RARRAY_AREF(ary, i), cX509Attr);
381
+ }
382
+ GetX509Req(self, req);
383
+ for (i = X509_REQ_get_attr_count(req); i > 0; i--)
384
+ X509_ATTRIBUTE_free(X509_REQ_delete_attr(req, 0));
385
+ for (i=0;i<RARRAY_LEN(ary); i++) {
386
+ item = RARRAY_AREF(ary, i);
387
+ attr = GetX509AttrPtr(item);
388
+ if (!X509_REQ_add1_attr(req, attr)) {
389
+ ossl_raise(eX509ReqError, "X509_REQ_add1_attr");
390
+ }
391
+ }
392
+ return ary;
393
+ }
394
+
395
+ static VALUE
396
+ ossl_x509req_add_attribute(VALUE self, VALUE attr)
397
+ {
398
+ X509_REQ *req;
399
+
400
+ GetX509Req(self, req);
401
+ if (!X509_REQ_add1_attr(req, GetX509AttrPtr(attr))) {
402
+ ossl_raise(eX509ReqError, NULL);
403
+ }
404
+
405
+ return attr;
406
+ }
407
+
408
+ /*
409
+ * X509_REQUEST init
410
+ */
411
+ void
412
+ Init_ossl_x509req(void)
413
+ {
414
+ #if 0
415
+ mOSSL = rb_define_module("OpenSSL");
416
+ eOSSLError = rb_define_class_under(mOSSL, "OpenSSLError", rb_eStandardError);
417
+ mX509 = rb_define_module_under(mOSSL, "X509");
418
+ #endif
419
+
420
+ eX509ReqError = rb_define_class_under(mX509, "RequestError", eOSSLError);
421
+
422
+ cX509Req = rb_define_class_under(mX509, "Request", rb_cObject);
423
+
424
+ rb_define_alloc_func(cX509Req, ossl_x509req_alloc);
425
+ rb_define_method(cX509Req, "initialize", ossl_x509req_initialize, -1);
426
+ rb_define_method(cX509Req, "initialize_copy", ossl_x509req_copy, 1);
427
+
428
+ rb_define_method(cX509Req, "to_pem", ossl_x509req_to_pem, 0);
429
+ rb_define_method(cX509Req, "to_der", ossl_x509req_to_der, 0);
430
+ rb_define_alias(cX509Req, "to_s", "to_pem");
431
+ rb_define_method(cX509Req, "to_text", ossl_x509req_to_text, 0);
432
+ rb_define_method(cX509Req, "version", ossl_x509req_get_version, 0);
433
+ rb_define_method(cX509Req, "version=", ossl_x509req_set_version, 1);
434
+ rb_define_method(cX509Req, "subject", ossl_x509req_get_subject, 0);
435
+ rb_define_method(cX509Req, "subject=", ossl_x509req_set_subject, 1);
436
+ rb_define_method(cX509Req, "signature_algorithm", ossl_x509req_get_signature_algorithm, 0);
437
+ rb_define_method(cX509Req, "public_key", ossl_x509req_get_public_key, 0);
438
+ rb_define_method(cX509Req, "public_key=", ossl_x509req_set_public_key, 1);
439
+ rb_define_method(cX509Req, "sign", ossl_x509req_sign, 2);
440
+ rb_define_method(cX509Req, "verify", ossl_x509req_verify, 1);
441
+ rb_define_method(cX509Req, "attributes", ossl_x509req_get_attributes, 0);
442
+ rb_define_method(cX509Req, "attributes=", ossl_x509req_set_attributes, 1);
443
+ rb_define_method(cX509Req, "add_attribute", ossl_x509req_add_attribute, 1);
444
+ }