Skip to content
Snippets Groups Projects
Commit c6bca076 authored by Pea Nut's avatar Pea Nut Committed by jkito
Browse files

Improve error handling when checking downloaded pem cert

We access pkBlock.Type later and pkBlock can be nil here.
parent 1f91f6f8
Branches
Tags
1 merge request!265enable setting introducer url using env variable
...@@ -329,9 +329,10 @@ func (b *Bitmask) getCert() error { ...@@ -329,9 +329,10 @@ func (b *Bitmask) getCert() error {
} }
b.certPemPath = b.getTempCertPemPath() b.certPemPath = b.getTempCertPemPath()
// If we start OpenVPN, openvpn.pem does not exist and isValidCert returns false // If we start OpenVPN for the first time, openvpn.pem does not exist
// If we start OpenVPN later again (not restarting the client), there // and isValidCert returns false
// should be a valid openvpn.pem // If we start OpenVPN later again (not restarting the client), there
// should be a valid openvpn.pem and isValidCert should return true
// If there is no valid openvpn.pem, fetch a new one from menshen // If there is no valid openvpn.pem, fetch a new one from menshen
// Note: b.tempdir is unique for every run of the desktop client // Note: b.tempdir is unique for every run of the desktop client
if !isValidCert(b.certPemPath) { if !isValidCert(b.certPemPath) {
......
...@@ -40,18 +40,19 @@ func isUpgradeAvailable() bool { ...@@ -40,18 +40,19 @@ func isUpgradeAvailable() bool {
func isValidCert(path string) bool { func isValidCert(path string) bool {
log.Trace(). log.Trace().
Str("path", path). Str("path", path).
Msg("Checking for a valid OpenVPN client credentials (key and certificate)") Msg("Checking for valid OpenVPN client credentials (key and certificate)")
data, err := ioutil.ReadFile(path) data, err := ioutil.ReadFile(path)
if err != nil { if err != nil {
log.Debug(). log.Debug().
Str("path", path). Str("path", path).
Str("err", err.Error()).
Msg("Could not read certificate file") Msg("Could not read certificate file")
return false return false
} }
pkBlock, rest := pem.Decode(data) pkBlock, rest := pem.Decode(data)
if rest == nil { if rest == nil || pkBlock == nil {
log.Warn(). log.Warn().
Str("data", string(data)). Str("data", string(data)).
Msg("Could not decode pem data") Msg("Could not decode pem data")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment