in crates/libs/core/src/types/common/security_credentials/x509_credentials.rs [102:150]
fn apply_inner(
&self,
settings_interface: mssf_com::FabricClient::IFabricClientSettings2,
) -> crate::Result<()> {
let allowed_common_names: Box<[PCWSTR]> = self
.AllowedCommonNames
.iter()
.map(WString::as_pcwstr)
.collect();
// technically speaking, doesn't need to be null in this case. but being paranoid
let allowed_common_names_ptr = if allowed_common_names.is_empty() {
std::ptr::null()
} else {
allowed_common_names.as_ptr()
};
let find_type = FABRIC_X509_FIND_TYPE::from(&self.FindType);
let find_value = match &self.FindType {
FabricX509FindType::FindByExtension { extension } => extension.as_pcwstr(),
FabricX509FindType::FindBySubjectName { subject_name } => subject_name.as_pcwstr(),
FabricX509FindType::FindByThumbprint { thumbprint } => thumbprint.as_pcwstr(),
}
.as_ptr() as *mut c_void;
let store_location = FABRIC_X509_STORE_LOCATION::from(self.StoreLocation);
let store_name = self.StoreName.as_pcwstr();
let protection_level = FABRIC_PROTECTION_LEVEL::from(self.ProtectionLevel);
let mut value = FABRIC_X509_CREDENTIALS {
AllowedCommonNameCount: u32::try_from(allowed_common_names.len()).unwrap(),
AllowedCommonNames: allowed_common_names_ptr,
FindType: find_type,
FindValue: find_value,
StoreLocation: store_location,
StoreName: store_name,
ProtectionLevel: protection_level,
// TODO: extensions
Reserved: std::ptr::null_mut(),
};
let security_credentials = FABRIC_SECURITY_CREDENTIALS {
Kind: FABRIC_SECURITY_CREDENTIAL_KIND_X509,
Value: addr_of_mut!(value) as *mut c_void,
};
// SAFETY: COM interop. SetSecurityCredentials does not retain reference to the passed in data after function returns.
let result = unsafe { settings_interface.SetSecurityCredentials(&security_credentials) }
.map_err(crate::Error::from);
#[cfg(miri)] // TODO: investigate what's wrong with windows_core::implement drop implement.
Box::leak(Box::new(settings_interface));
result
}