Skip to content

Commit f6676a2

Browse files
committed
Add implementation of OCSP nonce functions.
References sfackler#1045.
1 parent ec8aadb commit f6676a2

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

openssl-sys/src/ocsp.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ cfg_if! {
6666

6767
extern "C" {
6868
pub fn OCSP_request_add0_id(r: *mut OCSP_REQUEST, id: *mut OCSP_CERTID) -> *mut OCSP_ONEREQ;
69+
pub fn OCSP_request_add1_nonce(req: *mut OCSP_REQUEST, val: *mut c_uchar, len: c_int) -> c_int;
6970

7071
pub fn OCSP_resp_find_status(
7172
bs: *mut OCSP_BASICRESP,
@@ -85,6 +86,9 @@ extern "C" {
8586

8687
pub fn OCSP_response_status(resp: *mut OCSP_RESPONSE) -> c_int;
8788
pub fn OCSP_response_get1_basic(resp: *mut OCSP_RESPONSE) -> *mut OCSP_BASICRESP;
89+
pub fn OCSP_basic_add1_nonce(resp: *mut OCSP_BASICRESP, val: *mut c_uchar, len: c_int)
90+
-> c_int;
91+
pub fn OCSP_copy_nonce(resp: *mut OCSP_BASICRESP, req: *mut OCSP_REQUEST) -> c_int;
8892

8993
pub fn OCSP_response_create(status: c_int, bs: *mut OCSP_BASICRESP) -> *mut OCSP_RESPONSE;
9094

@@ -115,4 +119,6 @@ extern "C" {
115119
st: *mut X509_STORE,
116120
flags: c_ulong,
117121
) -> c_int;
122+
123+
pub fn OCSP_check_nonce(req: *mut OCSP_REQUEST, bs: *mut OCSP_BASICRESP) -> c_int;
118124
}

openssl/src/ocsp.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,24 @@ impl OcspBasicResponseRef {
200200
}
201201
}
202202
}
203+
204+
pub fn add_nonce(&mut self, val: Option<&[u8]>) -> Result<(), ErrorStack> {
205+
unsafe {
206+
let (ptr, len) = match val {
207+
Some(slice) => (slice.as_ptr() as *mut _, slice.len() as c_int),
208+
None => (ptr::null_mut(), 0),
209+
};
210+
cvt(ffi::OCSP_basic_add1_nonce(self.as_ptr(), ptr, len))?;
211+
Ok(())
212+
}
213+
}
214+
215+
pub fn copy_nonce(&mut self, req: OcspRequestRef) -> Result<(), ErrorStack> {
216+
unsafe {
217+
cvt(ffi::OCSP_copy_nonce(self.as_ptr(), req.as_ptr()))?;
218+
Ok(())
219+
}
220+
}
203221
}
204222

205223
foreign_type_and_impl_send_sync! {
@@ -336,6 +354,17 @@ impl OcspRequestRef {
336354
Ok(OcspOneReqRef::from_ptr_mut(ptr))
337355
}
338356
}
357+
358+
pub fn add_nonce(&mut self, val: Option<&[u8]>) -> Result<(), ErrorStack> {
359+
unsafe {
360+
let (ptr, len) = match val {
361+
Some(slice) => (slice.as_ptr() as *mut _, slice.len() as c_int),
362+
None => (ptr::null_mut(), 0),
363+
};
364+
cvt(ffi::OCSP_request_add1_nonce(self.as_ptr(), ptr, len))?;
365+
Ok(())
366+
}
367+
}
339368
}
340369

341370
foreign_type_and_impl_send_sync! {
@@ -345,3 +374,10 @@ foreign_type_and_impl_send_sync! {
345374
pub struct OcspOneReq;
346375
pub struct OcspOneReqRef;
347376
}
377+
378+
pub fn check_nonce(req: &OcspRequestRef, bs: &OcspBasicResponseRef) -> Result<(), ErrorStack> {
379+
unsafe {
380+
cvt(ffi::OCSP_check_nonce(req.as_ptr(), bs.as_ptr()))?;
381+
Ok(())
382+
}
383+
}

0 commit comments

Comments
 (0)