This repository has been archived by the owner on May 29, 2021. It is now read-only.
/
pretty.go
78 lines (66 loc) · 1.57 KB
/
pretty.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
75
76
77
78
package sslprobe
import (
"fmt"
tc "github.com/thijzert/go-termcolours"
)
func (c CipherInfo) String() string {
return c.Name
}
func (vd versionDetails) String() string {
if vd.Supported {
return vd.Version.String()
}
return fmt.Sprintf("no %s", vd.Version)
}
func (c CipherInfo) Pretty() string {
var colour func(string) string = nil
suffix := ""
if c.Kex.Broken || c.Auth.Broken || c.Cipher.Broken || c.MAC.Broken {
colour = tc.Red
suffix = " INSECURE"
} else if c.Cipher.KeySize < 128 || c.MAC.TagSize < 160 {
colour = tc.Yellow
suffix = " WEAK"
}
pad := " "
fs := tc.Yellow("no FS")
if c.Kex.ForwardSecure {
fs = tc.Green(" FS ")
}
aead := " "
if c.MAC.AEAD {
aead = "AEAD"
}
cstr := fmt.Sprintf("%3d", c.Cipher.KeySize)
if colour == nil && c.Kex.ForwardSecure && c.Cipher.KeySize >= 128 && c.MAC.AEAD {
colour = tc.Green
}
if colour == nil {
colour = func(s string) string {
return s
}
}
return fmt.Sprintf("%s%s %s %s %s%s", colour(c.Name), pad[len(c.Name)%len(pad):], fs, colour(cstr), colour(aead), colour(suffix))
}
func (vd versionDetails) Pretty() string {
var col func(string) string = nil
if vd.Supported {
if vd.Version == SSL_2_0 {
col = tc.Bred
} else if vd.Version == SSL_3_0 {
col = tc.Red
} else if vd.Version == TLS_1_2 || vd.Version == TLS_1_3 {
col = tc.Bgreen
} else {
col = tc.Green
}
} else {
if vd.Version != SSL_2_0 && vd.Version != TLS_1_3 {
col = tc.Bblack
}
}
if col != nil {
return col(vd.Version.String())
}
return ""
}