Skip to content

Commit

Permalink
Security structures setup changes (#336)
Browse files Browse the repository at this point in the history
* Add api to save security structure ids

* Add validation for primary threshold factors in isolation

* Add factors removal by list kind

* Add sampls and tests

* Fix import

* Make primary threshold invalid status more explicit

* Fix uniffi error

* Update role threshold model (#338)

* Update security structure threshold

* Update api and tests

* Update default threshold. Add tests

* Add test

* Fix swift tests

* Fix fs removing from primary threshold. Add test

* Update naming. Add Threshold ctor

* Address PR comments

* Remove unused variable

* Add tests

* Update sargon os security structure api

* Add tests

* Address review comment. Add tests

* Version bump
  • Loading branch information
sergiupuhalschi-rdx authored Jan 14, 2025
1 parent f98db7f commit 51d850f
Show file tree
Hide file tree
Showing 117 changed files with 1,217 additions and 657 deletions.
166 changes: 83 additions & 83 deletions Cargo.lock

Large diffs are not rendered by default.

50 changes: 31 additions & 19 deletions apple/Tests/TestCases/Profile/MFA/SecurityShieldsBuilderTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct ShieldTests {
func threshold() {
var builder = SecurityShieldBuilder()
#expect(builder.threshold == 0)
builder = builder.setThreshold(threshold: 42)
builder = builder.setThreshold(threshold: Threshold.specific(42))
#expect(builder.threshold == 42)
}

Expand Down Expand Up @@ -70,20 +70,20 @@ struct ShieldTests {
.addFactorSourceToPrimaryThreshold(factorSourceId: x)
.addFactorSourceToPrimaryThreshold(factorSourceId: y)
.addFactorSourceToPrimaryThreshold(factorSourceId: z)
.setThreshold(threshold: 3)
.setThreshold(threshold: Threshold.specific(3))
.addFactorSourceToRecoveryOverride(factorSourceId: y)
#expect(builder.recoveryRoleFactors == [y])

#expect(builder.threshold == 3)

builder = builder.removeFactorFromPrimary(factorSourceId: x)
builder = builder.removeFactorFromPrimary(factorSourceId: x, factorListKind: FactorListKind.threshold)
#expect(builder.threshold == 2)

builder = builder.removeFactorFromAllRoles(factorSourceId: y)
#expect(builder.recoveryRoleFactors == []) // assert `y` is removed from Recovery and Primary
#expect(builder.threshold == 1)

builder = builder.removeFactorFromPrimary(factorSourceId: z)
builder = builder.removeFactorFromPrimary(factorSourceId: z, factorListKind: FactorListKind.threshold)
#expect(builder.threshold == 0)
#expect(builder.primaryRoleThresholdFactors == [])
}
Expand All @@ -98,10 +98,10 @@ struct ShieldTests {

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

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

#expect(builder.validate() == .ConfirmationRoleMustHaveAtLeastOneFactor)
Expand All @@ -116,7 +116,7 @@ struct ShieldTests {
func primaryRoleWithThresholdFactorsCannotHaveAThresholdValueOfZero() throws {
var builder = SecurityShieldBuilder()
.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleLedger)
.setThreshold(threshold: 0)
.setThreshold(threshold: Threshold.specific(0))
#expect(builder.validate() == .PrimaryRoleWithThresholdFactorsCannotHaveAThresholdValueOfZero)
}

Expand Down Expand Up @@ -147,7 +147,7 @@ struct ShieldTests {
#expect(builder.primaryRoleThresholdFactors == [factor])
#expect(builder.primaryRoleOverrideFactors == [other])

builder = builder.removeFactorFromPrimary(factorSourceId: factor)
builder = builder.removeFactorFromPrimary(factorSourceId: factor, factorListKind: FactorListKind.threshold)
.addFactorSourceToPrimaryOverride(factorSourceId: factor)
.addFactorSourceToPrimaryThreshold(factorSourceId: other)
#expect(builder.primaryRoleThresholdFactors == [other])
Expand All @@ -166,14 +166,14 @@ struct ShieldTests {

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

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

builder = builder.addFactorSourceToRecoveryOverride(factorSourceId: .sampleArculus)
.addFactorSourceToConfirmationOverride(factorSourceId: .sampleArculusOther)
Expand All @@ -183,7 +183,7 @@ struct ShieldTests {
let shield = try! builder.build()

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

Expand All @@ -207,7 +207,7 @@ struct ShieldTests {
// Confirmation
.addFactorSourceToConfirmationOverride(factorSourceId: .sampleDevice)
// Remove
.removeFactorFromPrimary(factorSourceId: .sampleArculusOther)
.removeFactorFromPrimary(factorSourceId: .sampleArculusOther, factorListKind: FactorListKind.override)
.removeFactorFromRecovery(factorSourceId: .sampleLedgerOther)

builder.setAuthenticationSigningFactor(new: .sampleDevice)
Expand All @@ -232,15 +232,27 @@ struct ShieldTests {
#expect(shield.matrixOfFactors.confirmationRole.thresholdFactors == [])
}

@Test("selected factor sources for role status")
func selectedFactorSourcesForRoleStatus() {
@Test("selected primary threshold factors status")
func selectedPrimaryThresholdFactorsStatusInvalid() {
var builder = SecurityShieldBuilder()
.addFactorSourceToPrimaryThreshold(factorSourceId: .samplePassword)
.addFactorSourceToRecoveryOverride(factorSourceId: .sampleLedger)

#expect(builder.selectedFactorSourcesForRoleStatus(role: .primary) == .invalid)
#expect(builder.selectedFactorSourcesForRoleStatus(role: .recovery) == .optimal)
#expect(builder.selectedFactorSourcesForRoleStatus(role: .confirmation) == .insufficient)
#expect(builder.selectedPrimaryThresholdFactorsStatus() == .invalid(reason: SelectedPrimaryThresholdFactorsStatusInvalidReason.cannotBeUsedAlone(factorSourceKind: FactorSourceKind.password)))
}

@Test("selected primary threshold factors status")
func selectedPrimaryThresholdFactorsStatus() {
var builder = SecurityShieldBuilder()

#expect(builder.selectedPrimaryThresholdFactorsStatus() == .insufficient)

builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleDevice)

#expect(builder.selectedPrimaryThresholdFactorsStatus() == .suboptimal)

builder.addFactorSourceToPrimaryThreshold(factorSourceId: .sampleLedger)

#expect(builder.selectedPrimaryThresholdFactorsStatus() == .optimal)
}
}

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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
edition = "2021"

[dependencies]
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
edition = "2021"

[dependencies]
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
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.106"
version = "1.1.107"
edition = "2021"

[dependencies]
Expand Down
Loading

0 comments on commit 51d850f

Please sign in to comment.