Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

add a removeAllKeys or similar #28

Closed
renatosc opened this issue Nov 18, 2015 · 7 comments
Closed

add a removeAllKeys or similar #28

renatosc opened this issue Nov 18, 2015 · 7 comments

Comments

@renatosc
Copy link

First, congrats for the wrapper. Simple and efficient.

I just missed out one function: a removeAllKeys() function that would erase all Keychain items. That is very useful to clean the Keychain on the app first run.

@crashoverride777
Copy link

you need to add these 2 methods to do so.

 class func removeAllData() {
            deleteKeychainSecClass(kSecClassGenericPassword)
           deleteKeychainSecClass(kSecClassInternetPassword)
          deleteKeychainSecClass(kSecClassCertificate)
         deleteKeychainSecClass(kSecClassKey)
         deleteKeychainSecClass(kSecClassIdentity)
      }


   private class func deleteKeychainSecClass(secClass: AnyObject) -> Bool {
           let query = [ kSecClass as String : secClass ]
           let status: OSStatus = SecItemDelete(query as CFDictionaryRef)

          if status == errSecSuccess {
                   return true
           } else {
               return false
           }
      }

@crashoverride777
Copy link

Hey,

Thanks for the post. I was actually considering returning a bool for the deleteMethod as well, however in my case I am only using this method for internal testing so I didnt bother. However there might be situations where you need this method in a regular app so it probably a good idea to return a bool.

Hopefully the author puts this in his awesome helper.

Thanks again.

@jrendel
Copy link
Owner

jrendel commented Mar 23, 2016

Hey guys, I know you've been asking for this. I'm trying to find some time to work on the library, I've got a handful of changes I'd like to put into an update.

@crashoverride777
Copy link

Awesome, looking forward to it. Hope you keep it as simple and great as it is right now. The one thing I would also love to see is an option to directly save Bool and/or Int values, like you can in NSUserDefaults. (boolForKey(...), intForKey(...) )

Thank you for your great helper.

@jrendel
Copy link
Owner

jrendel commented Mar 28, 2016

I pulled the suggested delete operation into a new branch on the repo and started testing. I have mixed feelings about a "delete all" function that has the potential to wipe more than you expected. While I agree its useful, it can also be dangerous if you don't understand what you're doing, so at the very least I want to make sure its well documented before I release it. I've also added a delete that only deletes keys that match your current wrapper settings (service name and access group).

I'm going to be continuing on with several changes for what I'm considering a "v2" of the library, and pull the delete stuff into that. As part of these changes, I will also look at adding convenience functions such as boolForKey, intForKey, etc. I always wanted this to be simple to use, like NSUserDefaults, for someone that has no understanding of keychain. Hence, why it does things like only allow access when the device is unlocked.

At the same time, I also see the potential for users to want more control. So my approach for v2 will more closely follow the pattern established by NSUserDefaults. There will be a "StandardKeychainAccess" or something along those lines, a singleton that gives you quick and easy access with fixed settings. And then the option to create your own keychain wrapper instance with more custom settings such as ServiceName, access group and access level. For backwards compatibility, I'll leave the existing class methods on the wrapper, they will just default to using the standard instance instead of some static state.

I've started this work in a branch called "unstable" as I tend to commit often things that I am working on but also change them often as I think of different or better ways to do something. So you're welcome to track along, but don't get too attached to anything specific :)

@crashoverride777
Copy link

Awesome, thank you very much, looking forward to it.

@jrendel
Copy link
Owner

jrendel commented Jun 21, 2016

This is now part of the 2.0 release I'm working on in the develop branch. Hoping to do a bit more testing and get it pulled through to master soon.

@jrendel jrendel closed this as completed Jun 21, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants