Skip to content

Commit 6af36a7

Browse files
authored
Merge pull request #1801 from steffen-eiden/distpoint
Add basic X509 Distribution Point extension support
2 parents b127fb2 + 34171f4 commit 6af36a7

File tree

7 files changed

+141
-1
lines changed

7 files changed

+141
-1
lines changed

openssl-sys/src/handwritten/x509.rs

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pub struct X509_VAL {
99

1010
pub enum X509_NAME_ENTRY {}
1111

12+
stack!(stack_st_X509_NAME_ENTRY);
13+
1214
stack!(stack_st_X509_NAME);
1315

1416
pub enum X509_EXTENSION {}

openssl-sys/src/handwritten/x509v3.rs

+27
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,30 @@ extern "C" {
103103
#[cfg(ossl110)]
104104
pub fn X509_get_extended_key_usage(x: *mut X509) -> u32;
105105
}
106+
107+
#[repr(C)]
108+
pub struct DIST_POINT_NAME {
109+
pub type_: c_int,
110+
pub name: DIST_POINT_NAME_st_anon_union,
111+
pub dpname: *mut X509_NAME,
112+
}
113+
114+
#[repr(C)]
115+
pub union DIST_POINT_NAME_st_anon_union {
116+
pub fullname: *mut stack_st_GENERAL_NAME,
117+
pub relativename: *mut stack_st_X509_NAME_ENTRY,
118+
}
119+
120+
#[repr(C)]
121+
pub struct DIST_POINT {
122+
pub distpoint: *mut DIST_POINT_NAME,
123+
pub reasons: *mut ASN1_BIT_STRING,
124+
pub CRLissuer: *mut stack_st_GENERAL_NAME,
125+
pub dp_reasons: c_int,
126+
}
127+
stack!(stack_st_DIST_POINT);
128+
129+
extern "C" {
130+
pub fn DIST_POINT_free(dist_point: *mut DIST_POINT);
131+
pub fn DIST_POINT_NAME_free(dist_point: *mut DIST_POINT_NAME);
132+
}

openssl/src/x509/mod.rs

+57
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,20 @@ impl X509Ref {
423423
}
424424
}
425425

426+
/// Returns this certificate's CRL distribution points, if they exist.
427+
#[corresponds(X509_get_ext_d2i)]
428+
pub fn crl_distribution_points(&self) -> Option<Stack<DistPoint>> {
429+
unsafe {
430+
let stack = ffi::X509_get_ext_d2i(
431+
self.as_ptr(),
432+
ffi::NID_crl_distribution_points,
433+
ptr::null_mut(),
434+
ptr::null_mut(),
435+
);
436+
Stack::from_ptr_opt(stack as *mut _)
437+
}
438+
}
439+
426440
/// Returns this certificate's issuer alternative name entries, if they exist.
427441
#[corresponds(X509_get_ext_d2i)]
428442
pub fn issuer_alt_names(&self) -> Option<Stack<GeneralName>> {
@@ -1927,6 +1941,49 @@ impl Stackable for GeneralName {
19271941
type StackType = ffi::stack_st_GENERAL_NAME;
19281942
}
19291943

1944+
foreign_type_and_impl_send_sync! {
1945+
type CType = ffi::DIST_POINT;
1946+
fn drop = ffi::DIST_POINT_free;
1947+
1948+
/// A `X509` distribution point.
1949+
pub struct DistPoint;
1950+
/// Reference to `DistPoint`.
1951+
pub struct DistPointRef;
1952+
}
1953+
1954+
impl DistPointRef {
1955+
/// Returns the name of this distribution point if it exists
1956+
pub fn distpoint(&self) -> Option<&DistPointNameRef> {
1957+
unsafe { DistPointNameRef::from_const_ptr_opt((*self.as_ptr()).distpoint) }
1958+
}
1959+
}
1960+
1961+
foreign_type_and_impl_send_sync! {
1962+
type CType = ffi::DIST_POINT_NAME;
1963+
fn drop = ffi::DIST_POINT_NAME_free;
1964+
1965+
/// A `X509` distribution point.
1966+
pub struct DistPointName;
1967+
/// Reference to `DistPointName`.
1968+
pub struct DistPointNameRef;
1969+
}
1970+
1971+
impl DistPointNameRef {
1972+
/// Returns the contents of this DistPointName if it is a fullname.
1973+
pub fn fullname(&self) -> Option<&StackRef<GeneralName>> {
1974+
unsafe {
1975+
if (*self.as_ptr()).type_ != 0 {
1976+
return None;
1977+
}
1978+
StackRef::from_const_ptr_opt((*self.as_ptr()).name.fullname)
1979+
}
1980+
}
1981+
}
1982+
1983+
impl Stackable for DistPoint {
1984+
type StackType = ffi::stack_st_DIST_POINT;
1985+
}
1986+
19301987
foreign_type_and_impl_send_sync! {
19311988
type CType = ffi::ACCESS_DESCRIPTION;
19321989
fn drop = ffi::ACCESS_DESCRIPTION_free;

openssl/src/x509/tests.rs

+27
Original file line numberDiff line numberDiff line change
@@ -986,3 +986,30 @@ fn ipv6_as_subject_alternative_name_is_formatted_in_debug() {
986986
8u8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 128,
987987
]);
988988
}
989+
990+
#[test]
991+
fn test_dist_point() {
992+
let cert = include_bytes!("../../test/certv3.pem");
993+
let cert = X509::from_pem(cert).unwrap();
994+
995+
let dps = cert.crl_distribution_points().unwrap();
996+
let dp = dps.get(0).unwrap();
997+
let dp_nm = dp.distpoint().unwrap();
998+
let dp_gns = dp_nm.fullname().unwrap();
999+
let dp_gn = dp_gns.get(0).unwrap();
1000+
assert_eq!(dp_gn.uri().unwrap(), "http://example.com/crl.pem");
1001+
1002+
let dp = dps.get(1).unwrap();
1003+
let dp_nm = dp.distpoint().unwrap();
1004+
let dp_gns = dp_nm.fullname().unwrap();
1005+
let dp_gn = dp_gns.get(0).unwrap();
1006+
assert_eq!(dp_gn.uri().unwrap(), "http://example.com/crl2.pem");
1007+
assert!(dps.get(2).is_none())
1008+
}
1009+
1010+
#[test]
1011+
fn test_dist_point_null() {
1012+
let cert = include_bytes!("../../test/cert.pem");
1013+
let cert = X509::from_pem(cert).unwrap();
1014+
assert!(cert.crl_distribution_points().is_none());
1015+
}

openssl/test/certv3.pem

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-----BEGIN CERTIFICATE-----
2+
MIIDwTCCAqmgAwIBAgIUDeCGNunyJfBd3U/qUtmCcvbMyZwwDQYJKoZIhvcNAQEL
3+
BQAwRTELMAkGA1UEBhMCQVUxEzARBgNVBAgMClNvbWUtU3RhdGUxITAfBgNVBAoM
4+
GEludGVybmV0IFdpZGdpdHMgUHR5IEx0ZDAeFw0yMzAxMjMxMzMzNTJaFw0zMzAx
5+
MjAxMzMzNTJaMFoxCzAJBgNVBAYTAkFVMRMwEQY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yTWf3zIjhWUdp9TlzgRyFiyetP2FcKwremVVGdDq/Y6dfXaq8CA1
22+
6Fr9KTY=
23+
-----END CERTIFICATE-----

openssl/test/certv3_extfile

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
crlDistributionPoints=URI:http://example.com/crl.pem,URI:http://example.com/crl2.pem

systest/build.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,9 @@ fn main() {
110110
|| s.starts_with("CRYPTO_EX_")
111111
});
112112
cfg.skip_struct(|s| {
113-
s == "ProbeResult" || s == "X509_OBJECT_data" // inline union
113+
s == "ProbeResult" ||
114+
s == "X509_OBJECT_data" || // inline union
115+
s == "DIST_POINT_NAME_st_anon_union" // inline union
114116
});
115117
cfg.skip_fn(move |s| {
116118
s == "CRYPTO_memcmp" || // uses volatile
@@ -130,6 +132,7 @@ fn main() {
130132
cfg.skip_field_type(|s, field| {
131133
(s == "EVP_PKEY" && field == "pkey") || // union
132134
(s == "GENERAL_NAME" && field == "d") || // union
135+
(s == "DIST_POINT_NAME" && field == "name") || // union
133136
(s == "X509_OBJECT" && field == "data") // union
134137
});
135138
cfg.skip_signededness(|s| {

0 commit comments

Comments
 (0)