2 // ToolsViewController.m
5 // Created by john on 10/22/12.
9 #import "ToolsViewController.h"
10 #import "MyKeychain.h"
12 #include <CKBridge/SOSCloudKeychainClient.h>
13 #include <Security/SecureObjectSync/SOSCloudCircle.h>
14 #include <Security/SecureObjectSync/SOSCloudCircleInternal.h>
16 #include <dispatch/dispatch.h>
17 //#include <utilities/SecCFWrappers.h>
19 #include <CoreFoundation/CoreFoundation.h>
20 #include <CoreFoundation/CFUserNotification.h>
22 #import <QuartzCore/QuartzCore.h>
23 #include <Regressions/SOSTestDataSource.h>
24 #include <securityd/SOSCloudCircleServer.h>
25 #include <CKBridge/SOSCloudKeychainConstants.h>
26 //#import "PeerListCell.h"
28 static const uint64_t maxTimeToWaitInSeconds = 30ull * NSEC_PER_SEC;
30 static bool testClearAll(void *sender)
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);
37 SOSCloudKeychainClearAll(processQueue, ^(CFDictionaryRef returnedValues, CFErrorRef error)
40 // secerror("SOSCloudKeychainClearAll returned: %@", error);
41 dispatch_async(dispatch_get_main_queue(),
43 NSLog(@"Updating because of notification");
46 dispatch_semaphore_signal(waitSemaphore);
49 dispatch_semaphore_wait(waitSemaphore, finishTime);
50 //ARC dispatch_release(waitSemaphore);
51 // secerror("SOSCloudKeychainClearAll exit");
55 static void apply_block_1(const void *value, void *context)
57 return ((__bridge void (^)(const void *value))context)(value);
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));
64 static void dumpCircleInfo()
66 CFErrorRef error = NULL;
67 CFArrayRef applicantPeerInfos = NULL;
68 CFArrayRef peerInfos = NULL;
71 NSArray *ccmsgs = @[@"Error", @"InCircle", @"NotInCircle", @"RequestPending", @"CircleAbsent" ];
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]);
79 // Now look at current applicants
80 applicantPeerInfos = SOSCCCopyApplicantPeerInfo(&error);
81 if (applicantPeerInfos)
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);
91 NSLog(@"No applicants, error: %@", error);
94 peerInfos = SOSCCCopyPeerPeerInfo(&error);
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);
105 NSLog(@"No peers, error: %@", error);
109 @interface ToolsViewController ()
112 @implementation ToolsViewController
117 // Do any additional setup after loading the view, typically from a nib.
118 [self setStatus:@"Idle…"];
121 - (void)didReceiveMemoryWarning
123 [super didReceiveMemoryWarning];
124 // Dispose of any resources that can be recreated.
127 - (void)addPasswordItem:(NSString *)account service:(NSString *)service password:(NSString *) thePassword
129 [[MyKeychain sharedInstance] setPasswordFull:account service:service password:thePassword];
132 - (IBAction)handleAutoPopulate:(id)sender
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"];
146 - (IBAction)handleClearKeychain:(id)sender
148 NSLog(@"Clear All Keychain Items");
149 [[MyKeychain sharedInstance] clearAllKeychainItems];
152 - (IBAction)handleClearKVS:(id)sender
154 testClearAll((__bridge void *)(self));
157 - (IBAction)resetToEmpty:(id)sender
159 SOSCCResetToEmpty(NULL);
162 - (IBAction)handleDumpButton:(id)sender
167 - (IBAction)handleSync:(id)sender
169 //SOSCCSyncWithAllPeers();
173 - (void)setStatus:(NSString *)message
175 NSLog(@"%@", message);
176 _statusMessage.text = message;