From e9ea28ffd24021e0ba8031bb41d0370b50cd5f14 Mon Sep 17 00:00:00 2001 From: gmallard Date: Tue, 22 Oct 2013 07:55:58 -0400 Subject: [PATCH] TLS examples use unified common functionality. --- tlsexamps/tlsuc1/tlsuc1.go | 21 ++++++++++++--------- tlsexamps/tlsuc2/tlsuc2.go | 17 ++++++++--------- tlsexamps/tlsuc3/tlsuc3.go | 17 ++++++++--------- tlsexamps/tlsuc4/tlsuc4.go | 14 +++++++------- 4 files changed, 35 insertions(+), 34 deletions(-) diff --git a/tlsexamps/tlsuc1/tlsuc1.go b/tlsexamps/tlsuc1/tlsuc1.go index 25c9281..e4a6d34 100644 --- a/tlsexamps/tlsuc1/tlsuc1.go +++ b/tlsexamps/tlsuc1/tlsuc1.go @@ -15,7 +15,7 @@ // /* -Connect and Disconnect from a STOMP 1.2 broker with a TLS connection, use case 1. +Connect and Disconnect from a STOMP broker with a TLS connection, use case 1. TLS Use Case 1 - client does *not* authenticate broker. @@ -27,6 +27,11 @@ Connect and Disconnect from a STOMP 1.2 broker with a TLS connection, use case 1 - Expect connection failure (broker must be sent a valid client certificate) + Example use might be: + + go build + ./tlsuc1 + */ package main @@ -34,7 +39,7 @@ import ( "crypto/tls" "fmt" "github.com/gmallard/stompngo" - . "github.com/gmallard/stompngo_examples/sngecomm" + "github.com/gmallard/stompngo_examples/sngecomm" "log" "net" ) @@ -44,7 +49,7 @@ var ( testConfig *tls.Config ) -// Connect to a STOMP 1.2 broker using TLS and disconnect. +// Connect to a STOMP broker using TLS and disconnect. func main() { fmt.Println(exampid, "starts ...") @@ -53,7 +58,7 @@ func main() { testConfig.InsecureSkipVerify = true // Do *not* check the server's certificate // Get host and port - h, p := HostAndTLSPort12() + h, p := sngecomm.HostAndPort() fmt.Println(exampid, "host", h, "port", p) // Be polite, allow SNI (Server Virtual Hosting) @@ -71,11 +76,10 @@ func main() { log.Fatalln(e) // Handle this ...... } - DumpTLSConfig(testConfig, n) + sngecomm.DumpTLSConfig(testConfig, n) // Connect Headers - ch := stompngo.Headers{"accept-version", "1.2", - "host", Vhost()} + ch := sngecomm.ConnectHeaders() // Get a stomp connection. Parameters are: // a) the opened net connection @@ -90,8 +94,7 @@ func main() { // Polite Stomp disconnects are not required, but highly recommended. // Empty headers here. - eh := stompngo.Headers{} - e = conn.Disconnect(eh) + e = conn.Disconnect(stompngo.Headers{}) if e != nil { log.Fatalln(e) // Handle this ...... } diff --git a/tlsexamps/tlsuc2/tlsuc2.go b/tlsexamps/tlsuc2/tlsuc2.go index db7c540..cd3a731 100644 --- a/tlsexamps/tlsuc2/tlsuc2.go +++ b/tlsexamps/tlsuc2/tlsuc2.go @@ -15,7 +15,7 @@ // /* -Connect and Disconnect from a STOMP 1.2 broker with a TLS connection, use case 2. +Connect and Disconnect from a STOMP broker with a TLS connection, use case 2. TLS Use Case 2 - client *does* authenticate broker. @@ -30,6 +30,7 @@ Connect and Disconnect from a STOMP 1.2 broker with a TLS connection, use case 2 Example use might be: + go build ./tlsuc2 -srvCAFile=/ad3/gma/sslwork/2013/TestCA.crt # PEM format file */ @@ -42,7 +43,7 @@ import ( "flag" "fmt" "github.com/gmallard/stompngo" - . "github.com/gmallard/stompngo_examples/sngecomm" + "github.com/gmallard/stompngo_examples/sngecomm" "io/ioutil" "log" "net" @@ -58,7 +59,7 @@ func init() { flag.StringVar(&srvCAFile, "srvCAFile", "DUMMY", "Name of file with broker CA certificate") } -// Connect to a STOMP 1.2 broker using TLS and disconnect. +// Connect to a STOMP broker using TLS and disconnect. func main() { fmt.Println(exampid, "starts ...") @@ -71,7 +72,7 @@ func main() { testConfig.InsecureSkipVerify = false // *Do* check the broker's certificate // Get host and port - h, p := HostAndTLSPort12() + h, p := sngecomm.HostAndPort() fmt.Println(exampid, "host", h, "port", p) // Be polite, allow SNI (Server Virtual Hosting) @@ -107,11 +108,10 @@ func main() { } fmt.Println(exampid, "handshake complete ...") - DumpTLSConfig(testConfig, n) + sngecomm.DumpTLSConfig(testConfig, n) // Connect Headers - ch := stompngo.Headers{"accept-version", "1.2", - "host", Vhost()} + ch := sngecomm.ConnectHeaders() // Get a stomp connection. Parameters are: // a) the opened net connection @@ -126,8 +126,7 @@ func main() { // Polite Stomp disconnects are not required, but highly recommended. // Empty headers here. - eh := stompngo.Headers{} - e = conn.Disconnect(eh) + e = conn.Disconnect(stompngo.Headers{}) if e != nil { log.Fatalln(e) // Handle this ...... } diff --git a/tlsexamps/tlsuc3/tlsuc3.go b/tlsexamps/tlsuc3/tlsuc3.go index 991e14b..eeec6aa 100644 --- a/tlsexamps/tlsuc3/tlsuc3.go +++ b/tlsexamps/tlsuc3/tlsuc3.go @@ -15,7 +15,7 @@ // /* -Connect and Disconnect from a STOMP 1.2 broker with a TLS connection, use case 3. +Connect and Disconnect from a STOMP broker with a TLS connection, use case 3. TLS Use Case 3 - broker *does* authenticate client, client does *not* authenticate broker @@ -29,6 +29,7 @@ Connect and Disconnect from a STOMP 1.2 broker with a TLS connection, use case 3 Example use might be: + go build ./tlsuc3 -cliCertFile=/ad3/gma/sslwork/2013/client.crt -cliKeyFile=/ad3/gma/sslwork/2013/client.key */ @@ -39,7 +40,7 @@ import ( "flag" "fmt" "github.com/gmallard/stompngo" - . "github.com/gmallard/stompngo_examples/sngecomm" + "github.com/gmallard/stompngo_examples/sngecomm" "log" "net" ) @@ -56,7 +57,7 @@ func init() { flag.StringVar(&cliKeyFile, "cliKeyFile", "DUMMY_KEY", "Name of client key file") } -// Connect to a STOMP 1.2 broker using TLS and disconnect. +// Connect to a STOMP broker using TLS and disconnect. func main() { fmt.Println(exampid, "starts ...") @@ -70,7 +71,7 @@ func main() { testConfig.InsecureSkipVerify = true // Do *not* check the broker's certificate // Get host and port - h, p := HostAndTLSPort12() + h, p := sngecomm.HostAndPort() fmt.Println(exampid, "host", h, "port", p) // Be polite, allow SNI (Server Virtual Hosting) @@ -98,13 +99,12 @@ func main() { log.Fatalln(e) // Handle this ...... } - DumpTLSConfig(testConfig, n) + sngecomm.DumpTLSConfig(testConfig, n) fmt.Println(exampid, "handshake complete ...") // Connect Headers - ch := stompngo.Headers{"accept-version", "1.2", - "host", Vhost()} + ch := sngecomm.ConnectHeaders() // Get a stomp connection. Parameters are: // a) the opened net connection @@ -119,8 +119,7 @@ func main() { // Polite Stomp disconnects are not required, but highly recommended. // Empty headers here. - eh := stompngo.Headers{} - e = conn.Disconnect(eh) + e = conn.Disconnect(stompngo.Headers{}) if e != nil { log.Fatalln(e) // Handle this ...... } diff --git a/tlsexamps/tlsuc4/tlsuc4.go b/tlsexamps/tlsuc4/tlsuc4.go index 777561d..4ab4d01 100644 --- a/tlsexamps/tlsuc4/tlsuc4.go +++ b/tlsexamps/tlsuc4/tlsuc4.go @@ -15,7 +15,7 @@ // /* -Connect and Disconnect from a STOMP 1.2 broker with a TLS connection, use case 4. +Connect and Disconnect from a STOMP broker with a TLS connection, use case 4. TLS Use Case 4 - broker *does* authenticate client, client *does* authenticate broker @@ -29,6 +29,7 @@ Connect and Disconnect from a STOMP 1.2 broker with a TLS connection, use case 4 Example use might be: + go build ./tlsuc4 -srvCAFile=/ad3/gma/sslwork/2013/TestCA.crt -cliCertFile=/ad3/gma/sslwork/2013/client.crt -cliKeyFile=/ad3/gma/sslwork/2013/client.key */ @@ -41,7 +42,7 @@ import ( "flag" "fmt" "github.com/gmallard/stompngo" - . "github.com/gmallard/stompngo_examples/sngecomm" + "github.com/gmallard/stompngo_examples/sngecomm" "io/ioutil" "log" "net" @@ -61,7 +62,7 @@ func init() { flag.StringVar(&cliKeyFile, "cliKeyFile", "DUMMY_KEY", "Name of client key file") } -// Connect to a STOMP 1.2 broker using TLS and disconnect. +// Connect to a STOMP broker using TLS and disconnect. func main() { fmt.Println(exampid, "starts ...") @@ -76,7 +77,7 @@ func main() { testConfig.InsecureSkipVerify = false // *Do* check the broker's certificate // Get host and port - h, p := HostAndTLSPort12() + h, p := sngecomm.HostAndPort() fmt.Println(exampid, "host", h, "port", p) // Be polite, allow SNI (Server Virtual Hosting) @@ -121,13 +122,12 @@ func main() { log.Fatalln(e) // Handle this ...... } - DumpTLSConfig(testConfig, n) + sngecomm.DumpTLSConfig(testConfig, n) fmt.Println(exampid, "handshake complete ...") // Connect Headers - ch := stompngo.Headers{"accept-version", "1.2", - "host", Vhost()} + ch := sngecomm.ConnectHeaders() // Get a stomp connection. Parameters are: // a) the opened net connection -- 2.11.4.GIT