2021-05-11 17:10:51 +00:00
|
|
|
package cyberghost
|
|
|
|
|
|
|
|
|
|
import (
|
2022-01-06 06:40:23 -05:00
|
|
|
"fmt"
|
2021-05-11 17:10:51 +00:00
|
|
|
"strconv"
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
"github.com/qdm12/gluetun/internal/configuration/settings"
|
2021-05-11 17:10:51 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/constants"
|
|
|
|
|
"github.com/qdm12/gluetun/internal/models"
|
2022-01-06 06:40:23 -05:00
|
|
|
"github.com/qdm12/gluetun/internal/openvpn/parse"
|
2021-05-11 17:10:51 +00:00
|
|
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
|
|
|
|
)
|
|
|
|
|
|
2021-08-19 14:09:41 +00:00
|
|
|
func (c *Cyberghost) BuildConf(connection models.Connection,
|
2022-01-06 06:40:23 -05:00
|
|
|
settings settings.OpenVPN) (lines []string, err error) {
|
2021-10-05 20:36:23 +00:00
|
|
|
if len(settings.Ciphers) == 0 {
|
|
|
|
|
settings.Ciphers = []string{
|
|
|
|
|
constants.AES256gcm,
|
|
|
|
|
constants.AES256cbc,
|
|
|
|
|
constants.AES128gcm,
|
|
|
|
|
}
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
auth := *settings.Auth
|
|
|
|
|
if auth == "" {
|
|
|
|
|
auth = constants.SHA256
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
lines = []string{
|
|
|
|
|
"client",
|
|
|
|
|
"nobind",
|
|
|
|
|
"tls-exit",
|
2021-09-14 15:46:40 +00:00
|
|
|
"dev " + settings.Interface,
|
2022-01-06 06:40:23 -05:00
|
|
|
"verb " + strconv.Itoa(*settings.Verbosity),
|
2021-05-11 17:10:51 +00:00
|
|
|
|
|
|
|
|
// Cyberghost specific
|
2021-09-14 15:23:56 +00:00
|
|
|
"ping 10",
|
2021-09-14 15:46:40 +00:00
|
|
|
"remote-cert-tls server",
|
|
|
|
|
"auth-user-pass " + constants.OpenVPNAuthConf,
|
2022-01-06 06:40:23 -05:00
|
|
|
"auth " + auth,
|
2021-05-11 17:10:51 +00:00
|
|
|
|
|
|
|
|
// Added constant values
|
|
|
|
|
"auth-nocache",
|
|
|
|
|
"mute-replay-warnings",
|
|
|
|
|
"pull-filter ignore \"auth-token\"", // prevent auth failed loops
|
|
|
|
|
"auth-retry nointeract",
|
|
|
|
|
"suppress-timestamps",
|
|
|
|
|
|
2021-09-14 15:46:40 +00:00
|
|
|
// Connection variables
|
2021-08-19 14:09:41 +00:00
|
|
|
connection.OpenVPNProtoLine(),
|
|
|
|
|
connection.OpenVPNRemoteLine(),
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-05 20:36:23 +00:00
|
|
|
lines = append(lines, utils.CipherLines(settings.Ciphers, settings.Version)...)
|
2021-05-23 17:40:14 +00:00
|
|
|
|
2021-07-31 14:02:02 +00:00
|
|
|
if connection.Protocol == constants.UDP {
|
|
|
|
|
lines = append(lines, "explicit-exit-notify")
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
if !*settings.Root {
|
2021-08-18 16:16:47 +00:00
|
|
|
lines = append(lines, "user "+settings.ProcUser)
|
2021-09-14 14:54:59 +00:00
|
|
|
lines = append(lines, "persist-tun")
|
2021-09-14 14:55:39 +00:00
|
|
|
lines = append(lines, "persist-key")
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
if *settings.MSSFix > 0 {
|
|
|
|
|
lines = append(lines, "mssfix "+strconv.Itoa(int(*settings.MSSFix)))
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|
|
|
|
|
|
2022-01-06 06:40:23 -05:00
|
|
|
if !*settings.IPv6 {
|
2021-07-19 01:46:20 +00:00
|
|
|
lines = append(lines, `pull-filter ignore "route-ipv6"`)
|
|
|
|
|
lines = append(lines, `pull-filter ignore "ifconfig-ipv6"`)
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-11 17:10:51 +00:00
|
|
|
lines = append(lines, utils.WrapOpenvpnCA(
|
|
|
|
|
constants.CyberghostCertificate)...)
|
2022-01-06 06:40:23 -05:00
|
|
|
|
|
|
|
|
certData, err := parse.ExtractCert([]byte(*settings.ClientCrt))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("client cert is not valid: %w", err)
|
|
|
|
|
}
|
|
|
|
|
lines = append(lines, utils.WrapOpenvpnCert(certData)...)
|
|
|
|
|
|
|
|
|
|
keyData, err := parse.ExtractPrivateKey([]byte(*settings.ClientKey))
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, fmt.Errorf("client key is not valid: %w", err)
|
|
|
|
|
}
|
|
|
|
|
lines = append(lines, utils.WrapOpenvpnKey(keyData)...)
|
2021-05-11 17:10:51 +00:00
|
|
|
|
|
|
|
|
lines = append(lines, "")
|
|
|
|
|
|
2021-09-13 11:30:14 -04:00
|
|
|
return lines, nil
|
2021-05-11 17:10:51 +00:00
|
|
|
}
|