feat(GODT-2771): added CLI commands for cert install/uninstall/status check on macOS.

This commit is contained in:
Xavier Michelon
2023-08-18 09:01:40 +02:00
parent 452d3068f0
commit 43f7a989be
5 changed files with 128 additions and 19 deletions

View File

@ -40,7 +40,7 @@ func TestCertInKeychain(t *testing.T) {
}
// This test require human interaction (macOS security prompts), and is disabled by default.
func _TestCertificateTrust(t *testing.T) {
func _TestCertificateTrust(t *testing.T) { //nolint:unused
certPEM := generatePEMCertificate(t)
require.False(t, isCertTrusted(certPEM))
require.NoError(t, addCertToKeychain(certPEM))
@ -52,7 +52,7 @@ func _TestCertificateTrust(t *testing.T) {
}
// This test require human interaction (macOS security prompts), and is disabled by default.
func _TestInstallAndRemove(t *testing.T) {
func _TestInstallAndRemove(t *testing.T) { //nolint:unused
certPEM := generatePEMCertificate(t)
// fresh install

View File

@ -17,24 +17,48 @@
package certs
import "errors"
import (
"errors"
"github.com/sirupsen/logrus"
)
var (
ErrUserCanceledCertificateInstall = errors.New("the user cancelled the authorization dialog")
)
type Installer struct{}
type Installer struct {
log *logrus.Entry
}
func NewInstaller() *Installer {
return &Installer{}
return &Installer{
log: logrus.WithField("pkg", "certs"),
}
}
func (installer *Installer) InstallCert(certPEM []byte) error {
return installCert(certPEM)
installer.log.Info("Installing the Bridge TLS certificate in the OS keychain")
if err := installCert(certPEM); err != nil {
installer.log.WithError(err).Error("The Bridge TLS certificate could not be installed in the OS keychain")
return err
}
installer.log.Info("The Bridge TLS certificate was successfully installed in the OS keychain")
return nil
}
func (installer *Installer) UninstallCert(certPEM []byte) error {
return uninstallCert(certPEM)
installer.log.Info("Uninstalling the Bridge TLS certificate from the OS keychain")
if err := uninstallCert(certPEM); err != nil {
installer.log.WithError(err).Error("The Bridge TLS certificate could not be uninstalled from the OS keychain")
return err
}
installer.log.Info("The Bridge TLS certificate was successfully uninstalled from the OS keychain")
return nil
}
func (installer *Installer) IsCertInstalled(certPEM []byte) bool {