openssl 2.0.9 → 2.1.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of openssl might be problematic. Click here for more details.

Files changed (60) hide show
  1. checksums.yaml +5 -5
  2. data/History.md +28 -69
  3. data/README.md +1 -1
  4. data/ext/openssl/deprecation.rb +0 -3
  5. data/ext/openssl/extconf.rb +8 -52
  6. data/ext/openssl/openssl_missing.c +0 -67
  7. data/ext/openssl/openssl_missing.h +3 -50
  8. data/ext/openssl/ossl.c +81 -74
  9. data/ext/openssl/ossl.h +14 -27
  10. data/ext/openssl/ossl_asn1.c +287 -374
  11. data/ext/openssl/ossl_asn1.h +0 -4
  12. data/ext/openssl/ossl_bio.c +5 -20
  13. data/ext/openssl/ossl_bio.h +0 -2
  14. data/ext/openssl/ossl_bn.c +70 -28
  15. data/ext/openssl/ossl_cipher.c +18 -42
  16. data/ext/openssl/ossl_cipher.h +1 -1
  17. data/ext/openssl/ossl_digest.c +8 -12
  18. data/ext/openssl/ossl_digest.h +1 -1
  19. data/ext/openssl/ossl_engine.c +47 -47
  20. data/ext/openssl/ossl_hmac.c +19 -22
  21. data/ext/openssl/ossl_kdf.c +221 -0
  22. data/ext/openssl/ossl_kdf.h +6 -0
  23. data/ext/openssl/ossl_ns_spki.c +17 -21
  24. data/ext/openssl/ossl_ocsp.c +85 -80
  25. data/ext/openssl/ossl_pkcs12.c +15 -21
  26. data/ext/openssl/ossl_pkcs7.c +8 -21
  27. data/ext/openssl/ossl_pkey.c +24 -48
  28. data/ext/openssl/ossl_pkey.h +1 -6
  29. data/ext/openssl/ossl_pkey_dh.c +11 -11
  30. data/ext/openssl/ossl_pkey_dsa.c +16 -22
  31. data/ext/openssl/ossl_pkey_ec.c +43 -56
  32. data/ext/openssl/ossl_pkey_rsa.c +19 -19
  33. data/ext/openssl/ossl_rand.c +12 -12
  34. data/ext/openssl/ossl_ssl.c +291 -243
  35. data/ext/openssl/ossl_ssl.h +0 -5
  36. data/ext/openssl/ossl_ssl_session.c +7 -9
  37. data/ext/openssl/ossl_version.h +1 -1
  38. data/ext/openssl/ossl_x509.c +0 -15
  39. data/ext/openssl/ossl_x509.h +0 -7
  40. data/ext/openssl/ossl_x509attr.c +3 -7
  41. data/ext/openssl/ossl_x509cert.c +17 -54
  42. data/ext/openssl/ossl_x509crl.c +15 -25
  43. data/ext/openssl/ossl_x509ext.c +9 -14
  44. data/ext/openssl/ossl_x509name.c +76 -41
  45. data/ext/openssl/ossl_x509req.c +10 -47
  46. data/ext/openssl/ossl_x509revoked.c +8 -8
  47. data/ext/openssl/ossl_x509store.c +15 -45
  48. data/ext/openssl/ruby_missing.h +2 -13
  49. data/lib/openssl.rb +1 -0
  50. data/lib/openssl/bn.rb +2 -1
  51. data/lib/openssl/buffering.rb +24 -23
  52. data/lib/openssl/config.rb +12 -11
  53. data/lib/openssl/digest.rb +3 -6
  54. data/lib/openssl/pkcs5.rb +22 -0
  55. data/lib/openssl/pkey.rb +0 -41
  56. data/lib/openssl/ssl.rb +118 -16
  57. data/lib/openssl/x509.rb +7 -1
  58. metadata +8 -7
  59. data/ext/openssl/ossl_pkcs5.c +0 -180
  60. data/ext/openssl/ossl_pkcs5.h +0 -6
@@ -0,0 +1,6 @@
1
+ #if !defined(OSSL_KDF_H)
2
+ #define OSSL_KDF_H
3
+
4
+ void Init_ossl_kdf(void);
5
+
6
+ #endif
@@ -73,7 +73,7 @@ ossl_spki_alloc(VALUE klass)
73
73
  * SPKI.new([request]) => spki
74
74
  *
75
75
  * === Parameters
76
- * * +request+ - optional raw request, either in PEM or DER format.
76
+ * * _request_ - optional raw request, either in PEM or DER format.
77
77
  */
78
78
  static VALUE
79
79
  ossl_spki_initialize(int argc, VALUE *argv, VALUE self)
@@ -198,7 +198,7 @@ ossl_spki_get_public_key(VALUE self)
198
198
  * spki.public_key = pub => pkey
199
199
  *
200
200
  * === Parameters
201
- * * +pub+ - the public key to be set for this instance
201
+ * * _pub_ - the public key to be set for this instance
202
202
  *
203
203
  * Sets the public key to be associated with the SPKI, an instance of
204
204
  * OpenSSL::PKey. This should be the public key corresponding to the
@@ -208,13 +208,12 @@ static VALUE
208
208
  ossl_spki_set_public_key(VALUE self, VALUE key)
209
209
  {
210
210
  NETSCAPE_SPKI *spki;
211
- EVP_PKEY *pkey;
212
211
 
213
212
  GetSPKI(self, spki);
214
- pkey = GetPKeyPtr(key);
215
- ossl_pkey_check_public_key(pkey);
216
- if (!NETSCAPE_SPKI_set_pubkey(spki, pkey))
217
- ossl_raise(eSPKIError, "NETSCAPE_SPKI_set_pubkey");
213
+ if (!NETSCAPE_SPKI_set_pubkey(spki, GetPKeyPtr(key))) { /* NO NEED TO DUP */
214
+ ossl_raise(eSPKIError, NULL);
215
+ }
216
+
218
217
  return key;
219
218
  }
220
219
 
@@ -244,7 +243,7 @@ ossl_spki_get_challenge(VALUE self)
244
243
  * spki.challenge = str => string
245
244
  *
246
245
  * === Parameters
247
- * * +str+ - the challenge string to be set for this instance
246
+ * * _str_ - the challenge string to be set for this instance
248
247
  *
249
248
  * Sets the challenge to be associated with the SPKI. May be used by the
250
249
  * server, e.g. to prevent replay.
@@ -269,8 +268,8 @@ ossl_spki_set_challenge(VALUE self, VALUE str)
269
268
  * spki.sign(key, digest) => spki
270
269
  *
271
270
  * === Parameters
272
- * * +key+ - the private key to be used for signing this instance
273
- * * +digest+ - the digest to be used for signing this instance
271
+ * * _key_ - the private key to be used for signing this instance
272
+ * * _digest_ - the digest to be used for signing this instance
274
273
  *
275
274
  * To sign an SPKI, the private key corresponding to the public key set
276
275
  * for this instance should be used, in addition to a digest algorithm in
@@ -285,7 +284,7 @@ ossl_spki_sign(VALUE self, VALUE key, VALUE digest)
285
284
  const EVP_MD *md;
286
285
 
287
286
  pkey = GetPrivPKeyPtr(key); /* NO NEED TO DUP */
288
- md = GetDigestPtr(digest);
287
+ md = ossl_evp_get_digestbyname(digest);
289
288
  GetSPKI(self, spki);
290
289
  if (!NETSCAPE_SPKI_sign(spki, pkey, md)) {
291
290
  ossl_raise(eSPKIError, NULL);
@@ -299,7 +298,7 @@ ossl_spki_sign(VALUE self, VALUE key, VALUE digest)
299
298
  * spki.verify(key) => boolean
300
299
  *
301
300
  * === Parameters
302
- * * +key+ - the public key to be used for verifying the SPKI signature
301
+ * * _key_ - the public key to be used for verifying the SPKI signature
303
302
  *
304
303
  * Returns +true+ if the signature is valid, +false+ otherwise. To verify an
305
304
  * SPKI, the public key contained within the SPKI should be used.
@@ -308,20 +307,17 @@ static VALUE
308
307
  ossl_spki_verify(VALUE self, VALUE key)
309
308
  {
310
309
  NETSCAPE_SPKI *spki;
311
- EVP_PKEY *pkey;
312
310
 
313
311
  GetSPKI(self, spki);
314
- pkey = GetPKeyPtr(key);
315
- ossl_pkey_check_public_key(pkey);
316
- switch (NETSCAPE_SPKI_verify(spki, pkey)) {
317
- case 0:
318
- ossl_clear_error();
312
+ switch (NETSCAPE_SPKI_verify(spki, GetPKeyPtr(key))) { /* NO NEED TO DUP */
313
+ case 0:
319
314
  return Qfalse;
320
- case 1:
315
+ case 1:
321
316
  return Qtrue;
322
- default:
323
- ossl_raise(eSPKIError, "NETSCAPE_SPKI_verify");
317
+ default:
318
+ ossl_raise(eSPKIError, NULL);
324
319
  }
320
+ return Qnil; /* dummy */
325
321
  }
326
322
 
327
323
  /* Document-class: OpenSSL::Netscape::SPKI
@@ -22,10 +22,6 @@
22
22
  TypedData_Get_Struct((obj), OCSP_REQUEST, &ossl_ocsp_request_type, (req)); \
23
23
  if(!(req)) ossl_raise(rb_eRuntimeError, "Request wasn't initialized!"); \
24
24
  } while (0)
25
- #define SafeGetOCSPReq(obj, req) do { \
26
- OSSL_Check_Kind((obj), cOCSPReq); \
27
- GetOCSPReq((obj), (req)); \
28
- } while (0)
29
25
 
30
26
  #define NewOCSPRes(klass) \
31
27
  TypedData_Wrap_Struct((klass), &ossl_ocsp_response_type, 0)
@@ -37,10 +33,6 @@
37
33
  TypedData_Get_Struct((obj), OCSP_RESPONSE, &ossl_ocsp_response_type, (res)); \
38
34
  if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
39
35
  } while (0)
40
- #define SafeGetOCSPRes(obj, res) do { \
41
- OSSL_Check_Kind((obj), cOCSPRes); \
42
- GetOCSPRes((obj), (res)); \
43
- } while (0)
44
36
 
45
37
  #define NewOCSPBasicRes(klass) \
46
38
  TypedData_Wrap_Struct((klass), &ossl_ocsp_basicresp_type, 0)
@@ -52,10 +44,6 @@
52
44
  TypedData_Get_Struct((obj), OCSP_BASICRESP, &ossl_ocsp_basicresp_type, (res)); \
53
45
  if(!(res)) ossl_raise(rb_eRuntimeError, "Response wasn't initialized!"); \
54
46
  } while (0)
55
- #define SafeGetOCSPBasicRes(obj, res) do { \
56
- OSSL_Check_Kind((obj), cOCSPBasicRes); \
57
- GetOCSPBasicRes((obj), (res)); \
58
- } while (0)
59
47
 
60
48
  #define NewOCSPSingleRes(klass) \
61
49
  TypedData_Wrap_Struct((klass), &ossl_ocsp_singleresp_type, 0)
@@ -67,10 +55,6 @@
67
55
  TypedData_Get_Struct((obj), OCSP_SINGLERESP, &ossl_ocsp_singleresp_type, (res)); \
68
56
  if(!(res)) ossl_raise(rb_eRuntimeError, "SingleResponse wasn't initialized!"); \
69
57
  } while (0)
70
- #define SafeGetOCSPSingleRes(obj, res) do { \
71
- OSSL_Check_Kind((obj), cOCSPSingleRes); \
72
- GetOCSPSingleRes((obj), (res)); \
73
- } while (0)
74
58
 
75
59
  #define NewOCSPCertId(klass) \
76
60
  TypedData_Wrap_Struct((klass), &ossl_ocsp_certid_type, 0)
@@ -82,10 +66,6 @@
82
66
  TypedData_Get_Struct((obj), OCSP_CERTID, &ossl_ocsp_certid_type, (cid)); \
83
67
  if(!(cid)) ossl_raise(rb_eRuntimeError, "Cert ID wasn't initialized!"); \
84
68
  } while (0)
85
- #define SafeGetOCSPCertId(obj, cid) do { \
86
- OSSL_Check_Kind((obj), cOCSPCertId); \
87
- GetOCSPCertId((obj), (cid)); \
88
- } while (0)
89
69
 
90
70
  VALUE mOCSP;
91
71
  VALUE eOCSPError;
@@ -200,7 +180,7 @@ ossl_ocspreq_initialize_copy(VALUE self, VALUE other)
200
180
 
201
181
  rb_check_frozen(self);
202
182
  GetOCSPReq(self, req_old);
203
- SafeGetOCSPReq(other, req);
183
+ GetOCSPReq(other, req);
204
184
 
205
185
  req_new = ASN1_item_dup(ASN1_ITEM_rptr(OCSP_REQUEST), req);
206
186
  if (!req_new)
@@ -218,7 +198,7 @@ ossl_ocspreq_initialize_copy(VALUE self, VALUE other)
218
198
  * OpenSSL::OCSP::Request.new(request_der) -> request
219
199
  *
220
200
  * Creates a new OpenSSL::OCSP::Request. The request may be created empty or
221
- * from a +request_der+ string.
201
+ * from a _request_der_ string.
222
202
  */
223
203
 
224
204
  static VALUE
@@ -248,7 +228,7 @@ ossl_ocspreq_initialize(int argc, VALUE *argv, VALUE self)
248
228
  * call-seq:
249
229
  * request.add_nonce(nonce = nil) -> request
250
230
  *
251
- * Adds a +nonce+ to the OCSP request. If no nonce is given a random one will
231
+ * Adds a _nonce_ to the OCSP request. If no nonce is given a random one will
252
232
  * be generated.
253
233
  *
254
234
  * The nonce is used to prevent replay attacks but some servers do not support
@@ -281,7 +261,7 @@ ossl_ocspreq_add_nonce(int argc, VALUE *argv, VALUE self)
281
261
  * call-seq:
282
262
  * request.check_nonce(response) -> result
283
263
  *
284
- * Checks the nonce validity for this request and +response+.
264
+ * Checks the nonce validity for this request and _response_.
285
265
  *
286
266
  * The return value is one of the following:
287
267
  *
@@ -291,7 +271,7 @@ ossl_ocspreq_add_nonce(int argc, VALUE *argv, VALUE self)
291
271
  * 2 :: nonces both absent.
292
272
  * 3 :: nonce present in response only.
293
273
  *
294
- * For most responses, clients can check +result+ > 0. If a responder doesn't
274
+ * For most responses, clients can check _result_ > 0. If a responder doesn't
295
275
  * handle nonces <code>result.nonzero?</code> may be necessary. A result of
296
276
  * <code>0</code> is always an error.
297
277
  */
@@ -304,7 +284,7 @@ ossl_ocspreq_check_nonce(VALUE self, VALUE basic_resp)
304
284
  int res;
305
285
 
306
286
  GetOCSPReq(self, req);
307
- SafeGetOCSPBasicRes(basic_resp, bs);
287
+ GetOCSPBasicRes(basic_resp, bs);
308
288
  res = OCSP_check_nonce(req, bs);
309
289
 
310
290
  return INT2NUM(res);
@@ -314,7 +294,7 @@ ossl_ocspreq_check_nonce(VALUE self, VALUE basic_resp)
314
294
  * call-seq:
315
295
  * request.add_certid(certificate_id) -> request
316
296
  *
317
- * Adds +certificate_id+ to the request.
297
+ * Adds _certificate_id_ to the request.
318
298
  */
319
299
 
320
300
  static VALUE
@@ -371,17 +351,17 @@ ossl_ocspreq_get_certid(VALUE self)
371
351
  * call-seq:
372
352
  * request.sign(cert, key, certs = nil, flags = 0, digest = nil) -> self
373
353
  *
374
- * Signs this OCSP request using +cert+, +key+ and optional +digest+. If
375
- * +digest+ is not specified, SHA-1 is used. +certs+ is an optional Array of
354
+ * Signs this OCSP request using _cert_, _key_ and optional _digest_. If
355
+ * _digest_ is not specified, SHA-1 is used. _certs_ is an optional Array of
376
356
  * additional certificates which are included in the request in addition to
377
- * the signer certificate. Note that if +certs+ is nil or not given, flag
357
+ * the signer certificate. Note that if _certs_ is +nil+ or not given, flag
378
358
  * OpenSSL::OCSP::NOCERTS is enabled. Pass an empty array to include only the
379
359
  * signer certificate.
380
360
  *
381
- * +flags+ can be a bitwise OR of the following constants:
361
+ * _flags_ is a bitwise OR of the following constants:
382
362
  *
383
363
  * OpenSSL::OCSP::NOCERTS::
384
- * Don't include any certificates in the request. +certs+ will be ignored.
364
+ * Don't include any certificates in the request. _certs_ will be ignored.
385
365
  */
386
366
  static VALUE
387
367
  ossl_ocspreq_sign(int argc, VALUE *argv, VALUE self)
@@ -404,7 +384,7 @@ ossl_ocspreq_sign(int argc, VALUE *argv, VALUE self)
404
384
  if (NIL_P(digest))
405
385
  md = EVP_sha1();
406
386
  else
407
- md = GetDigestPtr(digest);
387
+ md = ossl_evp_get_digestbyname(digest);
408
388
  if (NIL_P(certs))
409
389
  flg |= OCSP_NOCERTS;
410
390
  else
@@ -421,9 +401,12 @@ ossl_ocspreq_sign(int argc, VALUE *argv, VALUE self)
421
401
  * call-seq:
422
402
  * request.verify(certificates, store, flags = 0) -> true or false
423
403
  *
424
- * Verifies this request using the given +certificates+ and +store+.
425
- * +certificates+ is an array of OpenSSL::X509::Certificate, +store+ is an
404
+ * Verifies this request using the given _certificates_ and _store_.
405
+ * _certificates_ is an array of OpenSSL::X509::Certificate, _store_ is an
426
406
  * OpenSSL::X509::Store.
407
+ *
408
+ * Note that +false+ is returned if the request does not have a signature.
409
+ * Use #signed? to check whether the request is signed or not.
427
410
  */
428
411
 
429
412
  static VALUE
@@ -472,6 +455,22 @@ ossl_ocspreq_to_der(VALUE self)
472
455
  return str;
473
456
  }
474
457
 
458
+ /*
459
+ * call-seq:
460
+ * request.signed? -> true or false
461
+ *
462
+ * Returns +true+ if the request is signed, +false+ otherwise. Note that the
463
+ * validity of the signature is *not* checked. Use #verify to verify that.
464
+ */
465
+ static VALUE
466
+ ossl_ocspreq_signed_p(VALUE self)
467
+ {
468
+ OCSP_REQUEST *req;
469
+
470
+ GetOCSPReq(self, req);
471
+ return OCSP_request_is_signed(req) ? Qtrue : Qfalse;
472
+ }
473
+
475
474
  /*
476
475
  * OCSP::Response
477
476
  */
@@ -479,7 +478,7 @@ ossl_ocspreq_to_der(VALUE self)
479
478
  /* call-seq:
480
479
  * OpenSSL::OCSP::Response.create(status, basic_response = nil) -> response
481
480
  *
482
- * Creates an OpenSSL::OCSP::Response from +status+ and +basic_response+.
481
+ * Creates an OpenSSL::OCSP::Response from _status_ and _basic_response_.
483
482
  */
484
483
 
485
484
  static VALUE
@@ -521,7 +520,7 @@ ossl_ocspres_initialize_copy(VALUE self, VALUE other)
521
520
 
522
521
  rb_check_frozen(self);
523
522
  GetOCSPRes(self, res_old);
524
- SafeGetOCSPRes(other, res);
523
+ GetOCSPRes(other, res);
525
524
 
526
525
  res_new = ASN1_item_dup(ASN1_ITEM_rptr(OCSP_RESPONSE), res);
527
526
  if (!res_new)
@@ -539,7 +538,7 @@ ossl_ocspres_initialize_copy(VALUE self, VALUE other)
539
538
  * OpenSSL::OCSP::Response.new(response_der) -> response
540
539
  *
541
540
  * Creates a new OpenSSL::OCSP::Response. The response may be created empty or
542
- * from a +response_der+ string.
541
+ * from a _response_der_ string.
543
542
  */
544
543
 
545
544
  static VALUE
@@ -677,7 +676,7 @@ ossl_ocspbres_initialize_copy(VALUE self, VALUE other)
677
676
 
678
677
  rb_check_frozen(self);
679
678
  GetOCSPBasicRes(self, bs_old);
680
- SafeGetOCSPBasicRes(other, bs);
679
+ GetOCSPBasicRes(other, bs);
681
680
 
682
681
  bs_new = ASN1_item_dup(ASN1_ITEM_rptr(OCSP_BASICRESP), bs);
683
682
  if (!bs_new)
@@ -693,7 +692,7 @@ ossl_ocspbres_initialize_copy(VALUE self, VALUE other)
693
692
  * call-seq:
694
693
  * OpenSSL::OCSP::BasicResponse.new(der_string = nil) -> basic_response
695
694
  *
696
- * Creates a new BasicResponse. If +der_string+ is given, decodes +der_string+
695
+ * Creates a new BasicResponse. If _der_string_ is given, decodes _der_string_
697
696
  * as DER.
698
697
  */
699
698
 
@@ -724,7 +723,7 @@ ossl_ocspbres_initialize(int argc, VALUE *argv, VALUE self)
724
723
  * call-seq:
725
724
  * basic_response.copy_nonce(request) -> Integer
726
725
  *
727
- * Copies the nonce from +request+ into this response. Returns 1 on success
726
+ * Copies the nonce from _request_ into this response. Returns 1 on success
728
727
  * and 0 on failure.
729
728
  */
730
729
 
@@ -736,7 +735,7 @@ ossl_ocspbres_copy_nonce(VALUE self, VALUE request)
736
735
  int ret;
737
736
 
738
737
  GetOCSPBasicRes(self, bs);
739
- SafeGetOCSPReq(request, req);
738
+ GetOCSPReq(request, req);
740
739
  ret = OCSP_copy_nonce(bs, req);
741
740
 
742
741
  return INT2NUM(ret);
@@ -746,7 +745,7 @@ ossl_ocspbres_copy_nonce(VALUE self, VALUE request)
746
745
  * call-seq:
747
746
  * basic_response.add_nonce(nonce = nil)
748
747
  *
749
- * Adds +nonce+ to this response. If no nonce was provided a random nonce
748
+ * Adds _nonce_ to this response. If no nonce was provided a random nonce
750
749
  * will be added.
751
750
  */
752
751
 
@@ -792,26 +791,26 @@ add_status_convert_time(VALUE obj)
792
791
  * call-seq:
793
792
  * basic_response.add_status(certificate_id, status, reason, revocation_time, this_update, next_update, extensions) -> basic_response
794
793
  *
795
- * Adds a certificate status for +certificate_id+. +status+ is the status, and
794
+ * Adds a certificate status for _certificate_id_. _status_ is the status, and
796
795
  * must be one of these:
797
796
  *
798
797
  * - OpenSSL::OCSP::V_CERTSTATUS_GOOD
799
798
  * - OpenSSL::OCSP::V_CERTSTATUS_REVOKED
800
799
  * - OpenSSL::OCSP::V_CERTSTATUS_UNKNOWN
801
800
  *
802
- * +reason+ and +revocation_time+ can be given only when +status+ is
803
- * OpenSSL::OCSP::V_CERTSTATUS_REVOKED. +reason+ describes the reason for the
801
+ * _reason_ and _revocation_time_ can be given only when _status_ is
802
+ * OpenSSL::OCSP::V_CERTSTATUS_REVOKED. _reason_ describes the reason for the
804
803
  * revocation, and must be one of OpenSSL::OCSP::REVOKED_STATUS_* constants.
805
- * +revocation_time+ is the time when the certificate is revoked.
804
+ * _revocation_time_ is the time when the certificate is revoked.
806
805
  *
807
- * +this_update+ and +next_update+ indicate the time at which ths status is
806
+ * _this_update_ and _next_update_ indicate the time at which ths status is
808
807
  * verified to be correct and the time at or before which newer information
809
- * will be available, respectively. +next_update+ is optional.
808
+ * will be available, respectively. _next_update_ is optional.
810
809
  *
811
- * +extensions+ is an Array of OpenSSL::X509::Extension to be included in the
810
+ * _extensions_ is an Array of OpenSSL::X509::Extension to be included in the
812
811
  * SingleResponse. This is also optional.
813
812
  *
814
- * Note that the times, +revocation_time+, +this_update+ and +next_update+
813
+ * Note that the times, _revocation_time_, _this_update_ and _next_update_
815
814
  * can be specified in either of Integer or Time object. If they are Integer, it
816
815
  * is treated as the relative seconds from the current time.
817
816
  */
@@ -829,7 +828,7 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
829
828
  VALUE tmp;
830
829
 
831
830
  GetOCSPBasicRes(self, bs);
832
- SafeGetOCSPCertId(cid, id);
831
+ GetOCSPCertId(cid, id);
833
832
  st = NUM2INT(status);
834
833
  if (!NIL_P(ext)) { /* All ext's members must be X509::Extension */
835
834
  ext = rb_check_array_type(ext);
@@ -888,7 +887,7 @@ ossl_ocspbres_add_status(VALUE self, VALUE cid, VALUE status,
888
887
  * Returns an Array of statuses for this response. Each status contains a
889
888
  * CertificateId, the status (0 for good, 1 for revoked, 2 for unknown), the
890
889
  * reason for the status, the revocation time, the time of this update, the time
891
- * for the next update and a list of OpenSSL::X509::Extensions.
890
+ * for the next update and a list of OpenSSL::X509::Extension.
892
891
  *
893
892
  * This should be superseded by BasicResponse#responses and #find_response that
894
893
  * return SingleResponse.
@@ -977,7 +976,7 @@ ossl_ocspbres_get_responses(VALUE self)
977
976
  * call-seq:
978
977
  * basic_response.find_response(certificate_id) -> SingleResponse | nil
979
978
  *
980
- * Returns a SingleResponse whose CertId matches with +certificate_id+, or nil
979
+ * Returns a SingleResponse whose CertId matches with _certificate_id_, or +nil+
981
980
  * if this BasicResponse does not contain it.
982
981
  */
983
982
  static VALUE
@@ -988,7 +987,7 @@ ossl_ocspbres_find_response(VALUE self, VALUE target)
988
987
  OCSP_CERTID *id;
989
988
  int n;
990
989
 
991
- SafeGetOCSPCertId(target, id);
990
+ GetOCSPCertId(target, id);
992
991
  GetOCSPBasicRes(self, bs);
993
992
 
994
993
  if ((n = OCSP_resp_find(bs, id, -1)) == -1)
@@ -1006,10 +1005,10 @@ ossl_ocspbres_find_response(VALUE self, VALUE target)
1006
1005
  * call-seq:
1007
1006
  * basic_response.sign(cert, key, certs = nil, flags = 0, digest = nil) -> self
1008
1007
  *
1009
- * Signs this OCSP response using the +cert+, +key+ and optional +digest+. This
1008
+ * Signs this OCSP response using the _cert_, _key_ and optional _digest_. This
1010
1009
  * behaves in the similar way as OpenSSL::OCSP::Request#sign.
1011
1010
  *
1012
- * +flags+ can include:
1011
+ * _flags_ can include:
1013
1012
  * OpenSSL::OCSP::NOCERTS:: don't include certificates
1014
1013
  * OpenSSL::OCSP::NOTIME:: don't set producedAt
1015
1014
  * OpenSSL::OCSP::RESPID_KEY:: use signer's public key hash as responderID
@@ -1036,7 +1035,7 @@ ossl_ocspbres_sign(int argc, VALUE *argv, VALUE self)
1036
1035
  if (NIL_P(digest))
1037
1036
  md = EVP_sha1();
1038
1037
  else
1039
- md = GetDigestPtr(digest);
1038
+ md = ossl_evp_get_digestbyname(digest);
1040
1039
  if (NIL_P(certs))
1041
1040
  flg |= OCSP_NOCERTS;
1042
1041
  else
@@ -1053,8 +1052,8 @@ ossl_ocspbres_sign(int argc, VALUE *argv, VALUE self)
1053
1052
  * call-seq:
1054
1053
  * basic_response.verify(certificates, store, flags = 0) -> true or false
1055
1054
  *
1056
- * Verifies the signature of the response using the given +certificates+ and
1057
- * +store+. This works in the similar way as OpenSSL::OCSP::Request#verify.
1055
+ * Verifies the signature of the response using the given _certificates_ and
1056
+ * _store_. This works in the similar way as OpenSSL::OCSP::Request#verify.
1058
1057
  */
1059
1058
  static VALUE
1060
1059
  ossl_ocspbres_verify(int argc, VALUE *argv, VALUE self)
@@ -1184,7 +1183,7 @@ ossl_ocspsres_alloc(VALUE klass)
1184
1183
  * call-seq:
1185
1184
  * OpenSSL::OCSP::SingleResponse.new(der_string) -> SingleResponse
1186
1185
  *
1187
- * Creates a new SingleResponse from +der_string+.
1186
+ * Creates a new SingleResponse from _der_string_.
1188
1187
  */
1189
1188
  static VALUE
1190
1189
  ossl_ocspsres_initialize(VALUE self, VALUE arg)
@@ -1213,7 +1212,7 @@ ossl_ocspsres_initialize_copy(VALUE self, VALUE other)
1213
1212
 
1214
1213
  rb_check_frozen(self);
1215
1214
  GetOCSPSingleRes(self, sres_old);
1216
- SafeGetOCSPSingleRes(other, sres);
1215
+ GetOCSPSingleRes(other, sres);
1217
1216
 
1218
1217
  sres_new = ASN1_item_dup(ASN1_ITEM_rptr(OCSP_SINGLERESP), sres);
1219
1218
  if (!sres_new)
@@ -1235,10 +1234,10 @@ ossl_ocspsres_initialize_copy(VALUE self, VALUE other)
1235
1234
  *
1236
1235
  * It is possible that the OCSP request takes a few seconds or the time is not
1237
1236
  * accurate. To avoid rejecting a valid response, this method allows the times
1238
- * to be within +nsec+ of the current time.
1237
+ * to be within _nsec_ seconds of the current time.
1239
1238
  *
1240
1239
  * Some responders don't set the nextUpdate field. This may cause a very old
1241
- * response to be considered valid. The +maxsec+ parameter can be used to limit
1240
+ * response to be considered valid. The _maxsec_ parameter can be used to limit
1242
1241
  * the age of responses.
1243
1242
  */
1244
1243
  static VALUE
@@ -1329,8 +1328,10 @@ ossl_ocspsres_get_this_update(VALUE self)
1329
1328
  status = OCSP_single_get0_status(sres, NULL, NULL, &time, NULL);
1330
1329
  if (status < 0)
1331
1330
  ossl_raise(eOCSPError, "OCSP_single_get0_status");
1331
+ if (!time)
1332
+ return Qnil;
1332
1333
 
1333
- return asn1time_to_time(time); /* will handle NULL */
1334
+ return asn1time_to_time(time);
1334
1335
  }
1335
1336
 
1336
1337
  /*
@@ -1348,6 +1349,8 @@ ossl_ocspsres_get_next_update(VALUE self)
1348
1349
  status = OCSP_single_get0_status(sres, NULL, NULL, NULL, &time);
1349
1350
  if (status < 0)
1350
1351
  ossl_raise(eOCSPError, "OCSP_single_get0_status");
1352
+ if (!time)
1353
+ return Qnil;
1351
1354
 
1352
1355
  return asn1time_to_time(time);
1353
1356
  }
@@ -1369,6 +1372,8 @@ ossl_ocspsres_get_revocation_time(VALUE self)
1369
1372
  ossl_raise(eOCSPError, "OCSP_single_get0_status");
1370
1373
  if (status != V_OCSP_CERTSTATUS_REVOKED)
1371
1374
  ossl_raise(eOCSPError, "certificate is not revoked");
1375
+ if (!time)
1376
+ return Qnil;
1372
1377
 
1373
1378
  return asn1time_to_time(time);
1374
1379
  }
@@ -1468,7 +1473,7 @@ ossl_ocspcid_initialize_copy(VALUE self, VALUE other)
1468
1473
 
1469
1474
  rb_check_frozen(self);
1470
1475
  GetOCSPCertId(self, cid_old);
1471
- SafeGetOCSPCertId(other, cid);
1476
+ GetOCSPCertId(other, cid);
1472
1477
 
1473
1478
  cid_new = OCSP_CERTID_dup(cid);
1474
1479
  if (!cid_new)
@@ -1485,14 +1490,13 @@ ossl_ocspcid_initialize_copy(VALUE self, VALUE other)
1485
1490
  * OpenSSL::OCSP::CertificateId.new(subject, issuer, digest = nil) -> certificate_id
1486
1491
  * OpenSSL::OCSP::CertificateId.new(der_string) -> certificate_id
1487
1492
  *
1488
- * Creates a new OpenSSL::OCSP::CertificateId for the given +subject+ and
1489
- * +issuer+ X509 certificates. The +digest+ is used to compute the
1490
- * certificate ID and must be an OpenSSL::Digest instance.
1493
+ * Creates a new OpenSSL::OCSP::CertificateId for the given _subject_ and
1494
+ * _issuer_ X509 certificates. The _digest_ is a digest algorithm that is used
1495
+ * to compute the hash values. This defaults to SHA-1.
1491
1496
  *
1492
1497
  * If only one argument is given, decodes it as DER representation of a
1493
1498
  * certificate ID.
1494
1499
  */
1495
-
1496
1500
  static VALUE
1497
1501
  ossl_ocspcid_initialize(int argc, VALUE *argv, VALUE self)
1498
1502
  {
@@ -1517,7 +1521,7 @@ ossl_ocspcid_initialize(int argc, VALUE *argv, VALUE self)
1517
1521
 
1518
1522
  x509s = GetX509CertPtr(subject); /* NO NEED TO DUP */
1519
1523
  x509i = GetX509CertPtr(issuer); /* NO NEED TO DUP */
1520
- md = !NIL_P(digest) ? GetDigestPtr(digest) : NULL;
1524
+ md = !NIL_P(digest) ? ossl_evp_get_digestbyname(digest) : NULL;
1521
1525
 
1522
1526
  newid = OCSP_cert_to_id(md, x509s, x509i);
1523
1527
  if (!newid)
@@ -1534,7 +1538,7 @@ ossl_ocspcid_initialize(int argc, VALUE *argv, VALUE self)
1534
1538
  * call-seq:
1535
1539
  * certificate_id.cmp(other) -> true or false
1536
1540
  *
1537
- * Compares this certificate id with +other+ and returns true if they are the
1541
+ * Compares this certificate id with _other_ and returns +true+ if they are the
1538
1542
  * same.
1539
1543
  */
1540
1544
  static VALUE
@@ -1544,7 +1548,7 @@ ossl_ocspcid_cmp(VALUE self, VALUE other)
1544
1548
  int result;
1545
1549
 
1546
1550
  GetOCSPCertId(self, id);
1547
- SafeGetOCSPCertId(other, id2);
1551
+ GetOCSPCertId(other, id2);
1548
1552
  result = OCSP_id_cmp(id, id2);
1549
1553
 
1550
1554
  return (result == 0) ? Qtrue : Qfalse;
@@ -1554,7 +1558,7 @@ ossl_ocspcid_cmp(VALUE self, VALUE other)
1554
1558
  * call-seq:
1555
1559
  * certificate_id.cmp_issuer(other) -> true or false
1556
1560
  *
1557
- * Compares this certificate id's issuer with +other+ and returns true if
1561
+ * Compares this certificate id's issuer with _other_ and returns +true+ if
1558
1562
  * they are the same.
1559
1563
  */
1560
1564
 
@@ -1565,7 +1569,7 @@ ossl_ocspcid_cmp_issuer(VALUE self, VALUE other)
1565
1569
  int result;
1566
1570
 
1567
1571
  GetOCSPCertId(self, id);
1568
- SafeGetOCSPCertId(other, id2);
1572
+ GetOCSPCertId(other, id2);
1569
1573
  result = OCSP_id_issuer_cmp(id, id2);
1570
1574
 
1571
1575
  return (result == 0) ? Qtrue : Qfalse;
@@ -1824,12 +1828,13 @@ Init_ossl_ocsp(void)
1824
1828
 
1825
1829
  cOCSPReq = rb_define_class_under(mOCSP, "Request", rb_cObject);
1826
1830
  rb_define_alloc_func(cOCSPReq, ossl_ocspreq_alloc);
1827
- rb_define_copy_func(cOCSPReq, ossl_ocspreq_initialize_copy);
1831
+ rb_define_method(cOCSPReq, "initialize_copy", ossl_ocspreq_initialize_copy, 1);
1828
1832
  rb_define_method(cOCSPReq, "initialize", ossl_ocspreq_initialize, -1);
1829
1833
  rb_define_method(cOCSPReq, "add_nonce", ossl_ocspreq_add_nonce, -1);
1830
1834
  rb_define_method(cOCSPReq, "check_nonce", ossl_ocspreq_check_nonce, 1);
1831
1835
  rb_define_method(cOCSPReq, "add_certid", ossl_ocspreq_add_certid, 1);
1832
1836
  rb_define_method(cOCSPReq, "certid", ossl_ocspreq_get_certid, 0);
1837
+ rb_define_method(cOCSPReq, "signed?", ossl_ocspreq_signed_p, 0);
1833
1838
  rb_define_method(cOCSPReq, "sign", ossl_ocspreq_sign, -1);
1834
1839
  rb_define_method(cOCSPReq, "verify", ossl_ocspreq_verify, -1);
1835
1840
  rb_define_method(cOCSPReq, "to_der", ossl_ocspreq_to_der, 0);
@@ -1842,7 +1847,7 @@ Init_ossl_ocsp(void)
1842
1847
  cOCSPRes = rb_define_class_under(mOCSP, "Response", rb_cObject);
1843
1848
  rb_define_singleton_method(cOCSPRes, "create", ossl_ocspres_s_create, 2);
1844
1849
  rb_define_alloc_func(cOCSPRes, ossl_ocspres_alloc);
1845
- rb_define_copy_func(cOCSPRes, ossl_ocspres_initialize_copy);
1850
+ rb_define_method(cOCSPRes, "initialize_copy", ossl_ocspres_initialize_copy, 1);
1846
1851
  rb_define_method(cOCSPRes, "initialize", ossl_ocspres_initialize, -1);
1847
1852
  rb_define_method(cOCSPRes, "status", ossl_ocspres_status, 0);
1848
1853
  rb_define_method(cOCSPRes, "status_string", ossl_ocspres_status_string, 0);
@@ -1857,7 +1862,7 @@ Init_ossl_ocsp(void)
1857
1862
 
1858
1863
  cOCSPBasicRes = rb_define_class_under(mOCSP, "BasicResponse", rb_cObject);
1859
1864
  rb_define_alloc_func(cOCSPBasicRes, ossl_ocspbres_alloc);
1860
- rb_define_copy_func(cOCSPBasicRes, ossl_ocspbres_initialize_copy);
1865
+ rb_define_method(cOCSPBasicRes, "initialize_copy", ossl_ocspbres_initialize_copy, 1);
1861
1866
  rb_define_method(cOCSPBasicRes, "initialize", ossl_ocspbres_initialize, -1);
1862
1867
  rb_define_method(cOCSPBasicRes, "copy_nonce", ossl_ocspbres_copy_nonce, 1);
1863
1868
  rb_define_method(cOCSPBasicRes, "add_nonce", ossl_ocspbres_add_nonce, -1);
@@ -1876,7 +1881,7 @@ Init_ossl_ocsp(void)
1876
1881
  */
1877
1882
  cOCSPSingleRes = rb_define_class_under(mOCSP, "SingleResponse", rb_cObject);
1878
1883
  rb_define_alloc_func(cOCSPSingleRes, ossl_ocspsres_alloc);
1879
- rb_define_copy_func(cOCSPSingleRes, ossl_ocspsres_initialize_copy);
1884
+ rb_define_method(cOCSPSingleRes, "initialize_copy", ossl_ocspsres_initialize_copy, 1);
1880
1885
  rb_define_method(cOCSPSingleRes, "initialize", ossl_ocspsres_initialize, 1);
1881
1886
  rb_define_method(cOCSPSingleRes, "check_validity", ossl_ocspsres_check_validity, -1);
1882
1887
  rb_define_method(cOCSPSingleRes, "certid", ossl_ocspsres_get_certid, 0);
@@ -1895,7 +1900,7 @@ Init_ossl_ocsp(void)
1895
1900
 
1896
1901
  cOCSPCertId = rb_define_class_under(mOCSP, "CertificateId", rb_cObject);
1897
1902
  rb_define_alloc_func(cOCSPCertId, ossl_ocspcid_alloc);
1898
- rb_define_copy_func(cOCSPCertId, ossl_ocspcid_initialize_copy);
1903
+ rb_define_method(cOCSPCertId, "initialize_copy", ossl_ocspcid_initialize_copy, 1);
1899
1904
  rb_define_method(cOCSPCertId, "initialize", ossl_ocspcid_initialize, -1);
1900
1905
  rb_define_method(cOCSPCertId, "cmp", ossl_ocspcid_cmp, 1);
1901
1906
  rb_define_method(cOCSPCertId, "cmp_issuer", ossl_ocspcid_cmp_issuer, 1);