Skip to content
This repository was archived by the owner on Aug 15, 2025. It is now read-only.

Commit 304d766

Browse files
committed
squashme: commit to push my shit!
1 parent d29b46b commit 304d766

File tree

4 files changed

+52
-21
lines changed

4 files changed

+52
-21
lines changed

src/certs/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,14 +177,14 @@ pub fn equal_domain_components(name_1: &Name, name_2: &Name) -> bool {
177177
let mut domain_components_2 = Vec::new();
178178
for rdn in name_1.0.iter() {
179179
for ava in rdn.0.iter() {
180-
if ava.oid.to_string().as_str() == OID_RDN_DOMAIN_COMPONENT {
180+
if ava.oid == OID_RDN_DOMAIN_COMPONENT {
181181
domain_components_1.push(String::from_utf8_lossy(ava.value.value()));
182182
}
183183
}
184184
}
185185
for rdn in name_2.0.iter() {
186186
for ava in rdn.0.iter() {
187-
if ava.oid.to_string().as_str() == OID_RDN_DOMAIN_COMPONENT {
187+
if ava.oid == OID_RDN_DOMAIN_COMPONENT {
188188
domain_components_2.push(String::from_utf8_lossy(ava.value.value()));
189189
}
190190
}

src/constraints/name.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl Constrained for Name {
3838
"[Name::validate()] Determining OID of RDN {rdn} and performing appropriate validation"
3939
);
4040
for item in rdn.0.iter() {
41-
match item.oid.to_string().as_str() {
41+
match item.oid {
4242
OID_RDN_UID => {
4343
log::trace!("[Name::validate()] Found UID in RDN: {item}");
4444
num_uid += 1;
@@ -106,9 +106,7 @@ impl Constrained for Name {
106106
} else if num_uid != 0 {
107107
validate_dc_matches_dc_in_uid(&vec_dc, &uid)?;
108108
}
109-
log::trace!(
110-
"Encountered {num_uid} UID components and {num_cn} Common Name components"
111-
);
109+
log::trace!("Encountered {num_uid} UID components and {num_cn} Common Name components");
112110
if num_uid != 0 && num_cn != 0 {
113111
log::trace!("Validating UID username matches Common Name");
114112
validate_uid_username_matches_cn(&uid, &cn)?;
@@ -163,16 +161,12 @@ fn validate_dc_matches_dc_in_uid(
163161
vec_dc: &[RelativeDistinguishedName],
164162
uid: &RelativeDistinguishedName,
165163
) -> Result<(), ConstraintError> {
166-
debug!(
167-
"Validating vec_dc {vec_dc:?} and uid {uid} have same domain components"
168-
);
164+
debug!("Validating vec_dc {vec_dc:?} and uid {uid} have same domain components");
169165
// Find the position of the @ in the UID
170166
let position_of_at = match uid.to_string().find('@') {
171167
Some(pos) => pos,
172168
None => {
173-
log::warn!(
174-
"[validate_dc_matches_dc_in_uid] UID {uid} does not contain an @"
175-
);
169+
log::warn!("[validate_dc_matches_dc_in_uid] UID {uid} does not contain an @");
176170
return Err(ConstraintError::Malformed(Some(
177171
"UID does not contain an @".to_string(),
178172
)));
@@ -245,9 +239,7 @@ fn validate_uid_username_matches_cn(
245239
let position_of_at = match uid_str.find('@') {
246240
Some(pos) => pos,
247241
None => {
248-
log::warn!(
249-
"[validate_dc_matches_dc_in_uid] UID \"{uid}\" does not contain an @"
250-
);
242+
log::warn!("[validate_dc_matches_dc_in_uid] UID \"{uid}\" does not contain an @");
251243
return Err(ConstraintError::Malformed(Some(
252244
"UID does not contain an @".to_string(),
253245
)));

src/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,15 @@ of this project.
148148
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
149149

150150
/// The OID for the domainComponent RDN
151-
pub const OID_RDN_DOMAIN_COMPONENT: &str = "0.9.2342.19200300.100.1.25";
151+
pub const OID_RDN_DOMAIN_COMPONENT: ObjectIdentifier =
152+
ObjectIdentifier::new_unwrap("0.9.2342.19200300.100.1.25");
152153
/// The OID for the commonName RDN
153-
pub const OID_RDN_COMMON_NAME: &str = "2.5.4.3";
154+
pub const OID_RDN_COMMON_NAME: ObjectIdentifier = ObjectIdentifier::new_unwrap("2.5.4.3");
154155
/// The OID for the uniqueIdentifier RDN
155-
pub const OID_RDN_UNIQUE_IDENTIFIER: &str = "0.9.2342.19200300.100.1.44";
156+
pub const OID_RDN_UNIQUE_IDENTIFIER: ObjectIdentifier =
157+
ObjectIdentifier::new_unwrap("0.9.2342.19200300.100.1.44");
156158
/// The OID for the uid RDN
157-
pub const OID_RDN_UID: &str = "0.9.2342.19200300.100.1.1";
159+
pub const OID_RDN_UID: ObjectIdentifier = ObjectIdentifier::new_unwrap("0.9.2342.19200300.100.1.1");
158160

159161
use certs::Target;
160162
use errors::base::ConstraintError;
@@ -184,6 +186,7 @@ mod constraints;
184186

185187
pub use der;
186188
pub use spki;
189+
use spki::ObjectIdentifier;
187190
pub use url;
188191
pub use x509_cert::name::*;
189192

src/types/pdn.rs

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
use std::hash::Hash;
22

3-
use x509_cert::name::RelativeDistinguishedName;
3+
use x509_cert::attr::AttributeTypeAndValue;
4+
use x509_cert::name::{Name, RelativeDistinguishedName};
45

56
use crate::certs::SessionId;
67
use crate::types::{DomainName, FederationId};
8+
use crate::{
9+
OID_RDN_COMMON_NAME, OID_RDN_DOMAIN_COMPONENT, OID_RDN_UID, OID_RDN_UNIQUE_IDENTIFIER,
10+
};
711

812
/// Higher-level abstraction of X.509 [distinguished names](https://ldap.com/ldap-dns-and-rdns/),
913
/// providing easier access to inner values compared to using [x509_cert::name::Name] in a raw manner.
1014
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1115
pub enum PolyprotoDistinguishedName {
12-
/// A `pDN` with all necessary fields
16+
/// A `pDN` with all necessary fields for an actor.
1317
ActorDn(ActorDN),
18+
/// A `pDN` with all necessary fields for a home server.
1419
HomeServerDn(HomeServerDN),
1520
}
1621

1722
#[derive(Debug, Clone, PartialEq, Eq)]
23+
/// A [PolyprotoDistinguishedName] with all necessary fields for an actor certificate.
24+
///
25+
/// This struct is a higher-level abstraction of X.509 [distinguished names](https://ldap.com/ldap-dns-and-rdns/),
26+
/// providing easier access to inner values compared to using [x509_cert::name::Name] in a raw manner.
1827
pub struct ActorDN {
1928
federation_id: FederationId,
2029
domain_name: DomainName,
@@ -34,6 +43,10 @@ impl Hash for ActorDN {
3443
}
3544

3645
#[derive(Debug, Clone, PartialEq, Eq)]
46+
/// A [PolyprotoDistinguishedName] with all necessary fields for a home server certificate.
47+
///
48+
/// This struct is a higher-level abstraction of X.509 [distinguished names](https://ldap.com/ldap-dns-and-rdns/),
49+
/// providing easier access to inner values compared to using [x509_cert::name::Name] in a raw manner.
3750
pub struct HomeServerDN {
3851
domain_name: DomainName,
3952
additional_fields: Vec<RelativeDistinguishedName>,
@@ -47,3 +60,26 @@ impl Hash for HomeServerDN {
4760
.for_each(|additional_field| additional_field.to_string().hash(state));
4861
}
4962
}
63+
64+
impl TryFrom<Name> for ActorDN {
65+
type Error = crate::errors::InvalidInput;
66+
67+
fn try_from(x509_distinguished_name: Name) -> Result<Self, Self::Error> {
68+
let federation_id: AttributeTypeAndValue;
69+
let domain_name: AttributeTypeAndValue;
70+
let session_id: AttributeTypeAndValue;
71+
let additional_fields: AttributeTypeAndValue;
72+
for relative_distinguished_name in x509_distinguished_name.0.into_iter() {
73+
for attribute_value_and_item in relative_distinguished_name.0.iter() {
74+
match attribute_value_and_item.oid {
75+
OID_RDN_COMMON_NAME => (),
76+
OID_RDN_UID => (),
77+
OID_RDN_UNIQUE_IDENTIFIER => (),
78+
OID_RDN_DOMAIN_COMPONENT => (),
79+
other => (),
80+
}
81+
}
82+
}
83+
todo!()
84+
}
85+
}

0 commit comments

Comments
 (0)