...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 package tlsutil
16
17 import (
18 "crypto/tls"
19 "fmt"
20 )
21
22
23
24 func GetCipherSuite(s string) (uint16, bool) {
25 for _, c := range tls.CipherSuites() {
26 if s == c.Name {
27 return c.ID, true
28 }
29 }
30 for _, c := range tls.InsecureCipherSuites() {
31 if s == c.Name {
32 return c.ID, true
33 }
34 }
35 switch s {
36 case "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305":
37 return tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, true
38 case "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305":
39 return tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, true
40 }
41 return 0, false
42 }
43
44
45 func GetCipherSuites(ss []string) ([]uint16, error) {
46 cs := make([]uint16, len(ss))
47 for i, s := range ss {
48 var ok bool
49 cs[i], ok = GetCipherSuite(s)
50 if !ok {
51 return nil, fmt.Errorf("unexpected TLS cipher suite %q", s)
52 }
53 }
54
55 return cs, nil
56 }
57
View as plain text