Skip to content

Commit

Permalink
fix: setting default value of nonStrictVerifySslCertificatesOfService…
Browse files Browse the repository at this point in the history
…s to … (#3029)

* Setting default value of nonStrictVerifySslCertificatesOfServices to false when certificate verification is enabled

Signed-off-by: sj895092 <[email protected]>

* refactoring the if conditions for certificate verification

Signed-off-by: sj895092 <[email protected]>

* wip strict conditions

Signed-off-by: Pablo Hernán Carle <[email protected]>

---------

Signed-off-by: sj895092 <[email protected]>
Signed-off-by: Pablo Hernán Carle <[email protected]>
Co-authored-by: Andrea Tabone <[email protected]>
Co-authored-by: Pablo Hernán Carle <[email protected]>
  • Loading branch information
3 people authored Aug 16, 2023
1 parent b1df6f0 commit 75b658c
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 26 deletions.
6 changes: 3 additions & 3 deletions api-catalog-package/src/main/resources/bin/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ fi
verify_certificates_config=$(echo "${ZWE_zowe_verifyCertificates}" | tr '[:lower:]' '[:upper:]')
if [ "${verify_certificates_config}" = "DISABLED" ]; then
verifySslCertificatesOfServices=false
nonStrictVerifySslCertificatesOfServices=false
nonStrictVerifySslCertificatesOfServices=true
elif [ "${verify_certificates_config}" = "NONSTRICT" ]; then
verifySslCertificatesOfServices=false
verifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=true
else
# default value is STRICT
verifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=false
fi

if [ "$(uname)" = "OS/390" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public SecurityFilterChain basicAuthOrTokenOrCertApiDocFilterChain(HttpSecurity
.authenticationProvider(gatewayTokenProvider)
.authenticationProvider(new CertificateAuthenticationProvider());

if (verifySslCertificatesOfServices || nonStrictVerifySslCertificatesOfServices) {
if (verifySslCertificatesOfServices || !nonStrictVerifySslCertificatesOfServices) {
if (isAttlsEnabled) {
http.x509()
.userDetailsService(x509UserDetailsService())
Expand Down
6 changes: 3 additions & 3 deletions caching-service-package/src/main/resources/bin/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,14 @@ fi
verify_certificates_config=$(echo "${ZWE_zowe_verifyCertificates}" | tr '[:lower:]' '[:upper:]')
if [ "${verify_certificates_config}" = "DISABLED" ]; then
verifySslCertificatesOfServices=false
nonStrictVerifySslCertificatesOfServices=false
nonStrictVerifySslCertificatesOfServices=true
elif [ "${verify_certificates_config}" = "NONSTRICT" ]; then
verifySslCertificatesOfServices=false
verifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=true
else
# default value is STRICT
verifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=false
fi

if [ "$(uname)" = "OS/390" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.headers().httpStrictTransportSecurity().disable()
.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS);

if (verifyCertificates || nonStrictVerifyCerts) {
if (verifyCertificates || !nonStrictVerifyCerts) {
http.authorizeRequests().anyRequest().authenticated().and()
.x509().userDetailsService(x509UserDetailsService());
if (isAttlsEnabled) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public CloseableHttpClient createSecureHttpClient(HttpClientConnectionManager co
}

public ConnectionSocketFactory createSslSocketFactory() {
if (config.isVerifySslCertificatesOfServices() || config.isNonStrictVerifySslCertificatesOfServices()) {
if (config.isVerifySslCertificatesOfServices()) {
return getSSLConnectionSocketFactory();
} else {
apimlLog.log("org.zowe.apiml.common.ignoringSsl");
Expand Down Expand Up @@ -218,7 +218,7 @@ private ConnectionSocketFactory getSSLConnectionSocketFactory() {
}

public SSLContext getSslContext() {
if (config.isVerifySslCertificatesOfServices() || config.isNonStrictVerifySslCertificatesOfServices()) {
if (config.isVerifySslCertificatesOfServices()) {
return createSecureSslContext();
} else {
return createIgnoringSslContext();
Expand Down Expand Up @@ -246,7 +246,7 @@ public void setSystemSslProperties() {
}

public HostnameVerifier getHostnameVerifier() {
if (config.isVerifySslCertificatesOfServices()) {
if (config.isVerifySslCertificatesOfServices() && !config.isNonStrictVerifySslCertificatesOfServices()) {
return SSLConnectionSocketFactory.getDefaultHostnameVerifier();
} else {
return new NoopHostnameVerifier();
Expand All @@ -268,7 +268,7 @@ public EurekaJerseyClientBuilder createEurekaJerseyClientBuilder(String eurekaSe
} else {
System.setProperty("com.netflix.eureka.shouldSSLConnectionsUseSystemSocketFactory", "true");

if (config.isVerifySslCertificatesOfServices() || config.isNonStrictVerifySslCertificatesOfServices()) {
if (config.isVerifySslCertificatesOfServices()) {
setSystemSslProperties();
}
builder.withCustomSSL(getSslContext());
Expand Down
6 changes: 3 additions & 3 deletions discovery-package/src/main/resources/bin/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ fi
verify_certificates_config=$(echo "${ZWE_zowe_verifyCertificates}" | tr '[:lower:]' '[:upper:]')
if [ "${verify_certificates_config}" = "DISABLED" ]; then
verifySslCertificatesOfServices=false
nonStrictVerifySslCertificatesOfServices=false
nonStrictVerifySslCertificatesOfServices=true
elif [ "${verify_certificates_config}" = "NONSTRICT" ]; then
verifySslCertificatesOfServices=false
verifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=true
else
# default value is STRICT
verifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=false
fi

if [ "$(uname)" = "OS/390" ]; then
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public SecurityFilterChain basicAuthOrTokenFilterChain(HttpSecurity http) throws
@Order(2)
public SecurityFilterChain clientCertificateFilterChain(HttpSecurity http) throws Exception {
baseConfigure(http.antMatcher("/eureka/**"));
if (verifySslCertificatesOfServices || nonStrictVerifySslCertificatesOfServices) {
if (verifySslCertificatesOfServices || !nonStrictVerifySslCertificatesOfServices) {
http.authorizeRequests()
.anyRequest().authenticated()
.and().x509().userDetailsService(x509UserDetailsService());
Expand All @@ -143,7 +143,7 @@ public SecurityFilterChain basicAuthOrTokenOrCertFilterChain(HttpSecurity http)
.authenticationProvider(gatewayLoginProvider)
.authenticationProvider(gatewayTokenProvider)
.httpBasic().realmName(DISCOVERY_REALM);
if (verifySslCertificatesOfServices || nonStrictVerifySslCertificatesOfServices) {
if (verifySslCertificatesOfServices || !nonStrictVerifySslCertificatesOfServices) {
http.authorizeRequests().anyRequest().authenticated().and()
.x509().userDetailsService(x509UserDetailsService());
if (isAttlsEnabled) {
Expand Down
6 changes: 3 additions & 3 deletions gateway-package/src/main/resources/bin/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,14 @@ fi
verify_certificates_config=$(echo "${ZWE_zowe_verifyCertificates}" | tr '[:lower:]' '[:upper:]')
if [ "${verify_certificates_config}" = "DISABLED" ]; then
verifySslCertificatesOfServices=false
nonStrictVerifySslCertificatesOfServices=false
nonStrictVerifySslCertificatesOfServices=true
elif [ "${verify_certificates_config}" = "NONSTRICT" ]; then
verifySslCertificatesOfServices=false
verifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=true
else
# default value is STRICT
verifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=false
fi

if [ -z "${ZWE_configs_apiml_catalog_serviceId}" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@

package org.zowe.apiml.util.config;

import lombok.extern.slf4j.Slf4j;
import org.zowe.apiml.zaasclient.config.ConfigProperties;

import static org.zowe.apiml.util.config.ConfigReader.environmentConfiguration;
import static org.zowe.apiml.util.requests.Endpoints.ROUTED_AUTH;

@Slf4j
public class ConfigReaderZaasClient {

public static ConfigProperties getConfigProperties() {
Expand Down
6 changes: 3 additions & 3 deletions metrics-service-package/src/main/resources/bin/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,14 @@ fi
verify_certificates_config=$(echo "${ZWE_zowe_verifyCertificates}" | tr '[:lower:]' '[:upper:]')
if [ "${verify_certificates_config}" = "DISABLED" ]; then
verifySslCertificatesOfServices=false
nonStrictVerifySslCertificatesOfServices=false
nonStrictVerifySslCertificatesOfServices=true
elif [ "${verify_certificates_config}" = "NONSTRICT" ]; then
verifySslCertificatesOfServices=false
verifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=true
else
# default value is STRICT
verifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=true
nonStrictVerifySslCertificatesOfServices=false
fi

if [ "$(uname)" = "OS/390" ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ private EurekaClient initializeEurekaClient(
builder.verifySslCertificatesOfServices(Boolean.TRUE.equals(sslConfig.getVerifySslCertificatesOfServices()));
builder.nonStrictVerifySslCertificatesOfServices(Boolean.TRUE.equals(sslConfig.getNonStrictVerifySslCertificatesOfServices()));
if (Boolean.TRUE.equals(sslConfig.getVerifySslCertificatesOfServices()) ||
Boolean.TRUE.equals(sslConfig.getNonStrictVerifySslCertificatesOfServices())) {
Boolean.FALSE.equals(sslConfig.getNonStrictVerifySslCertificatesOfServices())) {
builder.trustStore(sslConfig.getTrustStore())
.trustStoreType(sslConfig.getTrustStoreType())
.trustStorePassword(sslConfig.getTrustStorePassword());
Expand Down

0 comments on commit 75b658c

Please sign in to comment.