2024-02-23 14:28:59 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"crypto/tls"
|
2024-02-23 15:32:08 +01:00
|
|
|
"crypto/x509"
|
2024-02-23 14:28:59 +01:00
|
|
|
"fmt"
|
2024-02-23 15:32:08 +01:00
|
|
|
"io"
|
2024-02-23 14:28:59 +01:00
|
|
|
"log"
|
2024-02-23 18:23:31 +01:00
|
|
|
"net"
|
2024-02-23 14:28:59 +01:00
|
|
|
"os"
|
|
|
|
|
|
|
|
"git.qowevisa.me/Qowevisa/gotell/env"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-02-23 18:23:31 +01:00
|
|
|
host, err := env.GetHost()
|
2024-02-23 14:28:59 +01:00
|
|
|
if err != nil {
|
2024-02-23 18:23:31 +01:00
|
|
|
panic(err)
|
2024-02-23 14:28:59 +01:00
|
|
|
}
|
2024-02-23 18:23:31 +01:00
|
|
|
port, err := env.GetPort()
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2024-02-23 15:32:08 +01:00
|
|
|
}
|
2024-02-23 18:23:31 +01:00
|
|
|
//
|
|
|
|
rootCert, err := os.ReadFile("./server.pem")
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
2024-02-23 15:32:08 +01:00
|
|
|
}
|
2024-02-23 18:23:31 +01:00
|
|
|
//
|
2024-02-23 15:32:08 +01:00
|
|
|
|
2024-02-23 18:23:31 +01:00
|
|
|
roots := x509.NewCertPool()
|
|
|
|
ok := roots.AppendCertsFromPEM(rootCert)
|
|
|
|
if !ok {
|
|
|
|
log.Fatal("failed to parse root certificate")
|
2024-02-23 15:32:08 +01:00
|
|
|
}
|
2024-02-23 18:23:31 +01:00
|
|
|
config := &tls.Config{RootCAs: roots, ServerName: "localhost"}
|
2024-02-23 15:32:08 +01:00
|
|
|
|
2024-02-23 18:23:31 +01:00
|
|
|
connp, err := net.Dial("tcp", fmt.Sprintf("%s:%d", host, port))
|
2024-02-23 15:32:08 +01:00
|
|
|
if err != nil {
|
2024-02-23 18:23:31 +01:00
|
|
|
log.Fatal(err)
|
2024-02-23 14:28:59 +01:00
|
|
|
}
|
2024-02-23 15:32:08 +01:00
|
|
|
|
2024-02-23 18:23:31 +01:00
|
|
|
conn := tls.Client(connp, config)
|
|
|
|
io.WriteString(conn, "Hello secure Server")
|
|
|
|
conn.Close()
|
2024-02-23 14:28:59 +01:00
|
|
|
}
|