File tree 4 files changed +39
-3
lines changed
4 files changed +39
-3
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,25 @@ const char *getDefaultBrowserName() {
150
150
151
151
return "";
152
152
}
153
+
154
+ const char *certInKeychain() {
155
+ // Each line is a key-value of the dictionary. Note: the the inverted order, value first then key.
156
+ NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
157
+ (id)kSecClassCertificate, kSecClass,
158
+ CFSTR("Arduino"), kSecAttrLabel,
159
+ kSecMatchLimitOne, kSecMatchLimit,
160
+ kCFBooleanTrue, kSecReturnAttributes,
161
+ nil];
162
+
163
+ OSStatus err = noErr;
164
+ // Use this function to check for errors
165
+ err = SecItemCopyMatching((CFDictionaryRef)dict, nil);
166
+ NSString *exists = @"false";
167
+ if (err == noErr) {
168
+ exists = @"true";
169
+ }
170
+ return [exists cStringUsingEncoding:[NSString defaultCStringEncoding]];;
171
+ }
153
172
*/
154
173
import "C"
155
174
import (
@@ -213,3 +232,14 @@ func GetDefaultBrowserName() string {
213
232
p := C .getDefaultBrowserName ()
214
233
return C .GoString (p )
215
234
}
235
+
236
+ // CertInKeychain checks if the certificate is stored inside the keychain
237
+ func CertInKeychain () bool {
238
+ log .Infof ("Checking if the Arduino certificate is in the keychain" )
239
+ p := C .certInKeychain ()
240
+ s := C .GoString (p )
241
+ if s == "true" {
242
+ return true
243
+ }
244
+ return false
245
+ }
Original file line number Diff line number Diff line change @@ -48,3 +48,9 @@ func GetDefaultBrowserName() string {
48
48
log .Warn ("platform not supported for retrieving default browser name" )
49
49
return ""
50
50
}
51
+
52
+ // CertInKeychain won't do anything on unsupported Operative Systems
53
+ func CertInKeychain () bool {
54
+ log .Warn ("platform not supported for verifying the certificate existence" )
55
+ return false
56
+ }
Original file line number Diff line number Diff line change @@ -227,7 +227,7 @@ func loop() {
227
227
if exist , err := installCertsKeyExists (configPath .String ()); err != nil {
228
228
log .Panicf ("config.ini cannot be parsed: %s" , err )
229
229
} else if ! exist {
230
- if config .CertsExist () {
230
+ if cert . CertInKeychain () || config .CertsExist () {
231
231
err = config .SetInstallCertsIni (configPath .String (), "true" )
232
232
if err != nil {
233
233
log .Panicf ("config.ini cannot be parsed: %s" , err )
@@ -373,7 +373,7 @@ func loop() {
373
373
374
374
// check if the HTTPS certificates are expired or expiring and prompt the user to update them on macOS
375
375
if runtime .GOOS == "darwin" && * installCerts {
376
- if config .CertsExist () {
376
+ if cert . CertInKeychain () || config .CertsExist () {
377
377
certDir := config .GetCertificatesDir ()
378
378
if expired , err := cert .IsExpired (); err != nil {
379
379
log .Errorf ("cannot check if certificates are expired something went wrong: %s" , err )
Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ func (s *Systray) start() {
97
97
buttons := "{\" OK\" , \" Install the certificate for Safari\" }"
98
98
defaultButton := "Install the certificate for Safari"
99
99
certDir := config .GetCertificatesDir ()
100
- if config .CertsExist () {
100
+ if cert . CertInKeychain () || config .CertsExist () {
101
101
expDate , err := cert .GetExpirationDate ()
102
102
if err != nil {
103
103
log .Errorf ("cannot get certificates expiration date, something went wrong: %s" , err )
You can’t perform that action at this time.
0 commit comments