-
Notifications
You must be signed in to change notification settings - Fork 0
/
keychain-access-control.cc
45 lines (35 loc) · 1.47 KB
/
keychain-access-control.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil -*- */
/*
* Copyright (c) 2013, Yingdi Yu
* Author: Yingdi Yu <[email protected]>
*/
#include <CoreFoundation/CoreFoundation.h>
#include <Security/Security.h>
#include <CoreServices/CoreServices.h>
#include <iostream>
using namespace std;
int main (int argc, char** argv)
{
OSStatus res;
SecKeychainRef targetKeychain;
SecKeychainRef originKeychain;
res = SecKeychainCreate ("example.keychain", 4, "1234", false, NULL, &targetKeychain);
if(errSecDuplicateKeychain == res)
res = SecKeychainOpen ("example.keychain", &targetKeychain);
cerr << "Create/Open keychain res: " << res << endl;
res = SecKeychainCopyDefault (&originKeychain);
cerr << "Get default keychain res: " << res << endl;
res = SecKeychainSetDefault (targetKeychain);
cerr << "Set default keychain res: " << res << endl;
// SecKeychainCopyAccess is not implemented in Mac OS X 10.8. Let's try it in later version.
// SecAccessRef keychainAccess;
// CFArrayRef keychainAclList;
// res = SecKeychainCopyAccess (targetKeychain, &keychainAccess);
// cerr << "SecKeychainCopyAccess res: " << res << endl;
// res = SecAccessCopyACLList (keychainAccess, &keychainAclList);
// cerr << "SecAccessCopyACLList res: " << res << endl;
// cerr << "Number of ACL lists: " << CFArrayGetCount(keychainAclList) << endl;
res = SecKeychainSetDefault (originKeychain);
cerr << "Set default keychain back res: " << res << endl;
return 0;
}