Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit aee1a04

Browse files
authoredAug 19, 2024
Release de3b6e2bdddb8acf5c31db12a8e649e0042621bd (#21)
1 parent 29c6c62 commit aee1a04

File tree

3 files changed

+204
-2
lines changed

3 files changed

+204
-2
lines changed
 

‎Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ let package = Package(
2727
swiftSettings: [.unsafeFlags(["-suppress-warnings"])]),
2828
.binaryTarget(
2929
name: "BitwardenFFI",
30-
url: "https://bwlivefronttest.blob.core.windows.net/sdk/0d4c73c-BitwardenFFI.xcframework.zip",
31-
checksum: "e4a23c7a03b965a87b1e3fda6711ff9a6c974217f50dfc9a93177eff7300fe6f"),
30+
url: "https://bwlivefronttest.blob.core.windows.net/sdk/de3b6e2-BitwardenFFI.xcframework.zip",
31+
checksum: "37e884d820907af85e788b5e0ab483bfc5aa0299e5d6b39865ad70659322a202"),
3232
.testTarget(
3333
name: "BitwardenSdkTests",
3434
dependencies: ["BitwardenSdk"])

‎Sources/BitwardenSdk/BitwardenCore.swift

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,85 @@ public func FfiConverterTypeClientSettings_lower(_ value: ClientSettings) -> Rus
703703
}
704704

705705

706+
public struct DeriveKeyConnectorRequest {
707+
/**
708+
* Encrypted user key, used to validate the master key
709+
*/
710+
public let userKeyEncrypted: EncString
711+
public let password: String
712+
public let kdf: Kdf
713+
public let email: String
714+
715+
// Default memberwise initializers are never public by default, so we
716+
// declare one manually.
717+
public init(
718+
/**
719+
* Encrypted user key, used to validate the master key
720+
*/userKeyEncrypted: EncString, password: String, kdf: Kdf, email: String) {
721+
self.userKeyEncrypted = userKeyEncrypted
722+
self.password = password
723+
self.kdf = kdf
724+
self.email = email
725+
}
726+
}
727+
728+
729+
730+
extension DeriveKeyConnectorRequest: Equatable, Hashable {
731+
public static func ==(lhs: DeriveKeyConnectorRequest, rhs: DeriveKeyConnectorRequest) -> Bool {
732+
if lhs.userKeyEncrypted != rhs.userKeyEncrypted {
733+
return false
734+
}
735+
if lhs.password != rhs.password {
736+
return false
737+
}
738+
if lhs.kdf != rhs.kdf {
739+
return false
740+
}
741+
if lhs.email != rhs.email {
742+
return false
743+
}
744+
return true
745+
}
746+
747+
public func hash(into hasher: inout Hasher) {
748+
hasher.combine(userKeyEncrypted)
749+
hasher.combine(password)
750+
hasher.combine(kdf)
751+
hasher.combine(email)
752+
}
753+
}
754+
755+
756+
public struct FfiConverterTypeDeriveKeyConnectorRequest: FfiConverterRustBuffer {
757+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> DeriveKeyConnectorRequest {
758+
return
759+
try DeriveKeyConnectorRequest(
760+
userKeyEncrypted: FfiConverterTypeEncString.read(from: &buf),
761+
password: FfiConverterString.read(from: &buf),
762+
kdf: FfiConverterTypeKdf.read(from: &buf),
763+
email: FfiConverterString.read(from: &buf)
764+
)
765+
}
766+
767+
public static func write(_ value: DeriveKeyConnectorRequest, into buf: inout [UInt8]) {
768+
FfiConverterTypeEncString.write(value.userKeyEncrypted, into: &buf)
769+
FfiConverterString.write(value.password, into: &buf)
770+
FfiConverterTypeKdf.write(value.kdf, into: &buf)
771+
FfiConverterString.write(value.email, into: &buf)
772+
}
773+
}
774+
775+
776+
public func FfiConverterTypeDeriveKeyConnectorRequest_lift(_ buf: RustBuffer) throws -> DeriveKeyConnectorRequest {
777+
return try FfiConverterTypeDeriveKeyConnectorRequest.lift(buf)
778+
}
779+
780+
public func FfiConverterTypeDeriveKeyConnectorRequest_lower(_ value: DeriveKeyConnectorRequest) -> RustBuffer {
781+
return FfiConverterTypeDeriveKeyConnectorRequest.lower(value)
782+
}
783+
784+
706785
public struct DerivePinKeyResponse {
707786
/**
708787
* [UserKey](bitwarden_crypto::UserKey) protected by PIN
@@ -993,6 +1072,71 @@ public func FfiConverterTypeInitUserCryptoRequest_lower(_ value: InitUserCryptoR
9931072
}
9941073

9951074

1075+
public struct KeyConnectorResponse {
1076+
public let masterKey: String
1077+
public let encryptedUserKey: String
1078+
public let keys: RsaKeyPair
1079+
1080+
// Default memberwise initializers are never public by default, so we
1081+
// declare one manually.
1082+
public init(masterKey: String, encryptedUserKey: String, keys: RsaKeyPair) {
1083+
self.masterKey = masterKey
1084+
self.encryptedUserKey = encryptedUserKey
1085+
self.keys = keys
1086+
}
1087+
}
1088+
1089+
1090+
1091+
extension KeyConnectorResponse: Equatable, Hashable {
1092+
public static func ==(lhs: KeyConnectorResponse, rhs: KeyConnectorResponse) -> Bool {
1093+
if lhs.masterKey != rhs.masterKey {
1094+
return false
1095+
}
1096+
if lhs.encryptedUserKey != rhs.encryptedUserKey {
1097+
return false
1098+
}
1099+
if lhs.keys != rhs.keys {
1100+
return false
1101+
}
1102+
return true
1103+
}
1104+
1105+
public func hash(into hasher: inout Hasher) {
1106+
hasher.combine(masterKey)
1107+
hasher.combine(encryptedUserKey)
1108+
hasher.combine(keys)
1109+
}
1110+
}
1111+
1112+
1113+
public struct FfiConverterTypeKeyConnectorResponse: FfiConverterRustBuffer {
1114+
public static func read(from buf: inout (data: Data, offset: Data.Index)) throws -> KeyConnectorResponse {
1115+
return
1116+
try KeyConnectorResponse(
1117+
masterKey: FfiConverterString.read(from: &buf),
1118+
encryptedUserKey: FfiConverterString.read(from: &buf),
1119+
keys: FfiConverterTypeRsaKeyPair.read(from: &buf)
1120+
)
1121+
}
1122+
1123+
public static func write(_ value: KeyConnectorResponse, into buf: inout [UInt8]) {
1124+
FfiConverterString.write(value.masterKey, into: &buf)
1125+
FfiConverterString.write(value.encryptedUserKey, into: &buf)
1126+
FfiConverterTypeRsaKeyPair.write(value.keys, into: &buf)
1127+
}
1128+
}
1129+
1130+
1131+
public func FfiConverterTypeKeyConnectorResponse_lift(_ buf: RustBuffer) throws -> KeyConnectorResponse {
1132+
return try FfiConverterTypeKeyConnectorResponse.lift(buf)
1133+
}
1134+
1135+
public func FfiConverterTypeKeyConnectorResponse_lower(_ value: KeyConnectorResponse) -> RustBuffer {
1136+
return FfiConverterTypeKeyConnectorResponse.lower(value)
1137+
}
1138+
1139+
9961140
public struct MasterPasswordPolicyOptions {
9971141
public let minComplexity: UInt8
9981142
public let minLength: UInt8
@@ -1672,6 +1816,14 @@ public enum InitUserCryptoMethod {
16721816
* The user's symmetric crypto key, encrypted with the Device Key.
16731817
*/deviceProtectedUserKey: AsymmetricEncString
16741818
)
1819+
case keyConnector(
1820+
/**
1821+
* Base64 encoded master key, retrieved from the key connector.
1822+
*/masterKey: String,
1823+
/**
1824+
* The user's encrypted symmetric crypto key
1825+
*/userKey: String
1826+
)
16751827
}
16761828

16771829

@@ -1697,6 +1849,9 @@ public struct FfiConverterTypeInitUserCryptoMethod: FfiConverterRustBuffer {
16971849
case 5: return .deviceKey(deviceKey: try FfiConverterString.read(from: &buf), protectedDevicePrivateKey: try FfiConverterTypeEncString.read(from: &buf), deviceProtectedUserKey: try FfiConverterTypeAsymmetricEncString.read(from: &buf)
16981850
)
16991851

1852+
case 6: return .keyConnector(masterKey: try FfiConverterString.read(from: &buf), userKey: try FfiConverterString.read(from: &buf)
1853+
)
1854+
17001855
default: throw UniffiInternalError.unexpectedEnumCase
17011856
}
17021857
}
@@ -1734,6 +1889,12 @@ public struct FfiConverterTypeInitUserCryptoMethod: FfiConverterRustBuffer {
17341889
FfiConverterTypeEncString.write(protectedDevicePrivateKey, into: &buf)
17351890
FfiConverterTypeAsymmetricEncString.write(deviceProtectedUserKey, into: &buf)
17361891

1892+
1893+
case let .keyConnector(masterKey,userKey):
1894+
writeInt(&buf, Int32(6))
1895+
FfiConverterString.write(masterKey, into: &buf)
1896+
FfiConverterString.write(userKey, into: &buf)
1897+
17371898
}
17381899
}
17391900
}

‎Sources/BitwardenSdk/BitwardenSDK.swift

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -869,6 +869,11 @@ public protocol ClientAuthProtocol : AnyObject {
869869
*/
870870
func hashPassword(email: String, password: String, kdfParams: Kdf, purpose: HashPurpose) async throws -> String
871871

872+
/**
873+
* Generate keys needed to onboard a new user without master key to key connector
874+
*/
875+
func makeKeyConnectorKeys() throws -> KeyConnectorResponse
876+
872877
/**
873878
* Generate keys needed for registration process
874879
*/
@@ -1003,6 +1008,16 @@ open func hashPassword(email: String, password: String, kdfParams: Kdf, purpose:
10031008
)
10041009
}
10051010

1011+
/**
1012+
* Generate keys needed to onboard a new user without master key to key connector
1013+
*/
1014+
open func makeKeyConnectorKeys()throws -> KeyConnectorResponse {
1015+
return try FfiConverterTypeKeyConnectorResponse_lift(try rustCallWithError(FfiConverterTypeBitwardenError.lift) {
1016+
uniffi_bitwarden_uniffi_fn_method_clientauth_make_key_connector_keys(self.uniffiClonePointer(),$0
1017+
)
1018+
})
1019+
}
1020+
10061021
/**
10071022
* Generate keys needed for registration process
10081023
*/
@@ -1470,6 +1485,11 @@ public func FfiConverterTypeClientCollections_lower(_ value: ClientCollections)
14701485

14711486
public protocol ClientCryptoProtocol : AnyObject {
14721487

1488+
/**
1489+
* Derive the master key for migrating to the key connector
1490+
*/
1491+
func deriveKeyConnector(request: DeriveKeyConnectorRequest) throws -> String
1492+
14731493
/**
14741494
* Generates a PIN protected user key from the provided PIN. The result can be stored and later
14751495
* used to initialize another client instance by using the PIN and the PIN key with
@@ -1552,6 +1572,17 @@ open class ClientCrypto:
15521572

15531573

15541574

1575+
/**
1576+
* Derive the master key for migrating to the key connector
1577+
*/
1578+
open func deriveKeyConnector(request: DeriveKeyConnectorRequest)throws -> String {
1579+
return try FfiConverterString.lift(try rustCallWithError(FfiConverterTypeBitwardenError.lift) {
1580+
uniffi_bitwarden_uniffi_fn_method_clientcrypto_derive_key_connector(self.uniffiClonePointer(),
1581+
FfiConverterTypeDeriveKeyConnectorRequest_lower(request),$0
1582+
)
1583+
})
1584+
}
1585+
15551586
/**
15561587
* Generates a PIN protected user key from the provided PIN. The result can be stored and later
15571588
* used to initialize another client instance by using the PIN and the PIN key with
@@ -4793,6 +4824,10 @@ fileprivate struct FfiConverterDictionaryStringBool: FfiConverterRustBuffer {
47934824

47944825

47954826

4827+
4828+
4829+
4830+
47964831

47974832

47984833

@@ -4968,6 +5003,9 @@ private var initializationResult: InitializationResult = {
49685003
if (uniffi_bitwarden_uniffi_checksum_method_clientauth_hash_password() != 58719) {
49695004
return InitializationResult.apiChecksumMismatch
49705005
}
5006+
if (uniffi_bitwarden_uniffi_checksum_method_clientauth_make_key_connector_keys() != 11807) {
5007+
return InitializationResult.apiChecksumMismatch
5008+
}
49715009
if (uniffi_bitwarden_uniffi_checksum_method_clientauth_make_register_keys() != 4847) {
49725010
return InitializationResult.apiChecksumMismatch
49735011
}
@@ -5016,6 +5054,9 @@ private var initializationResult: InitializationResult = {
50165054
if (uniffi_bitwarden_uniffi_checksum_method_clientcollections_decrypt_list() != 34441) {
50175055
return InitializationResult.apiChecksumMismatch
50185056
}
5057+
if (uniffi_bitwarden_uniffi_checksum_method_clientcrypto_derive_key_connector() != 31169) {
5058+
return InitializationResult.apiChecksumMismatch
5059+
}
50195060
if (uniffi_bitwarden_uniffi_checksum_method_clientcrypto_derive_pin_key() != 33793) {
50205061
return InitializationResult.apiChecksumMismatch
50215062
}

0 commit comments

Comments
 (0)
Please sign in to comment.