Skip to content

Commit e7b4565

Browse files
author
Jonas Maier
committed
add getters & equality functionality s.t. one can extract digest+algo from a TsReq to confirm it matches the data it supposedly signs
1 parent 343c3b4 commit e7b4565

File tree

5 files changed

+64
-2
lines changed

5 files changed

+64
-2
lines changed

openssl-sys/src/handwritten/x509.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,8 @@ extern "C" {
214214
pub fn X509_ALGOR_free(x: *mut X509_ALGOR);
215215
pub fn X509_ALGOR_set_md(alg: *mut X509_ALGOR, md: *const EVP_MD);
216216

217+
pub fn X509_ALGOR_cmp(alg0: *const X509_ALGOR, alg1: *const X509_ALGOR) -> c_int;
218+
217219
pub fn X509_REVOKED_new() -> *mut X509_REVOKED;
218220
pub fn X509_REVOKED_free(x: *mut X509_REVOKED);
219221
}

openssl-sys/src/ts.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use libc::*;
22

3-
use crate::{ASN1_INTEGER, ASN1_OBJECT, BIO, EVP_MD, EVP_PKEY, X509, X509_ALGOR};
3+
use crate::{
4+
ASN1_INTEGER, ASN1_OBJECT, ASN1_OCTET_STRING, BIO, EVP_MD, EVP_PKEY, X509, X509_ALGOR,
5+
};
46

57
pub enum TS_MSG_IMPRINT {}
68
pub enum TS_REQ {}
@@ -62,7 +64,9 @@ extern "C" {
6264
pub fn TS_MSG_IMPRINT_new() -> *mut TS_MSG_IMPRINT;
6365
pub fn TS_MSG_IMPRINT_free(a: *mut TS_MSG_IMPRINT);
6466
pub fn TS_MSG_IMPRINT_set_algo(a: *mut TS_MSG_IMPRINT, alg: *mut X509_ALGOR) -> c_int;
67+
pub fn TS_MSG_IMPRINT_get_algo(a: *mut TS_MSG_IMPRINT) -> *mut X509_ALGOR;
6568
pub fn TS_MSG_IMPRINT_set_msg(a: *mut TS_MSG_IMPRINT, d: *mut c_uchar, length: c_int) -> c_int;
69+
pub fn TS_MSG_IMPRINT_get_msg(a: *mut TS_MSG_IMPRINT) -> *mut ASN1_OCTET_STRING;
6670

6771
pub fn TS_REQ_new() -> *mut TS_REQ;
6872
pub fn TS_REQ_free(a: *mut TS_REQ);

openssl/src/asn1.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,18 @@ impl Asn1OctetStringRef {
651651
}
652652
}
653653

654+
impl PartialEq for Asn1OctetStringRef {
655+
fn eq(&self, other: &Self) -> bool {
656+
self.as_slice() == other.as_slice()
657+
}
658+
}
659+
660+
impl PartialEq for Asn1OctetString {
661+
fn eq(&self, other: &Self) -> bool {
662+
Asn1OctetStringRef::eq(self, other)
663+
}
664+
}
665+
654666
foreign_type_and_impl_send_sync! {
655667
type CType = ffi::ASN1_OBJECT;
656668
fn drop = ffi::ASN1_OBJECT_free;

openssl/src/ts.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use openssl_macros::corresponds;
1111
use std::convert::TryFrom;
1212
use std::ptr;
1313

14-
use crate::asn1::{Asn1IntegerRef, Asn1ObjectRef};
14+
use crate::asn1::{Asn1IntegerRef, Asn1ObjectRef, Asn1OctetString};
1515
use crate::bio::MemBioSlice;
1616
use crate::error::ErrorStack;
1717
use crate::hash::{Hasher, MessageDigest};
@@ -31,6 +31,17 @@ foreign_type_and_impl_send_sync! {
3131
pub struct TsMsgImprintRef;
3232
}
3333

34+
impl PartialEq for TsMsgImprintRef {
35+
fn eq(&self, other: &Self) -> bool {
36+
self.get_msg() == other.get_msg() && self.get_algo() == other.get_algo()
37+
}
38+
}
39+
impl PartialEq for TsMsgImprint {
40+
fn eq(&self, other: &Self) -> bool {
41+
TsMsgImprintRef::eq(self, other)
42+
}
43+
}
44+
3445
impl TsMsgImprint {
3546
/// Creates a new message imprint.
3647
#[corresponds(TS_MSG_IMPRINT_new)]
@@ -91,6 +102,24 @@ impl TsMsgImprint {
91102
}
92103
}
93104

105+
impl TsMsgImprintRef {
106+
#[corresponds(TS_MSG_IMPRINT_get_msg)]
107+
pub fn get_msg(&self) -> Option<Asn1OctetString> {
108+
unsafe {
109+
let octet = ffi::TS_MSG_IMPRINT_get_msg(self.as_ptr());
110+
Asn1OctetString::from_ptr_opt(octet)
111+
}
112+
}
113+
114+
#[corresponds(TS_MSG_IMPRINT_get_algo)]
115+
pub fn get_algo(&self) -> Option<X509Algorithm> {
116+
unsafe {
117+
let algo = ffi::TS_MSG_IMPRINT_get_algo(self.as_ptr());
118+
X509Algorithm::from_ptr_opt(algo)
119+
}
120+
}
121+
}
122+
94123
foreign_type_and_impl_send_sync! {
95124
type CType = ffi::TS_REQ;
96125
fn drop = ffi::TS_REQ_free;

openssl/src/x509/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2340,13 +2340,28 @@ impl X509AlgorithmRef {
23402340
}
23412341
}
23422342

2343+
#[corresponds(X509_ALGOR_set_md)]
23432344
pub fn set_md(&mut self, md: MessageDigest) {
23442345
unsafe {
23452346
ffi::X509_ALGOR_set_md(self.as_ptr(), md.as_ptr());
23462347
}
23472348
}
23482349
}
23492350

2351+
impl PartialEq for X509AlgorithmRef {
2352+
fn eq(&self, other: &Self) -> bool {
2353+
unsafe {
2354+
ffi::X509_ALGOR_cmp(self.as_ptr(), other.as_ptr()) == 0
2355+
}
2356+
}
2357+
}
2358+
2359+
impl PartialEq for X509Algorithm {
2360+
fn eq(&self, other: &Self) -> bool {
2361+
X509AlgorithmRef::eq(self, other)
2362+
}
2363+
}
2364+
23502365
foreign_type_and_impl_send_sync! {
23512366
type CType = ffi::X509_OBJECT;
23522367
fn drop = X509_OBJECT_free;

0 commit comments

Comments
 (0)