-
-
Notifications
You must be signed in to change notification settings - Fork 150
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
Changes from 10 commits
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 a5bfc94
move `config.ini` in the right package and remove hack
umbynos 2ce9a06
fix linter
umbynos ac361f7
move `CrashesIsEmpty` function to the config package and rename it
umbynos 02eacd1
move `certificate.go` in it's own package and make functions public
umbynos 14dfc2b
update license header
umbynos f7d9772
add menu option to generate the certs only if they are not present
umbynos 1971f9e
systray is useless in this func
umbynos e83c557
add cert install on macos
umbynos bcaeb75
add cert install on win
umbynos 7f436f2
fix certificate not being valid for 127.0.0.1
umbynos 3a5cb38
disable the generation/install certs menuItem on OS that are not macos
umbynos b62a2ff
remove the cert generation from the installer, remove duplicate step
umbynos 2b41a4d
parallelization for notarization is no more required
umbynos d27ddb0
test new version of the installer config
umbynos 3e7fead
move archive generation in the CI and save a rename operation (we do …
umbynos 0b35ff4
removed `-` in arch matrix variable for clarity
umbynos b6f6947
Revert "add cert install on win"
umbynos 8007107
add popup on error
umbynos 4dde91e
Fixed warnings in obj-c code
cmaglie 85a7b00
remove the certs if the install process errors. The user is able to r…
umbynos bda1574
Revert "test new version of the installer config"
umbynos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 && !windows | ||
|
||
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") | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
// 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/>. | ||
|
||
// code inspired by https://github.com/FiloSottile/mkcert licenced under BSD3 | ||
|
||
package certificates | ||
|
||
import ( | ||
"encoding/pem" | ||
"fmt" | ||
"io/ioutil" | ||
"syscall" | ||
"unsafe" | ||
|
||
"github.com/arduino/go-paths-helper" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var ( | ||
modcrypt32 = syscall.NewLazyDLL("crypt32.dll") | ||
procCertAddEncodedCertificateToStore = modcrypt32.NewProc("CertAddEncodedCertificateToStore") | ||
procCertCloseStore = modcrypt32.NewProc("CertCloseStore") | ||
procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW") | ||
) | ||
|
||
// // InstallCertificate will install the certificates in the system keychain on windows | ||
func InstallCertificate(certFile *paths.Path) { | ||
// Load cert | ||
cert, err := ioutil.ReadFile(certFile.String()) | ||
if err != nil { | ||
log.Errorf("failed to read root certificate: %s", err) | ||
} | ||
// Decode PEM | ||
if certBlock, _ := pem.Decode(cert); certBlock == nil || certBlock.Type != "CERTIFICATE" { | ||
log.Error("invalid PEM data: decode pem") | ||
} else { | ||
cert = certBlock.Bytes | ||
} | ||
// Open root store | ||
store, err := openWindowsRootStore() | ||
if err != nil { | ||
log.Errorf("cannot open root store %s", err) | ||
} else { | ||
log.Info("opened Root Store") | ||
} | ||
defer store.close() | ||
// Add cert | ||
err = store.addCert(cert) | ||
if err != nil { | ||
log.Errorf("cannot install certificate in the system keychain: %s", err) | ||
} else { | ||
log.Info("certificate installed") | ||
} | ||
} | ||
|
||
type windowsRootStore uintptr | ||
|
||
func openWindowsRootStore() (windowsRootStore, error) { | ||
rootStr, err := syscall.UTF16PtrFromString("ROOT") | ||
if err != nil { | ||
return 0, err | ||
} | ||
store, _, err := procCertOpenSystemStoreW.Call(0, uintptr(unsafe.Pointer(rootStr))) | ||
if store != 0 { | ||
return windowsRootStore(store), nil | ||
} | ||
return 0, fmt.Errorf("failed to open windows root store: %s", err) | ||
} | ||
|
||
func (w windowsRootStore) close() error { | ||
ret, _, err := procCertCloseStore.Call(uintptr(w), 0) | ||
if ret != 0 { | ||
return nil | ||
} | ||
return fmt.Errorf("failed to close windows root store: %s", err) | ||
} | ||
|
||
func (w windowsRootStore) addCert(cert []byte) error { | ||
// this will always override | ||
ret, _, err := procCertAddEncodedCertificateToStore.Call( | ||
uintptr(w), // HCERTSTORE hCertStore | ||
uintptr(syscall.X509_ASN_ENCODING|syscall.PKCS_7_ASN_ENCODING), // DWORD dwCertEncodingType | ||
uintptr(unsafe.Pointer(&cert[0])), // const BYTE *pbCertEncoded | ||
uintptr(len(cert)), // DWORD cbCertEncoded | ||
3, // DWORD dwAddDisposition (CERT_STORE_ADD_REPLACE_EXISTING is 3) | ||
0, // PCCERT_CONTEXT *ppCertContext | ||
) | ||
if ret != 0 { | ||
return nil | ||
} | ||
return fmt.Errorf("failed adding cert: %s", err) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.