rename OWSAES256Key in swift to Aes256Key
This commit is contained in:
parent
7320874263
commit
e1cfd116a2
@ -54,10 +54,10 @@ public class _ProvisioningCoordinator_MessageFactoryWrapper: _ProvisioningCoordi
|
||||
|
||||
public protocol _ProvisioningCoordinator_ProfileManagerShim {
|
||||
|
||||
func localProfileKey() -> OWSAES256Key
|
||||
func localProfileKey() -> Aes256Key
|
||||
|
||||
func setLocalProfileKey(
|
||||
_ key: OWSAES256Key,
|
||||
_ key: Aes256Key,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
authedAccount: AuthedAccount,
|
||||
tx: DBWriteTransaction
|
||||
@ -72,12 +72,12 @@ public class _ProvisioningCoordinator_ProfileManagerWrapper: _ProvisioningCoordi
|
||||
self.profileManager = profileManager
|
||||
}
|
||||
|
||||
public func localProfileKey() -> OWSAES256Key {
|
||||
public func localProfileKey() -> Aes256Key {
|
||||
return profileManager.localProfileKey()
|
||||
}
|
||||
|
||||
public func setLocalProfileKey(
|
||||
_ key: OWSAES256Key,
|
||||
_ key: Aes256Key,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
authedAccount: AuthedAccount,
|
||||
tx: DBWriteTransaction
|
||||
|
||||
@ -328,7 +328,7 @@ public class ProvisioningCoordinatorImpl: ProvisioningCoordinator {
|
||||
|
||||
private func makeAccountAttributes(
|
||||
encryptedDeviceName encryptedDeviceNameRaw: Data,
|
||||
profileKey: OWSAES256Key,
|
||||
profileKey: Aes256Key,
|
||||
tx: DBWriteTransaction
|
||||
) -> AccountAttributes {
|
||||
// Secondary devices only use account attributes during registration;
|
||||
|
||||
@ -279,7 +279,7 @@ public protocol _RegistrationCoordinator_ProfileManagerShim {
|
||||
|
||||
// NOTE: non-optional because OWSProfileManager generates a random key
|
||||
// if one doesn't already exist.
|
||||
var localProfileKey: OWSAES256Key { get }
|
||||
var localProfileKey: Aes256Key { get }
|
||||
|
||||
func updateLocalProfile(
|
||||
givenName: OWSUserProfile.NameComponent,
|
||||
@ -299,7 +299,7 @@ public class _RegistrationCoordinator_ProfileManagerWrapper: _RegistrationCoordi
|
||||
|
||||
public var hasProfileName: Bool { manager.hasProfileName }
|
||||
|
||||
public var localProfileKey: OWSAES256Key { manager.localProfileKey() }
|
||||
public var localProfileKey: Aes256Key { manager.localProfileKey() }
|
||||
|
||||
public func updateLocalProfile(
|
||||
givenName: OWSUserProfile.NameComponent,
|
||||
|
||||
@ -644,7 +644,7 @@ public class RegistrationCoordinatorImpl: RegistrationCoordinator {
|
||||
var phoneNumberDiscoverability: PhoneNumberDiscoverability?
|
||||
|
||||
// OWSProfileManager state
|
||||
var profileKey: OWSAES256Key!
|
||||
var profileKey: Aes256Key!
|
||||
var udAccessKey: SMKUDAccessKey!
|
||||
var allowUnrestrictedUD = false
|
||||
var hasProfileName = false
|
||||
|
||||
@ -41,14 +41,14 @@ public class _ProvisioningCoordinator_ProfileManagerMock: _ProvisioningCoordinat
|
||||
|
||||
public init() {}
|
||||
|
||||
public var localProfileKeyMock: OWSAES256Key?
|
||||
public var localProfileKeyMock: Aes256Key?
|
||||
|
||||
public func localProfileKey() -> OWSAES256Key {
|
||||
public func localProfileKey() -> Aes256Key {
|
||||
return localProfileKeyMock!
|
||||
}
|
||||
|
||||
public func setLocalProfileKey(
|
||||
_ key: OWSAES256Key,
|
||||
_ key: Aes256Key,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
authedAccount: AuthedAccount,
|
||||
tx: DBWriteTransaction
|
||||
|
||||
@ -186,9 +186,9 @@ public class _RegistrationCoordinator_ProfileManagerMock: _RegistrationCoordinat
|
||||
|
||||
public var hasProfileName: Bool { return hasProfileNameMock() }
|
||||
|
||||
public var localProfileKeyMock: () -> OWSAES256Key = { OWSAES256Key() }
|
||||
public var localProfileKeyMock: () -> Aes256Key = { Aes256Key() }
|
||||
|
||||
public var localProfileKey: OWSAES256Key { return localProfileKeyMock() }
|
||||
public var localProfileKey: Aes256Key { return localProfileKeyMock() }
|
||||
|
||||
public var updateLocalProfileMock: ((
|
||||
_ givenName: OWSUserProfile.NameComponent,
|
||||
|
||||
@ -8,11 +8,11 @@ import LibSignalClient
|
||||
|
||||
class UserProfileMerger: RecipientMergeObserver {
|
||||
private let userProfileStore: UserProfileStore
|
||||
private let setProfileKeyShim: (OWSUserProfile, OWSAES256Key, DBWriteTransaction) -> Void
|
||||
private let setProfileKeyShim: (OWSUserProfile, Aes256Key, DBWriteTransaction) -> Void
|
||||
|
||||
init(
|
||||
userProfileStore: UserProfileStore,
|
||||
setProfileKeyShim: @escaping (OWSUserProfile, OWSAES256Key, DBWriteTransaction) -> Void
|
||||
setProfileKeyShim: @escaping (OWSUserProfile, Aes256Key, DBWriteTransaction) -> Void
|
||||
) {
|
||||
self.userProfileStore = userProfileStore
|
||||
self.setProfileKeyShim = setProfileKeyShim
|
||||
|
||||
@ -7,7 +7,7 @@ import Foundation
|
||||
|
||||
/// Key appropriate for use with AES-256.
|
||||
@objc(OWSAES256Key)
|
||||
public final class OWSAES256Key: NSObject, NSSecureCoding {
|
||||
public final class Aes256Key: NSObject, NSSecureCoding {
|
||||
|
||||
@objc
|
||||
public static let keyByteLength: UInt = 32
|
||||
@ -22,10 +22,10 @@ public final class OWSAES256Key: NSObject, NSSecureCoding {
|
||||
|
||||
/// Generates a new secure random key.
|
||||
///
|
||||
/// Equivalent to calling ``OWSAES256Key/init()``.
|
||||
/// Equivalent to calling ``Aes256Key/init()``.
|
||||
@objc(generateRandomKey)
|
||||
public static func generateRandom() -> OWSAES256Key {
|
||||
return OWSAES256Key()
|
||||
public static func generateRandom() -> Aes256Key {
|
||||
return Aes256Key()
|
||||
}
|
||||
|
||||
/// Returns a new instance if `data` is of appropriate length for an AES-256 key.
|
||||
@ -64,7 +64,7 @@ public final class OWSAES256Key: NSObject, NSSecureCoding {
|
||||
// MARK: Equatable
|
||||
|
||||
public override func isEqual(_ object: Any?) -> Bool {
|
||||
guard let otherKey = object as? OWSAES256Key else {
|
||||
guard let otherKey = object as? Aes256Key else {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
@ -13,7 +13,7 @@ public struct ProvisionMessage {
|
||||
public let pni: Pni?
|
||||
public let aciIdentityKeyPair: ECKeyPair
|
||||
public let pniIdentityKeyPair: ECKeyPair
|
||||
public let profileKey: OWSAES256Key
|
||||
public let profileKey: Aes256Key
|
||||
public let masterKey: Data
|
||||
public let areReadReceiptsEnabled: Bool?
|
||||
public let primaryUserAgent: String?
|
||||
@ -112,7 +112,7 @@ public class ProvisioningCipher {
|
||||
let pniIdentityKeyPair = try IdentityKeyPair(publicKey: PublicKey(proto.pniIdentityKeyPublic),
|
||||
privateKey: PrivateKey(proto.pniIdentityKeyPrivate))
|
||||
|
||||
guard let profileKey = OWSAES256Key(data: proto.profileKey) else {
|
||||
guard let profileKey = Aes256Key(data: proto.profileKey) else {
|
||||
throw ProvisioningError.invalidProvisionMessage("invalid profileKey - count: \(proto.profileKey.count)")
|
||||
}
|
||||
let areReadReceiptsEnabled = proto.hasReadReceipts ? proto.readReceipts : nil
|
||||
|
||||
@ -206,7 +206,7 @@ public class MessageBackupAccountDataArchiverImpl: MessageBackupAccountDataArchi
|
||||
_ accountData: BackupProto_AccountData,
|
||||
tx: DBWriteTransaction
|
||||
) -> MessageBackup.RestoreAccountDataResult {
|
||||
guard let profileKey = OWSAES256Key(data: accountData.profileKey) else {
|
||||
guard let profileKey = Aes256Key(data: accountData.profileKey) else {
|
||||
return .failure([.restoreFrameError(
|
||||
.invalidProtoData(.invalidLocalProfileKey),
|
||||
.localUser
|
||||
|
||||
@ -318,7 +318,7 @@ extension MessageBackup {
|
||||
case invalidServiceId(protoClass: Any.Type)
|
||||
/// Could not parse an E164. Includes the class of the offending proto.
|
||||
case invalidE164(protoClass: Any.Type)
|
||||
/// Could not parse an ``OWSAES256Key`` profile key. Includes the class
|
||||
/// Could not parse an ``Aes256Key`` profile key. Includes the class
|
||||
/// of the offending proto.
|
||||
case invalidProfileKey(protoClass: Any.Type)
|
||||
/// An invalid member (group, distribution list, etc) was specified as a distribution list member. Includes the offending proto
|
||||
|
||||
@ -201,7 +201,7 @@ public class MessageBackupContactRecipientArchiver: MessageBackupProtoArchiver {
|
||||
let aci: Aci?
|
||||
let pni: Pni?
|
||||
let e164: E164?
|
||||
let profileKey: OWSAES256Key?
|
||||
let profileKey: Aes256Key?
|
||||
if contactProto.hasAci {
|
||||
guard let aciUuid = UUID(data: contactProto.aci) else {
|
||||
return restoreFrameError(.invalidProtoData(.invalidAci(protoClass: BackupProto_Contact.self)))
|
||||
@ -227,7 +227,7 @@ public class MessageBackupContactRecipientArchiver: MessageBackupProtoArchiver {
|
||||
e164 = nil
|
||||
}
|
||||
if contactProto.hasProfileKey {
|
||||
guard let protoProfileKey = OWSAES256Key(data: contactProto.profileKey) else {
|
||||
guard let protoProfileKey = Aes256Key(data: contactProto.profileKey) else {
|
||||
return restoreFrameError(.invalidProtoData(.invalidProfileKey(protoClass: BackupProto_Contact.self)))
|
||||
}
|
||||
profileKey = protoProfileKey
|
||||
|
||||
@ -254,7 +254,7 @@ public class MessageBackupGroupRecipientArchiver: MessageBackupProtoArchiver {
|
||||
groupMembershipBuilder.addFullMember(aci, role: role)
|
||||
|
||||
if
|
||||
let profileKey = OWSAES256Key(data: fullMember.profileKey),
|
||||
let profileKey = Aes256Key(data: fullMember.profileKey),
|
||||
!profileKey.isAllZeroes
|
||||
{
|
||||
profileManager.setProfileKeyIfMissing(
|
||||
@ -293,7 +293,7 @@ public class MessageBackupGroupRecipientArchiver: MessageBackupProtoArchiver {
|
||||
groupMembershipBuilder.addRequestingMember(aci)
|
||||
|
||||
if
|
||||
let profileKey = OWSAES256Key(data: requestingMember.profileKey),
|
||||
let profileKey = Aes256Key(data: requestingMember.profileKey),
|
||||
!profileKey.isAllZeroes
|
||||
{
|
||||
profileManager.setProfileKeyIfMissing(
|
||||
@ -394,7 +394,7 @@ public class MessageBackupGroupRecipientArchiver: MessageBackupProtoArchiver {
|
||||
|
||||
// MARK: -
|
||||
|
||||
private extension OWSAES256Key {
|
||||
private extension Aes256Key {
|
||||
/// Is this profile key comprised of all-zeroes?
|
||||
///
|
||||
/// It's possible that other clients may not have a persisted profile key
|
||||
|
||||
@ -89,7 +89,7 @@ public protocol _MessageBackup_ProfileManagerShim {
|
||||
givenName: String,
|
||||
familyName: String?,
|
||||
avatarUrlPath: String?,
|
||||
profileKey: OWSAES256Key,
|
||||
profileKey: Aes256Key,
|
||||
tx: DBWriteTransaction
|
||||
)
|
||||
|
||||
@ -97,12 +97,12 @@ public protocol _MessageBackup_ProfileManagerShim {
|
||||
insertableAddress: OWSUserProfile.InsertableAddress,
|
||||
givenName: String?,
|
||||
familyName: String?,
|
||||
profileKey: OWSAES256Key?,
|
||||
profileKey: Aes256Key?,
|
||||
tx: DBWriteTransaction
|
||||
)
|
||||
|
||||
func setProfileKeyIfMissing(
|
||||
_ profileKey: OWSAES256Key,
|
||||
_ profileKey: Aes256Key,
|
||||
forAci aci: Aci,
|
||||
localIdentifiers: LocalIdentifiers,
|
||||
tx: DBWriteTransaction
|
||||
@ -152,7 +152,7 @@ public class _MessageBackup_ProfileManagerWrapper: _MessageBackup_ProfileManager
|
||||
givenName: String,
|
||||
familyName: String?,
|
||||
avatarUrlPath: String?,
|
||||
profileKey: OWSAES256Key,
|
||||
profileKey: Aes256Key,
|
||||
tx: DBWriteTransaction
|
||||
) {
|
||||
let sdsTx = SDSDB.shimOnlyBridge(tx)
|
||||
@ -181,7 +181,7 @@ public class _MessageBackup_ProfileManagerWrapper: _MessageBackup_ProfileManager
|
||||
insertableAddress: OWSUserProfile.InsertableAddress,
|
||||
givenName: String?,
|
||||
familyName: String?,
|
||||
profileKey: OWSAES256Key?,
|
||||
profileKey: Aes256Key?,
|
||||
tx: DBWriteTransaction
|
||||
) {
|
||||
if case .localUser = insertableAddress {
|
||||
@ -210,7 +210,7 @@ public class _MessageBackup_ProfileManagerWrapper: _MessageBackup_ProfileManager
|
||||
}
|
||||
|
||||
public func setProfileKeyIfMissing(
|
||||
_ profileKey: OWSAES256Key,
|
||||
_ profileKey: Aes256Key,
|
||||
forAci aci: Aci,
|
||||
localIdentifiers: LocalIdentifiers,
|
||||
tx: DBWriteTransaction
|
||||
|
||||
@ -110,7 +110,7 @@ extension OWSProfileManager: ProfileManager, Dependencies {
|
||||
profileBioEmoji: OptionalChange<String?>,
|
||||
profileAvatarData: OptionalAvatarChange<Data?>,
|
||||
visibleBadgeIds: OptionalChange<[String]>,
|
||||
unsavedRotatedProfileKey: OWSAES256Key?,
|
||||
unsavedRotatedProfileKey: Aes256Key?,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
authedAccount: AuthedAccount,
|
||||
tx: SDSAnyWriteTransaction
|
||||
@ -165,7 +165,7 @@ extension OWSProfileManager: ProfileManager, Dependencies {
|
||||
|
||||
// This will re-upload the existing local profile state.
|
||||
public func reuploadLocalProfile(
|
||||
unsavedRotatedProfileKey: OWSAES256Key?,
|
||||
unsavedRotatedProfileKey: Aes256Key?,
|
||||
mustReuploadAvatar: Bool,
|
||||
authedAccount: AuthedAccount,
|
||||
tx: DBWriteTransaction
|
||||
@ -359,7 +359,7 @@ extension OWSProfileManager: ProfileManager, Dependencies {
|
||||
// try to rotate your profile key again on the next app launch or blocklist
|
||||
// change and continue to use the old profile key.
|
||||
|
||||
let newProfileKey = OWSAES256Key.generateRandom()
|
||||
let newProfileKey = Aes256Key.generateRandom()
|
||||
let uploadPromise = await self.databaseStorage.awaitableWrite { tx in
|
||||
self.reuploadLocalProfile(
|
||||
unsavedRotatedProfileKey: newProfileKey,
|
||||
@ -635,7 +635,7 @@ extension OWSProfileManager: ProfileManager, Dependencies {
|
||||
) {
|
||||
let address = OWSUserProfile.insertableAddress(serviceId: serviceId, localIdentifiers: localIdentifiers)
|
||||
|
||||
guard let profileKey = OWSAES256Key(data: profileKeyData) else {
|
||||
guard let profileKey = Aes256Key(data: profileKeyData) else {
|
||||
owsFailDebug("Invalid profile key data for \(serviceId).")
|
||||
return
|
||||
}
|
||||
@ -771,7 +771,7 @@ extension OWSProfileManager: ProfileManager, Dependencies {
|
||||
var authedAccount: AuthedAccount
|
||||
|
||||
struct Parameters {
|
||||
var profileKey: OWSAES256Key?
|
||||
var profileKey: Aes256Key?
|
||||
var future: Future<Void>
|
||||
}
|
||||
}
|
||||
@ -957,7 +957,7 @@ extension OWSProfileManager: ProfileManager, Dependencies {
|
||||
|
||||
private func updateProfileOnService(
|
||||
profileChanges: PendingProfileUpdate,
|
||||
newProfileKey: OWSAES256Key?,
|
||||
newProfileKey: Aes256Key?,
|
||||
authedAccount: AuthedAccount
|
||||
) async throws {
|
||||
do {
|
||||
@ -1515,7 +1515,7 @@ extension OWSProfileManager {
|
||||
}
|
||||
}
|
||||
|
||||
public func downloadAndDecryptAvatar(avatarUrlPath: String, profileKey: OWSAES256Key) async throws -> URL {
|
||||
public func downloadAndDecryptAvatar(avatarUrlPath: String, profileKey: Aes256Key) async throws -> URL {
|
||||
let backgroundTask = OWSBackgroundTask(label: "\(#function)")
|
||||
defer { backgroundTask.end() }
|
||||
|
||||
@ -1528,7 +1528,7 @@ extension OWSProfileManager {
|
||||
|
||||
private static func _downloadAndDecryptAvatar(
|
||||
avatarUrlPath: String,
|
||||
profileKey: OWSAES256Key,
|
||||
profileKey: Aes256Key,
|
||||
remainingRetries: Int
|
||||
) async throws -> URL {
|
||||
assert(!avatarUrlPath.isEmpty)
|
||||
@ -1557,7 +1557,7 @@ extension OWSProfileManager {
|
||||
private static func decryptAvatar(
|
||||
at encryptedFileUrl: URL,
|
||||
to decryptedFileUrl: URL,
|
||||
profileKey: OWSAES256Key
|
||||
profileKey: Aes256Key
|
||||
) throws {
|
||||
let readHandle = try FileHandle(forReadingFrom: encryptedFileUrl)
|
||||
defer {
|
||||
|
||||
@ -184,9 +184,9 @@ public class ProfileFetcherJob {
|
||||
|
||||
private func fetchedProfile(
|
||||
for profile: SignalServiceProfile,
|
||||
profileKeyFromVersionedRequest: OWSAES256Key?
|
||||
profileKeyFromVersionedRequest: Aes256Key?
|
||||
) -> FetchedProfile {
|
||||
let profileKey: OWSAES256Key?
|
||||
let profileKey: Aes256Key?
|
||||
if let profileKeyFromVersionedRequest {
|
||||
// We sent a versioned request, so use the corresponding profile key for
|
||||
// decryption. If we don't, we might try to decrypt an old profile with a
|
||||
@ -463,18 +463,18 @@ public struct DecryptedProfile {
|
||||
|
||||
public struct FetchedProfile {
|
||||
let profile: SignalServiceProfile
|
||||
let profileKey: OWSAES256Key?
|
||||
let profileKey: Aes256Key?
|
||||
public let decryptedProfile: DecryptedProfile?
|
||||
public let identityKey: IdentityKey
|
||||
|
||||
init(profile: SignalServiceProfile, profileKey: OWSAES256Key?) {
|
||||
init(profile: SignalServiceProfile, profileKey: Aes256Key?) {
|
||||
self.profile = profile
|
||||
self.profileKey = profileKey
|
||||
self.decryptedProfile = Self.decrypt(profile: profile, profileKey: profileKey)
|
||||
self.identityKey = profile.identityKey
|
||||
}
|
||||
|
||||
private static func decrypt(profile: SignalServiceProfile, profileKey: OWSAES256Key?) -> DecryptedProfile? {
|
||||
private static func decrypt(profile: SignalServiceProfile, profileKey: Aes256Key?) -> DecryptedProfile? {
|
||||
guard let profileKey else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -20,7 +20,7 @@ public struct VersionedProfileUpdate {
|
||||
@objc
|
||||
public protocol VersionedProfileRequest: AnyObject {
|
||||
var request: TSRequest { get }
|
||||
var profileKey: OWSAES256Key? { get }
|
||||
var profileKey: Aes256Key? { get }
|
||||
}
|
||||
|
||||
// MARK: -
|
||||
@ -47,7 +47,7 @@ public protocol VersionedProfilesSwift: VersionedProfiles {
|
||||
profileBioEmoji: String?,
|
||||
profileAvatarMutation: VersionedProfileAvatarMutation,
|
||||
visibleBadgeIds: [String],
|
||||
profileKey: OWSAES256Key,
|
||||
profileKey: Aes256Key,
|
||||
authedAccount: AuthedAccount
|
||||
) async throws -> VersionedProfileUpdate
|
||||
|
||||
@ -114,7 +114,7 @@ public class MockVersionedProfiles: NSObject, VersionedProfilesSwift, VersionedP
|
||||
profileBioEmoji: String?,
|
||||
profileAvatarMutation: VersionedProfileAvatarMutation,
|
||||
visibleBadgeIds: [String],
|
||||
profileKey: OWSAES256Key,
|
||||
profileKey: Aes256Key,
|
||||
authedAccount: AuthedAccount
|
||||
) async throws -> VersionedProfileUpdate {
|
||||
owsFail("Not implemented.")
|
||||
|
||||
@ -9,11 +9,11 @@ import LibSignalClient
|
||||
public class VersionedProfileRequestImpl: NSObject, VersionedProfileRequest {
|
||||
public let request: TSRequest
|
||||
public let requestContext: ProfileKeyCredentialRequestContext?
|
||||
public let profileKey: OWSAES256Key?
|
||||
public let profileKey: Aes256Key?
|
||||
|
||||
public init(request: TSRequest,
|
||||
requestContext: ProfileKeyCredentialRequestContext?,
|
||||
profileKey: OWSAES256Key?) {
|
||||
profileKey: Aes256Key?) {
|
||||
self.request = request
|
||||
self.requestContext = requestContext
|
||||
self.profileKey = profileKey
|
||||
@ -124,7 +124,7 @@ public class VersionedProfilesImpl: NSObject, VersionedProfilesSwift, VersionedP
|
||||
profileBioEmoji: String?,
|
||||
profileAvatarMutation: VersionedProfileAvatarMutation,
|
||||
visibleBadgeIds: [String],
|
||||
profileKey: OWSAES256Key,
|
||||
profileKey: Aes256Key,
|
||||
authedAccount: AuthedAccount
|
||||
) async throws -> VersionedProfileUpdate {
|
||||
let tsAccountManager = DependenciesBridge.shared.tsAccountManager
|
||||
@ -270,7 +270,7 @@ public class VersionedProfilesImpl: NSObject, VersionedProfilesSwift, VersionedP
|
||||
var requestContext: ProfileKeyCredentialRequestContext?
|
||||
var profileKeyVersionArg: String?
|
||||
var credentialRequestArg: Data?
|
||||
var profileKeyForRequest: OWSAES256Key?
|
||||
var profileKeyForRequest: Aes256Key?
|
||||
try databaseStorage.read { transaction in
|
||||
// We try to include the profile key if we have one.
|
||||
guard let profileKeyForAddress = self.profileManager.profileKey(
|
||||
@ -310,7 +310,7 @@ public class VersionedProfilesImpl: NSObject, VersionedProfilesSwift, VersionedP
|
||||
|
||||
// MARK: -
|
||||
|
||||
public func parseProfileKey(profileKey: OWSAES256Key) throws -> ProfileKey {
|
||||
public func parseProfileKey(profileKey: Aes256Key) throws -> ProfileKey {
|
||||
let profileKeyData: Data = profileKey.keyData
|
||||
let profileKeyDataBytes = [UInt8](profileKeyData)
|
||||
return try ProfileKey(contents: profileKeyDataBytes)
|
||||
|
||||
@ -87,7 +87,7 @@ public protocol ProfileManager: ProfileManagerProtocol {
|
||||
func reuploadLocalProfile(authedAccount: AuthedAccount)
|
||||
|
||||
func reuploadLocalProfile(
|
||||
unsavedRotatedProfileKey: OWSAES256Key?,
|
||||
unsavedRotatedProfileKey: Aes256Key?,
|
||||
mustReuploadAvatar: Bool,
|
||||
authedAccount: AuthedAccount,
|
||||
tx: DBWriteTransaction
|
||||
@ -105,7 +105,7 @@ public protocol ProfileManager: ProfileManagerProtocol {
|
||||
/// this method will download it twice.
|
||||
func downloadAndDecryptAvatar(
|
||||
avatarUrlPath: String,
|
||||
profileKey: OWSAES256Key
|
||||
profileKey: Aes256Key
|
||||
) async throws -> URL
|
||||
|
||||
func updateProfile(
|
||||
@ -126,7 +126,7 @@ public protocol ProfileManager: ProfileManagerProtocol {
|
||||
profileBioEmoji: OptionalChange<String?>,
|
||||
profileAvatarData: OptionalAvatarChange<Data?>,
|
||||
visibleBadgeIds: OptionalChange<[String]>,
|
||||
unsavedRotatedProfileKey: OWSAES256Key?,
|
||||
unsavedRotatedProfileKey: Aes256Key?,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
authedAccount: AuthedAccount,
|
||||
tx: SDSAnyWriteTransaction
|
||||
|
||||
@ -244,7 +244,7 @@ extension Contact: DeepCopyable {
|
||||
// MARK: -
|
||||
|
||||
@objc
|
||||
extension OWSAES256Key: DeepCopyable {
|
||||
extension Aes256Key: DeepCopyable {
|
||||
public func deepCopy() throws -> AnyObject {
|
||||
// This class can use shallow copies.
|
||||
return try DeepCopies.shallowCopy(self)
|
||||
|
||||
@ -21,7 +21,7 @@ extension OWSFakeProfileManager: ProfileManager {
|
||||
throw OWSGenericError("Not supported.")
|
||||
}
|
||||
|
||||
public func downloadAndDecryptAvatar(avatarUrlPath: String, profileKey: OWSAES256Key) async throws -> URL {
|
||||
public func downloadAndDecryptAvatar(avatarUrlPath: String, profileKey: Aes256Key) async throws -> URL {
|
||||
throw OWSGenericError("Not supported.")
|
||||
}
|
||||
|
||||
@ -44,7 +44,7 @@ extension OWSFakeProfileManager: ProfileManager {
|
||||
profileBioEmoji: OptionalChange<String?>,
|
||||
profileAvatarData: OptionalAvatarChange<Data?>,
|
||||
visibleBadgeIds: OptionalChange<[String]>,
|
||||
unsavedRotatedProfileKey: OWSAES256Key?,
|
||||
unsavedRotatedProfileKey: Aes256Key?,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
authedAccount: AuthedAccount,
|
||||
tx: SDSAnyWriteTransaction
|
||||
@ -57,7 +57,7 @@ extension OWSFakeProfileManager: ProfileManager {
|
||||
}
|
||||
|
||||
public func reuploadLocalProfile(
|
||||
unsavedRotatedProfileKey: OWSAES256Key?,
|
||||
unsavedRotatedProfileKey: Aes256Key?,
|
||||
mustReuploadAvatar: Bool,
|
||||
authedAccount: AuthedAccount,
|
||||
tx: DBWriteTransaction
|
||||
@ -82,7 +82,7 @@ extension OWSFakeProfileManager: ProfileManager {
|
||||
authedAccount: AuthedAccount,
|
||||
tx: DBWriteTransaction
|
||||
) {
|
||||
self.profileKeys[SignalServiceAddress(serviceId)] = OWSAES256Key(data: profileKeyData)!
|
||||
self.profileKeys[SignalServiceAddress(serviceId)] = Aes256Key(data: profileKeyData)!
|
||||
}
|
||||
|
||||
public func fillInProfileKeys(
|
||||
|
||||
@ -220,7 +220,7 @@ public final class OWSUserProfile: NSObject, NSCopying, SDSCodableModel, Decodab
|
||||
private(set) public var avatarUrlPath: String?
|
||||
|
||||
@objc
|
||||
private(set) public var profileKey: OWSAES256Key?
|
||||
private(set) public var profileKey: Aes256Key?
|
||||
|
||||
@objc
|
||||
private(set) public var givenName: String?
|
||||
@ -259,7 +259,7 @@ public final class OWSUserProfile: NSObject, NSCopying, SDSCodableModel, Decodab
|
||||
address: Address,
|
||||
givenName: String? = nil,
|
||||
familyName: String? = nil,
|
||||
profileKey: OWSAES256Key? = nil,
|
||||
profileKey: Aes256Key? = nil,
|
||||
avatarUrlPath: String? = nil
|
||||
) {
|
||||
let serviceId: ServiceId?
|
||||
@ -299,7 +299,7 @@ public final class OWSUserProfile: NSObject, NSCopying, SDSCodableModel, Decodab
|
||||
phoneNumber: String?,
|
||||
avatarFileName: String?,
|
||||
avatarUrlPath: String?,
|
||||
profileKey: OWSAES256Key?,
|
||||
profileKey: Aes256Key?,
|
||||
givenName: String?,
|
||||
familyName: String?,
|
||||
bio: String?,
|
||||
@ -446,8 +446,8 @@ public final class OWSUserProfile: NSObject, NSCopying, SDSCodableModel, Decodab
|
||||
isPhoneNumberShared = try container.decodeIfPresent(Bool.self, forKey: .isPhoneNumberShared)
|
||||
}
|
||||
|
||||
private static func decodeProfileKey(_ profileKeyData: Data) throws -> OWSAES256Key {
|
||||
guard profileKeyData.count == OWSAES256Key.keyByteLength, let profileKey = OWSAES256Key(data: profileKeyData) else {
|
||||
private static func decodeProfileKey(_ profileKeyData: Data) throws -> Aes256Key {
|
||||
guard profileKeyData.count == Aes256Key.keyByteLength, let profileKey = Aes256Key(data: profileKeyData) else {
|
||||
// Historically, we encoded this using an NSKeyedArchiver. We assume it's
|
||||
// encoded in this way if it's not exactly 32 bytes.
|
||||
return try LegacySDSSerializer().deserializeLegacySDSData(profileKeyData, propertyName: "profileKey")
|
||||
@ -704,11 +704,11 @@ public final class OWSUserProfile: NSObject, NSCopying, SDSCodableModel, Decodab
|
||||
|
||||
// MARK: - Encryption
|
||||
|
||||
public class func encrypt(profileData: Data, profileKey: OWSAES256Key) throws -> Data {
|
||||
public class func encrypt(profileData: Data, profileKey: Aes256Key) throws -> Data {
|
||||
return try Aes256GcmEncryptedData.encrypt(profileData, key: profileKey.keyData).concatenate()
|
||||
}
|
||||
|
||||
public class func decrypt(profileData: Data, profileKey: OWSAES256Key) throws -> Data {
|
||||
public class func decrypt(profileData: Data, profileKey: Aes256Key) throws -> Data {
|
||||
return try Aes256GcmEncryptedData(concatenated: profileData).decrypt(key: profileKey.keyData)
|
||||
}
|
||||
|
||||
@ -717,7 +717,7 @@ public final class OWSUserProfile: NSObject, NSCopying, SDSCodableModel, Decodab
|
||||
case malformedValue
|
||||
}
|
||||
|
||||
class func decrypt(profileNameData: Data, profileKey: OWSAES256Key) throws -> (givenName: String, familyName: String?) {
|
||||
class func decrypt(profileNameData: Data, profileKey: Aes256Key) throws -> (givenName: String, familyName: String?) {
|
||||
let decryptedData = try decrypt(profileData: profileNameData, profileKey: profileKey)
|
||||
|
||||
func parseNameSegment(_ nameSegment: Data) throws -> String? {
|
||||
@ -738,7 +738,7 @@ public final class OWSUserProfile: NSObject, NSCopying, SDSCodableModel, Decodab
|
||||
return (givenName, try familyName.flatMap(parseNameSegment(_:)))
|
||||
}
|
||||
|
||||
class func decrypt(profileStringData: Data, profileKey: OWSAES256Key) throws -> String? {
|
||||
class func decrypt(profileStringData: Data, profileKey: Aes256Key) throws -> String? {
|
||||
let decryptedData = try decrypt(profileData: profileStringData, profileKey: profileKey)
|
||||
|
||||
// Remove padding.
|
||||
@ -749,7 +749,7 @@ public final class OWSUserProfile: NSObject, NSCopying, SDSCodableModel, Decodab
|
||||
return value.nilIfEmpty
|
||||
}
|
||||
|
||||
class func decrypt(profileBooleanData: Data, profileKey: OWSAES256Key) throws -> Bool {
|
||||
class func decrypt(profileBooleanData: Data, profileKey: Aes256Key) throws -> Bool {
|
||||
switch try decrypt(profileData: profileBooleanData, profileKey: profileKey) {
|
||||
case Data([1]):
|
||||
return true
|
||||
@ -763,7 +763,7 @@ public final class OWSUserProfile: NSObject, NSCopying, SDSCodableModel, Decodab
|
||||
public class func encrypt(
|
||||
givenName: OWSUserProfile.NameComponent,
|
||||
familyName: OWSUserProfile.NameComponent?,
|
||||
profileKey: OWSAES256Key
|
||||
profileKey: Aes256Key
|
||||
) throws -> ProfileValue {
|
||||
let encodedValues: [Data] = [givenName.dataValue, familyName?.dataValue].compacted()
|
||||
let encodedValue = Data(encodedValues.joined(separator: Data([0])))
|
||||
@ -771,7 +771,7 @@ public final class OWSUserProfile: NSObject, NSCopying, SDSCodableModel, Decodab
|
||||
return try encrypt(data: encodedValue, profileKey: profileKey, paddedLengths: [53, 257])
|
||||
}
|
||||
|
||||
public class func encrypt(data unpaddedData: Data, profileKey: OWSAES256Key, paddedLengths: [Int]) throws -> ProfileValue {
|
||||
public class func encrypt(data unpaddedData: Data, profileKey: Aes256Key, paddedLengths: [Int]) throws -> ProfileValue {
|
||||
assert(paddedLengths == paddedLengths.sorted())
|
||||
|
||||
guard let paddedLength = paddedLengths.first(where: { $0 >= unpaddedData.count }) else {
|
||||
@ -838,7 +838,7 @@ public final class OWSUserProfile: NSObject, NSCopying, SDSCodableModel, Decodab
|
||||
let userProfile = OWSUserProfile(address: address)
|
||||
if case .localUser = address {
|
||||
userProfile.update(
|
||||
profileKey: .setTo(OWSAES256Key.generateRandom()),
|
||||
profileKey: .setTo(Aes256Key.generateRandom()),
|
||||
userProfileWriter: userProfileWriter,
|
||||
transaction: tx,
|
||||
completion: nil
|
||||
@ -986,7 +986,7 @@ private struct UserProfileChanges {
|
||||
var avatarFileName: OptionalChange<String?>
|
||||
var lastFetchDate: OptionalChange<Date>
|
||||
var lastMessagingDate: OptionalChange<Date>
|
||||
var profileKey: OptionalChange<OWSAES256Key>
|
||||
var profileKey: OptionalChange<Aes256Key>
|
||||
var badges: OptionalChange<[OWSUserProfileBadgeInfo]>
|
||||
var isPhoneNumberShared: OptionalChange<Bool?>
|
||||
}
|
||||
@ -1086,7 +1086,7 @@ extension OWSUserProfile {
|
||||
visibleChangeCount += setIfChanged(changes.bio, keyPath: \.bio)
|
||||
visibleChangeCount += setIfChanged(changes.bioEmoji, keyPath: \.bioEmoji)
|
||||
visibleChangeCount += setIfChanged(changes.badges, keyPath: \.badges)
|
||||
visibleChangeCount += setIfChanged(changes.profileKey.map { $0 as OWSAES256Key? }, keyPath: \.profileKey)
|
||||
visibleChangeCount += setIfChanged(changes.profileKey.map { $0 as Aes256Key? }, keyPath: \.profileKey)
|
||||
visibleChangeCount += setIfChanged(changes.isPhoneNumberShared, keyPath: \.isPhoneNumberShared)
|
||||
|
||||
// Some properties are invisible/"polled", so changes don't matter.
|
||||
@ -1371,7 +1371,7 @@ extension OWSUserProfile {
|
||||
avatarFileName: OptionalChange<String?> = .noChange,
|
||||
lastFetchDate: OptionalChange<Date> = .noChange,
|
||||
lastMessagingDate: OptionalChange<Date> = .noChange,
|
||||
profileKey: OptionalChange<OWSAES256Key> = .noChange,
|
||||
profileKey: OptionalChange<Aes256Key> = .noChange,
|
||||
badges: OptionalChange<[OWSUserProfileBadgeInfo]> = .noChange,
|
||||
isPhoneNumberShared: OptionalChange<Bool?> = .noChange,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
@ -1401,7 +1401,7 @@ extension OWSUserProfile {
|
||||
@available(swift, obsoleted: 1.0)
|
||||
@objc
|
||||
public func clearProfile(
|
||||
profileKey: OWSAES256Key,
|
||||
profileKey: Aes256Key,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
transaction: SDSAnyWriteTransaction,
|
||||
completion: (() -> Void)?
|
||||
@ -1425,7 +1425,7 @@ extension OWSUserProfile {
|
||||
@available(swift, obsoleted: 1.0)
|
||||
@objc
|
||||
public func update(
|
||||
profileKey: OWSAES256Key,
|
||||
profileKey: Aes256Key,
|
||||
userProfileWriter: UserProfileWriter,
|
||||
transaction: SDSAnyWriteTransaction,
|
||||
completion: (() -> Void)?
|
||||
@ -1453,7 +1453,7 @@ extension OWSUserProfile {
|
||||
givenName: String?,
|
||||
familyName: String?,
|
||||
avatarUrlPath: String?,
|
||||
profileKey: OWSAES256Key?,
|
||||
profileKey: Aes256Key?,
|
||||
tx: SDSAnyWriteTransaction
|
||||
) {
|
||||
self.givenName = givenName
|
||||
@ -1471,7 +1471,7 @@ extension OWSUserProfile {
|
||||
/// - Important
|
||||
/// Only callers who are updating the profile in a vacuum should call this.
|
||||
public func upsertProfileKeyWithNoSideEffects(
|
||||
_ profileKey: OWSAES256Key,
|
||||
_ profileKey: Aes256Key,
|
||||
tx: SDSAnyWriteTransaction
|
||||
) {
|
||||
self.profileKey = profileKey
|
||||
|
||||
@ -87,7 +87,7 @@ class UserProfileMergerTest: XCTestCase {
|
||||
)
|
||||
}
|
||||
|
||||
finalProfile.setValue(OWSAES256Key(data: Data(repeating: 2, count: 32))!, forKey: "profileKey")
|
||||
finalProfile.setValue(Aes256Key(data: Data(repeating: 2, count: 32))!, forKey: "profileKey")
|
||||
otherAciProfile.phoneNumber = nil
|
||||
otherPniProfile.serviceIdString = nil
|
||||
XCTAssertEqual(userProfileStore.userProfiles, [localProfile, finalProfile, otherAciProfile, otherPniProfile])
|
||||
@ -101,7 +101,7 @@ class UserProfileMergerTest: XCTestCase {
|
||||
phoneNumber: phoneNumber,
|
||||
avatarFileName: nil,
|
||||
avatarUrlPath: nil,
|
||||
profileKey: profileKey.map { OWSAES256Key(data: $0)! },
|
||||
profileKey: profileKey.map { Aes256Key(data: $0)! },
|
||||
givenName: nil,
|
||||
familyName: nil,
|
||||
bio: nil,
|
||||
|
||||
@ -31,7 +31,7 @@ class OWSUDManagerTest: SSKBaseTest {
|
||||
// Configure UDManager
|
||||
self.write { transaction in
|
||||
self.profileManager.setProfileKeyData(
|
||||
OWSAES256Key.generateRandom().keyData,
|
||||
Aes256Key.generateRandom().keyData,
|
||||
for: localIdentifiers.aci,
|
||||
onlyFillInIfMissing: false,
|
||||
shouldFetchProfile: true,
|
||||
@ -105,7 +105,7 @@ class OWSUDManagerTest: SSKBaseTest {
|
||||
let bobRecipientAci = Aci.randomForTesting()
|
||||
self.write { transaction in
|
||||
self.profileManager.setProfileKeyData(
|
||||
OWSAES256Key.generateRandom().keyData,
|
||||
Aes256Key.generateRandom().keyData,
|
||||
for: bobRecipientAci,
|
||||
onlyFillInIfMissing: false,
|
||||
shouldFetchProfile: true,
|
||||
|
||||
@ -8,7 +8,7 @@ import SignalServiceKit
|
||||
|
||||
class SMKUDAccessKeyTest: XCTestCase {
|
||||
func testUDAccessKeyForProfileKey() {
|
||||
let profileKey = Data(count: Int(OWSAES256Key.keyByteLength))
|
||||
let profileKey = Data(count: Int(Aes256Key.keyByteLength))
|
||||
let udAccessKey1 = try! SMKUDAccessKey(profileKey: profileKey)
|
||||
XCTAssertEqual(udAccessKey1.keyData.count, SMKUDAccessKey.kUDAccessKeyLength)
|
||||
|
||||
@ -19,7 +19,7 @@ class SMKUDAccessKeyTest: XCTestCase {
|
||||
}
|
||||
|
||||
func testUDAccessKeyForProfileKey_badProfileKey() {
|
||||
let profileKey = Data(count: Int(OWSAES256Key.keyByteLength - 1))
|
||||
let profileKey = Data(count: Int(Aes256Key.keyByteLength - 1))
|
||||
XCTAssertThrowsError(try SMKUDAccessKey(profileKey: profileKey))
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ import XCTest
|
||||
|
||||
class OWSRequestFactoryTest: SSKBaseTest {
|
||||
private func getUdAccessKey() throws -> SMKUDAccessKey {
|
||||
let profileKey = Data(count: Int(OWSAES256Key.keyByteLength))
|
||||
let profileKey = Data(count: Int(Aes256Key.keyByteLength))
|
||||
let result = try? SMKUDAccessKey(profileKey: profileKey)
|
||||
return try XCTUnwrap(result)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user