|
8 | 8 | return [errString cStringUsingEncoding:[NSString defaultCStringEncoding]];
|
9 | 9 | }
|
10 | 10 |
|
| 11 | +// Returns a string describing the name of the default browser set for the user, nil in case of error. |
11 | 12 | const char *getDefaultBrowserName() {
|
12 | 13 | NSURL *defaultBrowserURL = [[NSWorkspace sharedWorkspace] URLForApplicationToOpenURL:[NSURL URLWithString:@"http://"]];
|
13 | 14 | if (defaultBrowserURL) {
|
|
87 | 88 | return "";
|
88 | 89 | }
|
89 | 90 |
|
90 |
| -const char *certInKeychain() { |
91 |
| - // Each line is a key-value of the dictionary. Note: the the inverted order, value first then key. |
92 |
| - NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys: |
93 |
| - (id)kSecClassCertificate, kSecClass, |
94 |
| - CFSTR("Arduino"), kSecAttrLabel, |
95 |
| - kSecMatchLimitOne, kSecMatchLimit, |
96 |
| - kCFBooleanTrue, kSecReturnAttributes, |
97 |
| - nil]; |
| 91 | +const bool certInKeychain() { |
| 92 | + // Create a key-value dictionary used to query the Keychain and look for the "Arduino" root certificate. |
| 93 | + NSDictionary *getquery = @{ |
| 94 | + (id)kSecClass: (id)kSecClassCertificate, |
| 95 | + (id)kSecAttrLabel: @"Arduino", |
| 96 | + (id)kSecReturnRef: @YES, |
| 97 | + }; |
98 | 98 |
|
99 |
| - OSStatus err = noErr; |
100 |
| - // Use this function to check for errors |
101 |
| - err = SecItemCopyMatching((CFDictionaryRef)dict, nil); |
102 |
| - NSString *exists = @"false"; |
103 |
| - if (err == noErr) { |
104 |
| - exists = @"true"; |
105 |
| - } |
106 |
| - return [exists cStringUsingEncoding:[NSString defaultCStringEncoding]]; |
| 99 | + OSStatus err = SecItemCopyMatching((CFDictionaryRef)getquery, nil); |
| 100 | + return (err == noErr); // No error means the certificate was found, otherwise err will be "errSecItemNotFound". |
107 | 101 | }
|
108 | 102 |
|
109 | 103 | // Returns the expiration date "kSecOIDX509V1ValidityNotAfter" of the Arduino certificate.
|
|
0 commit comments