Browse Source
Merge pull request #10311 from irynamatveieva/fix-error-mqtt-node
Fixed TLS Factory error when no password set in configuration
pull/10394/head
Viacheslav Klimov
3 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with
7 additions and
3 deletions
-
common/util/src/main/java/org/thingsboard/common/util/SslUtil.java
-
rule-engine/rule-engine-components/src/main/java/org/thingsboard/rule/engine/credentials/CertPemCredentials.java
|
|
|
@ -73,7 +73,7 @@ public class SslUtil { |
|
|
|
|
|
|
|
@SneakyThrows |
|
|
|
public static PrivateKey readPrivateKey(String fileContent, String passStr) { |
|
|
|
char[] password = StringUtils.isEmpty(passStr) ? EMPTY_PASS : passStr.toCharArray(); |
|
|
|
char[] password = getPassword(passStr); |
|
|
|
|
|
|
|
PrivateKey privateKey = null; |
|
|
|
JcaPEMKeyConverter keyConverter = new JcaPEMKeyConverter(); |
|
|
|
@ -102,4 +102,8 @@ public class SslUtil { |
|
|
|
return privateKey; |
|
|
|
} |
|
|
|
|
|
|
|
public static char[] getPassword(String passStr) { |
|
|
|
return StringUtils.isEmpty(passStr) ? EMPTY_PASS : passStr.toCharArray(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@ -87,7 +87,7 @@ public class CertPemCredentials implements ClientCredentials { |
|
|
|
|
|
|
|
private KeyManagerFactory createAndInitKeyManagerFactory() throws Exception { |
|
|
|
KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); |
|
|
|
kmf.init(loadKeyStore(), password.toCharArray()); |
|
|
|
kmf.init(loadKeyStore(), SslUtil.getPassword(password)); |
|
|
|
return kmf; |
|
|
|
} |
|
|
|
|
|
|
|
@ -107,7 +107,7 @@ public class CertPemCredentials implements ClientCredentials { |
|
|
|
CertPath certPath = factory.generateCertPath(certificates); |
|
|
|
List<? extends Certificate> path = certPath.getCertificates(); |
|
|
|
Certificate[] x509Certificates = path.toArray(new Certificate[0]); |
|
|
|
keyStore.setKeyEntry(PRIVATE_KEY_ALIAS, privateKey, password.toCharArray(), x509Certificates); |
|
|
|
keyStore.setKeyEntry(PRIVATE_KEY_ALIAS, privateKey, SslUtil.getPassword(password), x509Certificates); |
|
|
|
} |
|
|
|
return keyStore; |
|
|
|
} |
|
|
|
|