fix(settings): read PEM files but b64 env vars

- Extract base64 data from PEM files and secret files
- Environment variables are not PEM encoded and only the base64 data
- Affects OpenVPN certificate, key and encrypted key
This commit is contained in:
Quentin McGaw
2022-08-24 19:31:52 +00:00
parent 0413a0a1ab
commit 732f826ec2
8 changed files with 53 additions and 54 deletions

View File

@@ -30,15 +30,8 @@ func (r *Reader) readOpenVPN() (
openVPN.Auth = &auth
}
openVPN.ClientCrt, err = readBase64OrNil("OPENVPN_CLIENTCRT")
if err != nil {
return openVPN, fmt.Errorf("environment variable OPENVPN_CLIENTCRT: %w", err)
}
openVPN.ClientKey, err = readBase64OrNil("OPENVPN_CLIENTKEY")
if err != nil {
return openVPN, fmt.Errorf("environment variable OPENVPN_CLIENTKEY: %w", err)
}
openVPN.ClientCrt = envToStringPtr("OPENVPN_CLIENTCRT")
openVPN.ClientKey = envToStringPtr("OPENVPN_CLIENTKEY")
openVPN.PIAEncPreset = r.readPIAEncryptionPreset()
@@ -83,20 +76,6 @@ func (r *Reader) readOpenVPNPassword() (password string) {
return password
}
func readBase64OrNil(envKey string) (valueOrNil *string, err error) {
value := getCleanedEnv(envKey)
if value == "" {
return nil, nil //nolint:nilnil
}
decoded, err := decodeBase64(value)
if err != nil {
return nil, err
}
return &decoded, nil
}
func (r *Reader) readPIAEncryptionPreset() (presetPtr *string) {
_, preset := r.getEnvWithRetro(
"PRIVATE_INTERNET_ACCESS_OPENVPN_ENCRYPTION_PRESET",