SonarQube issues OpenSslEngine

Motivation:
SonarQube (clinker.netty.io/sonar) reported a few 'critical' issues related to the OpenSslEngine.

Modifications:
- Remove potential for dereference of null variable.
- Remove duplicate null check and TODO cleanup.

Results:
Less potential for null dereference, cleaner code, and 1 less TODO.
This commit is contained in:
scottmitch 2015-01-27 18:29:01 -05:00 committed by Norman Maurer
parent 8bbfcb05a0
commit 50a857cecf
2 changed files with 9 additions and 11 deletions

View File

@ -266,6 +266,12 @@ final class CipherSuiteConverter {
return hmacAlgo;
}
/**
* Convert from OpenSSL cipher suite name convention to java cipher suite name convention.
* @param openSslCipherSuite An OpenSSL cipher suite name.
* @param protocol The cryptographic protocol (i.e. SSL, TLS, ...).
* @return The translated cipher suite name according to java conventions. This will not be {@code null}.
*/
static String toJava(String openSslCipherSuite, String protocol) {
Map<String, String> p2j = o2j.get(openSslCipherSuite);
if (p2j == null) {

View File

@ -715,9 +715,7 @@ public final class OpenSslEngine extends SSLEngine {
return EmptyArrays.EMPTY_STRINGS;
} else {
for (int i = 0; i < enabled.length; i++) {
String c = enabled[i];
// TODO: Determine the protocol using SSL_CIPHER_get_version()
String mapped = CipherSuiteConverter.toJava(c, "TLS");
String mapped = toJavaCipherSuite(enabled[i]);
if (mapped != null) {
enabled[i] = mapped;
}
@ -1084,7 +1082,7 @@ public final class OpenSslEngine extends SSLEngine {
if (applicationProtocol != null) {
OpenSslEngine.this.applicationProtocol = applicationProtocol.replace(':', '_');
} else {
OpenSslEngine.this.applicationProtocol = "";
OpenSslEngine.this.applicationProtocol = applicationProtocol = "";
}
}
String version = SSL.getVersion(ssl);
@ -1241,13 +1239,7 @@ public final class OpenSslEngine extends SSLEngine {
}
String prefix = toJavaCipherSuitePrefix(SSL.getVersion(ssl));
String converted = CipherSuiteConverter.toJava(openSslCipherSuite, prefix);
if (converted != null) {
openSslCipherSuite = converted;
} else {
openSslCipherSuite = prefix + '_' + openSslCipherSuite.replace('-', '_');
}
return openSslCipherSuite;
return CipherSuiteConverter.toJava(openSslCipherSuite, prefix);
}
/**