openssl 3.3.3 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/CONTRIBUTING.md +3 -0
  3. data/History.md +111 -0
  4. data/README.md +12 -11
  5. data/ext/openssl/extconf.rb +30 -70
  6. data/ext/openssl/openssl_missing.h +0 -210
  7. data/ext/openssl/ossl.c +295 -304
  8. data/ext/openssl/ossl.h +13 -9
  9. data/ext/openssl/ossl_asn1.c +598 -406
  10. data/ext/openssl/ossl_asn1.h +15 -1
  11. data/ext/openssl/ossl_bio.c +8 -4
  12. data/ext/openssl/ossl_bn.c +286 -291
  13. data/ext/openssl/ossl_cipher.c +257 -209
  14. data/ext/openssl/ossl_cipher.h +10 -1
  15. data/ext/openssl/ossl_config.c +1 -6
  16. data/ext/openssl/ossl_digest.c +74 -43
  17. data/ext/openssl/ossl_digest.h +9 -1
  18. data/ext/openssl/ossl_engine.c +39 -103
  19. data/ext/openssl/ossl_hmac.c +30 -36
  20. data/ext/openssl/ossl_kdf.c +42 -53
  21. data/ext/openssl/ossl_ns_spki.c +27 -32
  22. data/ext/openssl/ossl_ocsp.c +208 -236
  23. data/ext/openssl/ossl_pkcs12.c +26 -26
  24. data/ext/openssl/ossl_pkcs7.c +175 -145
  25. data/ext/openssl/ossl_pkey.c +102 -158
  26. data/ext/openssl/ossl_pkey.h +99 -100
  27. data/ext/openssl/ossl_pkey_dh.c +31 -68
  28. data/ext/openssl/ossl_pkey_dsa.c +15 -54
  29. data/ext/openssl/ossl_pkey_ec.c +180 -238
  30. data/ext/openssl/ossl_pkey_rsa.c +56 -103
  31. data/ext/openssl/ossl_provider.c +0 -5
  32. data/ext/openssl/ossl_rand.c +7 -14
  33. data/ext/openssl/ossl_ssl.c +535 -384
  34. data/ext/openssl/ossl_ssl.h +8 -8
  35. data/ext/openssl/ossl_ssl_session.c +93 -97
  36. data/ext/openssl/ossl_ts.c +78 -124
  37. data/ext/openssl/ossl_x509.c +9 -28
  38. data/ext/openssl/ossl_x509attr.c +33 -54
  39. data/ext/openssl/ossl_x509cert.c +70 -101
  40. data/ext/openssl/ossl_x509crl.c +78 -89
  41. data/ext/openssl/ossl_x509ext.c +43 -64
  42. data/ext/openssl/ossl_x509name.c +64 -90
  43. data/ext/openssl/ossl_x509req.c +55 -62
  44. data/ext/openssl/ossl_x509revoked.c +28 -42
  45. data/ext/openssl/ossl_x509store.c +36 -54
  46. data/lib/openssl/buffering.rb +30 -24
  47. data/lib/openssl/digest.rb +1 -1
  48. data/lib/openssl/pkey.rb +71 -49
  49. data/lib/openssl/ssl.rb +12 -79
  50. data/lib/openssl/version.rb +2 -1
  51. data/lib/openssl/x509.rb +9 -0
  52. data/lib/openssl.rb +9 -6
  53. metadata +1 -3
  54. data/ext/openssl/openssl_missing.c +0 -41
  55. data/lib/openssl/asn1.rb +0 -188
@@ -11,17 +11,17 @@
11
11
  #define _OSSL_SSL_H_
12
12
 
13
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
- } \
14
+ TypedData_Get_Struct((obj), SSL, &ossl_ssl_type, (ssl)); \
15
+ if (!(ssl)) { \
16
+ ossl_raise(rb_eRuntimeError, "SSL is not initialized"); \
17
+ } \
18
18
  } while (0)
19
19
 
20
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
- } \
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
25
  } while (0)
26
26
 
27
27
  extern const rb_data_type_t ossl_ssl_type;
@@ -17,14 +17,14 @@ ossl_ssl_session_free(void *ptr)
17
17
  const rb_data_type_t ossl_ssl_session_type = {
18
18
  "OpenSSL/SSL/Session",
19
19
  {
20
- 0, ossl_ssl_session_free,
20
+ 0, ossl_ssl_session_free,
21
21
  },
22
22
  0, 0, RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED,
23
23
  };
24
24
 
25
25
  static VALUE ossl_ssl_session_alloc(VALUE klass)
26
26
  {
27
- return TypedData_Wrap_Struct(klass, &ossl_ssl_session_type, NULL);
27
+ return TypedData_Wrap_Struct(klass, &ossl_ssl_session_type, NULL);
28
28
  }
29
29
 
30
30
  /*
@@ -69,6 +69,7 @@ ossl_ssl_session_initialize(VALUE self, VALUE arg1)
69
69
  return self;
70
70
  }
71
71
 
72
+ /* :nodoc: */
72
73
  static VALUE
73
74
  ossl_ssl_session_initialize_copy(VALUE self, VALUE other)
74
75
  {
@@ -79,9 +80,9 @@ ossl_ssl_session_initialize_copy(VALUE self, VALUE other)
79
80
  GetSSLSession(other, sess_other);
80
81
 
81
82
  sess_new = ASN1_dup((i2d_of_void *)i2d_SSL_SESSION, (d2i_of_void *)d2i_SSL_SESSION,
82
- (char *)sess_other);
83
+ (char *)sess_other);
83
84
  if (!sess_new)
84
- ossl_raise(eSSLSession, "ASN1_dup");
85
+ ossl_raise(eSSLSession, "ASN1_dup");
85
86
 
86
87
  RTYPEDDATA_DATA(self) = sess_new;
87
88
  SSL_SESSION_free(sess);
@@ -98,9 +99,9 @@ ossl_SSL_SESSION_cmp(const SSL_SESSION *a, const SSL_SESSION *b)
98
99
  const unsigned char *b_sid = SSL_SESSION_get_id(b, &b_len);
99
100
 
100
101
  if (SSL_SESSION_get_protocol_version(a) != SSL_SESSION_get_protocol_version(b))
101
- return 1;
102
+ return 1;
102
103
  if (a_len != b_len)
103
- return 1;
104
+ return 1;
104
105
 
105
106
  return CRYPTO_memcmp(a_sid, b_sid, a_len);
106
107
  }
@@ -113,15 +114,15 @@ ossl_SSL_SESSION_cmp(const SSL_SESSION *a, const SSL_SESSION *b)
113
114
  */
114
115
  static VALUE ossl_ssl_session_eq(VALUE val1, VALUE val2)
115
116
  {
116
- SSL_SESSION *ctx1, *ctx2;
117
+ SSL_SESSION *ctx1, *ctx2;
117
118
 
118
- GetSSLSession(val1, ctx1);
119
- GetSSLSession(val2, ctx2);
119
+ GetSSLSession(val1, ctx1);
120
+ GetSSLSession(val2, ctx2);
120
121
 
121
- switch (ossl_SSL_SESSION_cmp(ctx1, ctx2)) {
122
- case 0: return Qtrue;
123
- default: return Qfalse;
124
- }
122
+ switch (ossl_SSL_SESSION_cmp(ctx1, ctx2)) {
123
+ case 0: return Qtrue;
124
+ default: return Qfalse;
125
+ }
125
126
  }
126
127
 
127
128
  /*
@@ -139,7 +140,7 @@ ossl_ssl_session_get_time(VALUE self)
139
140
  GetSSLSession(self, ctx);
140
141
  t = SSL_SESSION_get_time(ctx);
141
142
  if (t == 0)
142
- return Qnil;
143
+ return Qnil;
143
144
 
144
145
  return rb_funcall(rb_cTime, rb_intern("at"), 1, LONG2NUM(t));
145
146
  }
@@ -174,16 +175,16 @@ ossl_ssl_session_get_timeout(VALUE self)
174
175
  */
175
176
  static VALUE ossl_ssl_session_set_time(VALUE self, VALUE time_v)
176
177
  {
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);
178
+ SSL_SESSION *ctx;
179
+ long t;
180
+
181
+ GetSSLSession(self, ctx);
182
+ if (rb_obj_is_instance_of(time_v, rb_cTime)) {
183
+ time_v = rb_funcall(time_v, rb_intern("to_i"), 0);
184
+ }
185
+ t = NUM2LONG(time_v);
186
+ SSL_SESSION_set_time(ctx, t);
187
+ return ossl_ssl_session_get_time(self);
187
188
  }
188
189
 
189
190
  /*
@@ -194,13 +195,13 @@ static VALUE ossl_ssl_session_set_time(VALUE self, VALUE time_v)
194
195
  */
195
196
  static VALUE ossl_ssl_session_set_timeout(VALUE self, VALUE time_v)
196
197
  {
197
- SSL_SESSION *ctx;
198
- long t;
198
+ SSL_SESSION *ctx;
199
+ long t;
199
200
 
200
- GetSSLSession(self, ctx);
201
- t = NUM2LONG(time_v);
202
- SSL_SESSION_set_timeout(ctx, t);
203
- return ossl_ssl_session_get_timeout(self);
201
+ GetSSLSession(self, ctx);
202
+ t = NUM2LONG(time_v);
203
+ SSL_SESSION_set_timeout(ctx, t);
204
+ return ossl_ssl_session_get_timeout(self);
204
205
  }
205
206
 
206
207
  /*
@@ -208,18 +209,18 @@ static VALUE ossl_ssl_session_set_timeout(VALUE self, VALUE time_v)
208
209
  * session.id -> String
209
210
  *
210
211
  * Returns the Session ID.
211
- */
212
+ */
212
213
  static VALUE ossl_ssl_session_get_id(VALUE self)
213
214
  {
214
- SSL_SESSION *ctx;
215
- const unsigned char *p = NULL;
216
- unsigned int i = 0;
215
+ SSL_SESSION *ctx;
216
+ const unsigned char *p = NULL;
217
+ unsigned int i = 0;
217
218
 
218
- GetSSLSession(self, ctx);
219
+ GetSSLSession(self, ctx);
219
220
 
220
- p = SSL_SESSION_get_id(ctx, &i);
221
+ p = SSL_SESSION_get_id(ctx, &i);
221
222
 
222
- return rb_str_new((const char *) p, i);
223
+ return rb_str_new((const char *) p, i);
223
224
  }
224
225
 
225
226
  /*
@@ -230,22 +231,22 @@ static VALUE ossl_ssl_session_get_id(VALUE self)
230
231
  */
231
232
  static VALUE ossl_ssl_session_to_der(VALUE self)
232
233
  {
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;
234
+ SSL_SESSION *ctx;
235
+ unsigned char *p;
236
+ int len;
237
+ VALUE str;
238
+
239
+ GetSSLSession(self, ctx);
240
+ len = i2d_SSL_SESSION(ctx, NULL);
241
+ if (len <= 0) {
242
+ ossl_raise(eSSLSession, "i2d_SSL_SESSION");
243
+ }
244
+
245
+ str = rb_str_new(0, len);
246
+ p = (unsigned char *)RSTRING_PTR(str);
247
+ i2d_SSL_SESSION(ctx, &p);
248
+ ossl_str_adjust(str, p);
249
+ return str;
249
250
  }
250
251
 
251
252
  /*
@@ -256,22 +257,22 @@ static VALUE ossl_ssl_session_to_der(VALUE self)
256
257
  */
257
258
  static VALUE ossl_ssl_session_to_pem(VALUE self)
258
259
  {
259
- SSL_SESSION *ctx;
260
- BIO *out;
260
+ SSL_SESSION *ctx;
261
+ BIO *out;
261
262
 
262
- GetSSLSession(self, ctx);
263
+ GetSSLSession(self, ctx);
263
264
 
264
- if (!(out = BIO_new(BIO_s_mem()))) {
265
- ossl_raise(eSSLSession, "BIO_s_mem()");
266
- }
265
+ if (!(out = BIO_new(BIO_s_mem()))) {
266
+ ossl_raise(eSSLSession, "BIO_s_mem()");
267
+ }
267
268
 
268
- if (!PEM_write_bio_SSL_SESSION(out, ctx)) {
269
- BIO_free(out);
270
- ossl_raise(eSSLSession, "SSL_SESSION_print()");
271
- }
269
+ if (!PEM_write_bio_SSL_SESSION(out, ctx)) {
270
+ BIO_free(out);
271
+ ossl_raise(eSSLSession, "SSL_SESSION_print()");
272
+ }
272
273
 
273
274
 
274
- return ossl_membio2str(out);
275
+ return ossl_membio2str(out);
275
276
  }
276
277
 
277
278
 
@@ -283,49 +284,44 @@ static VALUE ossl_ssl_session_to_pem(VALUE self)
283
284
  */
284
285
  static VALUE ossl_ssl_session_to_text(VALUE self)
285
286
  {
286
- SSL_SESSION *ctx;
287
- BIO *out;
287
+ SSL_SESSION *ctx;
288
+ BIO *out;
288
289
 
289
- GetSSLSession(self, ctx);
290
+ GetSSLSession(self, ctx);
290
291
 
291
- if (!(out = BIO_new(BIO_s_mem()))) {
292
- ossl_raise(eSSLSession, "BIO_s_mem()");
293
- }
292
+ if (!(out = BIO_new(BIO_s_mem()))) {
293
+ ossl_raise(eSSLSession, "BIO_s_mem()");
294
+ }
294
295
 
295
- if (!SSL_SESSION_print(out, ctx)) {
296
- BIO_free(out);
297
- ossl_raise(eSSLSession, "SSL_SESSION_print()");
298
- }
296
+ if (!SSL_SESSION_print(out, ctx)) {
297
+ BIO_free(out);
298
+ ossl_raise(eSSLSession, "SSL_SESSION_print()");
299
+ }
299
300
 
300
- return ossl_membio2str(out);
301
+ return ossl_membio2str(out);
301
302
  }
302
303
 
303
304
  #endif /* !defined(OPENSSL_NO_SOCK) */
304
305
 
305
306
  void Init_ossl_ssl_session(void)
306
307
  {
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
308
  #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);
309
+ cSSLSession = rb_define_class_under(mSSL, "Session", rb_cObject);
310
+ eSSLSession = rb_define_class_under(cSSLSession, "SessionError", eOSSLError);
311
+
312
+ rb_define_alloc_func(cSSLSession, ossl_ssl_session_alloc);
313
+ rb_define_method(cSSLSession, "initialize", ossl_ssl_session_initialize, 1);
314
+ rb_define_method(cSSLSession, "initialize_copy", ossl_ssl_session_initialize_copy, 1);
315
+
316
+ rb_define_method(cSSLSession, "==", ossl_ssl_session_eq, 1);
317
+
318
+ rb_define_method(cSSLSession, "time", ossl_ssl_session_get_time, 0);
319
+ rb_define_method(cSSLSession, "time=", ossl_ssl_session_set_time, 1);
320
+ rb_define_method(cSSLSession, "timeout", ossl_ssl_session_get_timeout, 0);
321
+ rb_define_method(cSSLSession, "timeout=", ossl_ssl_session_set_timeout, 1);
322
+ rb_define_method(cSSLSession, "id", ossl_ssl_session_get_id, 0);
323
+ rb_define_method(cSSLSession, "to_der", ossl_ssl_session_to_der, 0);
324
+ rb_define_method(cSSLSession, "to_pem", ossl_ssl_session_to_pem, 0);
325
+ rb_define_method(cSSLSession, "to_text", ossl_ssl_session_to_text, 0);
330
326
  #endif /* !defined(OPENSSL_NO_SOCK) */
331
327
  }
@@ -103,7 +103,7 @@ static const rb_data_type_t ossl_ts_resp_type = {
103
103
  static void
104
104
  ossl_ts_token_info_free(void *ptr)
105
105
  {
106
- TS_TST_INFO_free(ptr);
106
+ TS_TST_INFO_free(ptr);
107
107
  }
108
108
 
109
109
  static const rb_data_type_t ossl_ts_token_info_type = {
@@ -132,44 +132,10 @@ asn1_to_der(void *template, int (*i2d)(void *template, unsigned char **pp))
132
132
  return str;
133
133
  }
134
134
 
135
- static ASN1_OBJECT*
136
- obj_to_asn1obj(VALUE obj)
137
- {
138
- ASN1_OBJECT *a1obj;
139
-
140
- StringValue(obj);
141
- a1obj = OBJ_txt2obj(RSTRING_PTR(obj), 0);
142
- if(!a1obj) a1obj = OBJ_txt2obj(RSTRING_PTR(obj), 1);
143
- if(!a1obj) ossl_raise(eASN1Error, "invalid OBJECT ID");
144
-
145
- return a1obj;
146
- }
147
-
148
135
  static VALUE
149
136
  obj_to_asn1obj_i(VALUE obj)
150
137
  {
151
- return (VALUE)obj_to_asn1obj(obj);
152
- }
153
-
154
- static VALUE
155
- get_asn1obj(ASN1_OBJECT *obj)
156
- {
157
- BIO *out;
158
- VALUE ret;
159
- int nid;
160
- if ((nid = OBJ_obj2nid(obj)) != NID_undef)
161
- ret = rb_str_new2(OBJ_nid2sn(nid));
162
- else{
163
- if (!(out = BIO_new(BIO_s_mem())))
164
- ossl_raise(eTimestampError, "BIO_new(BIO_s_mem())");
165
- if (i2a_ASN1_OBJECT(out, obj) <= 0) {
166
- BIO_free(out);
167
- ossl_raise(eTimestampError, "i2a_ASN1_OBJECT");
168
- }
169
- ret = ossl_membio2str(out);
170
- }
171
-
172
- return ret;
138
+ return (VALUE)ossl_to_asn1obj(obj);
173
139
  }
174
140
 
175
141
  static VALUE
@@ -236,11 +202,13 @@ ossl_ts_req_get_algorithm(VALUE self)
236
202
  TS_REQ *req;
237
203
  TS_MSG_IMPRINT *mi;
238
204
  X509_ALGOR *algor;
205
+ const ASN1_OBJECT *obj;
239
206
 
240
207
  GetTSRequest(self, req);
241
208
  mi = TS_REQ_get_msg_imprint(req);
242
209
  algor = TS_MSG_IMPRINT_get_algo(mi);
243
- return get_asn1obj(algor->algorithm);
210
+ X509_ALGOR_get0(&obj, NULL, NULL, algor);
211
+ return ossl_asn1obj_to_string(obj);
244
212
  }
245
213
 
246
214
  /*
@@ -262,7 +230,7 @@ ossl_ts_req_set_algorithm(VALUE self, VALUE algo)
262
230
  X509_ALGOR *algor;
263
231
 
264
232
  GetTSRequest(self, req);
265
- obj = obj_to_asn1obj(algo);
233
+ obj = ossl_to_asn1obj(algo);
266
234
  mi = TS_REQ_get_msg_imprint(req);
267
235
  algor = TS_MSG_IMPRINT_get_algo(mi);
268
236
  if (!X509_ALGOR_set0(algor, obj, V_ASN1_NULL, NULL)) {
@@ -369,7 +337,7 @@ ossl_ts_req_get_policy_id(VALUE self)
369
337
  GetTSRequest(self, req);
370
338
  if (!TS_REQ_get_policy_id(req))
371
339
  return Qnil;
372
- return get_asn1obj(TS_REQ_get_policy_id(req));
340
+ return ossl_asn1obj_to_string(TS_REQ_get_policy_id(req));
373
341
  }
374
342
 
375
343
  /*
@@ -392,7 +360,7 @@ ossl_ts_req_set_policy_id(VALUE self, VALUE oid)
392
360
  int ok;
393
361
 
394
362
  GetTSRequest(self, req);
395
- obj = obj_to_asn1obj(oid);
363
+ obj = ossl_to_asn1obj(oid);
396
364
  ok = TS_REQ_set_policy_id(req, obj);
397
365
  ASN1_OBJECT_free(obj);
398
366
  if (!ok)
@@ -490,13 +458,15 @@ ossl_ts_req_to_der(VALUE self)
490
458
  TS_REQ *req;
491
459
  TS_MSG_IMPRINT *mi;
492
460
  X509_ALGOR *algo;
461
+ const ASN1_OBJECT *obj;
493
462
  ASN1_OCTET_STRING *hashed_msg;
494
463
 
495
464
  GetTSRequest(self, req);
496
465
  mi = TS_REQ_get_msg_imprint(req);
497
466
 
498
467
  algo = TS_MSG_IMPRINT_get_algo(mi);
499
- if (OBJ_obj2nid(algo->algorithm) == NID_undef)
468
+ X509_ALGOR_get0(&obj, NULL, NULL, algo);
469
+ if (OBJ_obj2nid(obj) == NID_undef)
500
470
  ossl_raise(eTimestampError, "Message imprint missing algorithm");
501
471
 
502
472
  hashed_msg = TS_MSG_IMPRINT_get_msg(mi);
@@ -620,14 +590,7 @@ ossl_ts_resp_get_failure_info(VALUE self)
620
590
  {
621
591
  TS_RESP *resp;
622
592
  TS_STATUS_INFO *si;
623
-
624
- /* The ASN1_BIT_STRING_get_bit changed from 1.0.0. to 1.1.0, making this
625
- * const. */
626
- #if defined(HAVE_TS_STATUS_INFO_GET0_FAILURE_INFO)
627
593
  const ASN1_BIT_STRING *fi;
628
- #else
629
- ASN1_BIT_STRING *fi;
630
- #endif
631
594
 
632
595
  GetTSResponse(self, resp);
633
596
  si = TS_RESP_get_status_info(resp);
@@ -858,16 +821,26 @@ ossl_ts_resp_verify(int argc, VALUE *argv, VALUE self)
858
821
  X509_up_ref(cert);
859
822
  }
860
823
 
824
+ if (!X509_STORE_up_ref(x509st)) {
825
+ sk_X509_pop_free(x509inter, X509_free);
826
+ TS_VERIFY_CTX_free(ctx);
827
+ ossl_raise(eTimestampError, "X509_STORE_up_ref");
828
+ }
829
+
830
+ #ifdef HAVE_TS_VERIFY_CTX_SET0_CERTS
831
+ TS_VERIFY_CTX_set0_certs(ctx, x509inter);
832
+ TS_VERIFY_CTX_set0_store(ctx, x509st);
833
+ #else
834
+ # if OSSL_OPENSSL_PREREQ(3, 0, 0) || OSSL_IS_LIBRESSL
861
835
  TS_VERIFY_CTX_set_certs(ctx, x509inter);
862
- TS_VERIFY_CTX_add_flags(ctx, TS_VFY_SIGNATURE);
836
+ # else
837
+ TS_VERIFY_CTS_set_certs(ctx, x509inter);
838
+ # endif
863
839
  TS_VERIFY_CTX_set_store(ctx, x509st);
840
+ #endif
841
+ TS_VERIFY_CTX_add_flags(ctx, TS_VFY_SIGNATURE);
864
842
 
865
843
  ok = TS_RESP_verify_response(ctx, resp);
866
- /*
867
- * TS_VERIFY_CTX_set_store() call above does not increment the reference
868
- * counter, so it must be unset before TS_VERIFY_CTX_free() is called.
869
- */
870
- TS_VERIFY_CTX_set_store(ctx, NULL);
871
844
  TS_VERIFY_CTX_free(ctx);
872
845
 
873
846
  if (!ok)
@@ -954,7 +927,7 @@ ossl_ts_token_info_get_policy_id(VALUE self)
954
927
  TS_TST_INFO *info;
955
928
 
956
929
  GetTSTokenInfo(self, info);
957
- return get_asn1obj(TS_TST_INFO_get_policy_id(info));
930
+ return ossl_asn1obj_to_string(TS_TST_INFO_get_policy_id(info));
958
931
  }
959
932
 
960
933
  /*
@@ -976,11 +949,13 @@ ossl_ts_token_info_get_algorithm(VALUE self)
976
949
  TS_TST_INFO *info;
977
950
  TS_MSG_IMPRINT *mi;
978
951
  X509_ALGOR *algo;
952
+ const ASN1_OBJECT *obj;
979
953
 
980
954
  GetTSTokenInfo(self, info);
981
955
  mi = TS_TST_INFO_get_msg_imprint(info);
982
956
  algo = TS_MSG_IMPRINT_get_algo(mi);
983
- return get_asn1obj(algo->algorithm);
957
+ X509_ALGOR_get0(&obj, NULL, NULL, algo);
958
+ return ossl_asn1obj_to_string(obj);
984
959
  }
985
960
 
986
961
  /*
@@ -1146,9 +1121,14 @@ ossl_tsfac_time_cb(struct TS_resp_ctx *ctx, void *data, time_t *sec, long *usec)
1146
1121
  }
1147
1122
 
1148
1123
  static VALUE
1149
- ossl_evp_get_digestbyname_i(VALUE arg)
1124
+ ossl_evp_md_fetch_i(VALUE args_)
1150
1125
  {
1151
- return (VALUE)ossl_evp_get_digestbyname(arg);
1126
+ VALUE *args = (VALUE *)args_, md_holder;
1127
+ const EVP_MD *md;
1128
+
1129
+ md = ossl_evp_md_fetch(args[1], &md_holder);
1130
+ rb_ary_push(args[0], md_holder);
1131
+ return (VALUE)md;
1152
1132
  }
1153
1133
 
1154
1134
  static VALUE
@@ -1184,7 +1164,8 @@ ossl_obj2bio_i(VALUE arg)
1184
1164
  static VALUE
1185
1165
  ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request)
1186
1166
  {
1187
- VALUE serial_number, def_policy_id, gen_time, additional_certs, allowed_digests;
1167
+ VALUE serial_number, def_policy_id, gen_time, additional_certs,
1168
+ allowed_digests, allowed_digests_tmp = Qnil;
1188
1169
  VALUE str;
1189
1170
  STACK_OF(X509) *inter_certs;
1190
1171
  VALUE tsresp, ret = Qnil;
@@ -1245,7 +1226,7 @@ ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request)
1245
1226
  if (rb_obj_is_kind_of(additional_certs, rb_cArray)) {
1246
1227
  inter_certs = ossl_protect_x509_ary2sk(additional_certs, &status);
1247
1228
  if (status)
1248
- goto end;
1229
+ goto end;
1249
1230
 
1250
1231
  /* this dups the sk_X509 and ups each cert's ref count */
1251
1232
  TS_RESP_CTX_set_certs(ctx, inter_certs);
@@ -1261,16 +1242,18 @@ ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request)
1261
1242
 
1262
1243
  allowed_digests = ossl_tsfac_get_allowed_digests(self);
1263
1244
  if (rb_obj_is_kind_of(allowed_digests, rb_cArray)) {
1264
- int i;
1265
- VALUE rbmd;
1266
- const EVP_MD *md;
1267
-
1268
- for (i = 0; i < RARRAY_LEN(allowed_digests); i++) {
1269
- rbmd = rb_ary_entry(allowed_digests, i);
1270
- md = (const EVP_MD *)rb_protect(ossl_evp_get_digestbyname_i, rbmd, &status);
1245
+ allowed_digests_tmp = rb_ary_new_capa(RARRAY_LEN(allowed_digests));
1246
+ for (long i = 0; i < RARRAY_LEN(allowed_digests); i++) {
1247
+ VALUE args[] = {
1248
+ allowed_digests_tmp,
1249
+ rb_ary_entry(allowed_digests, i),
1250
+ };
1251
+ const EVP_MD *md = (const EVP_MD *)rb_protect(ossl_evp_md_fetch_i,
1252
+ (VALUE)args, &status);
1271
1253
  if (status)
1272
1254
  goto end;
1273
- TS_RESP_CTX_add_md(ctx, md);
1255
+ if (!TS_RESP_CTX_add_md(ctx, md))
1256
+ goto end;
1274
1257
  }
1275
1258
  }
1276
1259
 
@@ -1284,6 +1267,7 @@ ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request)
1284
1267
 
1285
1268
  response = TS_RESP_create_response(ctx, req_bio);
1286
1269
  BIO_free(req_bio);
1270
+ RB_GC_GUARD(allowed_digests_tmp);
1287
1271
 
1288
1272
  if (!response) {
1289
1273
  err_msg = "Error during response generation";
@@ -1297,7 +1281,7 @@ ossl_tsfac_create_ts(VALUE self, VALUE key, VALUE certificate, VALUE request)
1297
1281
  SetTSResponse(tsresp, response);
1298
1282
  ret = tsresp;
1299
1283
 
1300
- end:
1284
+ end:
1301
1285
  ASN1_INTEGER_free(asn1_serial);
1302
1286
  ASN1_OBJECT_free(def_policy_id_obj);
1303
1287
  TS_RESP_CTX_free(ctx);
@@ -1314,10 +1298,6 @@ end:
1314
1298
  void
1315
1299
  Init_ossl_ts(void)
1316
1300
  {
1317
- #if 0
1318
- mOSSL = rb_define_module("OpenSSL"); /* let rdoc know about mOSSL */
1319
- #endif
1320
-
1321
1301
  /*
1322
1302
  * Possible return value for +Response#failure_info+. Indicates that the
1323
1303
  * timestamp server rejects the message imprint algorithm used in the
@@ -1527,65 +1507,39 @@ Init_ossl_ts(void)
1527
1507
  * fac.default_policy_id = '1.2.3.4.5'
1528
1508
  * fac.additional_certificates = [ inter1, inter2 ]
1529
1509
  * timestamp = fac.create_timestamp(p12.key, p12.certificate, req)
1530
- *
1531
- * ==Attributes
1532
- *
1533
- * ===default_policy_id
1510
+ */
1511
+ cTimestampFactory = rb_define_class_under(mTimestamp, "Factory", rb_cObject);
1512
+ /*
1513
+ * The list of digest algorithms that the factory is allowed
1514
+ * create timestamps for. Known vulnerable or weak algorithms should not be
1515
+ * allowed where possible. Must be an Array of String or OpenSSL::Digest
1516
+ * subclass instances.
1517
+ */
1518
+ rb_attr(cTimestampFactory, rb_intern_const("allowed_digests"), 1, 1, 0);
1519
+ /*
1520
+ * A String representing the default policy object identifier, or +nil+.
1534
1521
  *
1535
1522
  * Request#policy_id will always be preferred over this if present in the
1536
- * Request, only if Request#policy_id is nil default_policy will be used.
1523
+ * Request, only if Request#policy_id is +nil+ default_policy will be used.
1537
1524
  * If none of both is present, a TimestampError will be raised when trying
1538
1525
  * to create a Response.
1539
- *
1540
- * call-seq:
1541
- * factory.default_policy_id = "string" -> string
1542
- * factory.default_policy_id -> string or nil
1543
- *
1544
- * ===serial_number
1545
- *
1546
- * Sets or retrieves the serial number to be used for timestamp creation.
1547
- * Must be present for timestamp creation.
1548
- *
1549
- * call-seq:
1550
- * factory.serial_number = number -> number
1551
- * factory.serial_number -> number or nil
1552
- *
1553
- * ===gen_time
1554
- *
1555
- * Sets or retrieves the Time value to be used in the Response. Must be
1556
- * present for timestamp creation.
1557
- *
1558
- * call-seq:
1559
- * factory.gen_time = Time -> Time
1560
- * factory.gen_time -> Time or nil
1561
- *
1562
- * ===additional_certs
1563
- *
1564
- * Sets or retrieves additional certificates apart from the timestamp
1565
- * certificate (e.g. intermediate certificates) to be added to the Response.
1566
- * Must be an Array of OpenSSL::X509::Certificate.
1567
- *
1568
- * call-seq:
1569
- * factory.additional_certs = [cert1, cert2] -> [ cert1, cert2 ]
1570
- * factory.additional_certs -> array or nil
1571
- *
1572
- * ===allowed_digests
1573
- *
1574
- * Sets or retrieves the digest algorithms that the factory is allowed
1575
- * create timestamps for. Known vulnerable or weak algorithms should not be
1576
- * allowed where possible.
1577
- * Must be an Array of String or OpenSSL::Digest subclass instances.
1578
- *
1579
- * call-seq:
1580
- * factory.allowed_digests = ["sha1", OpenSSL::Digest.new('SHA256').new] -> [ "sha1", OpenSSL::Digest) ]
1581
- * factory.allowed_digests -> array or nil
1582
- *
1583
1526
  */
1584
- cTimestampFactory = rb_define_class_under(mTimestamp, "Factory", rb_cObject);
1585
- rb_attr(cTimestampFactory, rb_intern_const("allowed_digests"), 1, 1, 0);
1586
1527
  rb_attr(cTimestampFactory, rb_intern_const("default_policy_id"), 1, 1, 0);
1528
+ /*
1529
+ * The serial number to be used for timestamp creation. Must be present for
1530
+ * timestamp creation. Must be an instance of OpenSSL::BN or Integer.
1531
+ */
1587
1532
  rb_attr(cTimestampFactory, rb_intern_const("serial_number"), 1, 1, 0);
1533
+ /*
1534
+ * The Time value to be used in the Response. Must be present for timestamp
1535
+ * creation.
1536
+ */
1588
1537
  rb_attr(cTimestampFactory, rb_intern_const("gen_time"), 1, 1, 0);
1538
+ /*
1539
+ * Additional certificates apart from the timestamp certificate (e.g.
1540
+ * intermediate certificates) to be added to the Response.
1541
+ * Must be an Array of OpenSSL::X509::Certificate, or +nil+.
1542
+ */
1589
1543
  rb_attr(cTimestampFactory, rb_intern_const("additional_certs"), 1, 1, 0);
1590
1544
  rb_define_method(cTimestampFactory, "create_timestamp", ossl_tsfac_create_ts, 3);
1591
1545
  }