1 #include <Security/SecKeychain.h>
2 #include <Security/SecKeychainPriv.h>
4 #include "keychain_regressions.h"
5 #include "kc-helpers.h"
7 int kc_45_change_password(int argc
, char *const *argv
)
11 initializeKeychainTests(__FUNCTION__
);
13 ok_status(SecKeychainSetUserInteractionAllowed(FALSE
), "SecKeychainSetUserInteractionAllowed(FALSE)");
15 SecKeychainRef keychain
= createNewKeychain("test", "before");
16 ok_status(SecKeychainLock(keychain
), "SecKeychainLock");
17 is_status(SecKeychainChangePassword(keychain
, 0, NULL
, 5, "after"), errSecInteractionNotAllowed
, "Change PW w/ null pw while locked"); // We're not responding to prompt so we can't do stuff while locked
18 checkPrompts(1, "Prompt to unlock keychain before password change");
19 is_status(SecKeychainChangePassword(keychain
, 5, "badpw", 5, "after"), errSecAuthFailed
, "Change PW w/ bad pw while locked");
20 ok_status(SecKeychainUnlock(keychain
, 6, "before", true), "SecKeychainUnlock");
21 is_status(SecKeychainChangePassword(keychain
, 0, NULL
, 5, "after"), errSecAuthFailed
, "Change PW w/ null pw while unlocked");
22 is_status(SecKeychainChangePassword(keychain
, 5, "badpw", 5, "after"), errSecAuthFailed
, "Change PW w/ bad pw while unlocked");
23 ok_status(SecKeychainChangePassword(keychain
, 6, "before", 7, "between"), "Change PW w/ good pw while unlocked");
24 ok_status(SecKeychainLock(keychain
), "SecKeychainLock");
25 ok_status(SecKeychainChangePassword(keychain
, 7, "between", 7, "after"), "Change PW w/ good pw while locked");
26 checkPrompts(0, "Unexpected keychain access prompt");
28 ok_status(SecKeychainDelete(keychain
), "%s: SecKeychainDelete", testName
);