Skip to content

Commit

Permalink
Clear previously saved items in Keychain (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
vpeschenkov authored May 6, 2024
1 parent 3f9d5d1 commit 06b6dcf
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PODS:
- SecureDefaults (1.0.7)
- SecureDefaults (1.1.0)

DEPENDENCIES:
- SecureDefaults (from `../`)
Expand All @@ -9,8 +9,8 @@ EXTERNAL SOURCES:
:path: "../"

SPEC CHECKSUMS:
SecureDefaults: 09bb6c96fd8cdd31da196853120f4f279207435a
SecureDefaults: 8dcb29ef1a2704b825b0b6b5c6bbf9cf79bb22ca

PODFILE CHECKSUM: 0c88f6a3b94820b9ca6ca078adc6fc94bf5338e2

COCOAPODS: 1.11.2
COCOAPODS: 1.11.3
6 changes: 3 additions & 3 deletions Example/Pods/Local Podspecs/SecureDefaults.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 38 additions & 5 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions Example/SecureDefaults/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@ import SecureDefaults
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
) -> Bool {
// To get some security in your app just replace `NSUserDefaults` by `SecureDefaults` and set a password 😎.
let defaults = SecureDefaults()
if !defaults.isKeyCreated {
defaults.password = UUID().uuidString
}
defaults.keychainAccessible = kSecAttrAccessibleAlwaysThisDeviceOnly as String
defaults.set("Thank you for using SecureDefaults!", forKey: "secure.greeting")
defaults.synchronize()

Expand Down
13 changes: 11 additions & 2 deletions Sources/SecureDefaults/SecureDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,17 @@ public class SecureDefaults: UserDefaults {
didSet {
let AESKey = suitename != nil ? "\(Keys.AESKey)-\(suitename!)" : Keys.AESKey
let AESIVKey = suitename != nil ? "\(Keys.AESIV)-\(suitename!)" : Keys.AESIV
KeychainHelper.remove(forKey: AESIVKey, accessible: keychainAccessible)
KeychainHelper.remove(forKey: AESKey, accessible: keychainAccessible)
let clearKeychain = { (AESIVKey: String, AESKey: String, accessible: String) in
KeychainHelper.remove(forKey: AESIVKey, accessible: accessible)
KeychainHelper.remove(forKey: AESKey, accessible: accessible)
}
clearKeychain(AESIVKey, AESKey, kSecAttrAccessibleWhenUnlocked as String)
clearKeychain(AESIVKey, AESKey, kSecAttrAccessibleAfterFirstUnlock as String)
clearKeychain(AESIVKey, AESKey, kSecAttrAccessibleAlways as String)
clearKeychain(AESIVKey, AESKey, kSecAttrAccessibleWhenPasscodeSetThisDeviceOnly as String)
clearKeychain(AESIVKey, AESKey, kSecAttrAccessibleWhenUnlockedThisDeviceOnly as String)
clearKeychain(AESIVKey, AESKey, kSecAttrAccessibleAfterFirstUnlockThisDeviceOnly as String)
clearKeychain(AESIVKey, AESKey, kSecAttrAccessibleAlwaysThisDeviceOnly as String)
}
}

Expand Down

0 comments on commit 06b6dcf

Please sign in to comment.