Skip to content

Commit 2d7aac6

Browse files
vgavinashGitHub Enterprise
authored andcommitted
Changes added (#715)
1 parent 6bb4a50 commit 2d7aac6

File tree

3 files changed

+19
-30
lines changed

3 files changed

+19
-30
lines changed

test/container/devconfig_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ func TestDevSecure(t *testing.T) {
120120
t.Run("JMS", func(t *testing.T) {
121121
// OpenJDK is used for running tests, hence pass "false" for 7th parameter.
122122
// Cipher name specified is compliant with non-IBM JRE naming.
123-
runJMSTests(t, cli, ID, true, "app", appPassword, "false", "TLS_RSA_WITH_AES_256_CBC_SHA256")
123+
runJMSTests(t, cli, ID, true, "app", appPassword, "false", "*TLS12ORHIGHER")
124124
})
125125
t.Run("REST admin", func(t *testing.T) {
126126
testRESTAdmin(t, cli, ID, insecureTLSConfig, "")
@@ -473,7 +473,7 @@ func TestSSLFIPSYES(t *testing.T) {
473473

474474
t.Run("JMS", func(t *testing.T) {
475475
// Run the JMS tests, with no password specified
476-
runJMSTests(t, cli, ID, true, "app", appPassword, "false", "TLS_RSA_WITH_AES_256_CBC_SHA256")
476+
runJMSTests(t, cli, ID, true, "app", appPassword, "false", "*TLS12ORHIGHER")
477477
})
478478

479479
// Stop the container cleanly
@@ -535,14 +535,14 @@ func TestDevSecureFIPSTrueWeb(t *testing.T) {
535535
waitForWebReady(t, cli, ID, createTLSConfig(t, cert, tlsPassPhrase))
536536

537537
// Create a TLS Config with a cipher to use when connecting over HTTPS
538-
var secureTLSConfig *tls.Config = createTLSConfigWithCipher(t, cert, tlsPassPhrase, []uint16{tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256})
538+
var secureTLSConfig *tls.Config = createTLSConfig(t, cert, tlsPassPhrase, withMinTLSVersion(tls.VersionTLS12))
539539
// Put a message to queue
540540
t.Run("REST messaging", func(t *testing.T) {
541541
testRESTMessaging(t, cli, ID, secureTLSConfig, qm, "app", appPassword, "")
542542
})
543543

544544
// Create a TLS Config with a non-FIPS cipher to use when connecting over HTTPS
545-
var secureNonFIPSCipherConfig *tls.Config = createTLSConfigWithCipher(t, cert, tlsPassPhrase, []uint16{tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA})
545+
var secureNonFIPSCipherConfig *tls.Config = createTLSConfig(t, cert, tlsPassPhrase, withMinTLSVersion(tls.VersionTLS12))
546546
// Put a message to queue - the attempt to put message will fail with a EOF return message.
547547
t.Run("REST messaging", func(t *testing.T) {
548548
testRESTMessaging(t, cli, ID, secureNonFIPSCipherConfig, qm, "app", appPassword, "EOF")
@@ -615,7 +615,7 @@ func TestDevSecureFalseFIPSWeb(t *testing.T) {
615615
}
616616

617617
// Just do a HTTPS GET as well to query installation details.
618-
var secureTLSConfig *tls.Config = createTLSConfigWithCipher(t, cert, tlsPassPhrase, []uint16{tls.TLS_RSA_WITH_AES_256_GCM_SHA384})
618+
var secureTLSConfig *tls.Config = createTLSConfig(t, cert, tlsPassPhrase, withMinTLSVersion(tls.VersionTLS12))
619619
t.Run("REST admin", func(t *testing.T) {
620620
testRESTAdmin(t, cli, ID, secureTLSConfig, "")
621621
})

test/container/devconfig_test_util.go

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func processJunitLogLine(outputLine string) bool {
193193
}
194194

195195
// createTLSConfig creates a tls.Config which trusts the specified certificate
196-
func createTLSConfig(t *testing.T, certFile, password string) *tls.Config {
196+
func createTLSConfig(t *testing.T, certFile, password string, tlsConfigOptions ...tlsConfigOption) *tls.Config {
197197
// Get the SystemCertPool, continue with an empty pool on error
198198
certs, err := x509.SystemCertPool()
199199
if err != nil {
@@ -210,10 +210,15 @@ func createTLSConfig(t *testing.T, certFile, password string) *tls.Config {
210210
t.Fatal("No certs appended")
211211
}
212212
// Trust the augmented cert pool in our client
213-
return &tls.Config{
213+
config := &tls.Config{
214214
InsecureSkipVerify: false,
215215
RootCAs: certs,
216216
}
217+
// Apply any additional config options
218+
for _, applyOpt := range tlsConfigOptions {
219+
applyOpt(config)
220+
}
221+
return config
217222
}
218223

219224
func testRESTAdmin(t *testing.T, cli ce.ContainerInterface, ID string, tlsConfig *tls.Config, errorExpected string) {
@@ -330,27 +335,11 @@ func testRESTMessaging(t *testing.T, cli ce.ContainerInterface, ID string, tlsCo
330335
}
331336
}
332337

333-
// createTLSConfig creates a tls.Config which trusts the specified certificate
334-
func createTLSConfigWithCipher(t *testing.T, certFile, password string, ciphers []uint16) *tls.Config {
335-
// Get the SystemCertPool, continue with an empty pool on error
336-
certs, err := x509.SystemCertPool()
337-
if err != nil {
338-
t.Fatal(err)
339-
}
340-
// Read in the cert file
341-
cert, err := os.ReadFile(certFile)
342-
if err != nil {
343-
t.Fatal(err)
344-
}
345-
// Append our cert to the system pool
346-
ok := certs.AppendCertsFromPEM(cert)
347-
if !ok {
348-
t.Fatal("No certs appended")
349-
}
350-
// Trust the augmented cert pool in our client
351-
return &tls.Config{
352-
InsecureSkipVerify: false,
353-
RootCAs: certs,
354-
CipherSuites: ciphers,
338+
type tlsConfigOption func(*tls.Config)
339+
340+
// withMinTLSVersion is a functional option to set the minimum version for TLS
341+
func withMinTLSVersion(version uint16) tlsConfigOption {
342+
return func(cfg *tls.Config) {
343+
cfg.MinVersion = version
355344
}
356345
}

test/container/mq_native_ha_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ func TestNativeHASecureCipherSpecFIPS(t *testing.T) {
224224
nhaPort := basePort + i
225225
containerConfig := getNativeHAContainerConfig(containerNames[i], containerNames, defaultHAPort)
226226
// MQ_NATIVE_HA_CIPHERSPEC is set a FIPS compliant cipherspec.
227-
containerConfig.Env = append(containerConfig.Env, "MQ_NATIVE_HA_TLS=true", "MQ_NATIVE_HA_CIPHERSPEC=TLS_RSA_WITH_AES_128_GCM_SHA256", "MQ_ENABLE_FIPS=true")
227+
containerConfig.Env = append(containerConfig.Env, "MQ_NATIVE_HA_TLS=true", "MQ_NATIVE_HA_CIPHERSPEC=ANY_TLS12_OR_HIGHER", "MQ_ENABLE_FIPS=true")
228228
hostConfig := getNativeHASecureHostConfig(t)
229229
hostConfig = populateNativeHAPortBindings([]int{9414}, nhaPort, hostConfig)
230230
networkingConfig := getNativeHANetworkConfig("host")

0 commit comments

Comments
 (0)