Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-gitlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ jobs:
project-id: ${{ secrets.PROJECT_ID }}
with:
cancel-outdated-pipelines: ${{ github.ref_name != 'main' }}
triggered-ref: v1.3.1
triggered-ref: v1.3.2
2 changes: 1 addition & 1 deletion ci/docker/tester-selenium/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM ghcr.io/nordsecurity/nordvpn-linux/tester:1.2.0
FROM ghcr.io/nordsecurity/nordvpn-linux/tester:1.6.1

LABEL org.opencontainers.image.source=https://github.com/NordSecurity/nordvpn-linux

Expand Down
2 changes: 1 addition & 1 deletion ci/docker/tester/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ RUN apt-get update && \
# linux app
apt-utils curl git iputils-ping sudo kmod systemd \
# preinstall deps required by nordvpn
libxml2 iproute2 iptables \
xsltproc iproute2 iptables \
# install wireguard tools for tests
wireguard-tools \
# install python for tests
Expand Down
4 changes: 2 additions & 2 deletions ci/nfpm/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ depends:
- iproute2 | iproute
- procps
- ca-certificates
- libxml2
- libidn2-0
- zlib1g
- libnl-genl-3-200
- libc6 (>= 2.29)
- libsqlite3-0
- xsltproc

# Basic file that applies to all packagers
contents:
Expand Down Expand Up @@ -147,12 +147,12 @@ overrides:
- iproute
- procps
- ca-certificates
- libxml2
- libidn2
- zlib
- (libnl3 or libnl3-200)
- glibc >= 2.29
- (libsqlite3-0 or sqlite-libs)
- xsltproc
# RPM specific scripts.
scripts:
preinstall: ${WORKDIR}/contrib/scriptlets/rpm/preinst
Expand Down
55 changes: 30 additions & 25 deletions daemon/vpn/openvpn/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ import (
"errors"
"fmt"
"net/netip"
"os"
"os/exec"
"path/filepath"
"regexp"
"strings"
"text/template"

"github.com/NordSecurity/nordvpn-linux/config"
"github.com/NordSecurity/nordvpn-linux/internal"

"github.com/jbowtie/gokogiri/xml"
"github.com/jbowtie/ratago/xslt"
)

const ovpnConfig = `<?xml version="1.0"?>
Expand Down Expand Up @@ -107,41 +106,47 @@ func generateConfigFile(protocol config.Protocol, serverIP netip.Addr, obfuscate
return ovpnConfig.Close()
}

func generateConfig(serverIP netip.Addr, identifier openvpnID, template []byte) ([]byte, error) {
func generateConfig(serverIP netip.Addr, identifier openvpnID, xsl []byte) ([]byte, error) {
xmlConfig, err := generateConfigXML(serverIP, identifier)
if err != nil {
return nil, fmt.Errorf("generating config XML file: %w", err)
}

xmlDoc, err := xml.Parse(xmlConfig, nil, nil, 0, nil)
out, err := applyXSLTWithXsltproc(xsl, xmlConfig)
if err != nil {
return nil, fmt.Errorf("parsing XML config: %w", err)
return nil, fmt.Errorf("xslt transform: %w", err)
}
return out, nil
}

sheetXMLDoc, err := xml.Parse(template, nil, nil, 0, nil)
// applyXSLTWithXsltproc runs `xsltproc --nonet` on xslBytes + xmlBytes and returns the transform's stdout.
func applyXSLTWithXsltproc(xslBytes, xmlBytes []byte) ([]byte, error) {
tmpdir, err := os.MkdirTemp("", "xsltproc-*")
if err != nil {
return nil, fmt.Errorf("parsing XML template file: %w", err)
return nil, fmt.Errorf("creating temp dir: %w", err)
}
defer os.RemoveAll(tmpdir)

// OpenVPN Templates are single files, therefore fileurl can be empty
sheet, err := xslt.ParseStylesheet(sheetXMLDoc, "")
if err != nil {
return nil, fmt.Errorf("parsing stylesheet: %w", err)
xslPath := filepath.Join(tmpdir, "sheet.xsl")
xmlPath := filepath.Join(tmpdir, "input.xml")

if err := os.WriteFile(xslPath, xslBytes, internal.PermUserRW); err != nil {
return nil, fmt.Errorf("writing xsl: %w", err)
}
out, err := sheet.Process(xmlDoc, xslt.StylesheetOptions{})
if err != nil {
return nil, fmt.Errorf("Processing XML config: %w", err)
if err := os.WriteFile(xmlPath, xmlBytes, internal.PermUserRW); err != nil {
return nil, fmt.Errorf("writing xml: %w", err)
}
return []byte(disableEscaping(out)), nil
}

func disableEscaping(out string) string {
out = strings.ReplaceAll(out, "&lt;", "<")
out = strings.ReplaceAll(out, "&gt;", ">")
out = strings.ReplaceAll(out, "&quot;", "\"")
out = strings.ReplaceAll(out, "&apos;", "'")
out = strings.ReplaceAll(out, "&amp;", "&")
return out
// NOTE: We are calling a binary here instead of using libraries, because the libs
// are bindings for old libxml which on newer distributions is not available.
cmd := exec.Command("xsltproc", "--nonet", xslPath, xmlPath)
var stdout, stderr bytes.Buffer
cmd.Stdout = &stdout
cmd.Stderr = &stderr

if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("xsltproc failed: %v: %s", err, stderr.String())
}
return stdout.Bytes(), nil
}

func generateConfigXML(serverIP netip.Addr, identifier openvpnID) ([]byte, error) {
Expand Down
3 changes: 2 additions & 1 deletion daemon/vpn/openvpn/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ func TestGenerateConfigXML(t *testing.T) {
}

func TestGenerateConfig(t *testing.T) {
category.Set(t, category.Unit)
category.Set(t, category.Integration)
t.Skip("LVPN-9415")
tests := []struct {
name string
ip netip.Addr
Expand Down
2 changes: 0 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/uuid v1.6.0
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b
github.com/jbowtie/gokogiri v0.0.0-20190301021639-37f655d3078f
github.com/jbowtie/ratago v0.0.0-20200401224626-3140c0a9b186
github.com/magefile/mage v1.14.0
github.com/milosgajdos/tenus v0.0.3
github.com/quic-go/quic-go v0.48.2
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,6 @@ github.com/grpc-ecosystem/grpc-gateway/v2 v2.20.0/go.mod h1:P+Lt/0by1T8bfcF3z737
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b h1:wDUNC2eKiL35DbLvsDhiblTUXHxcOPwQSCzi7xpQUN4=
github.com/hako/durafmt v0.0.0-20210608085754-5c1018a4e16b/go.mod h1:VzxiSdG6j1pi7rwGm/xYI5RbtpBgM8sARDXlvEvxlu0=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jbowtie/gokogiri v0.0.0-20190301021639-37f655d3078f h1:6UIvzqlGM38lOpKP380Wbl0kUyyjutcc7KJUaDM/U4o=
github.com/jbowtie/gokogiri v0.0.0-20190301021639-37f655d3078f/go.mod h1:C3R3VzPq+DAwilxue7DiV6F2QL1rrQX0L56GyI+sBxM=
github.com/jbowtie/ratago v0.0.0-20200401224626-3140c0a9b186 h1:8N1+ik35JbbQVslv63BvyO1yv0TC5Ol/ip26fOy+MP0=
github.com/jbowtie/ratago v0.0.0-20200401224626-3140c0a9b186/go.mod h1:0ZLxKWdtG2yYN5kJTy71ALuAcl/gFhkxuGbKCMufBwI=
github.com/jonboulle/clockwork v0.4.0 h1:p4Cf1aMWXnXAUh8lVfewRBx1zaTSYKrKMF2g3ST4RZ4=
github.com/jonboulle/clockwork v0.4.0/go.mod h1:xgRqUGwRcjKCO1vbZUEtSLrqKoPSsUpK7fnezOII0kc=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down
2 changes: 1 addition & 1 deletion magefiles/mage.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const (
imageSnapPackager = registryPrefix + "snaper:1.2.0"
imageProtobufGenerator = registryPrefix + "generator:1.4.2"
imageScanner = registryPrefix + "scanner:1.1.0"
imageTester = registryPrefix + "tester:1.6.0"
imageTester = registryPrefix + "tester:1.6.1"
imageQAPeer = registryPrefix + "qa-peer:1.0.4"
imageRuster = registryPrefix + "ruster:1.4.1"

Expand Down
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ parts:
- on arm64: ./bin/aarch64
stage-packages:
- wireguard-tools
- libxml2
- e2fsprogs
- dbus-x11
- libnl-genl-3-200
- libsqlite3-0
- xsltproc
organize:
nordvpn: bin/nordvpn
nordvpnd: bin/nordvpnd
Expand Down
Loading