Skip to content

Commit 80311ea

Browse files
committed
add popup on error
1 parent ae66104 commit 80311ea

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

certificates/install_darwin.go

+24-6
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ package certificates
2222
#cgo LDFLAGS: -framework Cocoa
2323
#import <Cocoa/Cocoa.h>
2424
25-
void installCert(const char *path) {
25+
char *installCert(const char *path) {
2626
NSURL *url = [NSURL fileURLWithPath:@(path) isDirectory:NO];
2727
NSData *rootCertData = [NSData dataWithContentsOfURL:url];
2828
2929
OSStatus err = noErr;
30+
NSMutableString *errString = [NSMutableString new];
31+
char *errReturnString = "\0";
3032
SecCertificateRef rootCert = SecCertificateCreateWithData(kCFAllocatorDefault, (CFDataRef) rootCertData);
3133
3234
CFTypeRef result;
@@ -41,22 +43,32 @@ void installCert(const char *path) {
4143
if( err == noErr) {
4244
NSLog(@"Install root certificate success");
4345
} else if( err == errSecDuplicateItem ) {
44-
NSLog(@"duplicate root certificate entry");
46+
errString = [@"duplicate root certificate entry. Error: " stringByAppendingFormat:@"%d ",err];
47+
NSLog(errString);
48+
errReturnString = [errString cStringUsingEncoding:[NSString defaultCStringEncoding]];
49+
return errReturnString;
4550
} else {
46-
NSLog(@"install root certificate failure");
51+
errString = [@"install root certificate failure. Error: " stringByAppendingFormat:@"%d ",err];
52+
NSLog(errString);
53+
errReturnString = [errString cStringUsingEncoding:[NSString defaultCStringEncoding]];
54+
return errReturnString;
4755
}
4856
4957
NSDictionary *newTrustSettings = @{(id)kSecTrustSettingsResult: [NSNumber numberWithInt:kSecTrustSettingsResultTrustRoot]};
5058
err = SecTrustSettingsSetTrustSettings(rootCert, kSecTrustSettingsDomainUser, (__bridge CFTypeRef)(newTrustSettings));
5159
if (err != errSecSuccess) {
52-
NSLog(@"Could not change the trust setting for a certificate. Error: %d", err);
53-
exit(0);
60+
errString = [@"Could not change the trust setting for a certificate. Error: " stringByAppendingFormat:@"%d ",err];
61+
NSLog(errString);
62+
errReturnString = [errString cStringUsingEncoding:[NSString defaultCStringEncoding]];
5463
}
64+
return errReturnString;
5565
}
5666
5767
*/
5868
import "C"
5969
import (
70+
"os/exec"
71+
6072
log "github.com/sirupsen/logrus"
6173

6274
"github.com/arduino/go-paths-helper"
@@ -65,5 +77,11 @@ import (
6577
// InstallCertificate will install the certificates in the system keychain on macos
6678
func InstallCertificate(cert *paths.Path) {
6779
log.Infof("Installing certificate: %s", cert)
68-
C.installCert(C.CString(cert.String()))
80+
p := C.installCert(C.CString(cert.String()))
81+
s := C.GoString(p)
82+
if len(s) != 0 {
83+
oscmd := exec.Command("osascript", "-e", "display dialog \""+s+"\" buttons \"OK\" with title \"Error installing certificates\"")
84+
_ = oscmd.Run()
85+
log.Info(oscmd.String())
86+
}
6987
}

0 commit comments

Comments
 (0)