@@ -89,6 +89,40 @@ const char *uninstallCert() {
89
89
}
90
90
return "";
91
91
}
92
+
93
+ const char *getExpirationDate(){
94
+ // Create a key-value dictionary used to query the Keychain and look for the "Arduino" root certificate.
95
+ NSDictionary *getquery = @{
96
+ (id)kSecClass: (id)kSecClassCertificate,
97
+ (id)kSecAttrLabel: @"Arduino",
98
+ (id)kSecReturnRef: @YES,
99
+ };
100
+
101
+ OSStatus err = noErr;
102
+ SecCertificateRef cert = NULL;
103
+
104
+ // Use this function to check for errors
105
+ err = SecItemCopyMatching((CFDictionaryRef)getquery, (CFTypeRef *)&cert);
106
+
107
+ if (err != errSecItemNotFound && err != noErr){
108
+ NSString *errString = [@"Error: " stringByAppendingFormat:@"%d", err];
109
+ NSLog(@"%@", errString);
110
+ return "";
111
+ }
112
+
113
+ // Get data from the certificate. We just need the "invalidity date" property.
114
+ CFDictionaryRef valuesDict = SecCertificateCopyValues(cert, (__bridge CFArrayRef)@[(__bridge id)kSecOIDInvalidityDate], NULL);
115
+
116
+ // TODO: Error checking.
117
+ CFDictionaryRef invalidityDateDictionaryRef = CFDictionaryGetValue(valuesDict, kSecOIDInvalidityDate);
118
+ CFTypeRef invalidityRef = CFDictionaryGetValue(invalidityDateDictionaryRef, kSecPropertyKeyValue);
119
+ id expirationDateValue = CFBridgingRelease(invalidityRef);
120
+
121
+ CFRelease(valuesDict);
122
+
123
+ NSString *outputString = [@"" stringByAppendingFormat:@"%@", expirationDateValue];
124
+ return [outputString cStringUsingEncoding:[NSString defaultCStringEncoding]];
125
+ }
92
126
*/
93
127
import "C"
94
128
import (
@@ -131,3 +165,14 @@ func UninstallCertificates() error {
131
165
}
132
166
return nil
133
167
}
168
+
169
+ // GetExpirationDate returns the expiration date of a certificate stored in the keychain
170
+ func GetExpirationDate () (string , error ) {
171
+ log .Infof ("Retrieving certificate's expiration date" )
172
+ p := C .getExpirationDate ()
173
+ s := C .GoString (p )
174
+ if len (s ) != 0 {
175
+ return s , nil
176
+ }
177
+ return "" , nil
178
+ }
0 commit comments