diff --git a/cli/main.go b/cli/main.go index 0535718..83ee1ca 100644 --- a/cli/main.go +++ b/cli/main.go @@ -4,10 +4,15 @@ import ( "flag" "fmt" "log" - "github.com/nemunaire/eyespot/eyespot/cipherts" - "github.com/nemunaire/eyespot/eyespot/protocolts" + "github.com/nemunaire/eyespot" + "github.com/nemunaire/eyespot/testsuite" ) +var tests = []eyespot.Test{ + testsuite.Protocols{}, + testsuite.Ciphers{}, +} + func main() { var protocol = flag.String("protocol", "tcp", "Protocol to test") var hostname = flag.String("hostname", "localhost", "Hostname to test") @@ -16,6 +21,13 @@ func main() { host := fmt.Sprintf("%s:%d", *hostname, *port) - log.Println(protocolts.Run(*protocol, host)) - log.Println(cipherts.Run(*protocol, host)) + for _, t := range tests { + log.Println(t.GetTestDescription()) + + if res, err := t.Run(*protocol, host); err != nil { + log.Println(err) + } else { + log.Println(res) + } + } } diff --git a/eyespot/cipherts/ciphers.go b/eyespot/cipherts/ciphers.go deleted file mode 100644 index de784f4..0000000 --- a/eyespot/cipherts/ciphers.go +++ /dev/null @@ -1,43 +0,0 @@ -package cipherts - -import ( - "crypto/tls" -) - -func Run(protocol string, host string) (map[uint16]bool) { - result := map[uint16]bool{} - - for _, c := range []uint16{ - tls.TLS_RSA_WITH_RC4_128_SHA, - tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, - tls.TLS_RSA_WITH_AES_128_CBC_SHA, - tls.TLS_RSA_WITH_AES_256_CBC_SHA, - tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, - tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, - tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, - tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA, - tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, - tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, - tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, - tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, - tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, - } { - r, _ := test(protocol, host, c) - result[c] = r - } - - return result -} - -func test(protocol string, host string, cipher uint16) (bool, error) { - conn, err := tls.Dial(protocol, host, &tls.Config{ - CipherSuites: []uint16{cipher}, - InsecureSkipVerify: true, - }) - if err != nil { - return false, err - } - defer conn.Close(); - - return true, nil -} diff --git a/eyespot/protocolts/protocols.go b/eyespot/protocolts/protocols.go deleted file mode 100644 index 7425ceb..0000000 --- a/eyespot/protocolts/protocols.go +++ /dev/null @@ -1,35 +0,0 @@ -package protocolts - -import ( - "crypto/tls" -) - -func Run(protocol string, host string) (map[uint16]bool) { - result := map[uint16]bool{} - - for _, v := range []uint16{ - tls.VersionSSL30, - tls.VersionTLS10, - tls.VersionTLS11, - tls.VersionTLS12, - } { - r, _ := test(protocol, host, v) - result[v] = r - } - - return result -} - -func 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, err - } - defer conn.Close(); - - return true, nil -} diff --git a/interfaces.go b/interfaces.go new file mode 100644 index 0000000..5aaf573 --- /dev/null +++ b/interfaces.go @@ -0,0 +1,11 @@ +package eyespot + +type Result struct { + Passed bool +} + +type Test interface { + GetTestDescription() string + + Run(protocol string, host string) (map[string]Result, error) +} diff --git a/testsuite/ciphers.go b/testsuite/ciphers.go new file mode 100644 index 0000000..7e66aec --- /dev/null +++ b/testsuite/ciphers.go @@ -0,0 +1,86 @@ +package testsuite + +import ( + "crypto/tls" + "github.com/nemunaire/eyespot" +) + +type Ciphers struct {} + +func (Ciphers) GetTestDescription() string { + return "Test the ciphers suite accepted by the remote host." +} + +func (test Ciphers) Run(protocol string, host string) (map[string]eyespot.Result, error) { + var results = map[string]eyespot.Result{} + + for _, c := range []uint16{ + tls.TLS_RSA_WITH_RC4_128_SHA, + tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, + tls.TLS_RSA_WITH_AES_128_CBC_SHA, + tls.TLS_RSA_WITH_AES_256_CBC_SHA, + tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, + tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, + tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, + tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA, + tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, + tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, + tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, + tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, + tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, + } { + if r, err := cipher_test(protocol, host, c); err != nil { + return results, err + } else { + var cstr string + + switch c { + case tls.TLS_RSA_WITH_RC4_128_SHA: + cstr = "TLS_RSA_WITH_RC4_128_SHA" + case tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA: + cstr = "TLS_RSA_WITH_3DES_EDE_CBC_SHA" + case tls.TLS_RSA_WITH_AES_128_CBC_SHA: + cstr = "TLS_RSA_WITH_AES_128_CBC_SHA" + case tls.TLS_RSA_WITH_AES_256_CBC_SHA: + cstr = "TLS_RSA_WITH_AES_256_CBC_SHA" + case tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA: + cstr = "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA" + case tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA: + cstr = "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA" + case tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA: + cstr = "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA" + case tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA: + cstr = "TLS_ECDHE_RSA_WITH_RC4_128_SHA" + case tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA: + cstr = "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA" + case tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA: + cstr = "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA" + case tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: + cstr = "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA" + case tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256: + cstr = "TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256" + case tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256: + cstr = "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256" + default: + cstr = "" + } + + results[cstr] = eyespot.Result{r} + } + } + + return results, nil +} + +func cipher_test(protocol string, host string, cipher uint16) (bool, error) { + conn, err := tls.Dial(protocol, host, &tls.Config{ + CipherSuites: []uint16{cipher}, + InsecureSkipVerify: true, + }) + if err != nil { + return false, nil + } + defer conn.Close(); + + return true, nil +} diff --git a/testsuite/protocols.go b/testsuite/protocols.go new file mode 100644 index 0000000..442a34b --- /dev/null +++ b/testsuite/protocols.go @@ -0,0 +1,61 @@ +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 +}