Use an interface for making tests and reporting test results
This commit is contained in:
parent
f48afca7e8
commit
5bbb306006
20
cli/main.go
20
cli/main.go
@ -4,10 +4,15 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"github.com/nemunaire/eyespot/eyespot/cipherts"
|
"github.com/nemunaire/eyespot"
|
||||||
"github.com/nemunaire/eyespot/eyespot/protocolts"
|
"github.com/nemunaire/eyespot/testsuite"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var tests = []eyespot.Test{
|
||||||
|
testsuite.Protocols{},
|
||||||
|
testsuite.Ciphers{},
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
var protocol = flag.String("protocol", "tcp", "Protocol to test")
|
var protocol = flag.String("protocol", "tcp", "Protocol to test")
|
||||||
var hostname = flag.String("hostname", "localhost", "Hostname to test")
|
var hostname = flag.String("hostname", "localhost", "Hostname to test")
|
||||||
@ -16,6 +21,13 @@ func main() {
|
|||||||
|
|
||||||
host := fmt.Sprintf("%s:%d", *hostname, *port)
|
host := fmt.Sprintf("%s:%d", *hostname, *port)
|
||||||
|
|
||||||
log.Println(protocolts.Run(*protocol, host))
|
for _, t := range tests {
|
||||||
log.Println(cipherts.Run(*protocol, host))
|
log.Println(t.GetTestDescription())
|
||||||
|
|
||||||
|
if res, err := t.Run(*protocol, host); err != nil {
|
||||||
|
log.Println(err)
|
||||||
|
} else {
|
||||||
|
log.Println(res)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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
|
|
||||||
}
|
|
@ -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
|
|
||||||
}
|
|
11
interfaces.go
Normal file
11
interfaces.go
Normal file
@ -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)
|
||||||
|
}
|
86
testsuite/ciphers.go
Normal file
86
testsuite/ciphers.go
Normal file
@ -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
|
||||||
|
}
|
61
testsuite/protocols.go
Normal file
61
testsuite/protocols.go
Normal file
@ -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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user