Repository navigation
Expand file tree
/
Copy pathtls.go
More file actions
81 lines (67 loc) · 1.82 KB
/
Copy pathtls.go
File metadata and controls
81 lines (67 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cmd
import (
"net"
"strconv"
"strings"
"time"
"certwiz/pkg/cert"
"certwiz/pkg/ui"
"github.com/spf13/cobra"
)
var (
tlsPort int
tlsTimeout time.Duration
)
var tlsCmd = &cobra.Command{
Use: "tls [hostname]",
Short: "Test supported TLS versions for a hostname",
Long: `Test which TLS versions are supported by a remote server.
This command attempts to connect to the specified hostname using each
TLS version (1.0, 1.1, 1.2, and 1.3) and reports which versions are
supported by the server. Versions are probed concurrently; a version that
fails while others succeed is retried once before being reported as
unsupported.
Examples:
cert tls google.com
cert tls https://example.com
cert tls example.com:443
cert tls 192.168.1.1 --port 443
cert tls localhost --timeout 2s`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
target := args[0]
// Strip URL scheme and path if present (e.g. https://example.com/path)
port := tlsPort
host := target
if i := strings.Index(host, "://"); i != -1 {
host = host[i+3:]
}
if i := strings.Index(host, "/"); i != -1 {
host = host[:i]
}
// Extract port from target if specified (handles IPv6 like [::1]:443)
if h, p, err := net.SplitHostPort(host); err == nil {
if pn, err := strconv.Atoi(p); err == nil {
host = h
port = pn
}
}
// Test TLS versions
result, err := cert.CheckTLSVersions(host, port, tlsTimeout)
if err != nil {
reportError(cmd, err)
return err
}
if jsonOutput {
printJSON(result.ToJSON())
} else {
ui.DisplayTLSVersionResults(result)
}
return nil
},
}
func init() {
tlsCmd.Flags().IntVar(&tlsPort, "port", 443, "Port for TLS testing")
tlsCmd.Flags().DurationVar(&tlsTimeout, "timeout", 5*time.Second, "Network timeout (e.g., 5s, 2s)")
rootCmd.AddCommand(tlsCmd)
}