@@ -61,6 +61,31 @@ const char *installCert(const char *path) {
61
61
return "";
62
62
}
63
63
64
+ const char *uninstallCert() {
65
+ CFStringRef label = CFSTR("Arduino");
66
+ NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
67
+ (id)kSecClassCertificate, kSecClass,
68
+ label, kSecAttrLabel,
69
+ kCFBooleanTrue, kSecReturnAttributes,
70
+ nil];
71
+
72
+ OSStatus err = noErr;
73
+ CFTypeRef itemList;
74
+ err = SecItemCopyMatching((CFDictionaryRef)dict, &itemList);
75
+ if (err == noErr) {
76
+ err = SecItemDelete((CFDictionaryRef)dict);
77
+ if (err != noErr) {
78
+ NSString *errString = [@"Could not delete the certificates. Error: " stringByAppendingFormat:@"%d", err];
79
+ NSLog(@"%@", errString);
80
+ return [errString cStringUsingEncoding:[NSString defaultCStringEncoding]];;
81
+ }
82
+ } else if (err != errSecItemNotFound){
83
+ NSString *errString = [@"Error: " stringByAppendingFormat:@"%d", err];
84
+ NSLog(@"%@", errString);
85
+ return [errString cStringUsingEncoding:[NSString defaultCStringEncoding]];;
86
+ }
87
+ return "";
88
+ }
64
89
*/
65
90
import "C"
66
91
import (
@@ -88,3 +113,17 @@ func InstallCertificate(cert *paths.Path) error {
88
113
}
89
114
return nil
90
115
}
116
+
117
+ // UninstallCertificates will uninstall the certificates from the system keychain on macos,
118
+ // if something goes wrong will show a dialog with the error and return an error
119
+ func UninstallCertificates () error {
120
+ log .Infof ("Uninstalling certificats" )
121
+ p := C .uninstallCert ()
122
+ s := C .GoString (p )
123
+ if len (s ) != 0 {
124
+ oscmd := exec .Command ("osascript" , "-e" , "display dialog \" " + s + "\" buttons \" OK\" with title \" Error uninstalling certificates\" " )
125
+ _ = oscmd .Run ()
126
+ return errors .New (s )
127
+ }
128
+ return nil
129
+ }
0 commit comments