Skip to content

Commit

Permalink
implemented KeychainReset
Browse files Browse the repository at this point in the history
  • Loading branch information
twocanoes committed Nov 11, 2022
1 parent e36e74d commit 0c34708
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions XCredsLoginPlugIn/Mechanisms/XCredsKeychainAdd.swift
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ class XCredsKeychainAdd : XCredsBaseMechanism {

}
}
else if (getManagedPreference(key: .KeychainReset) as? Bool ?? true ) {
os_log("Resetting keychain password.", log: "", type: .info)
clearKeychain(path: homeDir)
}
else {
TCSLogWithMark("Keychain is locked, exiting.")
allowLogin()
Expand Down Expand Up @@ -246,4 +250,25 @@ class XCredsKeychainAdd : XCredsBaseMechanism {
return (nil, nil)
}
}
func clearKeychain(path: String) {

// find the hardware UUID to kill the local items keychain
let service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOPlatformExpertDevice"))
guard let hardwareRaw = IORegistryEntryCreateCFProperty(service, kIOPlatformUUIDKey as CFString, kCFAllocatorDefault, 0) else { return }
let uuid = hardwareRaw.takeRetainedValue() as? String ?? ""

if uuid != "" {
// we have a uuid, now delete the folder
os_log("Removing local items keychain in order to purge it.", log: "")
do {
try fm.removeItem(atPath: path + "/Library/Keychains/" + uuid)
} catch {
os_log("Unable to remove Local Items folder.", log: "")
}
}

os_log("Resetting keychain.", log: "")

SecKeychainResetLogin(UInt32(userpass.count), userpass, true)
}
}
Binary file not shown.

0 comments on commit 0c34708

Please sign in to comment.