2 * secd-31-keychain-unreadable.c
5 * Created by Michael Brouwer on 5/23/08.
6 * Copyright (c) 2008-2010,2013 Apple Inc. All Rights Reserved.
10 #include <CoreFoundation/CoreFoundation.h>
11 #include <Security/SecBase.h>
12 #include <Security/SecItem.h>
13 #include <Security/SecInternal.h>
14 #include <utilities/SecFileLocations.h>
15 #include <utilities/SecCFWrappers.h>
23 #include "secd_regressions.h"
25 #include <securityd/SecItemServer.h>
27 #include "SecdTestKeychainUtilities.h"
30 /* Create an empty keychain file that can't be read or written and make sure
31 securityd can deal with it. */
32 static void tests(void)
34 /* custom keychain dir */
35 secd_test_setup_temp_keychain("secd_31_keychain_unreadable", ^{
36 CFStringRef keychain_path_cf
= __SecKeychainCopyPath();
38 CFStringPerformWithCString(keychain_path_cf
, ^(const char *keychain_path
) {
40 ok_unix(fd
= open(keychain_path
, O_RDWR
| O_CREAT
| O_TRUNC
, 0644),
41 "create keychain file '%s'", keychain_path
);
42 ok_unix(fchmod(fd
, 0), " keychain file '%s'", keychain_path
);
43 ok_unix(close(fd
), "close keychain file '%s'", keychain_path
);
47 CFReleaseSafe(keychain_path_cf
);
51 CFNumberRef eighty
= CFNumberCreate(NULL
, kCFNumberSInt32Type
, &v_eighty
);
52 const char *v_data
= "test";
53 CFDataRef pwdata
= CFDataCreate(NULL
, (UInt8
*)v_data
, strlen(v_data
));
54 CFMutableDictionaryRef query
= CFDictionaryCreateMutable(NULL
, 0, NULL
, NULL
);
55 CFDictionaryAddValue(query
, kSecClass
, kSecClassInternetPassword
);
56 CFDictionaryAddValue(query
, kSecAttrServer
, CFSTR("members.spamcop.net"));
57 CFDictionaryAddValue(query
, kSecAttrAccount
, CFSTR("smith"));
58 CFDictionaryAddValue(query
, kSecAttrPort
, eighty
);
59 CFDictionaryAddValue(query
, kSecAttrProtocol
, kSecAttrProtocolHTTP
);
60 CFDictionaryAddValue(query
, kSecAttrAuthenticationType
, kSecAttrAuthenticationTypeDefault
);
61 CFDictionaryAddValue(query
, kSecValueData
, pwdata
);
62 ok_status(SecItemAdd(query
, NULL
), "add internet password");
63 is_status(SecItemAdd(query
, NULL
), errSecDuplicateItem
,
64 "add internet password again");
66 ok_status(SecItemCopyMatching(query
, NULL
), "Found the item we added");
68 ok_status(SecItemDelete(query
),"Deleted the item we added");
70 CFReleaseSafe(eighty
);
71 CFReleaseSafe(pwdata
);
75 int secd_31_keychain_unreadable(int argc
, char *const *argv
)
77 plan_tests(7 + kSecdTestSetupTestCount
);