]> git.saurik.com Git - apple/security.git/blob - Keychain/ToolsViewController.m
Security-57336.1.9.tar.gz
[apple/security.git] / Keychain / ToolsViewController.m
1 //
2 // ToolsViewController.m
3 // Keychain
4 //
5 // Created by john on 10/22/12.
6 //
7 //
8
9 #import "ToolsViewController.h"
10 #import "MyKeychain.h"
11
12 #include <CKBridge/SOSCloudKeychainClient.h>
13 #include <Security/SecureObjectSync/SOSCloudCircle.h>
14 #include <Security/SecureObjectSync/SOSCloudCircleInternal.h>
15 #include <notify.h>
16 #include <dispatch/dispatch.h>
17 //#include <utilities/SecCFWrappers.h>
18
19 #include <CoreFoundation/CoreFoundation.h>
20 #include <CoreFoundation/CFUserNotification.h>
21
22 #import <QuartzCore/QuartzCore.h>
23 #include <Regressions/SOSTestDataSource.h>
24 #include <securityd/SOSCloudCircleServer.h>
25 #include <CKBridge/SOSCloudKeychainConstants.h>
26 //#import "PeerListCell.h"
27
28 static const uint64_t maxTimeToWaitInSeconds = 30ull * NSEC_PER_SEC;
29
30 static bool testClearAll(void *sender)
31 {
32 __block bool result = false;
33 dispatch_queue_t processQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
34 dispatch_semaphore_t waitSemaphore = dispatch_semaphore_create(0);
35 dispatch_time_t finishTime = dispatch_time(DISPATCH_TIME_NOW, maxTimeToWaitInSeconds);
36
37 SOSCloudKeychainClearAll(processQueue, ^(CFDictionaryRef returnedValues, CFErrorRef error)
38 {
39 result = true;
40 // secerror("SOSCloudKeychainClearAll returned: %@", error);
41 dispatch_async(dispatch_get_main_queue(),
42 ^{
43 NSLog(@"Updating because of notification");
44 });
45
46 dispatch_semaphore_signal(waitSemaphore);
47 });
48
49 dispatch_semaphore_wait(waitSemaphore, finishTime);
50 //ARC dispatch_release(waitSemaphore);
51 // secerror("SOSCloudKeychainClearAll exit");
52 return result;
53 }
54
55 static void apply_block_1(const void *value, void *context)
56 {
57 return ((__bridge void (^)(const void *value))context)(value);
58 }
59
60 static inline void CFArrayForEach(CFArrayRef array, void (^operation)(const void *value)) {
61 CFArrayApplyFunction(array, CFRangeMake(0, CFArrayGetCount(array)), apply_block_1, (__bridge void *)(operation));
62 }
63
64 static void dumpCircleInfo()
65 {
66 CFErrorRef error = NULL;
67 CFArrayRef applicantPeerInfos = NULL;
68 CFArrayRef peerInfos = NULL;
69 int idx;
70
71 NSArray *ccmsgs = @[@"Error", @"InCircle", @"NotInCircle", @"RequestPending", @"CircleAbsent" ];
72
73 SOSCCStatus ccstatus = SOSCCThisDeviceIsInCircle(&error);
74 NSLog(@"ccstatus: %d, error: %@", ccstatus, error);
75 idx = ccstatus-kSOSCCError;
76 if (0<=idx && idx<(int)[ccmsgs count])
77 NSLog(@"ccstatus: %d (%@)", ccstatus, ccmsgs[idx]);
78
79 // Now look at current applicants
80 applicantPeerInfos = SOSCCCopyApplicantPeerInfo(&error);
81 if (applicantPeerInfos)
82 {
83 NSLog(@"Applicants: %ld, error: %@", (long)CFArrayGetCount(applicantPeerInfos), error);
84 CFArrayForEach(applicantPeerInfos, ^(const void *value) {
85 SOSPeerInfoRef peer = (SOSPeerInfoRef)value;
86 CFStringRef peerName = SOSPeerInfoGetPeerName(peer);
87 NSLog(@"Applicant: %@", peerName);
88 });
89 }
90 else
91 NSLog(@"No applicants, error: %@", error);
92
93
94 peerInfos = SOSCCCopyPeerPeerInfo(&error);
95 if (peerInfos)
96 {
97 NSLog(@"Peers: %ld, error: %@", (long)CFArrayGetCount(peerInfos), error);
98 CFArrayForEach(peerInfos, ^(const void *value) {
99 SOSPeerInfoRef peer = (SOSPeerInfoRef)value;
100 CFStringRef peerName = SOSPeerInfoGetPeerName(peer);
101 NSLog(@"Peer: %@", peerName);
102 });
103 }
104 else
105 NSLog(@"No peers, error: %@", error);
106 }
107
108
109 @interface ToolsViewController ()
110 @end
111
112 @implementation ToolsViewController
113
114 - (void)viewDidLoad
115 {
116 [super viewDidLoad];
117 // Do any additional setup after loading the view, typically from a nib.
118 [self setStatus:@"Idle…"];
119 }
120
121 - (void)didReceiveMemoryWarning
122 {
123 [super didReceiveMemoryWarning];
124 // Dispose of any resources that can be recreated.
125 }
126
127 - (void)addPasswordItem:(NSString *)account service:(NSString *)service password:(NSString *) thePassword
128 {
129 [[MyKeychain sharedInstance] setPasswordFull:account service:service password:thePassword];
130 }
131
132 - (IBAction)handleAutoPopulate:(id)sender
133 {
134 [self addPasswordItem:@"12345678" service:@"Evernote" password:@"fiord42/sate"];
135 [self addPasswordItem:@"acct2433" service:@"SwissBank" password:@"nerd0)sorely"];
136 [self addPasswordItem:@"QR49BZQ77" service:@"Wells Fargo" password:@"per1}bargirl"];
137 [self addPasswordItem:@"03991993-9291" service:@"Bank of America" password:@"dabs35\angst"];
138 [self addPasswordItem:@"followme" service:@"Twitter" password:@"mica86[board"];
139 [self addPasswordItem:@"j18373@apple.com" service:@"Mail" password:@"macro13:VIII"];
140 [self addPasswordItem:@"j18373" service:@"Facebook" password:@"vow5:karakul"];
141 [self addPasswordItem:@"lonely22" service:@"G+Circles" password:@"vclub17'earls"];
142 [self addPasswordItem:@"yoyo9182" service:@"Skype" password:@"Andy137#FAQs"];
143 [self addPasswordItem:@"terminator3828" service:@"Blizzard" password:@"David95?hive"];
144 }
145
146 - (IBAction)handleClearKeychain:(id)sender
147 {
148 NSLog(@"Clear All Keychain Items");
149 [[MyKeychain sharedInstance] clearAllKeychainItems];
150 }
151
152 - (IBAction)handleClearKVS:(id)sender
153 {
154 testClearAll((__bridge void *)(self));
155 }
156
157 - (IBAction)resetToEmpty:(id)sender
158 {
159 SOSCCResetToEmpty(NULL);
160 }
161
162 - (IBAction)handleDumpButton:(id)sender
163 {
164 dumpCircleInfo();
165 }
166
167 - (IBAction)handleSync:(id)sender
168 {
169 //SOSCCSyncWithAllPeers();
170 }
171
172 //bool
173 - (void)setStatus:(NSString *)message
174 {
175 NSLog(@"%@", message);
176 _statusMessage.text = message;
177 }
178
179 @end
180