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
2 changes: 1 addition & 1 deletion certificates/install_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// 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
//go:build !darwin && !windows

package certificates

Expand Down
104 changes: 104 additions & 0 deletions certificates/install_windows.go
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)
}