-
Notifications
You must be signed in to change notification settings - Fork 0
/
tls.go
74 lines (64 loc) · 2.14 KB
/
tls.go
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
package squidr
import (
"bytes"
"crypto/tls"
"strconv"
"time"
"paepcke.de/squidr/openssltrace"
"paepcke.de/tlsinfo"
)
const (
_checkHeadLen = 27
_head = "<html><title>[squidr][report]"
)
func reportTLS(host, path string, conn *tls.Conn, connected bool, err error) error {
var buf bytes.Buffer
reportTLSHead(host, path, &buf)
reportTLSErr(err, &buf)
reportTLSTls(conn, connected, &buf)
reportTLSDns(host, &buf)
reportTLSOssl(host, &buf)
reportTLSFooter(&buf)
return writeReport(buf.Bytes(), _servTLS)
}
func reportTLSHead(host, path string, buf *bytes.Buffer) {
ts := time.Now()
if path == "" {
path = _none
}
buf.WriteString(_head + "[tls]</title><pre>\n")
buf.WriteString("[ -= SQUIDR TLS REPORT =- ]\n")
buf.WriteString("Report Timestamp: " + strconv.FormatInt(ts.UnixNano(), 10) + _linefeed)
buf.WriteString("Report Created : " + ts.Format(time.RFC3339) + _linefeed)
buf.WriteString("Target Domain : " + host + _linefeed)
buf.WriteString("Target Path : " + path + _linefeed)
for _, u := range tlsinfo.ExtCheckURLs {
buf.WriteString("External Report : <a href=\"" + u + host + "\" target=\"_blank\">" + u + host + "</a>" + _linefeed)
}
}
func reportTLSFooter(buf *bytes.Buffer) {
buf.WriteString("</pre></html>\n")
}
func reportTLSErr(err error, buf *bytes.Buffer) {
if err != nil {
buf.WriteString("\nGolang Runtime Environment Error Message\n")
buf.WriteString(err.Error())
buf.WriteString(_linefeed)
buf.WriteString(_linefeed)
}
}
func reportTLSTls(conn *tls.Conn, connected bool, buf *bytes.Buffer) {
if connected {
buf.WriteString("\nGolang TLS Runtime Environment State Summary Report\n\n")
buf.WriteString(tlsinfo.ReportConnText(conn))
}
}
func reportTLSDns(host string, buf *bytes.Buffer) {
buf.WriteString("\nDNS Environment State Summary Report (local resolver)\n\n")
reportLocal.Query, reportGoogle.Query, reportCloudflare.Query = host, host, host
buf.WriteString(reportLocal.Generate() + _linefeed)
}
func reportTLSOssl(host string, buf *bytes.Buffer) {
buf.WriteString("\nOpenSSL TLS Trace Summary Report\n\n")
buf.WriteString(openssltrace.OpenSSLReportHostText(host, _sslCaTrust, true) + _linefeed)
}