Skip to content

NIFI-11161 Simplify KeyedCipherPropertyEncryptor#6939

Closed
exceptionfactory wants to merge 1 commit intoapache:mainfrom
exceptionfactory:NIFI-11161
Closed

NIFI-11161 Simplify KeyedCipherPropertyEncryptor#6939
exceptionfactory wants to merge 1 commit intoapache:mainfrom
exceptionfactory:NIFI-11161

Conversation

@exceptionfactory
Copy link
Contributor

Summary

NIFI-11161 Simplifies the KeyedCipherPropertyEncryptor implementation that supports encryption and decryption of sensitive flow property values.

The existing implementation delegates Cipher instantiation to the AESKeyedCipherProvider, which includes a number of checks that are not necessary for the KeyedCipherPropertyEncryptor.

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using mvn clean install -P contrib-check
    • JDK 8
    • JDK 11
    • JDK 17

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

- Replaced KeyedCipherProvider references with direct Cipher instantiation
Copy link
Contributor

@greyp9 greyp9 left a comment

Choose a reason for hiding this comment

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

Nice refactor! Couple of questions for follow-up...

private static final int ARRAY_START = 0;

private final EncryptionMethod encryptionMethod;
private static final String CIPHER_ALGORITHM = "AES/GCM/NoPadding";
Copy link
Contributor

Choose a reason for hiding this comment

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

The IV length, tag length, and algorithm are each declared multiple times in the code base. Do you envision consolidating those usages at some point in the future?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's a good question. Theoretically, all the values should be the same across the board, but we would need to implement this in a way that avoid introducing unnecessary dependencies. There is other work to do for removing support for deprecated legacy algorithms. That might be an opportunity for consolidation.

public void testDecryptEncryptionException() {
final String encodedProperty = Hex.encodeHexString(PROPERTY.getBytes(DEFAULT_CHARSET));
assertThrows(EncryptionException.class, () -> encryptor.decrypt(encodedProperty));
assertThrows(Exception.class, () -> encryptor.decrypt(encodedProperty));
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not retain the more specific exception type here?

Copy link
Contributor Author

@exceptionfactory exceptionfactory Feb 27, 2023

Choose a reason for hiding this comment

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

The thrown exception is different based on the Java version, so switching to the more generic Exception provided the least amount of impact to the unit test.

final SecretKey secretKey) {
this.cipherProvider = cipherProvider;
this.encryptionMethod = encryptionMethod;
protected KeyedCipherPropertyEncryptor(final SecretKey secretKey) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is AES/GCM/NoPadding the previous default? Curious about the upgrade implications.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, AES/GCM/NoPadding is the current value for all instances of the KeyedCipherProvider, so this change does not impact compatibility with existing AES-GCM sensitive property algorithms.

Copy link
Contributor

@greyp9 greyp9 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@greyp9 greyp9 closed this in 9773105 Feb 28, 2023
exceptionfactory added a commit that referenced this pull request Mar 13, 2023
- Replaced KeyedCipherProvider references with direct Cipher instantiation

This closes #6939
Signed-off-by: Paul Grey <greyp@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants