-
Notifications
You must be signed in to change notification settings - Fork 66
[OSJC-125] exclude DHE (SSL) ciphers when supported keys are <= 1024 #159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,4 +4,5 @@ | |
| target | ||
| bin | ||
| .metadata | ||
| **/integrationTest.properties | ||
| **/integrationTest.properties | ||
| /target/ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2012 Red Hat, Inc. | ||
| * Copyright (c) 2012-2014 Red Hat, Inc. | ||
| * Distributed under license by Red Hat, Inc. All rights reserved. | ||
| * This program is made available under the terms of the | ||
| * Eclipse Public License v1.0 which accompanies this distribution, | ||
|
|
@@ -14,8 +14,10 @@ | |
| import java.io.IOException; | ||
|
|
||
| import com.openshift.client.IHttpClient.ISSLCertificateCallback; | ||
| import com.openshift.client.configuration.AbstractOpenshiftConfiguration.ConfigurationOptions; | ||
| import com.openshift.client.configuration.IOpenShiftConfiguration; | ||
| import com.openshift.client.configuration.OpenShiftConfiguration; | ||
| import com.openshift.client.utils.SSLUtils; | ||
| import com.openshift.internal.client.AbstractOpenShiftConnectionFactory; | ||
| import com.openshift.internal.client.IRestService; | ||
| import com.openshift.internal.client.RestService; | ||
|
|
@@ -33,7 +35,7 @@ | |
| * | ||
| */ | ||
| public class OpenShiftConnectionFactory extends AbstractOpenShiftConnectionFactory { | ||
| private IOpenShiftConfiguration configuration = null; | ||
| private IOpenShiftConfiguration configuration; | ||
| /** | ||
| * Establish a connection with the clientId along with user's password. | ||
| * User's login and Server URL are retrieved from the local configuration | ||
|
|
@@ -49,11 +51,7 @@ public class OpenShiftConnectionFactory extends AbstractOpenShiftConnectionFacto | |
| * @throws OpenShiftException | ||
| */ | ||
| public IOpenShiftConnection getConnection(final String clientId, final String password) throws OpenShiftException { | ||
| try { | ||
| configuration = new OpenShiftConfiguration(); | ||
| } catch (IOException e) { | ||
| throw new OpenShiftException(e, "Failed to load OpenShift configuration file."); | ||
| } | ||
| IOpenShiftConfiguration configuration = getConfiguration(); | ||
| return getConnection(clientId, configuration.getRhlogin(), password, configuration.getLibraServer()); | ||
| } | ||
|
|
||
|
|
@@ -75,12 +73,7 @@ public IOpenShiftConnection getConnection(final String clientId, final String pa | |
| */ | ||
| public IOpenShiftConnection getConnection(final String clientId, final String username, final String password) | ||
| throws OpenShiftException { | ||
| try { | ||
| configuration = new OpenShiftConfiguration(); | ||
| } catch (IOException e) { | ||
| throw new OpenShiftException(e, "Failed to load OpenShift configuration file."); | ||
| } | ||
| return getConnection(clientId, username, password, configuration.getLibraServer()); | ||
| return getConnection(clientId, username, password, getConfiguration().getLibraServer()); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -115,6 +108,23 @@ public IOpenShiftConnection getConnection(final String clientId, final String us | |
| return getConnection(clientId, username, password, null, null, serverUrl, null); | ||
| } | ||
|
|
||
| public IOpenShiftConnection getConnection(final String clientId, final String username, final String password, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what is the difference from this getconnection and other getconnections ?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are all overloads. There's now an overload with a regex to exclude ciphers. |
||
| final String authKey, final String authIV, final String serverUrl, | ||
| final ISSLCertificateCallback sslCertificateCallback) throws OpenShiftException { | ||
| return getConnection(clientId, username, password, authKey, authIV, serverUrl, sslCertificateCallback, createCipherExclusionRegex(getConfiguration())); | ||
| } | ||
|
|
||
| protected String createCipherExclusionRegex(IOpenShiftConfiguration configuration) { | ||
| if(configuration.getDisableBadSSLCiphers() == ConfigurationOptions.YES | ||
| || (configuration.getDisableBadSSLCiphers() == ConfigurationOptions.AUTO) && !SSLUtils.supportsDHECipherKeysOf(1024 + 64)) { | ||
| // jdk < 1.8 only support DHE cipher keys <= 1024 bit | ||
| // https://issues.jboss.org/browse/JBIDE-18454 | ||
| return SSLUtils.CIPHER_DHE_REGEX; | ||
| } else { | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Establish a connection with the clientId along with user's login and | ||
| * password. | ||
|
|
@@ -133,31 +143,47 @@ public IOpenShiftConnection getConnection(final String clientId, final String us | |
| * @throws OpenShiftException | ||
| */ | ||
| public IOpenShiftConnection getConnection(final String clientId, final String username, final String password, | ||
| final String authKey, final String authIV, final String serverUrl, | ||
| final ISSLCertificateCallback sslCertificateCallback) throws OpenShiftException { | ||
| if (configuration == null) { | ||
| try { | ||
| configuration = new OpenShiftConfiguration(); | ||
| } catch (IOException e) { | ||
| throw new OpenShiftException(e, "Failed to load OpenShift configuration file."); | ||
| } | ||
| } | ||
| final String authKey, final String authIV, final String serverUrl, | ||
| final ISSLCertificateCallback sslCertificateCallback, String exludeSSLCipherRegex) | ||
| throws OpenShiftException { | ||
|
|
||
| Assert.notNull(clientId); | ||
| Assert.notNull(username); | ||
| Assert.notNull(password); | ||
| Assert.notNull(serverUrl); | ||
|
|
||
| IHttpClient httpClient = createClient( | ||
| clientId, username, password, authKey, authIV, serverUrl, sslCertificateCallback, exludeSSLCipherRegex); | ||
| try { | ||
| IHttpClient httpClient = | ||
| new UrlConnectionHttpClientBuilder() | ||
| return getConnection(clientId, username, password, serverUrl, httpClient); | ||
| } catch (IOException e) { | ||
| throw new OpenShiftException(e, "Failed to establish connection for user ''{0}}''", username); | ||
| } | ||
| } | ||
|
|
||
| protected IHttpClient createClient(final String clientId, final String username, final String password, | ||
| final String authKey, final String authIV, final String serverUrl, | ||
| final ISSLCertificateCallback sslCertificateCallback, String exludeSSLCipherRegex) { | ||
| return new UrlConnectionHttpClientBuilder() | ||
| .setCredentials(username, password, authKey, authIV) | ||
| .setSSLCertificateCallback(sslCertificateCallback) | ||
| .setConfigTimeout(configuration.getTimeout()) | ||
| .setConfigTimeout(getConfiguration().getTimeout()) | ||
| .excludeSSLCipher(exludeSSLCipherRegex) | ||
| .client(); | ||
| return getConnection(clientId, username, password, serverUrl, httpClient); | ||
| } | ||
|
|
||
| protected IOpenShiftConfiguration getConfiguration() throws OpenShiftException { | ||
| if (this.configuration == null) { | ||
| this.configuration = createConfiguration(); | ||
| } | ||
| return this.configuration; | ||
| } | ||
|
|
||
| protected IOpenShiftConfiguration createConfiguration() throws OpenShiftException { | ||
| try { | ||
| return new OpenShiftConfiguration(); | ||
| } catch (IOException e) { | ||
| throw new OpenShiftException(e, "Failed to establish connection for user ''{0}}''", username); | ||
| throw new OpenShiftException(e, "Failed to load OpenShift configuration file."); | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| /******************************************************************************* | ||
| * Copyright (c) 2011 Red Hat, Inc. | ||
| * Copyright (c) 2011-2014 Red Hat, Inc. | ||
| * Distributed under license by Red Hat, Inc. All rights reserved. | ||
| * This program is made available under the terms of the | ||
| * Eclipse Public License v1.0 which accompanies this distribution, | ||
|
|
@@ -33,26 +33,42 @@ public abstract class AbstractOpenshiftConfiguration implements IOpenShiftConfig | |
| protected static final String KEY_LIBRA_SERVER = "libra_server"; | ||
| protected static final String KEY_LIBRA_DOMAIN = "libra_domain"; | ||
|
|
||
|
|
||
| protected static final String KEY_PASSWORD = "rhpassword"; | ||
| protected static final String KEY_CLIENT_ID = "client_id"; | ||
|
|
||
| protected static final String KEY_TIMEOUT = "timeout"; | ||
| protected static final String DEFAULT_OPENSHIFT_TIMEOUT = "180000"; //3 minutes | ||
| protected static final String DEFAULT_OPENSHIFT_TIMEOUT = "180000"; // 3mins | ||
|
|
||
| protected static final String KEY_DISABLE_BAD_SSL_CIPHERS = "disable_bad_sslciphers"; | ||
|
|
||
| private static final Pattern QUOTED_REGEX = Pattern.compile("['\"]*([^'\"]+)['\"]*"); | ||
| private static final char SINGLEQUOTE = '\''; | ||
|
|
||
| private static final String SYSPROPERTY_PROXY_PORT = "proxyPort"; | ||
| private static final String SYSPROPERTY_PROXY_HOST = "proxyHost"; | ||
| private static final String SYSPROPERTY_PROXY_SET = "proxySet"; | ||
|
|
||
| private Properties properties; | ||
| private File file; | ||
|
|
||
| // TODO: implement | ||
|
|
||
| private boolean doSSLChecks = false; | ||
|
|
||
| public enum ConfigurationOptions { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this really need to be public api ? |
||
| YES, NO, AUTO; | ||
|
|
||
| private static ConfigurationOptions safeValueOf(String string) { | ||
| if (string == null) { | ||
| return NO; | ||
| } | ||
|
|
||
| try { | ||
| return valueOf(string.toUpperCase()); | ||
| } catch (IllegalArgumentException e) { | ||
| return NO; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected AbstractOpenshiftConfiguration() throws FileNotFoundException, IOException { | ||
| this(null, null); | ||
| } | ||
|
|
@@ -164,34 +180,45 @@ protected String removeQuotes(String value) { | |
| return value; | ||
| } | ||
| } | ||
|
|
||
| public String getPassword() { | ||
| return properties.getProperty(KEY_PASSWORD); | ||
| } | ||
|
|
||
| public String getClientId() { | ||
| return properties.getProperty(KEY_CLIENT_ID); | ||
| } | ||
|
|
||
| public ConfigurationOptions getDisableBadSSLCiphers() { | ||
| return ConfigurationOptions.safeValueOf( | ||
| removeQuotes(properties.getProperty(KEY_DISABLE_BAD_SSL_CIPHERS))); | ||
| } | ||
|
|
||
| public void setDisableBadSSLCiphers(ConfigurationOptions option) { | ||
| properties.setProperty(KEY_DISABLE_BAD_SSL_CIPHERS, option.toString()); | ||
| } | ||
|
|
||
| public void setEnableSSLCertChecks(boolean doSSLChecks) { | ||
| this.doSSLChecks = doSSLChecks; | ||
| } | ||
|
|
||
| public boolean getProxySet() { | ||
| String set = properties.getProperty(SYSPROPERTY_PROXY_SET); | ||
|
|
||
| if (set != null) | ||
| return Boolean.parseBoolean(removeQuotes(set)); | ||
| else | ||
| return false; | ||
| return toBoolean(removeQuotes(properties.getProperty(SYSPROPERTY_PROXY_SET))); | ||
| } | ||
|
|
||
| public String getProxyHost() { | ||
| return removeQuotes(properties.getProperty(SYSPROPERTY_PROXY_HOST)); | ||
| } | ||
|
|
||
| public String getProxyPort() { | ||
| return removeQuotes(properties.getProperty(SYSPROPERTY_PROXY_PORT)); | ||
| } | ||
|
|
||
| private boolean toBoolean(String string) { | ||
| if (string != null) { | ||
| return Boolean.parseBoolean(string); | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this seem to change api - should it not be 2.7.0 then ?