Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TND #52

Merged
merged 2 commits into from
Dec 19, 2023
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/godbus/dbus/v5 v5.1.0
github.com/miekg/dns v1.1.57
github.com/sirupsen/logrus v1.9.3
github.com/telekom-mms/tnd v0.2.0
github.com/telekom-mms/tnd v0.3.0
github.com/vishvananda/netlink v1.1.0
golang.org/x/sys v0.15.0
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVs
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/telekom-mms/tnd v0.2.0 h1:sPGFObbLEw2vFQsbw1WGk8UDW1MDxJBZYoUi3RHCOUw=
github.com/telekom-mms/tnd v0.2.0/go.mod h1:qcxCJ9vQZiw2ECctoY7mCCmFmbG9mE7bDvxKTARlQlk=
github.com/telekom-mms/tnd v0.3.0 h1:CdYbcBPycv+2ioQWhlIDywHPHwyYYQ7L2moNxZ44WQs=
github.com/telekom-mms/tnd v0.3.0/go.mod h1:7nZhV5fs1idEzP7bo+K2QDDkUpflvmmnVXzNl5p9Wz0=
github.com/vishvananda/netlink v1.1.0 h1:1iyaYNBLmP6L0220aDnYQpo1QEV4t4hJ+xEEhhJH8j0=
github.com/vishvananda/netlink v1.1.0/go.mod h1:cTgwzPIzzgDAYoQrMm0EdrjRUBkTqKYppBueQtXaqoE=
github.com/vishvananda/netns v0.0.0-20191106174202-0a2b9b5464df/go.mod h1:JP3t17pCcGlemwknint6hfoeCVQrEMVwxRLRjXpq+BU=
Expand Down
10 changes: 5 additions & 5 deletions internal/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,10 +511,8 @@ func (d *Daemon) getProfileAllowedHosts() (hosts []string) {

// initTNDServers sets the TND servers from the xml profile
func (d *Daemon) initTNDServers() {
urls, hashes := d.profile.GetTNDHTTPSServers()
for i, url := range urls {
d.tnd.AddServer(url, hashes[i])
}
servers := d.profile.GetTNDHTTPSServers()
d.tnd.SetServers(servers)
}

// setTNDDialer sets a custom dialer for TND
Expand Down Expand Up @@ -563,7 +561,9 @@ func (d *Daemon) startTND() {
d.tnd = tnd.NewDetector(d.config.TND)
d.initTNDServers()
d.setTNDDialer()
d.tnd.Start()
if err := d.tnd.Start(); err != nil {
log.Fatal(err)
}
}

// stopTND stops TND if it's running
Expand Down
9 changes: 3 additions & 6 deletions pkg/xmlprofile/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,11 @@ func (p *Profile) GetTNDServers() (servers []string) {
}

// GetTNDHTTPSServers gets the TND HTTPS server URLs and their hashes in the XML profile
func (p *Profile) GetTNDHTTPSServers() (urls, hashes []string) {
func (p *Profile) GetTNDHTTPSServers() (servers map[string]string) {
servers = make(map[string]string)
for _, s := range p.AutomaticVPNPolicy.TrustedHTTPSServerList {
url := fmt.Sprintf("https://%s:%s", s.Address, s.Port)
urls = append(urls, url)
hashes = append(hashes, s.CertificateHash)
}
if len(urls) != len(hashes) {
return nil, nil
servers[url] = s.CertificateHash
}
return
}
Expand Down
31 changes: 10 additions & 21 deletions pkg/xmlprofile/profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,10 @@ func TestProfileGetTNDHTTPSServers(t *testing.T) {
p := NewProfile()

// test empty
var wantURLs []string
var wantHashes []string
gotURLs, gotHashes := p.GetTNDHTTPSServers()
if !reflect.DeepEqual(gotURLs, wantURLs) ||
!reflect.DeepEqual(gotHashes, wantHashes) {

t.Errorf("got %v, %v, want %v, %v",
gotURLs, gotHashes, wantURLs, wantHashes)
want := map[string]string{}
got := p.GetTNDHTTPSServers()
if !reflect.DeepEqual(got, want) {
t.Errorf("got %v, want %v", got, want)
}

// test filled
Expand All @@ -156,20 +152,13 @@ func TestProfileGetTNDHTTPSServers(t *testing.T) {
CertificateHash: "hash of tnd2 certificate",
},
}
wantURLs = []string{
"https://tnd1.mycompany.com:443",
"https://tnd2.mycompany.com:443",
}
wantHashes = []string{
"hash of tnd1 certificate",
"hash of tnd2 certificate",
want = map[string]string{
"https://tnd1.mycompany.com:443": "hash of tnd1 certificate",
"https://tnd2.mycompany.com:443": "hash of tnd2 certificate",
}
gotURLs, gotHashes = p.GetTNDHTTPSServers()
if !reflect.DeepEqual(gotURLs, wantURLs) ||
!reflect.DeepEqual(gotHashes, wantHashes) {

t.Errorf("got %v, %v, want %v, %v",
gotURLs, gotHashes, wantURLs, wantHashes)
got = p.GetTNDHTTPSServers()
if !reflect.DeepEqual(got, want) {
t.Errorf("got %v, want %v", got, want)
}
}

Expand Down