Skip to content

Commit

Permalink
Allow building a weak shield (#347)
Browse files Browse the repository at this point in the history
* Uniffi expose primary threshold

* Add remove all override factors function

* Update shield validation

* Add time period as recovery  emergency fallback

* Add samples. Add test

* Add samples. Add test

* Add extensions

* Add swift tests

* Expose functions and add tests

* PR review

* Shield builder status

* Add tests. Allow adding fs while violating rules

* WIP

* Fix

* Update shield saving result

* Test

* Add asserts

* Renaming

* Remove years time period

* Add missing errors

* Release 1.1.113

[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]

Generated by cargo-workspaces
  • Loading branch information
sergiupuhalschi-rdx authored Jan 21, 2025
1 parent 91655f5 commit 4131464
Show file tree
Hide file tree
Showing 94 changed files with 923 additions and 360 deletions.
167 changes: 84 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct ShieldTests {
@Test("primary override validation status trustedContact")
func primValidationStatusTrustedContact() {
let builder = SecurityShieldBuilder()
#expect(builder.validationForAdditionOfFactorSourceToPrimaryOverrideForEach(factorSources: [TrustedContactFactorSource.sample.asGeneral.id]).compactMap(\.reasonIfInvalid) == [FactorSourceValidationStatusReasonIfInvalid.nonBasic(SecurityShieldBuilderInvalidReason.PrimaryCannotContainTrustedContact)])
#expect(builder.validationForAdditionOfFactorSourceToPrimaryOverrideForEach(factorSources: [TrustedContactFactorSource.sample.asGeneral.id]).compactMap(\.reasonIfInvalid) == [FactorSourceValidationStatusReasonIfInvalid.nonBasic(SecurityShieldBuilderRuleViolation.PrimaryCannotContainTrustedContact)])
}

@Test("Auto lowering of threshold upon deletion")
Expand Down Expand Up @@ -88,32 +88,6 @@ struct ShieldTests {
#expect(builder.primaryRoleThresholdFactors == [])
}

@Test("basic validation")
func basicValidation() throws {
var builder = SecurityShieldBuilder()
#expect(builder.validate() == .MissingAuthSigningFactor)
builder = builder.setAuthenticationSigningFactor(new: .sampleDevice)
#expect(builder.validate() == .PrimaryRoleMustHaveAtLeastOneFactor)
builder = builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDevice)
.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDevice) // did not get added, duplicates are not allowed
#expect(builder.primaryRoleThresholdFactors == [.sampleDevice])

builder = builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDeviceOther) // actually this is added
#expect(builder.validate() == .PrimaryCannotHaveMultipleDevices)
builder = builder.removeFactorFromPrimary(factorSourceId: .sampleDeviceOther, factorListKind: FactorListKind.threshold)

#expect(builder.validate() == .RecoveryRoleMustHaveAtLeastOneFactor)
builder = builder.removeFactorFromPrimary(factorSourceId: .sampleDeviceOther, factorListKind: FactorListKind.threshold)
.addFactorSourceToRecoveryOverride(factorSourceId: .sampleLedger)

#expect(builder.validate() == .ConfirmationRoleMustHaveAtLeastOneFactor)
builder = builder.addFactorSourceToConfirmationOverride(factorSourceId: .sampleArculus)
.setAuthenticationSigningFactor(new: .sampleDevice)

#expect(builder.validate() == nil)
#expect((try? builder.build()) != nil)
}

@Test("cannot add forbidden FactorSourceKinds")
func preventAddOfForbiddenFactorSourceKinds() throws {
let builder = SecurityShieldBuilder()
Expand Down Expand Up @@ -147,49 +121,17 @@ struct ShieldTests {
#expect(builder.primaryRoleThresholdFactors == [other])
#expect(builder.primaryRoleOverrideFactors == [other, factor])

// But when validated/built is err
#expect(builder.validate() != nil)
// But when statusd/built is err
#expect(builder.status() != nil)
#expect((try? builder.build()) == nil)
}

@Test("Primary password never alone")
func primaryPasswordNeverAlone() {
var builder = SecurityShieldBuilder()
.setAuthenticationSigningFactor(new: .sampleDevice)
.addFactorSourceToPrimaryOverride(factorSourceId: .samplePassword) // not allowed
#expect(builder.primaryRoleOverrideFactors.isEmpty)

builder = builder.addFactorSourceToPrimaryThreshold(factorSourceId: .samplePassword)
#expect(builder.validate() == .PrimaryRoleWithPasswordInThresholdListMustHaveAnotherFactor)
builder = builder.setThreshold(threshold: Threshold.all)

builder = builder.setThreshold(threshold: Threshold.specific(1))
#expect(builder.validate() == .PrimaryRoleWithPasswordInThresholdListMustHaveAnotherFactor)
builder = builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleLedger)
#expect(builder.validate() == .PrimaryRoleWithPasswordInThresholdListMustThresholdGreaterThanOne)
builder = builder.setThreshold(threshold: Threshold.specific(2))

builder = builder.addFactorSourceToRecoveryOverride(factorSourceId: .sampleArculus)
.addFactorSourceToConfirmationOverride(factorSourceId: .sampleArculusOther)

builder = builder.setAuthenticationSigningFactor(new: .sampleDevice)

let shield = try! builder.build()

#expect(shield.matrixOfFactors.primaryRole.overrideFactors.isEmpty)
#expect(shield.matrixOfFactors.primaryRole.threshold == Threshold.specific(2))
#expect(shield.matrixOfFactors.primaryRole.thresholdFactors == [.samplePassword, .sampleLedger])
}

@Test("Build")
func build() throws {
var builder = SecurityShieldBuilder()
.setName(name: "S.H.I.E.L.D.")
.setTimePeriodUntilAutoConfirm(timePeriod: TimePeriod(days: 42))

#expect(builder.validate() == .MissingAuthSigningFactor)
builder = builder.setAuthenticationSigningFactor(new: .sampleDevice)
#expect(builder.validate() == .PrimaryRoleMustHaveAtLeastOneFactor)
.setAuthenticationSigningFactor(new: .sampleDevice)

// Primary
#expect(builder.threshold == Threshold.all)
Expand All @@ -208,8 +150,8 @@ struct ShieldTests {

builder = builder.setAuthenticationSigningFactor(new: .sampleDevice)

// Validate
#expect(builder.validate() == nil)
// status
#expect(builder.status() == SecurityShieldBuilderStatus.strong)

// Build
let shield0 = try builder.build()
Expand Down
2 changes: 1 addition & 1 deletion crates/app/home-cards/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "home-cards"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/key-derivation-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "key-derivation-traits"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/radix-connect-models/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "radix-connect-models"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/radix-connect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "radix-connect"
version = "1.1.112"
version = "1.1.113"
edition = "2021"


Expand Down
2 changes: 1 addition & 1 deletion crates/app/security-center/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "security-center"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/signing-traits/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "signing-traits"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/app/signing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "signing"
version = "1.1.112"
version = "1.1.113"
edition = "2021"


Expand Down
2 changes: 1 addition & 1 deletion crates/common/build-info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "build-info"
version = "1.1.112"
version = "1.1.113"
edition = "2021"
build = "build.rs"

Expand Down
2 changes: 1 addition & 1 deletion crates/common/bytes/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bytes"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/entity-foundation/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "entity-foundation"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/host-info/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "host-info"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/identified-vec-of/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "identified-vec-of"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/metadata/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "metadata"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/network/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "network"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/numeric/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "numeric"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/common/short-string/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "short-string"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/assert-json/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "assert-json"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/collections/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core-collections"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/error/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "error"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
5 changes: 5 additions & 0 deletions crates/core/error/src/common_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,11 @@ pub enum CommonError {

#[error("Signing failed due to too many factor sources were neglected.")]
SigningFailedTooManyFactorSourcesNeglected = 10247,

#[error(
"SecurityStructure already exists in profile, FactorSourceID {bad_value}."
)]
StructureAlreadyExists { bad_value: String } = 10248,
}

impl CommonError {
Expand Down
2 changes: 1 addition & 1 deletion crates/core/has-sample-values/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "has-sample-values"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/misc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core-misc"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/prelude/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "prelude"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/time-utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "time-utils"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/core/utils/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "core-utils"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
3 changes: 0 additions & 3 deletions crates/core/utils/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ pub const MINUTES_PER_DAY: u32 = 24 * 60;
/// Number of days per week.
pub const DAYS_PER_WEEK: u16 = 7;

/// Number of days per year.
pub const DAYS_PER_YEAR: u16 = 365;

#[cfg(test)]
mod tests {
use super::*;
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/addresses/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "addresses"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/cap26-models/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cap26-models"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/ecc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ecc"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/encryption/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "encryption"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/hash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hash"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/crypto/hd/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "hierarchical-deterministic"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/factors/factors/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "factors"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/factors/instances-provider/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "factor-instances-provider"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/factors/keys-collector/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "keys-collector"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/factors/next-derivation-index-ephemeral/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "next-derivation-index-ephemeral"
version = "1.1.112"
version = "1.1.113"
edition = "2021"

[dependencies]
Expand Down
Loading

0 comments on commit 4131464

Please sign in to comment.