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

NIFI-6026 - First commit which adds a new tls-toolkit mode called Key… #3340

Closed
wants to merge 5 commits into from

Conversation

thenatog
Copy link
Contributor

…store. Should instead integrate the functionality into standalone mode.

NIFI-6026 - Updated splitKeystore to use standalone mode with a -splitKeystore argument.

NIFI-6026 - Removed unused file and references.

Thank you for submitting a contribution to Apache NiFi.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

For all changes:

  • Is there a JIRA ticket associated with this PR? Is it referenced
    in the commit message?

  • Does your PR title start with NIFI-XXXX where XXXX is the JIRA number you are trying to resolve? Pay particular attention to the hyphen "-" character.

  • Has your PR been rebased against the latest commit within the target branch (typically master)?

  • Is your initial contribution a single, squashed commit?

For code changes:

  • Have you ensured that the full suite of tests is executed via mvn -Pcontrib-check clean install at the root nifi folder?
  • Have you written or updated unit tests to verify your changes?
  • If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under ASF 2.0?
  • If applicable, have you updated the LICENSE file, including the main LICENSE file under nifi-assembly?
  • If applicable, have you updated the NOTICE file, including the main NOTICE file found under nifi-assembly?
  • If adding new Properties, have you added .displayName in addition to .name (programmatic access) for each of the new properties?

For documentation related changes:

  • Have you ensured that format looks appropriate for the output in which it is rendered?

Note:

Please ensure that once the PR is submitted, you check travis-ci for build issues and submit an update to your PR as soon as possible.

…store. Should instead integrate the functionality into standalone mode.

NIFI-6026 - Updated splitKeystore to use standalone mode with a -splitKeystore argument.

NIFI-6026 - Removed unused file and references.
…argument checking in the command line parsing.
@alopresto
Copy link
Contributor

Reviewing...

tlsToolkitStandaloneCommandLine.printUsage("Error generating TLS configuration. (" + e.getMessage() + ")");
System.exit(ExitCode.ERROR_GENERATING_CONFIG.ordinal());

StandaloneConfig conf = tlsToolkitStandaloneCommandLine.createSplitKeystoreConfig();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to check isSplitKeystore before creating this config object because currently this is always created whether it is needed or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated this to use the command line parsed args rather than the config, and will no longer create the config unless it's required.

@@ -168,6 +188,17 @@ protected CommandLine doParse(String... args) throws CommandLineParseException {
clientPasswordsGenerated = commandLine.getOptionValues(CLIENT_CERT_PASSWORD_ARG) == null;
overwrite = commandLine.hasOption(OVERWRITE_ARG);

if(commandLine.hasOption(SPLIT_KEYSTORE_ARG)) {
if(commandLine.hasOption(KEY_STORE_PASSWORD_ARG) && commandLine.hasOption(KEY_PASSWORD_ARG)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think KEY_PASSWORD_ARG can legitimately be empty if the keystore password and key password are the same (i.e. no explicit key password was set).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use the keystore password if no key password is provided and added unit test.

@alopresto
Copy link
Contributor

Why did nifi-commons/nifi-security-utils/src/test/resources/keystore.jks get added in this PR?

… if keystore and key passwords are the same. Added some more tests.
@thenatog
Copy link
Contributor Author

Why did nifi-commons/nifi-security-utils/src/test/resources/keystore.jks get added in this PR?

Using this for unit tests as it has known keystore and key passwords.

@@ -113,6 +118,8 @@ protected TlsToolkitStandaloneCommandLine(PasswordUtil passwordUtil) {
addOptionWithArg(null, NIFI_DN_SUFFIX_ARG, "String to append to hostname(s) when determining DN.", TlsConfig.DEFAULT_DN_SUFFIX);
addOptionNoArg("O", OVERWRITE_ARG, "Overwrite existing host output.");
addOptionWithArg(null, ADDITIONAL_CA_CERTIFICATE_ARG, "Path to additional CA certificate (used to sign toolkit CA certificate) in PEM format if necessary");
addOptionWithArg("splitKeystore", SPLIT_KEYSTORE_ARG, "Split out a given keystore into its unencrypted key and certificates. Use -S and -K to specify the keystore and key passwords.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Providing the "splitKeystore" string as the first argument to this call means that -splitKeystore and --splitKeystore are both supported here. Please pass null as the first argument instead, otherwise this leads to ambiguity and breaks consistency.

}

@Test
public void testOutputCertsAsPem() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer if these tests were more descriptive -- list the expectations for what is happening here. The keystore should have a known number of entries, and that number should match the number of outputs. In addition, the key signature should be compared with that queried from the keystore directly, not just asserted that it is non-null. The same goes for the key assertions in the subsequent test.

HashMap<String, Key> keys = TlsHelper.extractKeys(keyStore, "changeit".toCharArray());
assertEquals(1, keys.size());
keys.forEach((String alias, Key key) -> assertEquals("PKCS#8", key.getFormat()));
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to see test cases documenting the following use cases:

  • Run with no keystore provided
  • Run with no keystore password provided
  • Run with wrong keystore password provided
  • Run with keystore with no aliases
  • Run with keystore with multiple aliases
  • Run with correct keystore password but wrong key password provided

@alopresto
Copy link
Contributor

I ran through a series of manual tests on the toolkit mode. I like the functionality, and it works with both keystore formats. I made some comments requesting some unit test improvements and the removal of the "single hyphen" long argument in the CLI invocation. Once those are done, I will +1 and merge. Thanks.

@asfgit asfgit closed this in fdea4c5 May 7, 2019
@alopresto
Copy link
Contributor

Ran contrib-check and all tests pass. +1, merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants