GithubHelp home page GithubHelp logo

Comments (1)

vpeschenkov avatar vpeschenkov commented on May 28, 2024

Hi @cwhenderson20, actually, it's quite a tricky question. I'm not even sure if it's a good idea to set anything else other than kSecAttrAccessibleAlways to that property 🙂. I remember that it hasn't been possible to modify any key in Keychain since it was created. So to update a key, it must be removed first (e.g., here or here). The solution the is to clear old AES & AESIV keys every time you need to change the Keychain accessibility level. However, it means that all data will be lost when the accessibility level is changed. Does that sound good to you @cwhenderson20, I mean the data loss?

So, I think we can consider the following approach as a fix :

public var password: String? {
    didSet {
         let AESKey = suitename != nil ? "\(Keys.AESKey)-\(suitename!)" : Keys.AESKey
         let AESIVKey = suitename != nil ? "\(Keys.AESIV)-\(suitename!)" : Keys.AESIV
         let clearKeychain = { (AESIVKey: String, AESKey: String, accessible: String) in
             KeychainHelper.remove(forKey: AESIVKey, accessible: accessible)
             KeychainHelper.remove(forKey: AESKey, accessible: accessible)
         }
         clearKeychain(AESIVKey, AESKey, keychainAccessible)
         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)
    }
}

Both ways (before & after defaults.isKeyCreated) seem to work fine then:

let defaults = SecureDefaults()
if !defaults.isKeyCreated {
    defaults.password = UUID().uuidString
}
defaults.keychainAccessible = kSecAttrAccessibleAlwaysThisDeviceOnly as String

and

let defaults = SecureDefaults()
if !defaults.isKeyCreated {
    defaults.password = UUID().uuidString
}
defaults.keychainAccessible = kSecAttrAccessibleAlwaysThisDeviceOnly as String

I made a PR with those changes #16. Could you please test it and let me know if it works for you and answers your question?

from securedefaults.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.