Skip to content
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

Add enabledCipherSuites to MqttConnectOptions and Support to set provider for KeyStore.getInstance. #892

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public class MqttConnectOptions {
private boolean automaticReconnect = false;
private int maxReconnectDelay = 128000;
private Properties customWebSocketHeaders = null;
private String[] enabledCipherSuites = null;

// Client Operation Parameters
private int executorServiceTimeout = 1; // How long to wait in seconds when terminating the executor service.
Expand Down Expand Up @@ -700,5 +701,23 @@ public Properties getCustomWebSocketHeaders() {
public String toString() {
return Debug.dumpProperties(getDebug(), "Connection options");
}


/**
* Returns the enabled cipher suites.
*
* @return a string array of enabled Cipher suites
*/
public String[] getEnabledCipherSuites() {
return enabledCipherSuites;
}

/**
* Sets the enabled cipher suites on the underlying network socket.
*
* @param enabledCipherSuites
* a String array of cipher suites to enable
*/
public void setEnabledCipherSuites(String[] enabledCipherSuites) {
this.enabledCipherSuites = enabledCipherSuites;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,18 @@ public NetworkModule createNetworkModule(URI brokerUri, MqttConnectOptions optio
netModule.setSSLhandshakeTimeout(options.getConnectionTimeout());
netModule.setSSLHostnameVerifier(options.getSSLHostnameVerifier());
netModule.setHttpsHostnameVerificationEnabled(options.isHttpsHostnameVerificationEnabled());

// Ciphers suites need to be set, if they are available
if (factoryFactory != null) {
String[] enabledCiphers = factoryFactory.getEnabledCipherSuites(null);
if (enabledCiphers != null) {
netModule.setEnabledCiphers(enabledCiphers);
}
} else {
String[] cipherSuites = options.getEnabledCipherSuites();
if (cipherSuites != null) {
netModule.setEnabledCiphers(cipherSuites);
}
}
return netModule;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1203,11 +1203,13 @@ private SSLContext getSSLContext(String configID)

if(keyStoreName!=null && keyStoreType!=null && keyMgrAlgo!=null) {
try {
keyStore=KeyStore.getInstance(keyStoreType);
keyStore.load(new FileInputStream(keyStoreName), keyStorePwd);
if(keyMgrProvider!=null) {
if (keyMgrProvider != null) {
keyStore = KeyStore.getInstance(keyStoreType, keyMgrProvider);
keyStore.load(new FileInputStream(keyStoreName), keyStorePwd);
keyMgrFact = KeyManagerFactory.getInstance(keyMgrAlgo, keyMgrProvider);
} else {
keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(new FileInputStream(keyStoreName), keyStorePwd);
keyMgrFact = KeyManagerFactory.getInstance(keyMgrAlgo);
}
if (logger != null) {
Expand Down Expand Up @@ -1269,11 +1271,13 @@ private SSLContext getSSLContext(String configID)

if(trustStoreName!=null && trustStoreType!=null && trustMgrAlgo!=null) {
try {
trustStore=KeyStore.getInstance(trustStoreType);
trustStore.load(new FileInputStream(trustStoreName), trustStorePwd);
if(trustMgrProvider!=null) {
if (trustMgrProvider != null) {
trustStore = KeyStore.getInstance(trustStoreType, trustMgrProvider);
trustStore.load(new FileInputStream(trustStoreName), trustStorePwd);
trustMgrFact = TrustManagerFactory.getInstance(trustMgrAlgo, trustMgrProvider);
} else {
trustStore = KeyStore.getInstance(trustStoreType);
trustStore.load(new FileInputStream(trustStoreName), trustStorePwd);
trustMgrFact = TrustManagerFactory.getInstance(trustMgrAlgo);
}
if (logger != null) {
Expand Down