-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathciphersuite.go
executable file
·81 lines (76 loc) · 1.88 KB
/
ciphersuite.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
79
80
81
package main
import (
"fmt"
"strings"
"encoding/hex"
"errors"
"bufio"
"os"
)
type cipherSuite struct {
code uint32
id string
name string
sslVer string
kx string
au string
enc string
mac string
export bool
}
func (cs cipherSuite) String() string {
return fmt.Sprintf("%s %s %s %s %s %s %s %v", cs.id, cs.name, cs.sslVer, cs.kx, cs.au,
cs.enc, cs.mac, cs.export)
}
func parseCode(text string) (uint32, error) {
text = strings.Replace(text, "0x", "", -1)
text = strings.Replace(text, ",", "", -1)
hc, err := hex.DecodeString(text)
if err != nil {
return 0, err
}
var code uint32
switch len(hc) {
case 2:
code = uint32(hc[1]) | uint32(hc[0])<<8
case 3:
code = uint32(hc[2]) | uint32(hc[1])<<8 | uint32(hc[0])<<16
default:
return 0, errors.New("parse code fail")
}
return code, nil
}
func getCipherSuites() map[uint32]cipherSuite {
cs := make(map[uint32]cipherSuite)
reader := bufio.NewReader(os.Stdin)
text, _ := reader.ReadString('\n')
for len(text) > 0 {
cipher := strings.Fields(text)
if len(cipher) < 8 {
fmt.Println("wrong ciper:", text)
text, _ = reader.ReadString('\n')
continue
}
code, err := parseCode(cipher[0])
if err != nil {
fmt.Println("cannot parse code:", text)
text, _ = reader.ReadString('\n')
continue
}
c := cipherSuite{}
c.id = cipher[0]
c.code = code
c.name = cipher[2]
c.sslVer = cipher[3]
c.kx = cipher[4]
c.au = cipher[5]
c.enc = cipher[6]
c.mac = cipher[7]
if len(cipher) == 9 && cipher[8] == "export" {
c.export = true
}
cs[code] = c
text, _ = reader.ReadString('\n')
}
return cs
}