Configure and use TLS by default
Plaintext connections can still be started by running the client with the "--insecure" flag
This commit is contained in:
parent
7cb7d0a574
commit
b88c207b63
34
main.go
34
main.go
|
@ -1,6 +1,7 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/tls"
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -16,14 +17,22 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
RemoteIP string = "192.168.1.181"
|
// CONFIGURATION VALUES
|
||||||
|
RemoteIP string = "127.0.0.1"
|
||||||
RemotePort string = "1302"
|
RemotePort string = "1302"
|
||||||
Remote_IP_Requester string = "https://ip.bulgariu.xyz"
|
Remote_IP_Requester string = "https://ip.bulgariu.xyz"
|
||||||
retryRate time.Duration = 5
|
retryRate time.Duration = 5
|
||||||
|
useTLS bool = true
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.SetPrefix("[TIAMAT-CLIENT] ")
|
log.SetPrefix("[TIAMAT-CLIENT] ")
|
||||||
|
for _, v := range os.Args {
|
||||||
|
if v == "--insecure" {
|
||||||
|
useTLS = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if err := start(); err != nil {
|
if err := start(); err != nil {
|
||||||
log.Print(err)
|
log.Print(err)
|
||||||
|
@ -32,8 +41,29 @@ func main() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func start() error {
|
func startSecureConnection() (net.Conn, error) {
|
||||||
|
conf := &tls.Config{
|
||||||
|
InsecureSkipVerify: true,
|
||||||
|
}
|
||||||
|
conn, err := tls.Dial("tcp", RemoteIP+":"+RemotePort, conf)
|
||||||
|
return conn, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func startInsecureConnection() (net.Conn, error) {
|
||||||
conn, err := net.Dial("tcp", RemoteIP+":"+RemotePort)
|
conn, err := net.Dial("tcp", RemoteIP+":"+RemotePort)
|
||||||
|
return conn, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func start() error {
|
||||||
|
var conn net.Conn
|
||||||
|
var err error
|
||||||
|
if useTLS != true {
|
||||||
|
log.Println("WARNING: Starting unencrypted connection!")
|
||||||
|
conn, err = startInsecureConnection()
|
||||||
|
} else {
|
||||||
|
conn, err = startSecureConnection()
|
||||||
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
e := fmt.Errorf("Error happened connecting to server: %v\n", err)
|
e := fmt.Errorf("Error happened connecting to server: %v\n", err)
|
||||||
return e
|
return e
|
||||||
|
|
Loading…
Reference in New Issue