Skip to content

Commit

Permalink
Use named the constants for property names in config creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ohuopio committed Mar 11, 2024
1 parent 4ddf2d9 commit 08e9edb
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ use super::{
s_mime_config_parser::SignedDocument,
types::{
BuiltinPermissionsCredentialToken, BuiltinPermissionsToken,
BuiltinPluginParticipantSecurityAttributes,
BuiltinPluginParticipantSecurityAttributes, QOS_GOVERNANCE_DOCUMENT_PROPERTY_NAME,
QOS_PERMISSIONS_CERTIFICATE_PROPERTY_NAME, QOS_PERMISSIONS_DOCUMENT_PROPERTY_NAME,
},
};

const QOS_PERMISSIONS_CERTIFICATE_PROPERTY_NAME: &str = "dds.sec.access.permissions_ca";
const QOS_GOVERNANCE_DOCUMENT_PROPERTY_NAME: &str = "dds.sec.access.governance";
const QOS_PERMISSIONS_DOCUMENT_PROPERTY_NAME: &str = "dds.sec.access.permissions";

impl AccessControlBuiltin {
fn check_participant(
&self,
Expand Down
8 changes: 8 additions & 0 deletions src/security/access_control/access_control_builtin/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,14 @@ impl EndpointSecurityAttributes {
const PERMISSIONS_TOKEN_CLASS_ID: &str = "DDS:Access:Permissions:1.0";
const PERMISSIONS_TOKEN_SUBJECT_NAME_PROPERTY_NAME: &str = "dds.perm_ca.sn";
const PERMISSIONS_TOKEN_ALGORITHM_PROPERTY_NAME: &str = "dds.perm_ca.algo";

pub(in crate::security) const QOS_PERMISSIONS_CERTIFICATE_PROPERTY_NAME: &str =
"dds.sec.access.permissions_ca";
pub(in crate::security) const QOS_GOVERNANCE_DOCUMENT_PROPERTY_NAME: &str =
"dds.sec.access.governance";
pub(in crate::security) const QOS_PERMISSIONS_DOCUMENT_PROPERTY_NAME: &str =
"dds.sec.access.permissions";

// 9.4.2.2
pub(super) struct BuiltinPermissionsToken {
pub permissions_ca_subject_name: Option<DistinguishedName>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@ use super::{
types::{
parse_signature_algo_name_to_ring, BuiltinAuthenticatedPeerCredentialToken,
BuiltinIdentityToken, DH_MODP_KAGREE_ALGO_NAME, ECDH_KAGREE_ALGO_NAME,
QOS_IDENTITY_CA_PROPERTY_NAME, QOS_IDENTITY_CERTIFICATE_PROPERTY_NAME,
QOS_PASSWORD_PROPERTY_NAME, QOS_PRIVATE_KEY_PROPERTY_NAME,
},
BuiltinHandshakeState, DHKeys, LocalParticipantInfo, RemoteParticipantInfo,
};

// DDS Security spec v1.1
// Section "9.3.1 Configuration" , Table 44

const QOS_IDENTITY_CA_PROPERTY_NAME: &str = "dds.sec.auth.identity_ca";
const QOS_IDENTITY_CERTIFICATE_PROPERTY_NAME: &str = "dds.sec.auth.identity_certificate";
const QOS_PRIVATE_KEY_PROPERTY_NAME: &str = "dds.sec.auth.private_key";
const QOS_PASSWORD_PROPERTY_NAME: &str = "dds.sec.auth.password";

impl Authentication for AuthenticationBuiltin {
fn validate_local_identity(
&mut self,
Expand Down
7 changes: 7 additions & 0 deletions src/security/authentication/authentication_builtin/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ use crate::{

pub const IDENTITY_TOKEN_CLASS_ID: &str = "DDS:Auth:PKI-DH:1.0";

// Section "9.3.1 Configuration" , Table 44
pub(in crate::security) const QOS_IDENTITY_CA_PROPERTY_NAME: &str = "dds.sec.auth.identity_ca";
pub(in crate::security) const QOS_IDENTITY_CERTIFICATE_PROPERTY_NAME: &str =
"dds.sec.auth.identity_certificate";
pub(in crate::security) const QOS_PRIVATE_KEY_PROPERTY_NAME: &str = "dds.sec.auth.private_key";
pub(in crate::security) const QOS_PASSWORD_PROPERTY_NAME: &str = "dds.sec.auth.password";

// Expected property names in IdentityToken
pub(in crate::security) const CERT_SN_PROPERTY_NAME: &str = "dds.cert.sn";
const CERT_ALGO_PROPERTY_NAME: &str = "dds.cert.algo";
Expand Down
26 changes: 18 additions & 8 deletions src/security/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ use crate::{
authentication::authentication_builtin::types::CertificateAlgorithm, private_key::PrivateKey,
},
};
use super::{
access_control::access_control_builtin::types::{
QOS_GOVERNANCE_DOCUMENT_PROPERTY_NAME, QOS_PERMISSIONS_CERTIFICATE_PROPERTY_NAME,
QOS_PERMISSIONS_DOCUMENT_PROPERTY_NAME,
},
authentication::authentication_builtin::types::{
QOS_IDENTITY_CA_PROPERTY_NAME, QOS_IDENTITY_CERTIFICATE_PROPERTY_NAME,
QOS_PASSWORD_PROPERTY_NAME, QOS_PRIVATE_KEY_PROPERTY_NAME,
},
};

/// How to access Certificate's private key for signing.
pub enum PrivateSigningKey {
Expand Down Expand Up @@ -118,14 +128,14 @@ impl DomainParticipantSecurityConfigFiles {

pub fn into_property_policy(self) -> qos::policy::Property {
let mut value = vec![
mk_file_prop("dds.sec.auth.identity_ca", &self.identity_ca_certificate),
mk_file_prop(QOS_IDENTITY_CA_PROPERTY_NAME, &self.identity_ca_certificate),
mk_file_prop(
"dds.sec.auth.identity_certificate",
QOS_IDENTITY_CERTIFICATE_PROPERTY_NAME,
&self.participant_identity_certificate,
),
match self.participant_identity_private_key {
PrivateSigningKey::Files { ref file_path, .. } => {
mk_file_prop("dds.sec.auth.private_key", file_path)
mk_file_prop(QOS_PRIVATE_KEY_PROPERTY_NAME, file_path)
}
PrivateSigningKey::Pkcs11 {
ref token_label,
Expand All @@ -143,24 +153,24 @@ impl DomainParticipantSecurityConfigFiles {
hsm_access_library.display()
));
}
mk_string_prop("dds.sec.auth.private_key", pkcs11_uri)
mk_string_prop(QOS_PRIVATE_KEY_PROPERTY_NAME, pkcs11_uri)
}
},
mk_file_prop(
"dds.sec.access.permissions_ca",
QOS_PERMISSIONS_CERTIFICATE_PROPERTY_NAME,
&self.permissions_ca_certificate,
),
mk_file_prop(
"dds.sec.access.governance",
QOS_GOVERNANCE_DOCUMENT_PROPERTY_NAME,
&self.domain_governance_document,
),
mk_file_prop(
"dds.sec.access.permissions",
QOS_PERMISSIONS_DOCUMENT_PROPERTY_NAME,
&self.participant_permissions_document,
),
];
if let PrivateSigningKey::Files { file_password, .. } = self.participant_identity_private_key {
value.push(mk_string_prop("dds.sec.auth.password", file_password));
value.push(mk_string_prop(QOS_PASSWORD_PROPERTY_NAME, file_password));
}

qos::policy::Property {
Expand Down

0 comments on commit 08e9edb

Please sign in to comment.