Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save migueldeicaza/adb5a3ccabab75a14381d02b25d6942e to your computer and use it in GitHub Desktop.
Save migueldeicaza/adb5a3ccabab75a14381d02b25d6942e to your computer and use it in GitHub Desktop.
Dumps passwords from the iOS keychain
func dump () {
let k = kSecClassGenericPassword
let query: [String: Any] = [
kSecClass as String: k,
kSecMatchLimit as String: kSecMatchLimitAll,
kSecReturnRef as String: true,
kSecReturnAttributes as String: true
]
var itemCopy: AnyObject?
let status = SecItemCopyMatching(query as CFDictionary, &itemCopy)
if status != 0 {
print ("Dump passwords is unable to dump")
}
if let array = itemCopy as? NSArray {
print ("Found \(array.count) elements")
for element in array {
if let dict = element as? NSDictionary {
//let ref = dict.object(forKey: kSecValueRef)
if let desc = dict.object(forKey: kSecAttrDescription) {
print (" description = \(desc)")
}
if let comment = dict.object(forKey: kSecAttrComment) {
print (" comment = \(comment)")
}
if let label = dict.object(forKey: kSecAttrLabel) {
print (" label = \(label)")
}
if let account = dict.object(forKey: kSecAttrAccount) {
print (" account = \(account)")
}
}
}
} else {
print ("Dump: was expecting an array, did not get it")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment