Skip to content

Add the ability to generate SSL certs from tray icon #778

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c611395
move `config.go` to it's own package and make functions public.
umbynos Mar 23, 2023
a5bfc94
move `config.ini` in the right package and remove hack
umbynos Mar 30, 2023
2ce9a06
fix linter
umbynos Mar 30, 2023
ac361f7
move `CrashesIsEmpty` function to the config package and rename it
umbynos Mar 23, 2023
02eacd1
move `certificate.go` in it's own package and make functions public
umbynos Mar 23, 2023
14dfc2b
update license header
umbynos Mar 31, 2023
f7d9772
add menu option to generate the certs only if they are not present
umbynos Mar 28, 2023
1971f9e
systray is useless in this func
umbynos Mar 28, 2023
e83c557
add cert install on macos
umbynos Mar 30, 2023
bcaeb75
add cert install on win
umbynos Apr 7, 2023
7f436f2
fix certificate not being valid for 127.0.0.1
umbynos Apr 6, 2023
3a5cb38
disable the generation/install certs menuItem on OS that are not macos
umbynos Apr 12, 2023
b62a2ff
remove the cert generation from the installer, remove duplicate step
umbynos Apr 14, 2023
2b41a4d
parallelization for notarization is no more required
umbynos Apr 14, 2023
d27ddb0
test new version of the installer config
umbynos Apr 14, 2023
3e7fead
move archive generation in the CI and save a rename operation (we do …
umbynos Apr 17, 2023
0b35ff4
removed `-` in arch matrix variable for clarity
umbynos Apr 17, 2023
b6f6947
Revert "add cert install on win"
umbynos Apr 19, 2023
8007107
add popup on error
umbynos Apr 20, 2023
4dde91e
Fixed warnings in obj-c code
cmaglie Apr 20, 2023
85a7b00
remove the certs if the install process errors. The user is able to r…
umbynos Apr 21, 2023
bda1574
Revert "test new version of the installer config"
umbynos Apr 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add cert install on macos
leverage objective C APIs to install our CA certificate in the user's trusted keystore
  • Loading branch information
umbynos committed Apr 11, 2023
commit e83c5571709e378a0cdf3f93719dca1fca7c3c83
69 changes: 69 additions & 0 deletions certificates/install_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
// Copyright 2023 Arduino SA
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

package certificates

//inspired by https://stackoverflow.com/questions/12798950/ios-install-ssl-certificate-programmatically

/*
#cgo CFLAGS: -x objective-c
#cgo LDFLAGS: -framework Cocoa
#import <Cocoa/Cocoa.h>

void installCert(const char *path) {
NSURL *url = [NSURL fileURLWithPath:@(path) isDirectory:NO];
NSData *rootCertData = [NSData dataWithContentsOfURL:url];

OSStatus err = noErr;
SecCertificateRef rootCert = SecCertificateCreateWithData(kCFAllocatorDefault, (CFDataRef) rootCertData);

CFTypeRef result;

NSDictionary* dict = [NSDictionary dictionaryWithObjectsAndKeys:
(id)kSecClassCertificate, kSecClass,
rootCert, kSecValueRef,
nil];

err = SecItemAdd((CFDictionaryRef)dict, &result);

if( err == noErr) {
NSLog(@"Install root certificate success");
} else if( err == errSecDuplicateItem ) {
NSLog(@"duplicate root certificate entry");
} else {
NSLog(@"install root certificate failure");
}

NSDictionary *newTrustSettings = @{(id)kSecTrustSettingsResult: [NSNumber numberWithInt:kSecTrustSettingsResultTrustRoot]};
err = SecTrustSettingsSetTrustSettings(rootCert, kSecTrustSettingsDomainUser, (__bridge CFTypeRef)(newTrustSettings));
if (err != errSecSuccess) {
NSLog(@"Could not change the trust setting for a certificate. Error: %d", err);
exit(0);
}
}

*/
import "C"
import (
log "github.com/sirupsen/logrus"

"github.com/arduino/go-paths-helper"
)

// InstallCertificate will install the certificates in the system keychain on macos
func InstallCertificate(cert *paths.Path) {
log.Infof("Installing certificate: %s", cert)
C.installCert(C.CString(cert.String()))
}
29 changes: 29 additions & 0 deletions certificates/install_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2023 Arduino SA
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//go:build !darwin

package certificates

import (
log "github.com/sirupsen/logrus"

"github.com/arduino/go-paths-helper"
)

// InstallCertificate won't do anything on unsupported Operative Systems
func InstallCertificate(cert *paths.Path) {
log.Warn("platform not supported for the certificate install")
}
3 changes: 2 additions & 1 deletion systray/systray_real.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func (s *Systray) start() {
mRmCrashes := systray.AddMenuItem("Remove crash reports", "")
s.updateMenuItem(mRmCrashes, config.LogsIsEmpty())

mGenCerts := systray.AddMenuItem("Generate HTTPS certificates", "HTTPS Certs")
mGenCerts := systray.AddMenuItem("Generate and Install HTTPS certificates", "HTTPS Certs")
s.updateMenuItem(mGenCerts, config.CertsExist())

// Add pause/quit
Expand All @@ -90,6 +90,7 @@ func (s *Systray) start() {
s.updateMenuItem(mRmCrashes, config.LogsIsEmpty())
case <-mGenCerts.ClickedCh:
cert.GenerateCertificates(config.GetCertificatesDir())
cert.InstallCertificate(config.GetCertificatesDir().Join("ca.cert.cer"))
s.Restart()
case <-mPause.ClickedCh:
s.Pause()
Expand Down