-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add accessibility support to
SecKey
, SecKeyPair
, SecCertificate
…
… & `SecIdentity` Allows selecting accessibility (i.e. `kSecAttrAccessible`) when generating or saving items. As a requirement we add `kSecUseDataProtectionKeychain` to keychain requests. This has the benefit of normalizing keychain access across macOS & iOS, tvOS, watchOS); allowing the removal of the last usage of `#if os(macOS)/#endif` when accessing the keychain. `SecKey.attributes()` now retrieves _all_ attributes from using `SecItemCopyMatching` instead of `SecKeyCopyAttributes`; this is backward compatible with previous functionality with _more_ attributes. `SecKey.keyAttributes()` can be used to get previous _smaller_ list of attributes (which may also be faster).
- Loading branch information
Showing
8 changed files
with
236 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// | ||
// SecAccessibility.swift | ||
// Shield | ||
// | ||
// Copyright © 2021 Outfox, inc. | ||
// | ||
// | ||
// Distributed under the MIT License, See LICENSE for details. | ||
// | ||
|
||
import Security | ||
|
||
|
||
public enum SecAccessibility: Equatable { | ||
case `default` | ||
case unlocked(afterFirst: Bool, shared: Bool) | ||
case passcodeEnabled | ||
#if ACCESSIBILITY_ALWAYS_ENABLED | ||
case always(shared: Bool) | ||
#endif | ||
} | ||
|
||
|
||
extension SecAccessibility { | ||
|
||
var attr: Any { | ||
|
||
switch self { | ||
|
||
#if ACCESSIBILITY_ALWAYS_ENABLED | ||
case .always(shared: true): | ||
return kSecAttrAccessibleAlways as String | ||
|
||
case .always(shared: false): | ||
return kSecAttrAccessibleAlwaysThisDeviceOnly as String | ||
#endif | ||
|
||
case .unlocked(afterFirst: true, shared: true): | ||
return kSecAttrAccessibleAfterFirstUnlock as String | ||
|
||
case .unlocked(afterFirst: true, shared: false): | ||
return kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly as String | ||
|
||
case .unlocked(afterFirst: false, shared: true), .default: | ||
return kSecAttrAccessibleWhenUnlocked as String | ||
|
||
case .unlocked(afterFirst: false, shared: false): | ||
return kSecAttrAccessibleWhenUnlockedThisDeviceOnly as String | ||
|
||
case .passcodeEnabled: | ||
return kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly as String | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.