Skip to content

Commit 657bf24

Browse files
committed
bitwarden/sdk-internal@9eb8c6e 3.0.0-6662-9eb8c6e - [PM-31128] Add reinit_user_crypto for mobile (bitwarden/sdk-internal#1148)
1 parent abd61bf commit 657bf24

3 files changed

Lines changed: 331 additions & 84 deletions

File tree

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ let package = Package(
3030
dependencies: ["BitwardenSdk"]),
3131
.binaryTarget(
3232
name: "BitwardenFFI",
33-
url: "https://github.com/bitwarden/sdk-swift/releases/download/v3.0.0-6650-5bdc976/BitwardenFFI-3.0.0-5bdc976.xcframework.zip",
34-
checksum: "f475da64fb7eb49b88d074bb6644753ec6b9aae73b7766b78ac441cbde5ef187")
33+
url: "https://github.com/bitwarden/sdk-swift/releases/download/v3.0.0-6662-9eb8c6e/BitwardenFFI-3.0.0-9eb8c6e.xcframework.zip",
34+
checksum: "bf2af8be3328ea036369a5092afed1cf0bbbfae845f37b607bd9116dfcae0e4a")
3535
]
3636
)

Sources/BitwardenSdk/BitwardenCore.swift

Lines changed: 219 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3795,6 +3795,82 @@ public func FfiConverterTypeRegisterTdeKeyResponse_lower(_ value: RegisterTdeKey
37953795
}
37963796

37973797

3798+
/**
3799+
* State used to re-initialize an unlocked user's cryptographic state after
3800+
* `accountCryptographicState` and `V2UpgradeToken` are received in a sync.
3801+
*
3802+
* This presumes the SDK is already unlocked (has user key in memory).
3803+
*/
3804+
public struct ReinitUserCryptoRequest: Equatable, Hashable, Codable {
3805+
/**
3806+
* The user's account cryptographic state, encrypted under the user key
3807+
*/
3808+
public let accountCryptographicState: WrappedAccountCryptographicState
3809+
/**
3810+
* The SDK uses the in-store (V1) user key to extract the V2 user key from the token,
3811+
* then sets the V2 user key as the active user key before decrypting
3812+
* `account_cryptographic_state`.
3813+
*/
3814+
public let upgradeToken: V2UpgradeToken
3815+
3816+
// Default memberwise initializers are never public by default, so we
3817+
// declare one manually.
3818+
public init(
3819+
/**
3820+
* The user's account cryptographic state, encrypted under the user key
3821+
*/accountCryptographicState: WrappedAccountCryptographicState,
3822+
/**
3823+
* The SDK uses the in-store (V1) user key to extract the V2 user key from the token,
3824+
* then sets the V2 user key as the active user key before decrypting
3825+
* `account_cryptographic_state`.
3826+
*/upgradeToken: V2UpgradeToken) {
3827+
self.accountCryptographicState = accountCryptographicState
3828+
self.upgradeToken = upgradeToken
3829+
}
3830+
3831+
3832+
3833+
3834+
}
3835+
3836+
#if compiler(>=6)
3837+
extension ReinitUserCryptoRequest: Sendable {}
3838+
#endif
3839+
3840+
#if swift(>=5.8)
3841+
@_documentation(visibility: private)
3842+
#endif
3843+
public struct FfiConverterTypeReinitUserCryptoRequest: FfiConverterRustBuffer {
3844+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ReinitUserCryptoRequest {
3845+
return
3846+
try ReinitUserCryptoRequest(
3847+
accountCryptographicState: FfiConverterTypeWrappedAccountCryptographicState.read(from: &buf),
3848+
upgradeToken: FfiConverterTypeV2UpgradeToken.read(from: &buf)
3849+
)
3850+
}
3851+
3852+
public static func write(_ value: ReinitUserCryptoRequest, into buf: inout [UInt8]) {
3853+
FfiConverterTypeWrappedAccountCryptographicState.write(value.accountCryptographicState, into: &buf)
3854+
FfiConverterTypeV2UpgradeToken.write(value.upgradeToken, into: &buf)
3855+
}
3856+
}
3857+
3858+
3859+
#if swift(>=5.8)
3860+
@_documentation(visibility: private)
3861+
#endif
3862+
public func FfiConverterTypeReinitUserCryptoRequest_lift(_ buf: RustBuffer) throws -> ReinitUserCryptoRequest {
3863+
return try FfiConverterTypeReinitUserCryptoRequest.lift(buf)
3864+
}
3865+
3866+
#if swift(>=5.8)
3867+
@_documentation(visibility: private)
3868+
#endif
3869+
public func FfiConverterTypeReinitUserCryptoRequest_lower(_ value: ReinitUserCryptoRequest) -> RustBuffer {
3870+
return FfiConverterTypeReinitUserCryptoRequest.lower(value)
3871+
}
3872+
3873+
37983874
/**
37993875
* Request to verify a user's secret.
38003876
*/
@@ -4568,12 +4644,6 @@ public enum AccountCryptographyInitializationError: Swift.Error, Equatable, Hash
45684644
*/
45694645
case TamperedData(message: String)
45704646

4571-
/**
4572-
* The key store is already initialized with account keys. Currently, updating keys is not a
4573-
* supported operation
4574-
*/
4575-
case KeyStoreAlreadyInitialized(message: String)
4576-
45774647
/**
45784648
* A generic cryptographic error occurred.
45794649
*/
@@ -4624,11 +4694,7 @@ public struct FfiConverterTypeAccountCryptographyInitializationError: FfiConvert
46244694
message: try FfiConverterString.read(from: &buf)
46254695
)
46264696

4627-
case 5: return .KeyStoreAlreadyInitialized(
4628-
message: try FfiConverterString.read(from: &buf)
4629-
)
4630-
4631-
case 6: return .GenericCrypto(
4697+
case 5: return .GenericCrypto(
46324698
message: try FfiConverterString.read(from: &buf)
46334699
)
46344700

@@ -4651,10 +4717,8 @@ public struct FfiConverterTypeAccountCryptographyInitializationError: FfiConvert
46514717
writeInt(&buf, Int32(3))
46524718
case .TamperedData(_ /* message is ignored*/):
46534719
writeInt(&buf, Int32(4))
4654-
case .KeyStoreAlreadyInitialized(_ /* message is ignored*/):
4655-
writeInt(&buf, Int32(5))
46564720
case .GenericCrypto(_ /* message is ignored*/):
4657-
writeInt(&buf, Int32(6))
4721+
writeInt(&buf, Int32(5))
46584722

46594723

46604724
}
@@ -6486,6 +6550,147 @@ public func FfiConverterTypePinUnlockStatus_lower(_ value: PinUnlockStatus) -> R
64866550

64876551

64886552

6553+
/**
6554+
* Errors that can occur when re-initializing user cryptography state.
6555+
*/
6556+
public enum ReinitUserCryptoError: Swift.Error, Equatable, Hashable, Codable, Foundation.LocalizedError {
6557+
6558+
6559+
6560+
/**
6561+
* The SDK is not in an unlocked state, so it cannot re-initialize user crypto.
6562+
*/
6563+
case NotUnlocked(message: String)
6564+
6565+
/**
6566+
* The provided account cryptographic state is not V2. Re-initialization is only supported for
6567+
* upgrading to V2 encryption.
6568+
*/
6569+
case InvalidAccountCryptographicState(message: String)
6570+
6571+
/**
6572+
* The local migrations (pin key and local user data key) that runs as part of the V1->V2
6573+
* upgrade failed, likely due to missing state or keys that should be present during the
6574+
* upgrade process. Clients should deconstruct the SDK and initialize a fresh instance to
6575+
* recover.
6576+
*/
6577+
case LocalMigrationFailed(message: String)
6578+
6579+
/**
6580+
* The provided upgrade token was invalid, such as not decrypting properly with the active user
6581+
* key, or containing unexpected data.
6582+
*/
6583+
case InvalidUpgradeToken(message: String)
6584+
6585+
/**
6586+
* An error occurred during the cryptographic operations to re-initialize user crypto.
6587+
*/
6588+
case CryptoInitialization(message: String)
6589+
6590+
/**
6591+
* The SDK does not have a state bridge registered, which is required to perform V1->V2 local
6592+
* data migrations.
6593+
*/
6594+
case StateBridgeNotRegistered(message: String)
6595+
6596+
6597+
6598+
6599+
6600+
6601+
6602+
public var errorDescription: String? {
6603+
String(reflecting: self)
6604+
}
6605+
6606+
}
6607+
6608+
#if compiler(>=6)
6609+
extension ReinitUserCryptoError: Sendable {}
6610+
#endif
6611+
6612+
#if swift(>=5.8)
6613+
@_documentation(visibility: private)
6614+
#endif
6615+
public struct FfiConverterTypeReinitUserCryptoError: FfiConverterRustBuffer {
6616+
typealias SwiftType = ReinitUserCryptoError
6617+
6618+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> ReinitUserCryptoError {
6619+
let variant: Int32 = try readInt(&buf)
6620+
switch variant {
6621+
6622+
6623+
6624+
6625+
case 1: return .NotUnlocked(
6626+
message: try FfiConverterString.read(from: &buf)
6627+
)
6628+
6629+
case 2: return .InvalidAccountCryptographicState(
6630+
message: try FfiConverterString.read(from: &buf)
6631+
)
6632+
6633+
case 3: return .LocalMigrationFailed(
6634+
message: try FfiConverterString.read(from: &buf)
6635+
)
6636+
6637+
case 4: return .InvalidUpgradeToken(
6638+
message: try FfiConverterString.read(from: &buf)
6639+
)
6640+
6641+
case 5: return .CryptoInitialization(
6642+
message: try FfiConverterString.read(from: &buf)
6643+
)
6644+
6645+
case 6: return .StateBridgeNotRegistered(
6646+
message: try FfiConverterString.read(from: &buf)
6647+
)
6648+
6649+
6650+
default: throw UniffiInternalError.unexpectedEnumCase
6651+
}
6652+
}
6653+
6654+
public static func write(_ value: ReinitUserCryptoError, into buf: inout [UInt8]) {
6655+
switch value {
6656+
6657+
6658+
6659+
6660+
case .NotUnlocked(_ /* message is ignored*/):
6661+
writeInt(&buf, Int32(1))
6662+
case .InvalidAccountCryptographicState(_ /* message is ignored*/):
6663+
writeInt(&buf, Int32(2))
6664+
case .LocalMigrationFailed(_ /* message is ignored*/):
6665+
writeInt(&buf, Int32(3))
6666+
case .InvalidUpgradeToken(_ /* message is ignored*/):
6667+
writeInt(&buf, Int32(4))
6668+
case .CryptoInitialization(_ /* message is ignored*/):
6669+
writeInt(&buf, Int32(5))
6670+
case .StateBridgeNotRegistered(_ /* message is ignored*/):
6671+
writeInt(&buf, Int32(6))
6672+
6673+
6674+
}
6675+
}
6676+
}
6677+
6678+
6679+
#if swift(>=5.8)
6680+
@_documentation(visibility: private)
6681+
#endif
6682+
public func FfiConverterTypeReinitUserCryptoError_lift(_ buf: RustBuffer) throws -> ReinitUserCryptoError {
6683+
return try FfiConverterTypeReinitUserCryptoError.lift(buf)
6684+
}
6685+
6686+
#if swift(>=5.8)
6687+
@_documentation(visibility: private)
6688+
#endif
6689+
public func FfiConverterTypeReinitUserCryptoError_lower(_ value: ReinitUserCryptoError) -> RustBuffer {
6690+
return FfiConverterTypeReinitUserCryptoError.lower(value)
6691+
}
6692+
6693+
64896694
/**
64906695
* Errors that can occur during rotation of the account cryptographic state.
64916696
*/

0 commit comments

Comments
 (0)