Skip to content

Commit

Permalink
Add implementation of OCSP nonce functions.
Browse files Browse the repository at this point in the history
References sfackler#1045.
  • Loading branch information
scolby33 committed Jan 24, 2019
1 parent ec8aadb commit f6676a2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions openssl-sys/src/ocsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ cfg_if! {

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

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

pub fn OCSP_response_status(resp: *mut OCSP_RESPONSE) -> c_int;
pub fn OCSP_response_get1_basic(resp: *mut OCSP_RESPONSE) -> *mut OCSP_BASICRESP;
pub fn OCSP_basic_add1_nonce(resp: *mut OCSP_BASICRESP, val: *mut c_uchar, len: c_int)
-> c_int;
pub fn OCSP_copy_nonce(resp: *mut OCSP_BASICRESP, req: *mut OCSP_REQUEST) -> c_int;

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

Expand Down Expand Up @@ -115,4 +119,6 @@ extern "C" {
st: *mut X509_STORE,
flags: c_ulong,
) -> c_int;

pub fn OCSP_check_nonce(req: *mut OCSP_REQUEST, bs: *mut OCSP_BASICRESP) -> c_int;
}
36 changes: 36 additions & 0 deletions openssl/src/ocsp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,24 @@ impl OcspBasicResponseRef {
}
}
}

pub fn add_nonce(&mut self, val: Option<&[u8]>) -> Result<(), ErrorStack> {
unsafe {
let (ptr, len) = match val {
Some(slice) => (slice.as_ptr() as *mut _, slice.len() as c_int),
None => (ptr::null_mut(), 0),
};
cvt(ffi::OCSP_basic_add1_nonce(self.as_ptr(), ptr, len))?;
Ok(())
}
}

pub fn copy_nonce(&mut self, req: OcspRequestRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::OCSP_copy_nonce(self.as_ptr(), req.as_ptr()))?;
Ok(())
}
}
}

foreign_type_and_impl_send_sync! {
Expand Down Expand Up @@ -336,6 +354,17 @@ impl OcspRequestRef {
Ok(OcspOneReqRef::from_ptr_mut(ptr))
}
}

pub fn add_nonce(&mut self, val: Option<&[u8]>) -> Result<(), ErrorStack> {
unsafe {
let (ptr, len) = match val {
Some(slice) => (slice.as_ptr() as *mut _, slice.len() as c_int),
None => (ptr::null_mut(), 0),
};
cvt(ffi::OCSP_request_add1_nonce(self.as_ptr(), ptr, len))?;
Ok(())
}
}
}

foreign_type_and_impl_send_sync! {
Expand All @@ -345,3 +374,10 @@ foreign_type_and_impl_send_sync! {
pub struct OcspOneReq;
pub struct OcspOneReqRef;
}

pub fn check_nonce(req: &OcspRequestRef, bs: &OcspBasicResponseRef) -> Result<(), ErrorStack> {
unsafe {
cvt(ffi::OCSP_check_nonce(req.as_ptr(), bs.as_ptr()))?;
Ok(())
}
}

0 comments on commit f6676a2

Please sign in to comment.