This commit is contained in:
Alex Tsai 2021-04-10 10:00:11 +08:00
parent 2bc30e939c
commit 1033eafed9
3 changed files with 6 additions and 7 deletions

View File

@ -8,7 +8,7 @@ import (
"os/exec"
"runtime"
"github.com/net-byte/vtun/util"
"github.com/net-byte/vtun/common/cipher"
"github.com/songgao/water"
)
@ -24,7 +24,7 @@ func New(local *string, remote *string, port *int, key *string) {
log.Fatal("Only support linux!")
return
}
hashKey := util.CreateHash(*key)
hashKey := cipher.CreateHash(*key)
// create tun
config := water.Config{
DeviceType: water.TAP,
@ -64,7 +64,7 @@ func New(local *string, remote *string, port *int, key *string) {
}
b := buf[:n]
// decrypt data
util.Decrypt(&b, hashKey)
cipher.Decrypt(&b, hashKey)
iface.Write(b)
}
}()
@ -77,7 +77,7 @@ func New(local *string, remote *string, port *int, key *string) {
}
b := packet[:n]
// encrypt data
util.Encrypt(&b, hashKey)
cipher.Encrypt(&b, hashKey)
conn.WriteToUDP(b, remoteAddr)
}
}
@ -95,6 +95,6 @@ func execCmd(c string, args ...string) {
cmd.Stdin = os.Stdin
err := cmd.Run()
if nil != err {
log.Fatalln("Error running /sbin/ip:", err)
log.Fatalln("Exec /sbin/ip error:", err)
}
}

View File

@ -1,4 +1,4 @@
package util
package cipher
import (
"crypto/sha256"

1
go.mod
View File

@ -5,5 +5,4 @@ go 1.16
require (
github.com/songgao/water v0.0.0-20200317203138-2b4b6d7c09d8
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3
)