@@ -38,23 +38,13 @@ func stringInSlice(a string, list []string) bool {
3838}
3939
4040func (t * insecureConfigTLS ) processTLSCipherSuites (n ast.Node , c * gas.Context ) * gas.Issue {
41- tlsConfig := gas .MatchCompLit (n , c , t .requiredType )
42- if tlsConfig == nil {
43- return nil
44- }
4541
46- for _ , expr := range tlsConfig .Elts {
47- if keyvalExpr , ok := expr .(* ast.KeyValueExpr ); ok {
48- if keyname , ok := keyvalExpr .Key .(* ast.Ident ); ok && keyname .Name == "CipherSuites" {
49- if ciphers , ok := keyvalExpr .Value .(* ast.CompositeLit ); ok {
50- for _ , cipher := range ciphers .Elts {
51- if ident , ok := cipher .(* ast.SelectorExpr ); ok {
52- if ! stringInSlice (ident .Sel .Name , t .goodCiphers ) {
53- str := fmt .Sprintf ("TLS Bad Cipher Suite: %s" , ident .Sel .Name )
54- return gas .NewIssue (c , n , str , gas .High , gas .High )
55- }
56- }
57- }
42+ if ciphers , ok := n .(* ast.CompositeLit ); ok {
43+ for _ , cipher := range ciphers .Elts {
44+ if ident , ok := cipher .(* ast.SelectorExpr ); ok {
45+ if ! stringInSlice (ident .Sel .Name , t .goodCiphers ) {
46+ err := fmt .Sprintf ("TLS Bad Cipher Suite: %s" , ident .Sel .Name )
47+ return gas .NewIssue (c , ident , err , gas .High , gas .High )
5848 }
5949 }
6050 }
@@ -65,6 +55,7 @@ func (t *insecureConfigTLS) processTLSCipherSuites(n ast.Node, c *gas.Context) *
6555func (t * insecureConfigTLS ) processTLSConfVal (n * ast.KeyValueExpr , c * gas.Context ) * gas.Issue {
6656 if ident , ok := n .Key .(* ast.Ident ); ok {
6757 switch ident .Name {
58+
6859 case "InsecureSkipVerify" :
6960 if node , ok := n .Value .(* ast.Ident ); ok {
7061 if node .Name != "false" {
@@ -104,7 +95,7 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gas.Contex
10495 }
10596
10697 case "CipherSuites" :
107- if ret := t .processTLSCipherSuites (n , c ); ret != nil {
98+ if ret := t .processTLSCipherSuites (n . Value , c ); ret != nil {
10899 return ret
109100 }
110101
@@ -114,24 +105,24 @@ func (t *insecureConfigTLS) processTLSConfVal(n *ast.KeyValueExpr, c *gas.Contex
114105 return nil
115106}
116107
117- func (t * insecureConfigTLS ) Match (n ast.Node , c * gas.Context ) (gi * gas.Issue , err error ) {
118- if node := gas . MatchCompLit ( n , c , t . requiredType ); node != nil {
119- for _ , elt := range node .Elts {
108+ func (t * insecureConfigTLS ) Match (n ast.Node , c * gas.Context ) (* gas.Issue , error ) {
109+ if complit , ok := n .( * ast. CompositeLit ); ok && c . Info . TypeOf ( complit . Type ). String () == t . requiredType {
110+ for _ , elt := range complit .Elts {
120111 if kve , ok := elt .(* ast.KeyValueExpr ); ok {
121- gi = t .processTLSConfVal (kve , c )
122- if gi != nil {
123- break
112+ issue : = t .processTLSConfVal (kve , c )
113+ if issue != nil {
114+ return issue , nil
124115 }
125116 }
126117 }
127118 }
128- return
119+ return nil , nil
129120}
130121
131122// NewModernTLSCheck see: https://wiki.mozilla.org/Security/Server_Side_TLS#Modern_compatibility
132123func NewModernTLSCheck (conf gas.Config ) (gas.Rule , []ast.Node ) {
133124 return & insecureConfigTLS {
134- requiredType : "tls.Config" ,
125+ requiredType : "crypto/ tls.Config" ,
135126 MinVersion : 0x0303 , // TLS 1.2 only
136127 MaxVersion : 0x0303 ,
137128 goodCiphers : []string {
@@ -146,7 +137,7 @@ func NewModernTLSCheck(conf gas.Config) (gas.Rule, []ast.Node) {
146137// NewIntermediateTLSCheck see: https://wiki.mozilla.org/Security/Server_Side_TLS#Intermediate_compatibility_.28default.29
147138func NewIntermediateTLSCheck (conf gas.Config ) (gas.Rule , []ast.Node ) {
148139 return & insecureConfigTLS {
149- requiredType : "tls.Config" ,
140+ requiredType : "crypto/ tls.Config" ,
150141 MinVersion : 0x0301 , // TLS 1.2, 1.1, 1.0
151142 MaxVersion : 0x0303 ,
152143 goodCiphers : []string {
@@ -172,7 +163,7 @@ func NewIntermediateTLSCheck(conf gas.Config) (gas.Rule, []ast.Node) {
172163// NewCompatTLSCheck see: https://wiki.mozilla.org/Security/Server_Side_TLS#Old_compatibility_.28default.29
173164func NewCompatTLSCheck (conf gas.Config ) (gas.Rule , []ast.Node ) {
174165 return & insecureConfigTLS {
175- requiredType : "tls.Config" ,
166+ requiredType : "crypto/ tls.Config" ,
176167 MinVersion : 0x0301 , // TLS 1.2, 1.1, 1.0
177168 MaxVersion : 0x0303 ,
178169 goodCiphers : []string {
0 commit comments