@@ -139,6 +139,40 @@ const char *evaluateCert(){
139
139
}
140
140
return "";
141
141
}
142
+
143
+ const char *getExpirationDate(){
144
+ // Create a key-value dictionary used to query the Keychain and look for the "Arduino" root certificate.
145
+ NSDictionary *getquery = @{
146
+ (id)kSecClass: (id)kSecClassCertificate,
147
+ (id)kSecAttrLabel: @"Arduino",
148
+ (id)kSecReturnRef: @YES,
149
+ };
150
+
151
+ OSStatus err = noErr;
152
+ SecCertificateRef cert = NULL;
153
+
154
+ // Use this function to check for errors
155
+ err = SecItemCopyMatching((CFDictionaryRef)getquery, (CFTypeRef *)&cert);
156
+
157
+ if (err != errSecItemNotFound && err != noErr){
158
+ NSString *errString = [@"Error: " stringByAppendingFormat:@"%d", err];
159
+ NSLog(@"%@", errString);
160
+ return "";
161
+ }
162
+
163
+ // Get data from the certificate. We just need the "invalidity date" property.
164
+ CFDictionaryRef valuesDict = SecCertificateCopyValues(cert, (__bridge CFArrayRef)@[(__bridge id)kSecOIDInvalidityDate], NULL);
165
+
166
+ // TODO: Error checking.
167
+ CFDictionaryRef invalidityDateDictionaryRef = CFDictionaryGetValue(valuesDict, kSecOIDInvalidityDate);
168
+ CFTypeRef invalidityRef = CFDictionaryGetValue(invalidityDateDictionaryRef, kSecPropertyKeyValue);
169
+ id expirationDateValue = CFBridgingRelease(invalidityRef);
170
+
171
+ CFRelease(valuesDict);
172
+
173
+ NSString *outputString = [@"" stringByAppendingFormat:@"%@", expirationDateValue];
174
+ return [outputString cStringUsingEncoding:[NSString defaultCStringEncoding]];
175
+ }
142
176
*/
143
177
import "C"
144
178
import (
@@ -195,3 +229,14 @@ func EvaluateCertificates() error {
195
229
}
196
230
return nil
197
231
}
232
+
233
+ // GetExpirationDate returns the expiration date of a certificate stored in the keychain
234
+ func GetExpirationDate () (string , error ) {
235
+ log .Infof ("Retrieving certificate's expiration date" )
236
+ p := C .getExpirationDate ()
237
+ s := C .GoString (p )
238
+ if len (s ) != 0 {
239
+ return s , nil
240
+ }
241
+ return "" , nil
242
+ }
0 commit comments