Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .swiftformat
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# format options
--indent 4
--ifdef noindent
--swiftversion 5.8.1
--swiftversion 6.2
--header strip
--funcattributes prev-line
--typeattributes prev-line
Expand Down
4 changes: 2 additions & 2 deletions Authenticator/Application/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD

func application(
_: UIApplication,
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil,
) -> Bool {
// Exit early if testing to avoid running any app functionality.
guard !isTesting else { return true }
Expand All @@ -45,7 +45,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterD

let services = ServiceContainer(
application: UIApplication.shared,
errorReporter: errorReporter
errorReporter: errorReporter,
)
let appModule = DefaultAppModule(services: services)
appProcessor = AppProcessor(appModule: appModule, services: services)
Expand Down
8 changes: 4 additions & 4 deletions Authenticator/Application/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
func scene(
_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions
options connectionOptions: UIScene.ConnectionOptions,
) {
guard let windowScene = scene as? UIWindowScene else { return }
guard let appProcessor else {
Expand Down Expand Up @@ -56,7 +56,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
await appProcessor.start(
appContext: .mainApp,
navigator: rootViewController,
window: appWindow
window: appWindow,
)
hideSplash()
isStartingUp = false
Expand Down Expand Up @@ -84,7 +84,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
window.isHidden = false
window.rootViewController = UIStoryboard(
name: "LaunchScreen",
bundle: .main
bundle: .main,
).instantiateInitialViewController()
window.windowLevel = UIWindow.Level.alert + 1
return window
Expand Down Expand Up @@ -115,7 +115,7 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
private func addTripleTapGestureRecognizer(to window: UIWindow) {
let tapGesture = UITapGestureRecognizer(
target: self,
action: #selector(handleTripleTapGesture)
action: #selector(handleTripleTapGesture),
)
tapGesture.numberOfTapsRequired = 3
tapGesture.numberOfTouchesRequired = 1
Expand Down
12 changes: 6 additions & 6 deletions AuthenticatorBridgeKit/AuthenticatorBridgeDataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public class AuthenticatorBridgeDataStore {
public init(
errorReporter: ErrorReporter,
groupIdentifier: String,
storeType: AuthenticatorBridgeStoreType = .persisted
storeType: AuthenticatorBridgeStoreType = .persisted,
) {
self.errorReporter = errorReporter

persistentContainer = NSPersistentContainer(
name: authenticatorBridgeModelName,
managedObjectModel: Self.managedObjectModel
managedObjectModel: Self.managedObjectModel,
)
let storeDescription: NSPersistentStoreDescription
switch storeType {
Expand Down Expand Up @@ -105,7 +105,7 @@ public class AuthenticatorBridgeDataStore {
try await backgroundContext.perform {
try self.backgroundContext.executeAndMergeChanges(
batchDeleteRequest: request,
additionalContexts: [self.persistentContainer.viewContext]
additionalContexts: [self.persistentContainer.viewContext],
)
}
}
Expand All @@ -118,7 +118,7 @@ public class AuthenticatorBridgeDataStore {
try await backgroundContext.perform {
try self.backgroundContext.executeAndMergeChanges(
batchInsertRequest: request,
additionalContexts: [self.persistentContainer.viewContext]
additionalContexts: [self.persistentContainer.viewContext],
)
}
}
Expand All @@ -132,13 +132,13 @@ public class AuthenticatorBridgeDataStore {
///
public func executeBatchReplace(
deleteRequest: NSBatchDeleteRequest,
insertRequest: NSBatchInsertRequest
insertRequest: NSBatchInsertRequest,
) async throws {
try await backgroundContext.perform {
try self.backgroundContext.executeAndMergeChanges(
batchDeleteRequest: deleteRequest,
batchInsertRequest: insertRequest,
additionalContexts: [self.persistentContainer.viewContext]
additionalContexts: [self.persistentContainer.viewContext],
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions AuthenticatorBridgeKit/AuthenticatorBridgeItemData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AuthenticatorBridgeItemData: NSManagedObject, CodableModelData {
convenience init(
context: NSManagedObjectContext,
userId: String,
authenticatorItem: AuthenticatorBridgeItemDataModel
authenticatorItem: AuthenticatorBridgeItemDataModel,
) throws {
self.init(context: context)
id = authenticatorItem.id
Expand All @@ -54,7 +54,7 @@ extension AuthenticatorBridgeItemData: ManagedUserObject {
#keyPath(AuthenticatorBridgeItemData.userId),
userId,
#keyPath(AuthenticatorBridgeItemData.id),
id
id,
)
}

Expand Down
18 changes: 9 additions & 9 deletions AuthenticatorBridgeKit/AuthenticatorBridgeItemService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ public class DefaultAuthenticatorBridgeItemService: AuthenticatorBridgeItemServi

public func fetchTemporaryItem() async throws -> AuthenticatorBridgeItemDataView? {
let decryptedItems = try await fetchAllForUserId(
DefaultAuthenticatorBridgeItemService.temporaryUserId
DefaultAuthenticatorBridgeItemService.temporaryUserId,
)
try await deleteAllForUserId(
DefaultAuthenticatorBridgeItemService.temporaryUserId
DefaultAuthenticatorBridgeItemService.temporaryUserId,
)

return decryptedItems.first
Expand All @@ -178,14 +178,14 @@ public class DefaultAuthenticatorBridgeItemService: AuthenticatorBridgeItemServi
forUserId userId: String) async throws {
let encryptedItems = try await cryptoService.encryptAuthenticatorItems(items)
try await dataStore.executeBatchInsert(
AuthenticatorBridgeItemData.batchInsertRequest(objects: encryptedItems, userId: userId)
AuthenticatorBridgeItemData.batchInsertRequest(objects: encryptedItems, userId: userId),
)
}

public func insertTemporaryItem(_ item: AuthenticatorBridgeItemDataView) async throws {
try await replaceAllItems(
with: [item],
forUserId: DefaultAuthenticatorBridgeItemService.temporaryUserId
forUserId: DefaultAuthenticatorBridgeItemService.temporaryUserId,
)
}

Expand All @@ -201,11 +201,11 @@ public class DefaultAuthenticatorBridgeItemService: AuthenticatorBridgeItemServi
let deleteRequest = AuthenticatorBridgeItemData.deleteByUserIdRequest(userId: userId)
let insertRequest = try AuthenticatorBridgeItemData.batchInsertRequest(
objects: encryptedItems,
userId: userId
userId: userId,
)
try await dataStore.executeBatchReplace(
deleteRequest: deleteRequest,
insertRequest: insertRequest
insertRequest: insertRequest,
)
}

Expand All @@ -214,13 +214,13 @@ public class DefaultAuthenticatorBridgeItemService: AuthenticatorBridgeItemServi
try await checkForLogout()
let fetchRequest = AuthenticatorBridgeItemData.fetchRequest(
predicate: NSPredicate(
format: "userId != %@", DefaultAuthenticatorBridgeItemService.temporaryUserId
)
format: "userId != %@", DefaultAuthenticatorBridgeItemService.temporaryUserId,
),
)
fetchRequest.sortDescriptors = [NSSortDescriptor(keyPath: \AuthenticatorBridgeItemData.userId, ascending: true)]
return FetchedResultsPublisher(
context: dataStore.persistentContainer.viewContext,
request: fetchRequest
request: fetchRequest,
)
.map { dataItems in
dataItems.compactMap(\.model)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public final class MockSharedTimeoutService: SharedTimeoutService {
public func updateTimeout(
forUserId userId: String,
lastActiveDate: Date?,
timeoutLength: SessionTimeoutValue
timeoutLength: SessionTimeoutValue,
) async throws {
if let updateTimeoutError {
throw updateTimeoutError
Expand Down
16 changes: 8 additions & 8 deletions AuthenticatorBridgeKit/SharedCryptographyService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public protocol SharedCryptographyService: AnyObject {
/// key is not in the shared repository.
///
func decryptAuthenticatorItems(
_ items: [AuthenticatorBridgeItemDataModel]
_ items: [AuthenticatorBridgeItemDataModel],
) async throws -> [AuthenticatorBridgeItemDataView]

/// Takes an array of `AuthenticatorBridgeItemDataView` with decrypted data and
Expand All @@ -28,7 +28,7 @@ public protocol SharedCryptographyService: AnyObject {
/// key is not in the shared repository.
///
func encryptAuthenticatorItems(
_ items: [AuthenticatorBridgeItemDataView]
_ items: [AuthenticatorBridgeItemDataView],
) async throws -> [AuthenticatorBridgeItemDataModel]
}

Expand All @@ -55,7 +55,7 @@ public class DefaultAuthenticatorCryptographyService: SharedCryptographyService
// MARK: Methods

public func decryptAuthenticatorItems(
_ items: [AuthenticatorBridgeItemDataModel]
_ items: [AuthenticatorBridgeItemDataModel],
) async throws -> [AuthenticatorBridgeItemDataView] {
guard !items.isEmpty else { return [] }

Expand All @@ -70,13 +70,13 @@ public class DefaultAuthenticatorCryptographyService: SharedCryptographyService
id: item.id,
name: (try? decrypt(item.name, withKey: symmetricKey)) ?? "",
totpKey: try? decrypt(item.totpKey, withKey: symmetricKey),
username: try? decrypt(item.username, withKey: symmetricKey)
username: try? decrypt(item.username, withKey: symmetricKey),
)
}
}

public func encryptAuthenticatorItems(
_ items: [AuthenticatorBridgeItemDataView]
_ items: [AuthenticatorBridgeItemDataView],
) async throws -> [AuthenticatorBridgeItemDataModel] {
let key = try await sharedKeychainRepository.getAuthenticatorKey()
let symmetricKey = SymmetricKey(data: key)
Expand All @@ -89,7 +89,7 @@ public class DefaultAuthenticatorCryptographyService: SharedCryptographyService
id: item.id,
name: encrypt(item.name, withKey: symmetricKey) ?? "",
totpKey: encrypt(item.totpKey, withKey: symmetricKey),
username: encrypt(item.username, withKey: symmetricKey)
username: encrypt(item.username, withKey: symmetricKey),
)
}
}
Expand All @@ -106,11 +106,11 @@ public class DefaultAuthenticatorCryptographyService: SharedCryptographyService
return nil
}
let encryptedSealedBox = try AES.GCM.SealedBox(
combined: data
combined: data,
)
let decryptedBox = try AES.GCM.open(
encryptedSealedBox,
using: key
using: key,
)
return String(data: decryptedBox, encoding: .utf8)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public protocol SharedKeychainRepository {
/// - Returns: The time the user should be automatically logged out. If `nil`, then the user should not be.
///
func getAccountAutoLogoutTime(
userId: String
userId: String,
) async throws -> Date?

/// Sets when a user account should automatically log out.
Expand All @@ -40,7 +40,7 @@ public protocol SharedKeychainRepository {
///
func setAccountAutoLogoutTime(
_ value: Date?,
userId: String
userId: String,
) async throws
}

Expand Down Expand Up @@ -94,7 +94,7 @@ public class DefaultSharedKeychainRepository: SharedKeychainRepository {
///
public func setAccountAutoLogoutTime(
_ value: Date?,
userId: String
userId: String,
) async throws {
try await storage.setValue(value, for: .accountAutoLogout(userId: userId))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class SharedKeychainRepositoryTests: BitwardenTestCase {
override func setUp() {
storage = MockSharedKeychainStorage()
subject = DefaultSharedKeychainRepository(
storage: storage
storage: storage,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public enum SharedKeychainServiceError: Error, Equatable, CustomNSError {
public var errorUserInfo: [String: Any] {
switch self {
case let .keyNotFound(keychainItem):
return ["Keychain Item": keychainItem.unformattedKey]
["Keychain Item": keychainItem.unformattedKey]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public class DefaultSharedKeychainStorage: SharedKeychainStorage {
/// - sharedAppGroupIdentifier: An identifier for the shared access group used by the application.
public init(
keychainService: SharedKeychainService,
sharedAppGroupIdentifier: String
sharedAppGroupIdentifier: String,
) {
self.keychainService = keychainService
self.sharedAppGroupIdentifier = sharedAppGroupIdentifier
Expand All @@ -89,7 +89,7 @@ public class DefaultSharedKeychainStorage: SharedKeychainStorage {
kSecAttrAccessGroup: sharedAppGroupIdentifier,
kSecAttrAccount: item.unformattedKey,
kSecClass: kSecClassGenericPassword,
] as CFDictionary
] as CFDictionary,
)
}

Expand All @@ -103,7 +103,7 @@ public class DefaultSharedKeychainStorage: SharedKeychainStorage {
kSecAttrAccessible: kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly,
kSecAttrAccount: item.unformattedKey,
kSecClass: kSecClassGenericPassword,
] as CFDictionary
] as CFDictionary,
)

guard let resultDictionary = foundItem as? [String: Any],
Expand All @@ -128,7 +128,7 @@ public class DefaultSharedKeychainStorage: SharedKeychainStorage {
try? keychainService.delete(query: query)

try keychainService.add(
attributes: query
attributes: query,
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final class SharedKeychainStorageTests: BitwardenTestCase {
keychainService = MockSharedKeychainService()
subject = DefaultSharedKeychainStorage(
keychainService: keychainService,
sharedAppGroupIdentifier: accessGroup
sharedAppGroupIdentifier: accessGroup,
)
}

Expand Down
4 changes: 2 additions & 2 deletions AuthenticatorBridgeKit/SharedTimeoutService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public final class DefaultSharedTimeoutService: SharedTimeoutService {

public init(
sharedKeychainRepository: SharedKeychainRepository,
timeProvider: TimeProvider
timeProvider: TimeProvider,
) {
self.sharedKeychainRepository = sharedKeychainRepository
self.timeProvider = timeProvider
Expand All @@ -67,7 +67,7 @@ public final class DefaultSharedTimeoutService: SharedTimeoutService {
public func updateTimeout(
forUserId userId: String,
lastActiveDate: Date?,
timeoutLength: SessionTimeoutValue
timeoutLength: SessionTimeoutValue,
) async throws {
guard let lastActiveDate else {
try await clearTimeout(forUserId: userId)
Expand Down
Loading