diff --git a/Signal/Provisioning/ProvisioningCoordinator+Shims.swift b/Signal/Provisioning/ProvisioningCoordinator+Shims.swift index 9c29948229..8dbc7a0ba7 100644 --- a/Signal/Provisioning/ProvisioningCoordinator+Shims.swift +++ b/Signal/Provisioning/ProvisioningCoordinator+Shims.swift @@ -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 diff --git a/Signal/Provisioning/ProvisioningCoordinatorImpl.swift b/Signal/Provisioning/ProvisioningCoordinatorImpl.swift index 31e83c5365..5c558c7809 100644 --- a/Signal/Provisioning/ProvisioningCoordinatorImpl.swift +++ b/Signal/Provisioning/ProvisioningCoordinatorImpl.swift @@ -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; diff --git a/Signal/Registration/RegistrationCoodinatorShims.swift b/Signal/Registration/RegistrationCoodinatorShims.swift index 45aa27a05a..32ee1a68a7 100644 --- a/Signal/Registration/RegistrationCoodinatorShims.swift +++ b/Signal/Registration/RegistrationCoodinatorShims.swift @@ -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, diff --git a/Signal/Registration/RegistrationCoordinatorImpl.swift b/Signal/Registration/RegistrationCoordinatorImpl.swift index cc6f43ca3c..0380dd1228 100644 --- a/Signal/Registration/RegistrationCoordinatorImpl.swift +++ b/Signal/Registration/RegistrationCoordinatorImpl.swift @@ -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 diff --git a/Signal/test/Provisioning/ProvisioningCoordinator+Mocks.swift b/Signal/test/Provisioning/ProvisioningCoordinator+Mocks.swift index 3607065589..8b88e56264 100644 --- a/Signal/test/Provisioning/ProvisioningCoordinator+Mocks.swift +++ b/Signal/test/Provisioning/ProvisioningCoordinator+Mocks.swift @@ -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 diff --git a/Signal/test/Registration/RegistrationCoordinatorTestShims.swift b/Signal/test/Registration/RegistrationCoordinatorTestShims.swift index 5d992d12fc..faeacd1008 100644 --- a/Signal/test/Registration/RegistrationCoordinatorTestShims.swift +++ b/Signal/test/Registration/RegistrationCoordinatorTestShims.swift @@ -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, diff --git a/SignalServiceKit/Contacts/UserProfileMerger.swift b/SignalServiceKit/Contacts/UserProfileMerger.swift index 972d97b94e..4c0f3d9be0 100644 --- a/SignalServiceKit/Contacts/UserProfileMerger.swift +++ b/SignalServiceKit/Contacts/UserProfileMerger.swift @@ -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 diff --git a/SignalServiceKit/Cryptography/Aes256Key.swift b/SignalServiceKit/Cryptography/Aes256Key.swift index ee35234cde..be63d16f12 100644 --- a/SignalServiceKit/Cryptography/Aes256Key.swift +++ b/SignalServiceKit/Cryptography/Aes256Key.swift @@ -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 } diff --git a/SignalServiceKit/Devices/ProvisioningCipher.swift b/SignalServiceKit/Devices/ProvisioningCipher.swift index 2ee5473273..aaa5144412 100644 --- a/SignalServiceKit/Devices/ProvisioningCipher.swift +++ b/SignalServiceKit/Devices/ProvisioningCipher.swift @@ -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 diff --git a/SignalServiceKit/MessageBackup/Archivers/AccountData/MessageBackupAccountDataArchiver.swift b/SignalServiceKit/MessageBackup/Archivers/AccountData/MessageBackupAccountDataArchiver.swift index d81f7f666c..cfe876e56e 100644 --- a/SignalServiceKit/MessageBackup/Archivers/AccountData/MessageBackupAccountDataArchiver.swift +++ b/SignalServiceKit/MessageBackup/Archivers/AccountData/MessageBackupAccountDataArchiver.swift @@ -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 diff --git a/SignalServiceKit/MessageBackup/Archivers/MessageBackupErrors.swift b/SignalServiceKit/MessageBackup/Archivers/MessageBackupErrors.swift index 467fdaf18b..03b2f25bef 100644 --- a/SignalServiceKit/MessageBackup/Archivers/MessageBackupErrors.swift +++ b/SignalServiceKit/MessageBackup/Archivers/MessageBackupErrors.swift @@ -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 diff --git a/SignalServiceKit/MessageBackup/Archivers/Recipient/MessageBackupContactRecipientArchiver.swift b/SignalServiceKit/MessageBackup/Archivers/Recipient/MessageBackupContactRecipientArchiver.swift index a16b1e344d..bc6b00e306 100644 --- a/SignalServiceKit/MessageBackup/Archivers/Recipient/MessageBackupContactRecipientArchiver.swift +++ b/SignalServiceKit/MessageBackup/Archivers/Recipient/MessageBackupContactRecipientArchiver.swift @@ -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 diff --git a/SignalServiceKit/MessageBackup/Archivers/Recipient/MessageBackupGroupRecipientArchiver.swift b/SignalServiceKit/MessageBackup/Archivers/Recipient/MessageBackupGroupRecipientArchiver.swift index 640a7bbfe4..ebe5989cf5 100644 --- a/SignalServiceKit/MessageBackup/Archivers/Recipient/MessageBackupGroupRecipientArchiver.swift +++ b/SignalServiceKit/MessageBackup/Archivers/Recipient/MessageBackupGroupRecipientArchiver.swift @@ -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 diff --git a/SignalServiceKit/MessageBackup/MessageBackupManager+Shims.swift b/SignalServiceKit/MessageBackup/MessageBackupManager+Shims.swift index dcb5cde641..9ebae83d1c 100644 --- a/SignalServiceKit/MessageBackup/MessageBackupManager+Shims.swift +++ b/SignalServiceKit/MessageBackup/MessageBackupManager+Shims.swift @@ -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 diff --git a/SignalServiceKit/Profiles/OWSProfileManager.swift b/SignalServiceKit/Profiles/OWSProfileManager.swift index 5c008971cb..e372fc079e 100644 --- a/SignalServiceKit/Profiles/OWSProfileManager.swift +++ b/SignalServiceKit/Profiles/OWSProfileManager.swift @@ -110,7 +110,7 @@ extension OWSProfileManager: ProfileManager, Dependencies { profileBioEmoji: OptionalChange, profileAvatarData: OptionalAvatarChange, 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 } } @@ -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 { diff --git a/SignalServiceKit/Profiles/ProfileFetcherJob.swift b/SignalServiceKit/Profiles/ProfileFetcherJob.swift index b80449ac2a..4503bd33c1 100644 --- a/SignalServiceKit/Profiles/ProfileFetcherJob.swift +++ b/SignalServiceKit/Profiles/ProfileFetcherJob.swift @@ -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 } diff --git a/SignalServiceKit/Profiles/VersionedProfiles.swift b/SignalServiceKit/Profiles/VersionedProfiles.swift index 8cb2932857..f0dd61be6e 100644 --- a/SignalServiceKit/Profiles/VersionedProfiles.swift +++ b/SignalServiceKit/Profiles/VersionedProfiles.swift @@ -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.") diff --git a/SignalServiceKit/Profiles/VersionedProfilesImpl.swift b/SignalServiceKit/Profiles/VersionedProfilesImpl.swift index d8cd711b0b..ad7de447d2 100644 --- a/SignalServiceKit/Profiles/VersionedProfilesImpl.swift +++ b/SignalServiceKit/Profiles/VersionedProfilesImpl.swift @@ -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) diff --git a/SignalServiceKit/Protocols/ProfileManager.swift b/SignalServiceKit/Protocols/ProfileManager.swift index d6dd1c0f9f..110aeb84a7 100644 --- a/SignalServiceKit/Protocols/ProfileManager.swift +++ b/SignalServiceKit/Protocols/ProfileManager.swift @@ -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, profileAvatarData: OptionalAvatarChange, visibleBadgeIds: OptionalChange<[String]>, - unsavedRotatedProfileKey: OWSAES256Key?, + unsavedRotatedProfileKey: Aes256Key?, userProfileWriter: UserProfileWriter, authedAccount: AuthedAccount, tx: SDSAnyWriteTransaction diff --git a/SignalServiceKit/Storage/Database/DeepCopy.swift b/SignalServiceKit/Storage/Database/DeepCopy.swift index d796cf74dc..74950803c1 100644 --- a/SignalServiceKit/Storage/Database/DeepCopy.swift +++ b/SignalServiceKit/Storage/Database/DeepCopy.swift @@ -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) diff --git a/SignalServiceKit/TestUtils/OWSFakeProfileManager.swift b/SignalServiceKit/TestUtils/OWSFakeProfileManager.swift index 8a0510ee60..e7d33ac69b 100644 --- a/SignalServiceKit/TestUtils/OWSFakeProfileManager.swift +++ b/SignalServiceKit/TestUtils/OWSFakeProfileManager.swift @@ -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, profileAvatarData: OptionalAvatarChange, 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( diff --git a/SignalServiceKit/Util/OWSUserProfile.swift b/SignalServiceKit/Util/OWSUserProfile.swift index f34b3dff92..fb0c063f34 100644 --- a/SignalServiceKit/Util/OWSUserProfile.swift +++ b/SignalServiceKit/Util/OWSUserProfile.swift @@ -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 var lastFetchDate: OptionalChange var lastMessagingDate: OptionalChange - var profileKey: OptionalChange + var profileKey: OptionalChange var badges: OptionalChange<[OWSUserProfileBadgeInfo]> var isPhoneNumberShared: OptionalChange } @@ -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 = .noChange, lastFetchDate: OptionalChange = .noChange, lastMessagingDate: OptionalChange = .noChange, - profileKey: OptionalChange = .noChange, + profileKey: OptionalChange = .noChange, badges: OptionalChange<[OWSUserProfileBadgeInfo]> = .noChange, isPhoneNumberShared: OptionalChange = .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 diff --git a/SignalServiceKit/tests/Contacts/UserProfileMergerTest.swift b/SignalServiceKit/tests/Contacts/UserProfileMergerTest.swift index bf460b65df..3c52cb7ee6 100644 --- a/SignalServiceKit/tests/Contacts/UserProfileMergerTest.swift +++ b/SignalServiceKit/tests/Contacts/UserProfileMergerTest.swift @@ -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, diff --git a/SignalServiceKit/tests/Messages/OWSUDManagerTest.swift b/SignalServiceKit/tests/Messages/OWSUDManagerTest.swift index efb3beebed..b1550308b6 100644 --- a/SignalServiceKit/tests/Messages/OWSUDManagerTest.swift +++ b/SignalServiceKit/tests/Messages/OWSUDManagerTest.swift @@ -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, diff --git a/SignalServiceKit/tests/Messages/SMKUDAccessKeyTest.swift b/SignalServiceKit/tests/Messages/SMKUDAccessKeyTest.swift index ce775abd8f..2e412fd0f7 100644 --- a/SignalServiceKit/tests/Messages/SMKUDAccessKeyTest.swift +++ b/SignalServiceKit/tests/Messages/SMKUDAccessKeyTest.swift @@ -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)) } } diff --git a/SignalServiceKit/tests/Network/OWSRequestFactoryTest.swift b/SignalServiceKit/tests/Network/OWSRequestFactoryTest.swift index 4e32917749..d4403e5ad4 100644 --- a/SignalServiceKit/tests/Network/OWSRequestFactoryTest.swift +++ b/SignalServiceKit/tests/Network/OWSRequestFactoryTest.swift @@ -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) }