forked from Silverfish/proton-bridge
feat(GODT-2771): removed cert check and install on app startup on macOS.
This commit is contained in:
@ -22,7 +22,6 @@ import (
|
|||||||
"path"
|
"path"
|
||||||
|
|
||||||
"github.com/ProtonMail/gluon/async"
|
"github.com/ProtonMail/gluon/async"
|
||||||
"github.com/ProtonMail/proton-bridge/v3/internal/certs"
|
|
||||||
"github.com/ProtonMail/proton-bridge/v3/internal/constants"
|
"github.com/ProtonMail/proton-bridge/v3/internal/constants"
|
||||||
"github.com/ProtonMail/proton-bridge/v3/internal/locations"
|
"github.com/ProtonMail/proton-bridge/v3/internal/locations"
|
||||||
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
|
"github.com/ProtonMail/proton-bridge/v3/internal/vault"
|
||||||
@ -45,23 +44,6 @@ func WithVault(locations *locations.Locations, panicHandler async.PanicHandler,
|
|||||||
"corrupt": corrupt,
|
"corrupt": corrupt,
|
||||||
}).Debug("Vault created")
|
}).Debug("Vault created")
|
||||||
|
|
||||||
// Install the certificates if needed.
|
|
||||||
if installed := encVault.GetCertsInstalled(); !installed {
|
|
||||||
logrus.Debug("Installing certificates")
|
|
||||||
|
|
||||||
certPEM, _ := encVault.GetBridgeTLSCert()
|
|
||||||
|
|
||||||
if err := certs.NewInstaller().InstallCert(certPEM); err != nil {
|
|
||||||
return fmt.Errorf("failed to install certs: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := encVault.SetCertsInstalled(true); err != nil {
|
|
||||||
return fmt.Errorf("failed to set certs installed: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
logrus.Debug("Certificates successfully installed")
|
|
||||||
}
|
|
||||||
|
|
||||||
// GODT-1950: Add teardown actions (e.g. to close the vault).
|
// GODT-1950: Add teardown actions (e.g. to close the vault).
|
||||||
|
|
||||||
return fn(encVault, insecure, corrupt)
|
return fn(encVault, insecure, corrupt)
|
||||||
|
|||||||
@ -234,10 +234,6 @@ const (
|
|||||||
errAuthorizationCanceled = -60006
|
errAuthorizationCanceled = -60006
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
ErrUserCanceledCertificateInstall = errors.New("the user cancelled the authorization dialog")
|
|
||||||
)
|
|
||||||
|
|
||||||
// certPEMToDER converts a certificate in PEM format to DER format, which is the format required by Apple's Security framework.
|
// certPEMToDER converts a certificate in PEM format to DER format, which is the format required by Apple's Security framework.
|
||||||
func certPEMToDER(certPEM []byte) ([]byte, error) {
|
func certPEMToDER(certPEM []byte) ([]byte, error) {
|
||||||
block, left := pem.Decode(certPEM)
|
block, left := pem.Decode(certPEM)
|
||||||
|
|||||||
@ -40,7 +40,7 @@ func TestCertInKeychain(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// This test require human interaction (macOS security prompts), and is disabled by default.
|
// This test require human interaction (macOS security prompts), and is disabled by default.
|
||||||
func TestCertificateTrust(t *testing.T) {
|
func _TestCertificateTrust(t *testing.T) {
|
||||||
certPEM := generatePEMCertificate(t)
|
certPEM := generatePEMCertificate(t)
|
||||||
require.False(t, isCertTrusted(certPEM))
|
require.False(t, isCertTrusted(certPEM))
|
||||||
require.NoError(t, addCertToKeychain(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.
|
// This test require human interaction (macOS security prompts), and is disabled by default.
|
||||||
func TestInstallAndRemove(t *testing.T) {
|
func _TestInstallAndRemove(t *testing.T) {
|
||||||
certPEM := generatePEMCertificate(t)
|
certPEM := generatePEMCertificate(t)
|
||||||
|
|
||||||
// fresh install
|
// fresh install
|
||||||
|
|||||||
@ -25,6 +25,6 @@ func uninstallCert([]byte) error {
|
|||||||
return nil // Linux doesn't have a root cert store.
|
return nil // Linux doesn't have a root cert store.
|
||||||
}
|
}
|
||||||
|
|
||||||
func isCertInstalled([]byte) error {
|
func isCertInstalled([]byte) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -25,6 +25,6 @@ func uninstallCert([]byte) error {
|
|||||||
return nil // NOTE(GODT-986): Uninstall certs from root cert store?
|
return nil // NOTE(GODT-986): Uninstall certs from root cert store?
|
||||||
}
|
}
|
||||||
|
|
||||||
func isCertInstalled([]byte) error {
|
func isCertInstalled([]byte) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,12 @@
|
|||||||
|
|
||||||
package certs
|
package certs
|
||||||
|
|
||||||
|
import "errors"
|
||||||
|
|
||||||
|
var (
|
||||||
|
ErrUserCanceledCertificateInstall = errors.New("the user cancelled the authorization dialog")
|
||||||
|
)
|
||||||
|
|
||||||
type Installer struct{}
|
type Installer struct{}
|
||||||
|
|
||||||
func NewInstaller() *Installer {
|
func NewInstaller() *Installer {
|
||||||
|
|||||||
@ -66,16 +66,6 @@ func (vault *Vault) SetBridgeTLSCertKey(cert, key []byte) error {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func (vault *Vault) GetCertsInstalled() bool {
|
|
||||||
return vault.getSafe().Certs.Installed
|
|
||||||
}
|
|
||||||
|
|
||||||
func (vault *Vault) SetCertsInstalled(installed bool) error {
|
|
||||||
return vault.modSafe(func(data *Data) {
|
|
||||||
data.Certs.Installed = installed
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func readPEMCert(certPEMPath, keyPEMPath string) ([]byte, []byte, error) {
|
func readPEMCert(certPEMPath, keyPEMPath string) ([]byte, []byte, error) {
|
||||||
certPEM, err := os.ReadFile(filepath.Clean(certPEMPath))
|
certPEM, err := os.ReadFile(filepath.Clean(certPEMPath))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -31,13 +31,4 @@ func TestVault_TLSCerts(t *testing.T) {
|
|||||||
cert, key := s.GetBridgeTLSCert()
|
cert, key := s.GetBridgeTLSCert()
|
||||||
require.NotEmpty(t, cert)
|
require.NotEmpty(t, cert)
|
||||||
require.NotEmpty(t, key)
|
require.NotEmpty(t, key)
|
||||||
|
|
||||||
// Check the certificates are not installed.
|
|
||||||
require.False(t, s.GetCertsInstalled())
|
|
||||||
|
|
||||||
// Install the certificates.
|
|
||||||
require.NoError(t, s.SetCertsInstalled(true))
|
|
||||||
|
|
||||||
// Check the certificates are installed.
|
|
||||||
require.True(t, s.GetCertsInstalled())
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -20,8 +20,7 @@ package vault
|
|||||||
import "github.com/ProtonMail/proton-bridge/v3/internal/certs"
|
import "github.com/ProtonMail/proton-bridge/v3/internal/certs"
|
||||||
|
|
||||||
type Certs struct {
|
type Certs struct {
|
||||||
Bridge Cert
|
Bridge Cert
|
||||||
Installed bool
|
|
||||||
|
|
||||||
// If non-empty, the path to the PEM-encoded certificate file.
|
// If non-empty, the path to the PEM-encoded certificate file.
|
||||||
CustomCertPath string
|
CustomCertPath string
|
||||||
|
|||||||
Reference in New Issue
Block a user