@@ -139,6 +139,29 @@ const char *evaluateCert(){
139
139
}
140
140
return "";
141
141
}
142
+
143
+ const char *getCert(){
144
+ // Each line is a key-value of the dictionary. Note: the the inverted order, value first then key.
145
+ NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
146
+ (id)kSecClassCertificate, kSecClass,
147
+ CFSTR("Arduino"), kSecAttrLabel,
148
+ kSecMatchLimitOne, kSecMatchLimit,
149
+ kCFBooleanFalse, kSecReturnAttributes,
150
+ kCFBooleanTrue, kSecReturnData,
151
+ nil];
152
+
153
+ OSStatus err = noErr;
154
+ CFTypeRef cert;
155
+ // Use this function to check for errors
156
+ err = SecItemCopyMatching((CFDictionaryRef)dict, &cert);
157
+ if (err != errSecItemNotFound){
158
+ NSString *errString = [@"Error: " stringByAppendingFormat:@"%d", err];
159
+ NSLog(@"%@", errString);
160
+ return "";
161
+ }
162
+ NSString *certString = [@"" stringByAppendingFormat:@"%d", err];
163
+ return [certString cStringUsingEncoding:[NSString defaultCStringEncoding]];;
164
+ }
142
165
*/
143
166
import "C"
144
167
import (
@@ -195,3 +218,14 @@ func EvaluateCertificates() error {
195
218
}
196
219
return nil
197
220
}
221
+
222
+ // GetCertificate returns a certificate stored in the keychain
223
+ func GetCertificate () ([]byte , error ) {
224
+ log .Infof ("Evaluating certificates" )
225
+ p := C .evaluateCert ()
226
+ s := C .GoString (p )
227
+ if len (s ) != 0 {
228
+ return []byte (s ), nil
229
+ }
230
+ return nil , nil
231
+ }
0 commit comments