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