-
-
Notifications
You must be signed in to change notification settings - Fork 774
Add OCSP nonce functionality #1046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
f6676a2
7d5ec83
5e06a9a
8792ac6
d688e83
fc795f0
c238645
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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! { | ||
|
@@ -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! { | ||
|
@@ -345,3 +374,48 @@ 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()))?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This function will need a custom return type, looking at the documentation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've implemented this custom return. I don't love what I've done, especially how for the |
||
Ok(()) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use hex::FromHex; | ||
|
||
use super::*; | ||
use hash::MessageDigest; | ||
use x509::X509; | ||
|
||
#[test] | ||
fn test_create_ocsp_request() { | ||
let subject = include_bytes!("../test/cert.pem"); | ||
let subject = X509::from_pem(subject).unwrap(); | ||
let issuer = include_bytes!("../test/root-ca.pem"); | ||
let issuer = X509::from_pem(issuer).unwrap(); | ||
|
||
let req_der = include_bytes!("../test/ocsp-req.der"); | ||
let req_nonce_der = include_bytes!("../test/ocsp-req-nonce.der"); | ||
|
||
let cert_id = OcspCertId::from_cert( | ||
MessageDigest::sha1(), | ||
&subject, | ||
&issuer | ||
).unwrap(); | ||
|
||
let mut req = OcspRequest::new().unwrap(); | ||
req.add_id(cert_id).unwrap(); | ||
|
||
assert_eq!(&*req.to_der().unwrap(), req_der.as_ref()); | ||
|
||
|
||
let nonce = Vec::from_hex("4413A2C5019A7C3A384CDD8AB30E3816").unwrap(); | ||
req.add_nonce(Some(&nonce)).unwrap(); | ||
|
||
assert_eq!(&*req.to_der().unwrap(), req_nonce_der.as_ref()); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should take
&OcspRequestRef
, notOcspRequestRef
.