eyespot/testsuite/protocols.go

62 lines
1.2 KiB
Go

package testsuite
import (
"crypto/tls"
"github.com/nemunaire/eyespot"
)
type Protocols struct {
}
func (Protocols) GetTestDescription() string {
return "Test for protocols accepted by the remote host."
}
func (test Protocols) Run(protocol string, host string) (map[string]eyespot.Result, error) {
var results = map[string]eyespot.Result{}
for _, v := range []uint16{
tls.VersionSSL30,
tls.VersionTLS10,
tls.VersionTLS11,
tls.VersionTLS12,
} {
if r, err := protocol_test(protocol, host, v); err != nil {
return results, err
} else {
var cstr string
switch v {
case tls.VersionSSL30:
cstr = "VersionSSL30"
case tls.VersionTLS10:
cstr = "VersionTLS10"
case tls.VersionTLS11:
cstr = "VersionTLS11"
case tls.VersionTLS12:
cstr = "VersionTLS12"
default:
cstr = ""
}
results[cstr] = eyespot.Result{r}
}
}
return results, nil
}
func protocol_test(protocol string, host string, version uint16) (bool, error) {
conn, err := tls.Dial(protocol, host, &tls.Config{
MinVersion: version,
MaxVersion: version,
InsecureSkipVerify: true,
})
if err != nil {
return false, nil
}
defer conn.Close();
return true, nil
}