Skip to content

Commit dd05b49

Browse files
committed
Merge branch 'topic/ocsp-request-is-signed'
* topic/ocsp-request-is-signed: ocsp: add OpenSSL::OCSP::Request#signed?
2 parents b215e40 + af8a14d commit dd05b49

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

ext/openssl/ossl_ocsp.c

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ ossl_ocspreq_sign(int argc, VALUE *argv, VALUE self)
404404
* Verifies this request using the given _certificates_ and _store_.
405405
* _certificates_ is an array of OpenSSL::X509::Certificate, _store_ is an
406406
* 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.
407410
*/
408411

409412
static VALUE
@@ -452,6 +455,22 @@ ossl_ocspreq_to_der(VALUE self)
452455
return str;
453456
}
454457

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+
455474
/*
456475
* OCSP::Response
457476
*/
@@ -1809,6 +1828,7 @@ Init_ossl_ocsp(void)
18091828
rb_define_method(cOCSPReq, "check_nonce", ossl_ocspreq_check_nonce, 1);
18101829
rb_define_method(cOCSPReq, "add_certid", ossl_ocspreq_add_certid, 1);
18111830
rb_define_method(cOCSPReq, "certid", ossl_ocspreq_get_certid, 0);
1831+
rb_define_method(cOCSPReq, "signed?", ossl_ocspreq_signed_p, 0);
18121832
rb_define_method(cOCSPReq, "sign", ossl_ocspreq_sign, -1);
18131833
rb_define_method(cOCSPReq, "verify", ossl_ocspreq_verify, -1);
18141834
rb_define_method(cOCSPReq, "to_der", ossl_ocspreq_to_der, 0);

test/test_ocsp.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,21 @@ def test_request_sign_verify
128128
# fixed by OpenSSL 1.0.1j, 1.0.2 and LibreSSL 2.4.2
129129
pend "RT2560: ocsp_req_find_signer"
130130
end
131+
132+
# not signed
133+
req = OpenSSL::OCSP::Request.new.add_certid(cid)
134+
assert_equal false, req.verify([], store)
135+
end
136+
137+
def test_request_is_signed
138+
cid = OpenSSL::OCSP::CertificateId.new(@cert, @ca_cert)
139+
req = OpenSSL::OCSP::Request.new
140+
req.add_certid(cid)
141+
assert_equal false, req.signed?
142+
assert_equal false, OpenSSL::OCSP::Request.new(req.to_der).signed?
143+
req.sign(@cert, @cert_key, [])
144+
assert_equal true, req.signed?
145+
assert_equal true, OpenSSL::OCSP::Request.new(req.to_der).signed?
131146
end
132147

133148
def test_request_nonce

0 commit comments

Comments
 (0)