mirror of
https://github.com/qdm12/gluetun.git
synced 2026-05-06 20:10:11 +02:00
fix(openvpn): bundle provider CA certificates in one block (#3258)
This commit is contained in:
@@ -175,8 +175,8 @@ func OpenVPNConfig(provider OpenVPNProviderSettings,
|
|||||||
lines.add("setenv", envKey, envValue)
|
lines.add("setenv", envKey, envValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, ca := range provider.CAs {
|
if len(provider.CAs) > 0 {
|
||||||
lines.addLines(WrapOpenvpnCA(ca))
|
lines.addLines(WrapOpenvpnCAs(provider.CAs))
|
||||||
}
|
}
|
||||||
if provider.CRLVerify != "" {
|
if provider.CRLVerify != "" {
|
||||||
lines.addLines(WrapOpenvpnCRLVerify(provider.CRLVerify))
|
lines.addLines(WrapOpenvpnCRLVerify(provider.CRLVerify))
|
||||||
@@ -268,13 +268,20 @@ func defaultStringSlice(value, defaultValue []string) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
func WrapOpenvpnCA(certificate string) (lines []string) {
|
func WrapOpenvpnCA(certificate string) (lines []string) {
|
||||||
return []string{
|
return WrapOpenvpnCAs([]string{certificate})
|
||||||
"<ca>",
|
}
|
||||||
|
|
||||||
|
func WrapOpenvpnCAs(certificates []string) (lines []string) {
|
||||||
|
lines = append(lines, "<ca>")
|
||||||
|
for _, certificate := range certificates {
|
||||||
|
lines = append(lines,
|
||||||
"-----BEGIN CERTIFICATE-----",
|
"-----BEGIN CERTIFICATE-----",
|
||||||
certificate,
|
certificate,
|
||||||
"-----END CERTIFICATE-----",
|
"-----END CERTIFICATE-----",
|
||||||
"</ca>",
|
)
|
||||||
}
|
}
|
||||||
|
lines = append(lines, "</ca>")
|
||||||
|
return lines
|
||||||
}
|
}
|
||||||
|
|
||||||
func WrapOpenvpnCert(clientCertificate string) (lines []string) {
|
func WrapOpenvpnCert(clientCertificate string) (lines []string) {
|
||||||
|
|||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package utils
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWrapOpenvpnCAs(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
lines := WrapOpenvpnCAs([]string{"cert1", "cert2"})
|
||||||
|
|
||||||
|
assert.Equal(t, []string{
|
||||||
|
"<ca>",
|
||||||
|
"-----BEGIN CERTIFICATE-----",
|
||||||
|
"cert1",
|
||||||
|
"-----END CERTIFICATE-----",
|
||||||
|
"-----BEGIN CERTIFICATE-----",
|
||||||
|
"cert2",
|
||||||
|
"-----END CERTIFICATE-----",
|
||||||
|
"</ca>",
|
||||||
|
}, lines)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestWrapOpenvpnCA(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
|
||||||
|
lines := WrapOpenvpnCA("cert1")
|
||||||
|
|
||||||
|
assert.Equal(t, []string{
|
||||||
|
"<ca>",
|
||||||
|
"-----BEGIN CERTIFICATE-----",
|
||||||
|
"cert1",
|
||||||
|
"-----END CERTIFICATE-----",
|
||||||
|
"</ca>",
|
||||||
|
}, lines)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user