-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start adding support for FabricClientSettings and FabricSecurityCrede…
…ntials (#139) I'd like to have support for ergonomic (i.e. safe) versions of FABRIC_CLIENT_SETTINGS and FABRIC_SECURITY_CREDENTIALS This makes necessary error handling changes (that are breaking), as FabricClientBuilder::build() now can error if there are invalid settings. It's a small step towards #140 * For now, the error type remains opaque (as it isn't actually instantiated anyway). * The FabricClientSettings struct remains empty (and adding new Optional defaults shouldn't breaking) * The FabricSecurityCredentials enum is also empty (and marked non_exhaustive, so adding more entries in future will not be a breaking change) * Also add some trivial wrapper types for the next PR, empty modules, and so on.
- Loading branch information
1 parent
883ca78
commit dd4d857
Showing
13 changed files
with
268 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
|
||
use mssf_com::FabricClient::IFabricClientSettings2; | ||
|
||
/// A idiomatic Rust version of FABRIC_CLIENT_SETTINGS | ||
/// | ||
/// Note: we may choose to add additional optional fields in future without considering that a SemVer breaking change. | ||
/// You should default fields you're not interested in like so: | ||
/// ``` | ||
/// # use std::num::NonZeroU32; | ||
/// # use mssf_core::types::FabricClientSettings; | ||
/// let my_settings = FabricClientSettings { | ||
/// // TODO: uncomment in next PR | ||
/// // PartitionLocationCacheLimit: Some(NonZeroU32::new(1).expect("Non-zero value")), | ||
/// // Any other hypothetical settings you're interested in here, | ||
/// ..Default::default() | ||
/// }; | ||
/// ``` | ||
#[derive(Default)] | ||
pub struct FabricClientSettings {} | ||
|
||
impl FabricClientSettings { | ||
/// Note: only overrides non-default settings; leaves any settings set previously that don't explicitly have new values alone | ||
pub(crate) fn apply(&self, _settings_interface: &IFabricClientSettings2) -> crate::Result<()> { | ||
// Placeholder | ||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
crates/libs/core/src/types/common/security_credentials/claims_credentials.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
#![deny(unsafe_op_in_unsafe_fn)] | ||
#![deny(clippy::undocumented_unsafe_blocks)] | ||
// TODO: implement |
45 changes: 45 additions & 0 deletions
45
crates/libs/core/src/types/common/security_credentials/fabric_protection_level.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
use mssf_com::FabricTypes::{ | ||
FABRIC_PROTECTION_LEVEL, FABRIC_PROTECTION_LEVEL_ENCRYPTANDSIGN, FABRIC_PROTECTION_LEVEL_NONE, | ||
FABRIC_PROTECTION_LEVEL_SIGN, | ||
}; | ||
|
||
/// The Fabric Protection Level | ||
/// See https://learn.microsoft.com/en-us/dotnet/api/system.fabric.protectionlevel?view=azure-dotnet | ||
#[non_exhaustive] | ||
#[derive(Copy, Clone, PartialEq, Eq)] | ||
pub enum FabricProtectionLevel { | ||
None, | ||
Sign, | ||
EncryptAndSign, | ||
} | ||
|
||
#[derive(Debug)] | ||
#[allow(dead_code, reason = "For error handling")] | ||
pub struct FabricProtectionLevelUnknownValueError(pub FABRIC_PROTECTION_LEVEL); | ||
|
||
impl TryFrom<FABRIC_PROTECTION_LEVEL> for FabricProtectionLevel { | ||
type Error = FabricProtectionLevelUnknownValueError; | ||
|
||
fn try_from(value: FABRIC_PROTECTION_LEVEL) -> Result<Self, Self::Error> { | ||
match value { | ||
FABRIC_PROTECTION_LEVEL_NONE => Ok(FabricProtectionLevel::None), | ||
FABRIC_PROTECTION_LEVEL_SIGN => Ok(FabricProtectionLevel::Sign), | ||
FABRIC_PROTECTION_LEVEL_ENCRYPTANDSIGN => Ok(FabricProtectionLevel::EncryptAndSign), | ||
x => Err(FabricProtectionLevelUnknownValueError(x)), | ||
} | ||
} | ||
} | ||
|
||
impl From<FabricProtectionLevel> for FABRIC_PROTECTION_LEVEL { | ||
fn from(value: FabricProtectionLevel) -> Self { | ||
match value { | ||
FabricProtectionLevel::None => FABRIC_PROTECTION_LEVEL_NONE, | ||
FabricProtectionLevel::Sign => FABRIC_PROTECTION_LEVEL_SIGN, | ||
FabricProtectionLevel::EncryptAndSign => FABRIC_PROTECTION_LEVEL_ENCRYPTANDSIGN, | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
crates/libs/core/src/types/common/security_credentials/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
#![deny(unsafe_op_in_unsafe_fn)] | ||
#![deny(clippy::undocumented_unsafe_blocks)] | ||
use mssf_com::FabricClient::IFabricClientSettings2; | ||
|
||
mod claims_credentials; | ||
mod fabric_protection_level; | ||
pub use fabric_protection_level::*; | ||
mod windows_credentials; | ||
mod x509_credentials; | ||
pub use x509_credentials::*; | ||
|
||
/// Idiomatic FABRIC_SECURITY_CREDENTIALS wrapper | ||
/// Currently, just a placeholder | ||
#[non_exhaustive] | ||
pub enum FabricSecurityCredentials {} | ||
|
||
impl FabricSecurityCredentials { | ||
/// Note: only overrides non-default settings; leaves any settings set previously that don't explicitly have new values alone | ||
pub(crate) fn apply(&self, _settings_interface: &IFabricClientSettings2) -> crate::Result<()> { | ||
// Placeholder | ||
Ok(()) | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
crates/libs/core/src/types/common/security_credentials/windows_credentials.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
#![deny(unsafe_op_in_unsafe_fn)] | ||
#![deny(clippy::undocumented_unsafe_blocks)] | ||
// TODO: implement |
81 changes: 81 additions & 0 deletions
81
crates/libs/core/src/types/common/security_credentials/x509_credentials.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
// ------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License (MIT). See License.txt in the repo root for license information. | ||
// ------------------------------------------------------------ | ||
#![deny(unsafe_op_in_unsafe_fn)] | ||
#![deny(clippy::undocumented_unsafe_blocks)] | ||
|
||
use mssf_com::FabricTypes::{ | ||
FABRIC_X509_FIND_TYPE, FABRIC_X509_FIND_TYPE_FINDBYEXTENSION, | ||
FABRIC_X509_FIND_TYPE_FINDBYSUBJECTNAME, FABRIC_X509_FIND_TYPE_FINDBYTHUMBPRINT, | ||
FABRIC_X509_STORE_LOCATION, FABRIC_X509_STORE_LOCATION_CURRENTUSER, | ||
FABRIC_X509_STORE_LOCATION_INVALID, FABRIC_X509_STORE_LOCATION_LOCALMACHINE, | ||
}; | ||
use windows_core::WString; | ||
|
||
/// How to find the X509 certificate. | ||
#[non_exhaustive] | ||
pub enum FabricX509FindType { | ||
FindByExtension { extension: WString }, | ||
FindBySubjectName { subject_name: WString }, | ||
FindByThumbprint { thumbprint: WString }, | ||
} | ||
|
||
impl From<&FabricX509FindType> for FABRIC_X509_FIND_TYPE { | ||
fn from(value: &FabricX509FindType) -> Self { | ||
match value { | ||
FabricX509FindType::FindByExtension { extension: _ } => { | ||
FABRIC_X509_FIND_TYPE_FINDBYEXTENSION | ||
} | ||
FabricX509FindType::FindBySubjectName { subject_name: _ } => { | ||
FABRIC_X509_FIND_TYPE_FINDBYSUBJECTNAME | ||
} | ||
FabricX509FindType::FindByThumbprint { thumbprint: _ } => { | ||
FABRIC_X509_FIND_TYPE_FINDBYTHUMBPRINT | ||
} | ||
} | ||
} | ||
} | ||
|
||
/// What store location the certificate will be found in | ||
#[non_exhaustive] | ||
#[derive(Copy, Clone)] | ||
pub enum FabricX509StoreLocation { | ||
CurrentUser, | ||
LocalMachine, | ||
} | ||
|
||
#[non_exhaustive] | ||
#[derive(Copy, Clone)] | ||
pub enum FabricX509StoreLocationConversionError { | ||
InvalidValue, | ||
UnknownValue(FABRIC_X509_STORE_LOCATION), | ||
} | ||
|
||
impl TryFrom<FABRIC_X509_STORE_LOCATION> for FabricX509StoreLocation { | ||
type Error = FabricX509StoreLocationConversionError; | ||
|
||
fn try_from(value: FABRIC_X509_STORE_LOCATION) -> Result<Self, Self::Error> { | ||
match value { | ||
FABRIC_X509_STORE_LOCATION_CURRENTUSER => Ok(FabricX509StoreLocation::CurrentUser), | ||
FABRIC_X509_STORE_LOCATION_LOCALMACHINE => Ok(FabricX509StoreLocation::LocalMachine), | ||
FABRIC_X509_STORE_LOCATION_INVALID => { | ||
Err(FabricX509StoreLocationConversionError::InvalidValue) | ||
} | ||
x => Err(FabricX509StoreLocationConversionError::UnknownValue(x)), | ||
} | ||
} | ||
} | ||
|
||
impl From<FabricX509StoreLocation> for FABRIC_X509_STORE_LOCATION { | ||
fn from(value: FabricX509StoreLocation) -> Self { | ||
match value { | ||
FabricX509StoreLocation::CurrentUser => FABRIC_X509_STORE_LOCATION_CURRENTUSER, | ||
FabricX509StoreLocation::LocalMachine => FABRIC_X509_STORE_LOCATION_LOCALMACHINE, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.