Security Update #6
|
@ -36,6 +36,7 @@ func init() {
|
|||
rootCmd.AddCommand(clientCmd)
|
||||
clientCmd.PersistentFlags().StringP("ip", "i", "", "Server IP to connect to")
|
||||
clientCmd.PersistentFlags().StringP("port", "p", "1302", "Server port to connect to")
|
||||
clientCmd.Flags().Bool("insecure", false, "[UNSAFE] Do not use TLS encryption")
|
||||
}
|
||||
|
||||
func setClientParameters(cmd *cobra.Command) error {
|
||||
|
@ -57,5 +58,10 @@ func setClientParameters(cmd *cobra.Command) error {
|
|||
}
|
||||
serverIP = parameterIP
|
||||
|
||||
insecure, err := cmd.Flags().GetBool("insecure")
|
||||
if insecure == true {
|
||||
clientInsecure = true
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -40,14 +40,32 @@ var (
|
|||
serverPort string = "1302"
|
||||
serverIP string
|
||||
data Message
|
||||
clientInsecure bool
|
||||
)
|
||||
|
||||
func Client() {
|
||||
//conn, err := net.Dial("tcp", serverIP+":"+serverPort)
|
||||
func startSecureConnection() (net.Conn, error) {
|
||||
conf := &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
conn, err := tls.Dial("tcp", serverIP+":"+serverPort, conf)
|
||||
return conn, err
|
||||
}
|
||||
|
||||
func startInsecureConnection() (net.Conn, error) {
|
||||
conn, err := net.Dial("tcp", serverIP+":"+serverPort)
|
||||
return conn, err
|
||||
}
|
||||
|
||||
func Client() {
|
||||
var conn net.Conn
|
||||
var err error
|
||||
if clientInsecure == true {
|
||||
fmt.Println("WARNING: Starting unencrypted connection!")
|
||||
conn, err = startInsecureConnection()
|
||||
} else {
|
||||
conn, err = startSecureConnection()
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatalf("Error occurred trying to connect to server: %v\n", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue