]> Cypherpunks.ru repositories - ucspi.git/blobdiff - cmd/tlsc/main.go
Returned parsed certificates also in CertPoolFromFile
[ucspi.git] / cmd / tlsc / main.go
index 8d32b827275c3805628f61dd3f00a836207c9c74..7f1651a9301f5d2a4d7eca353d958098a37509ca 100644 (file)
@@ -41,6 +41,7 @@ func main() {
        prvPath := flag.String("key", "", "Path to client PKCS#8 private key")
        casPath := flag.String("ca", "", "Path to CA certificates file")
        hostname := flag.String("name", "example.com", "Expected server's hostname")
+       insecure := flag.Bool("insecure", false, "Insecure mode")
        fpr := flag.String("fpr", "", "Expected SHA256 hash of server certificate's SPKI")
        flag.Usage = func() {
                fmt.Fprintf(os.Stderr, `Usage: tcpclient host port tlsc -name expected.name
@@ -59,9 +60,10 @@ func main() {
        }
 
        cfg := &tls.Config{}
-       if *hostname == "" || *onlyShow {
+       if *hostname == "" || *onlyShow || *insecure {
                cfg.InsecureSkipVerify = true
-       } else {
+       }
+       if *hostname != "" {
                cfg.ServerName = *hostname
        }
        if *crtPath != "" {
@@ -80,7 +82,7 @@ func main() {
        }
        if *casPath != "" {
                var err error
-               cfg.RootCAs, err = ucspi.CertPoolFromFile(*casPath)
+               _, cfg.RootCAs, err = ucspi.CertPoolFromFile(*casPath)
                if err != nil {
                        log.Fatalln(err)
                }
@@ -114,8 +116,10 @@ func main() {
        connState := tlsConn.ConnectionState()
        if *onlyShow {
                fmt.Fprintf(
-                       os.Stderr, "Version: %04x\nCipherSuite: %s\n",
-                       connState.Version, tls.CipherSuiteName(connState.CipherSuite),
+                       os.Stderr,
+                       "Version: %s\nCipherSuite: %s\n",
+                       ucspi.TLSVersion(connState.Version),
+                       tls.CipherSuiteName(connState.CipherSuite),
                )
                for _, cert := range connState.PeerCertificates {
                        os.Stderr.WriteString("\n")