mirror of https://github.com/apache/nifi.git
NIFI-6571 Check token length on TLS toolkit server startup
This closes #3659. Signed-off-by: Joey Frazee <jfrazee@apache.org>
This commit is contained in:
parent
7034d7e44c
commit
a9e9e5d137
|
@ -66,6 +66,11 @@ public enum ExitCode {
|
||||||
*/
|
*/
|
||||||
ERROR_TOKEN_ARG_EMPTY,
|
ERROR_TOKEN_ARG_EMPTY,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Token does not meet minimum size of 16 bytes
|
||||||
|
*/
|
||||||
|
ERROR_TOKEN_ARG_TOO_SHORT,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unable to read nifi.properties
|
* Unable to read nifi.properties
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.nifi.toolkit.tls.configuration.TlsConfig;
|
||||||
import org.apache.nifi.util.StringUtils;
|
import org.apache.nifi.util.StringUtils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Common base argument logic for the CA server and client
|
* Common base argument logic for the CA server and client
|
||||||
|
@ -81,6 +82,14 @@ public abstract class BaseCertificateAuthorityCommandLine extends BaseTlsToolkit
|
||||||
if (StringUtils.isEmpty(token) && StringUtils.isEmpty(configJsonIn)) {
|
if (StringUtils.isEmpty(token) && StringUtils.isEmpty(configJsonIn)) {
|
||||||
printUsageAndThrow(TOKEN_ARG + " argument must not be empty unless " + USE_CONFIG_JSON_ARG + " or " + READ_CONFIG_JSON_ARG+ " set", ExitCode.ERROR_TOKEN_ARG_EMPTY);
|
printUsageAndThrow(TOKEN_ARG + " argument must not be empty unless " + USE_CONFIG_JSON_ARG + " or " + READ_CONFIG_JSON_ARG+ " set", ExitCode.ERROR_TOKEN_ARG_EMPTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(token)) {
|
||||||
|
byte[] tokenBytes = token.getBytes(StandardCharsets.UTF_8);
|
||||||
|
if (tokenBytes.length < 16) {
|
||||||
|
printUsageAndThrow(TOKEN_ARG + " does not meet minimum size of 16 bytes", ExitCode.ERROR_TOKEN_ARG_TOO_SHORT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
port = getIntValue(commandLine, PORT_ARG, TlsConfig.DEFAULT_PORT);
|
port = getIntValue(commandLine, PORT_ARG, TlsConfig.DEFAULT_PORT);
|
||||||
dn = commandLine.getOptionValue(DN_ARG, new TlsConfig().calcDefaultDn(getDnHostname()));
|
dn = commandLine.getOptionValue(DN_ARG, new TlsConfig().calcDefaultDn(getDnHostname()));
|
||||||
return commandLine;
|
return commandLine;
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class TlsCertificateAuthorityClientCommandLineTest {
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
tlsCertificateAuthorityClientCommandLine = new TlsCertificateAuthorityClientCommandLine();
|
tlsCertificateAuthorityClientCommandLine = new TlsCertificateAuthorityClientCommandLine();
|
||||||
testToken = "testToken";
|
testToken = "testToken16bytes";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -44,7 +44,7 @@ public class TlsCertificateAuthorityServiceCommandLineTest {
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
tlsCertificateAuthorityServiceCommandLine = new TlsCertificateAuthorityServiceCommandLine(inputStreamFactory);
|
tlsCertificateAuthorityServiceCommandLine = new TlsCertificateAuthorityServiceCommandLine(inputStreamFactory);
|
||||||
testToken = "testToken";
|
testToken = "testToken16bytes";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue