Skip to content

Commit

Permalink
mark supported OpenSSL version range, make CI happy
Browse files Browse the repository at this point in the history
Signed-off-by: Markus Theil <theil.markus@gmail.com>
  • Loading branch information
thillux committed Oct 12, 2023
1 parent e93ab39 commit 815a951
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 20 deletions.
43 changes: 40 additions & 3 deletions openssl-sys/src/handwritten/x509_sbgp.rs
Original file line number Diff line number Diff line change
@@ -1,80 +1,111 @@
#[cfg(ossl110)]
use super::super::*;
#[cfg(ossl110)]
use libc::*;

#[repr(C)]
#[cfg(ossl110)]
pub struct ASRange {
pub min: *mut ASN1_INTEGER,
pub max: *mut ASN1_INTEGER,
}

#[repr(C)]
#[cfg(ossl110)]
pub struct ASIdOrRange {
pub type_: c_int,
pub u: ASIdOrRange_st_anon_union,
}

#[repr(C)]
#[cfg(ossl110)]
pub union ASIdOrRange_st_anon_union {
pub id: *mut ASN1_INTEGER,
pub range: *mut ASRange,
}

#[cfg(ossl110)]
stack!(stack_st_ASIdOrRange);

#[repr(C)]
#[cfg(ossl110)]
pub union ASIdentifierChoice_st_anon_union {
pub asIdsOrRanges: *mut stack_st_ASIdOrRange,
}

#[repr(C)]
#[cfg(ossl110)]
pub struct ASIdentifierChoice {
pub type_: c_int,
pub asIdsOrRanges: *mut stack_st_ASIdOrRange,
pub u: ASIdentifierChoice_st_anon_union,
}

#[repr(C)]
#[cfg(ossl110)]
pub struct ASIdentifiers {
pub asnum: *mut ASIdentifierChoice,
pub rdi: *mut ASIdentifierChoice,
}

#[repr(C)]
#[cfg(ossl110)]
pub struct IPAddressRange {
pub min: *mut ASN1_BIT_STRING,
pub max: *mut ASN1_BIT_STRING,
}

#[repr(C)]
#[cfg(ossl110)]
pub struct IPAddressOrRange {
pub type_: c_int,
pub u: IPAddressOrRange_st_anon_union,
}
#[repr(C)]
#[cfg(ossl110)]
pub union IPAddressOrRange_st_anon_union {
pub addressPrefix: *mut ASN1_BIT_STRING,
pub addressRange: *mut IPAddressRange,
}

#[cfg(ossl110)]
stack!(stack_st_IPAddressOrRange);
#[cfg(ossl110)]
type IPAddressOrRanges = stack_st_IPAddressOrRange;

#[repr(C)]
#[cfg(ossl110)]
pub union IPAddressChoice_st_anon_union {
pub addressesOrRanges: *mut IPAddressOrRanges,
}

#[repr(C)]
#[cfg(ossl110)]
pub struct IPAddressChoice {
pub type_: c_int,
pub addressesOrRanges: *mut IPAddressOrRanges,
pub u: IPAddressChoice_st_anon_union,
}

#[repr(C)]
#[cfg(ossl110)]
pub struct IPAddressFamily {
pub addressFamily: *mut ASN1_OCTET_STRING,
pub ipAddressChoice: *mut IPAddressChoice,
}

#[cfg(ossl110)]
stack!(stack_st_IPAddressFamily);
#[cfg(ossl110)]
type IPAddrBlocks = stack_st_IPAddressFamily;

#[cfg(ossl110)]
extern "C" {
pub fn ASIdentifiers_free(asi: *mut ASIdentifiers);
pub fn ASIdOrRange_free(asi: *mut ASIdOrRange);
pub fn IPAddressFamily_free(asi: *mut IPAddressFamily);
pub fn IPAddressOrRange_free(asi: *mut IPAddressOrRange);
}

#[cfg(ossl110)]
pub unsafe fn X509v3_addr_get_afi(f: *mut IPAddressFamily) -> c_int {
if f.is_null() {
0
Expand All @@ -84,11 +115,12 @@ pub unsafe fn X509v3_addr_get_afi(f: *mut IPAddressFamily) -> c_int {
0
} else {
let raw = ASN1_STRING_get0_data(d);
((*raw.offset(0) as i32) << 8) | *raw.offset(1) as i32
((*raw.offset(0) as c_int) << 8) | *raw.offset(1) as c_int
}
}
}

#[cfg(ossl110)]
fn length_from_afi(afi: c_int) -> isize {
match afi {
IANA_AFI_IPV4 => 4,
Expand All @@ -97,6 +129,7 @@ fn length_from_afi(afi: c_int) -> isize {
}
}

#[cfg(ossl110)]
struct ASN1_STRING_internal {
length: c_int,
type_: c_int,
Expand All @@ -108,10 +141,12 @@ struct ASN1_STRING_internal {
*/
flags: c_int,
}

/*
* Expand the bitstring form of an address into a raw byte array.
* At the moment this is coded for simplicity, not speed.
*/
#[cfg(ossl110)]
fn addr_expand(addr: *mut u8, bs: *const ASN1_BIT_STRING, length: isize, fill: u8) -> bool {
unsafe {
let str = bs as *mut ASN1_STRING;
Expand Down Expand Up @@ -151,6 +186,7 @@ fn addr_expand(addr: *mut u8, bs: *const ASN1_BIT_STRING, length: isize, fill: u
/*
* Extract min and max values from an IPAddressOrRange.
*/
#[cfg(ossl110)]
fn extract_min_max(aor: *mut IPAddressOrRange, min: *mut u8, max: *mut u8, length: isize) -> bool {
unsafe {
match (*aor).type_ {
Expand All @@ -167,6 +203,7 @@ fn extract_min_max(aor: *mut IPAddressOrRange, min: *mut u8, max: *mut u8, lengt
}
}

#[cfg(ossl110)]
pub fn X509v3_addr_get_range(
aor: *mut IPAddressOrRange,
afi: c_int,
Expand Down
12 changes: 12 additions & 0 deletions openssl-sys/src/x509_sbgp.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,30 @@
#[cfg(ossl110)]
use libc::*;

#[cfg(ossl110)]
use super::*;

#[cfg(ossl110)]
pub const ASIdOrRange_id: c_int = 0;
#[cfg(ossl110)]
pub const ASIdOrRange_range: c_int = 1;

#[cfg(ossl110)]
pub const ASIdentifierChoice_inherit: c_int = 0;
#[cfg(ossl110)]
pub const ASIdentifierChoice_asIdsOrRanges: c_int = 1;

#[cfg(ossl110)]
pub const IPAddressOrRange_addressPrefix: c_int = 0;
#[cfg(ossl110)]
pub const IPAddressOrRange_addressRange: c_int = 1;

#[cfg(ossl110)]
pub const IPAddressChoice_inherit: c_int = 0;
#[cfg(ossl110)]
pub const IPAddressChoice_addressesOrRanges: c_int = 1;

#[cfg(ossl110)]
pub const IANA_AFI_IPV4: c_int = 1;
#[cfg(ossl110)]
pub const IANA_AFI_IPV6: c_int = 2;
6 changes: 6 additions & 0 deletions openssl/src/x509/extension.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,17 +428,20 @@ impl AuthorityKeyIdentifier {
}
}

#[cfg(ossl110)]
pub struct SbgpAsIdentifier {
critical: bool,
asn: Vec<(u32, u32)>,
}

#[cfg(ossl110)]
impl Default for SbgpAsIdentifier {
fn default() -> SbgpAsIdentifier {
SbgpAsIdentifier::new()
}
}

#[cfg(ossl110)]
impl SbgpAsIdentifier {
/// Construct a new `SbgpAsIdentifier` extension.
pub fn new() -> SbgpAsIdentifier {
Expand Down Expand Up @@ -484,17 +487,20 @@ impl SbgpAsIdentifier {
}
}

#[cfg(ossl110)]
pub struct SbgpIpAddressIdentifier {
critical: bool,
ip_ranges: Vec<(std::net::IpAddr, std::net::IpAddr)>,
}

#[cfg(ossl110)]
impl Default for SbgpIpAddressIdentifier {
fn default() -> SbgpIpAddressIdentifier {
SbgpIpAddressIdentifier::new()
}
}

#[cfg(ossl110)]
impl SbgpIpAddressIdentifier {
/// Construct a new `SbgpIpAddressIdentifier` extension.
pub fn new() -> SbgpIpAddressIdentifier {
Expand Down
32 changes: 26 additions & 6 deletions openssl/src/x509/sbgp.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,28 @@
#[cfg(ossl110)]
use std::convert::TryInto;
#[cfg(ossl110)]
use std::mem::MaybeUninit;

#[cfg(ossl110)]
use ffi::{
ASIdOrRange_id, ASIdOrRange_range, ASIdentifierChoice_asIdsOrRanges,
ASIdentifierChoice_inherit, IPAddressChoice_addressesOrRanges, X509v3_addr_get_afi,
X509v3_addr_get_range, ASN1_INTEGER, IANA_AFI_IPV4, IANA_AFI_IPV6,
};
#[cfg(ossl110)]
use foreign_types::{ForeignType, ForeignTypeRef};

#[cfg(ossl110)]
use crate::{
asn1::Asn1IntegerRef,
stack::{Stack, StackRef, Stackable},
util::{ForeignTypeExt, ForeignTypeRefExt},
};

#[cfg(ossl110)]
use super::X509;

#[cfg(ossl110)]
foreign_type_and_impl_send_sync! {
type CType = ffi::ASIdOrRange;
fn drop = ffi::ASIdOrRange_free;
Expand All @@ -24,11 +32,12 @@ foreign_type_and_impl_send_sync! {
/// Reference to `ASIdOrRange`.
pub struct ASIdOrRangeRef;
}

#[cfg(ossl110)]
impl Stackable for ASIdOrRange {
type StackType = ffi::stack_st_ASIdOrRange;
}

#[cfg(ossl110)]
foreign_type_and_impl_send_sync! {
type CType = ffi::ASIdentifiers;
fn drop = ffi::ASIdentifiers_free;
Expand All @@ -39,6 +48,7 @@ foreign_type_and_impl_send_sync! {
pub struct ASIdentifiersRef;
}

#[cfg(ossl110)]
impl ASIdentifiers {
pub fn inherited(&self) -> bool {
unsafe {
Expand All @@ -56,7 +66,7 @@ impl ASIdentifiers {
if (*asnum).type_ != ASIdentifierChoice_asIdsOrRanges {
return None;
}
if let Some(s) = StackRef::<ASIdOrRange>::from_const_ptr_opt((*asnum).asIdsOrRanges) {
if let Some(s) = StackRef::<ASIdOrRange>::from_const_ptr_opt((*asnum).u.asIdsOrRanges) {
for a_ptr in s {
let a = a_ptr.as_ptr();
if (*a).type_ == ASIdOrRange_id {
Expand Down Expand Up @@ -85,6 +95,7 @@ impl ASIdentifiers {
}
}

#[cfg(ossl110)]
foreign_type_and_impl_send_sync! {
type CType = ffi::IPAddressOrRange;
fn drop = ffi::IPAddressOrRange_free;
Expand All @@ -95,10 +106,12 @@ foreign_type_and_impl_send_sync! {
pub struct IPAddressOrRangeRef;
}

#[cfg(ossl110)]
impl Stackable for IPAddressOrRange {
type StackType = ffi::stack_st_IPAddressOrRange;
}

#[cfg(ossl110)]
foreign_type_and_impl_send_sync! {
type CType = ffi::IPAddressFamily;
fn drop = ffi::IPAddressFamily_free;
Expand All @@ -109,21 +122,24 @@ foreign_type_and_impl_send_sync! {
pub struct IPAddressFamilyRef;
}

#[cfg(ossl110)]
impl Stackable for IPAddressFamily {
type StackType = ffi::stack_st_IPAddressFamily;
}

#[derive(PartialEq, Eq, Debug)]
#[cfg(ossl110)]
pub enum IPVersion {
V4,
V6,
}

#[cfg(ossl110)]
impl IPAddressFamily {
pub fn fam(&self) -> Option<IPVersion> {
let ptr = self.0;
unsafe {
match X509v3_addr_get_afi(ptr) {
match X509v3_addr_get_afi(ptr) as libc::c_int {
IANA_AFI_IPV4 => Some(IPVersion::V4),
IANA_AFI_IPV6 => Some(IPVersion::V6),
_ => None,
Expand All @@ -140,7 +156,7 @@ impl IPAddressFamily {
return None;
}
let stack =
StackRef::<IPAddressOrRange>::from_const_ptr_opt((*choice).addressesOrRanges)?;
StackRef::<IPAddressOrRange>::from_const_ptr_opt((*choice).u.addressesOrRanges)?;
for e in stack {
let mut min = MaybeUninit::<[u8; 16]>::uninit();
let mut max = MaybeUninit::<[u8; 16]>::uninit();
Expand All @@ -152,8 +168,10 @@ impl IPAddressFamily {
16,
);
r.push((
Self::data_to_ip_addr(min.assume_init(), size)?,
Self::data_to_ip_addr(max.assume_init(), size)?,
#[allow(clippy::useless_conversion)]
Self::data_to_ip_addr(min.assume_init(), size.try_into().unwrap())?,
#[allow(clippy::useless_conversion)]
Self::data_to_ip_addr(max.assume_init(), size.try_into().unwrap())?,
))
}
}
Expand All @@ -180,11 +198,13 @@ impl IPAddressFamily {
}
}

#[cfg(ossl110)]
pub trait ExtractSBGPInfo {
fn asn(&self) -> Option<ASIdentifiers>;
fn ip_addresses(&self) -> Option<Stack<IPAddressFamily>>;
}

#[cfg(ossl110)]
impl ExtractSBGPInfo for X509 {
fn asn(&self) -> Option<ASIdentifiers> {
unsafe {
Expand Down

0 comments on commit 815a951

Please sign in to comment.