@@ -127,6 +127,7 @@ struct Options {
127
127
on_initial_expect_curve_id : Option < NamedGroup > ,
128
128
on_resume_expect_curve_id : Option < NamedGroup > ,
129
129
wait_for_debugger : bool ,
130
+ ocsp : OcspValidation ,
130
131
}
131
132
132
133
impl Options {
@@ -197,6 +198,7 @@ impl Options {
197
198
on_initial_expect_curve_id : None ,
198
199
on_resume_expect_curve_id : None ,
199
200
wait_for_debugger : false ,
201
+ ocsp : OcspValidation :: default ( ) ,
200
202
}
201
203
}
202
204
@@ -411,10 +413,11 @@ impl ClientCertVerifier for DummyClientAuth {
411
413
#[ derive( Debug ) ]
412
414
struct DummyServerAuth {
413
415
parent : Arc < dyn ServerCertVerifier > ,
416
+ ocsp : OcspValidation ,
414
417
}
415
418
416
419
impl DummyServerAuth {
417
- fn new ( trusted_cert_file : & str ) -> Self {
420
+ fn new ( trusted_cert_file : & str , ocsp : OcspValidation ) -> Self {
418
421
Self {
419
422
parent : WebPkiServerVerifier :: builder_with_provider (
420
423
load_root_certs ( trusted_cert_file) ,
@@ -424,6 +427,7 @@ impl DummyServerAuth {
424
427
)
425
428
. build ( )
426
429
. unwrap ( ) ,
430
+ ocsp,
427
431
}
428
432
}
429
433
}
@@ -437,6 +441,9 @@ impl ServerCertVerifier for DummyServerAuth {
437
441
_ocsp : & [ u8 ] ,
438
442
_now : UnixTime ,
439
443
) -> Result < ServerCertVerified , Error > {
444
+ if let OcspValidation :: Reject = self . ocsp {
445
+ return Err ( CertificateError :: InvalidOcspResponse . into ( ) ) ;
446
+ }
440
447
Ok ( ServerCertVerified :: assertion ( ) )
441
448
}
442
449
@@ -465,6 +472,16 @@ impl ServerCertVerifier for DummyServerAuth {
465
472
}
466
473
}
467
474
475
+ #[ derive( Clone , Copy , Debug , Default ) ]
476
+ enum OcspValidation {
477
+ /// Totally ignore `ocsp_response` value
478
+ #[ default]
479
+ None ,
480
+
481
+ /// Return an error (irrespective of `ocsp_response` value)
482
+ Reject ,
483
+ }
484
+
468
485
#[ derive( Debug ) ]
469
486
struct FixedSignatureSchemeSigningKey {
470
487
key : Arc < dyn sign:: SigningKey > ,
@@ -807,7 +824,10 @@ fn make_client_cfg(opts: &Options) -> Arc<ClientConfig> {
807
824
808
825
let cfg = cfg
809
826
. dangerous ( )
810
- . with_custom_certificate_verifier ( Arc :: new ( DummyServerAuth :: new ( & opts. trusted_cert_file ) ) ) ;
827
+ . with_custom_certificate_verifier ( Arc :: new ( DummyServerAuth :: new (
828
+ & opts. trusted_cert_file ,
829
+ opts. ocsp ,
830
+ ) ) ) ;
811
831
812
832
let mut cfg = if !opts. cert_file . is_empty ( ) && !opts. key_file . is_empty ( ) {
813
833
let cert = CertificateDer :: pem_file_iter ( & opts. cert_file )
@@ -1016,6 +1036,10 @@ fn handle_err(opts: &Options, err: Error) -> ! {
1016
1036
Error :: InvalidCertificate ( CertificateError :: UnsupportedSignatureAlgorithm ) => {
1017
1037
quit ( ":WRONG_SIGNATURE_TYPE:" )
1018
1038
}
1039
+ Error :: InvalidCertificate ( CertificateError :: InvalidOcspResponse ) => {
1040
+ // note: only use is in this file.
1041
+ quit ( ":OCSP_CB_ERROR:" )
1042
+ }
1019
1043
Error :: InvalidCertificate ( e) => quit ( & format ! ( ":BAD_CERT: ({e:?})" ) ) ,
1020
1044
Error :: PeerSentOversizedRecord => quit ( ":DATA_LENGTH_TOO_LONG:" ) ,
1021
1045
_ => {
@@ -1645,6 +1669,9 @@ pub fn main() {
1645
1669
"-server-preference" => {
1646
1670
opts. server_preference = true ;
1647
1671
}
1672
+ "-fail-ocsp-callback" => {
1673
+ opts. ocsp = OcspValidation :: Reject ;
1674
+ }
1648
1675
"-wait-for-debugger" => {
1649
1676
#[ cfg( windows) ]
1650
1677
{
@@ -1669,6 +1696,7 @@ pub fn main() {
1669
1696
"-expect-no-session" |
1670
1697
"-expect-ticket-renewal" |
1671
1698
"-enable-ocsp-stapling" |
1699
+ "-use-ocsp-callback" |
1672
1700
"-forbid-renegotiation-after-handshake" |
1673
1701
// internal openssl details:
1674
1702
"-async" |
0 commit comments