Debian Codegraph @

crypto/x509util/types.go

raw symbols SCIP
1 package x509util
2
3 import (
4 "crypto/tls"
5 "fmt"
6
7 "github.com/pkg/errors"
8 )
9
10 // ASN1DN contains ASN1.DN attributes that are used in Subject and Issuer
11 // x509 Certificate blocks.
12 type ASN1DN struct {
13 Country string `json:"country,omitempty" step:"country"`
14 Organization string `json:"organization,omitempty" step:"organization"`
15 OrganizationalUnit string `json:"organizationalUnit,omitempty" step:"organizationalUnit"`
16 Locality string `json:"locality,omitempty" step:"locality"`
17 Province string `json:"province,omitempty" step:"province"`
18 StreetAddress string `json:"streetAddress,omitempty" step:"streetAddress"`
19 CommonName string `json:"commonName,omitempty" step:"commonName"`
20 }
21
22 // TLSVersion represents a TLS version number.
23 type TLSVersion float64
24
25 // Validate implements models.Validator and checks that a cipher suite is
26 // valid.
27 func (v TLSVersion) Validate() error {
28 if _, ok := tlsVersions[v]; ok {
29 return nil
30 }
31 return errors.Errorf("%f is not a valid tls version", v)
32 }
33
34 // Value returns the Go constant for the TLSVersion.
35 func (v TLSVersion) Value() uint16 {
36 return tlsVersions[v]
37 }
38
39 // String returns the Go constant for the TLSVersion.
40 func (v TLSVersion) String() string {
41 k := v.Value()
42 switch k {
43 case tls.VersionTLS10:
44 return "1.0"
45 case tls.VersionTLS11:
46 return "1.1"
47 case tls.VersionTLS12:
48 return "1.2"
49 default:
50 return fmt.Sprintf("unexpected value: %d", k)
51 }
52 }
53
54 // tlsVersions has the list of supported tls version.
55 var tlsVersions = map[TLSVersion]uint16{
56 // Defaults to TLS 1.2
57 0: tls.VersionTLS12,
58 // Options
59 1.0: tls.VersionTLS10,
60 1.1: tls.VersionTLS11,
61 1.2: tls.VersionTLS12,
62 }
63
64 // CipherSuites represents an array of string codes representing the cipher
65 // suites.
66 type CipherSuites []string
67
68 // Validate implements models.Validator and checks that a cipher suite is
69 // valid.
70 func (c CipherSuites) Validate() error {
71 for _, s := range c {
72 if _, ok := cipherSuites[s]; !ok {
73 return errors.Errorf("%s is not a valid cipher suite", s)
74 }
75 }
76 return nil
77 }
78
79 // Value returns an []uint16 for the cipher suites.
80 func (c CipherSuites) Value() []uint16 {
81 values := make([]uint16, len(c))
82 for i, s := range c {
83 values[i] = cipherSuites[s]
84 }
85 return values
86 }
87
88 // cipherSuites has the list of supported cipher suites.
89 var cipherSuites = map[string]uint16{
90 "TLS_RSA_WITH_RC4_128_SHA": tls.TLS_RSA_WITH_RC4_128_SHA,
91 "TLS_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA,
92 "TLS_RSA_WITH_AES_128_CBC_SHA": tls.TLS_RSA_WITH_AES_128_CBC_SHA,
93 "TLS_RSA_WITH_AES_256_CBC_SHA": tls.TLS_RSA_WITH_AES_256_CBC_SHA,
94 "TLS_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_RSA_WITH_AES_128_CBC_SHA256,
95 "TLS_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
96 "TLS_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
97 "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA,
98 "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
99 "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,
100 "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
101 "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
102 "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
103 "TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
104 "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA,
105 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
106 "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
107 "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,
108 "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
109 "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
110 "TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305": tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
111 }