You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by GitBox <gi...@apache.org> on 2020/07/24 03:08:44 UTC

[GitHub] [nifi] alopresto opened a new pull request #4427: NIFI-7638 Added PBE AEAD algorithm for flow sensitive properties

alopresto opened a new pull request #4427:
URL: https://github.com/apache/nifi/pull/4427


   ## This PR is dependent on PR 4421 and should not be merged until that one is
   
   ### The actual changes are only in `StringEncryptor`, `StringEncryptorTest`, a single method scope change in `RandomIVPBECipherProvider`, and `administration-guide.adoc`. 
   
   Thank you for submitting a contribution to Apache NiFi.
   
   Please provide a short description of the PR here:
   
   #### Description of PR
   
   _Adds a new algorithm for `nifi.sensitive.props.algorithm` to support robust encryption of sensitive flow values._
   
   In order to streamline the review of the contribution we ask you
   to ensure the following steps have been taken:
   
   ### For all changes:
   - [x] Is there a JIRA ticket associated with this PR? Is it referenced 
        in the commit message?
   
   - [x] 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.
   
   - [x] Has your PR been rebased against the latest commit within the target branch (typically `main`)?
   
   - [x] Is your initial contribution a single, squashed commit? _Additional commits in response to PR reviewer feedback should be made on this branch and pushed to allow change tracking. Do not `squash` or use `--force` when pushing to allow for clean monitoring of changes._
   
   ### For code changes:
   - [x] Have you ensured that the full suite of tests is executed via `mvn -Pcontrib-check clean install` at the root `nifi` folder?
   - [x] Have you written or updated unit tests to verify your changes?
   - [ ] Have you verified that the full build is successful on JDK 8?
   - [x] Have you verified that the full build is successful on JDK 11?
   - [ ] If adding new dependencies to the code, are these dependencies licensed in a way that is compatible for inclusion under [ASF 2.0](http://www.apache.org/legal/resolved.html#category-a)? 
   - [ ] 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:
   - [x] 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 GitHub Actions CI for build issues and submit an update to your PR as soon as possible.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] alopresto commented on pull request #4427: NIFI-7638 Added PBE AEAD algorithm for flow sensitive properties

Posted by GitBox <gi...@apache.org>.
alopresto commented on pull request #4427:
URL: https://github.com/apache/nifi/pull/4427#issuecomment-663786904


   Thanks all for the reviews. Merging. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] joewitt commented on a change in pull request #4427: NIFI-7638 Added PBE AEAD algorithm for flow sensitive properties

Posted by GitBox <gi...@apache.org>.
joewitt commented on a change in pull request #4427:
URL: https://github.com/apache/nifi/pull/4427#discussion_r460253175



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/encrypt/StringEncryptor.java
##########
@@ -408,27 +468,34 @@ public String decrypt(String cipherText) throws EncryptionException {
 
     private byte[] decryptPBE(byte[] cipherBytes) {
         PBECipherProvider pbecp = (PBECipherProvider) cipherProvider;
-        final EncryptionMethod encryptionMethod = EncryptionMethod.forAlgorithm(algorithm);
+        final EncryptionMethod encryptionMethod = getEncryptionMethodForAlgorithm(algorithm);
 
         // Extract salt
-        int saltLength = CipherUtility.getSaltLengthForAlgorithm(algorithm);
+        int saltLength = determineSaltLength(algorithm);
         byte[] salt = new byte[saltLength];
         System.arraycopy(cipherBytes, 0, salt, 0, saltLength);
 
-        byte[] actualCipherBytes = Arrays.copyOfRange(cipherBytes, saltLength, cipherBytes.length);
+        // Read IV if necessary (allows for future use of Argon2, PBKDF2, Bcrypt, or Scrypt)
+        byte[] ivBytes = new byte[0];

Review comment:
       maybe it isn't worth the effort.  by preallocating a 16 byte array to reuse over and over seems like it would perform quite well and relax GC pressure particularly in the event of larger objects.  am I overthinking that one?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] mtien-apache commented on pull request #4427: NIFI-7638 Added PBE AEAD algorithm for flow sensitive properties

Posted by GitBox <gi...@apache.org>.
mtien-apache commented on pull request #4427:
URL: https://github.com/apache/nifi/pull/4427#issuecomment-663777695


   +1 LGTM. Able to run a full build, confirmed I receive the exception message when password is too short or not provided.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] alopresto commented on a change in pull request #4427: NIFI-7638 Added PBE AEAD algorithm for flow sensitive properties

Posted by GitBox <gi...@apache.org>.
alopresto commented on a change in pull request #4427:
URL: https://github.com/apache/nifi/pull/4427#discussion_r460260432



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/encrypt/StringEncryptor.java
##########
@@ -408,27 +468,34 @@ public String decrypt(String cipherText) throws EncryptionException {
 
     private byte[] decryptPBE(byte[] cipherBytes) {
         PBECipherProvider pbecp = (PBECipherProvider) cipherProvider;
-        final EncryptionMethod encryptionMethod = EncryptionMethod.forAlgorithm(algorithm);
+        final EncryptionMethod encryptionMethod = getEncryptionMethodForAlgorithm(algorithm);
 
         // Extract salt
-        int saltLength = CipherUtility.getSaltLengthForAlgorithm(algorithm);
+        int saltLength = determineSaltLength(algorithm);
         byte[] salt = new byte[saltLength];
         System.arraycopy(cipherBytes, 0, salt, 0, saltLength);
 
-        byte[] actualCipherBytes = Arrays.copyOfRange(cipherBytes, saltLength, cipherBytes.length);
+        // Read IV if necessary (allows for future use of Argon2, PBKDF2, Bcrypt, or Scrypt)
+        byte[] ivBytes = new byte[0];

Review comment:
       The actual `ivBytes` array is only instantiated when the algorithm dictates a random IV. For 99.9% of users, this won't be the case and so it makes sense not to instantiate it at all. 
   
   For users who select one of the custom algorithms, the `byte[16]` is instantiated and filled with a random value, but this happens every time and is intentionally unique on each invocation, so pre-allocating wouldn't gain anything unless I am missing your concern. 
   
   The size of the object to be encrypted is independent of the IV size -- the IV is always 0 or 16 bytes depending solely on the algorithm. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] bbende commented on a change in pull request #4427: NIFI-7638 Added PBE AEAD algorithm for flow sensitive properties

Posted by GitBox <gi...@apache.org>.
bbende commented on a change in pull request #4427:
URL: https://github.com/apache/nifi/pull/4427#discussion_r460291793



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/encrypt/StringEncryptor.java
##########
@@ -267,6 +296,16 @@ private boolean paramsAreValid() {
         return algorithmAndProviderValid && secretIsValid;
     }
 
+    private boolean customSecretIsValid(PBEKeySpec password, SecretKeySpec key, String algorithm) {
+        // Currently, the only custom algorithms use AES-G/CM with a password via Argon2
+        String rawPassword = new String(password.getPassword());
+        final boolean secretIsValid = StringUtils.isNotBlank(rawPassword) && rawPassword.trim().length() >= 12;
+        if (!secretIsValid) {
+            logger.error("The nifi.sensitive.props.key password provided is invalid for algorithm {}; must be >= 12 characters", algorithm);

Review comment:
       Just to clarify, we do print this first....
   ```
   
   2020-07-24 17:12:31,384 ERROR [main] org.apache.nifi.encrypt.StringEncryptor ********************************************************************************
   2020-07-24 17:12:31,385 ERROR [main] org.apache.nifi.encrypt.StringEncryptor *                A blank sensitive properties key was provided                 *
   2020-07-24 17:12:31,385 ERROR [main] org.apache.nifi.encrypt.StringEncryptor *                   Specify a unique key in nifi.properties                    *
   2020-07-24 17:12:31,385 ERROR [main] org.apache.nifi.encrypt.StringEncryptor *                         for nifi.sensitive.props.key                         *
   2020-07-24 17:12:31,385 ERROR [main] org.apache.nifi.encrypt.StringEncryptor *                                                                              *
   2020-07-24 17:12:31,385 ERROR [main] org.apache.nifi.encrypt.StringEncryptor *            The Encrypt Config Tool in NiFi Toolkit can be used to            *
   2020-07-24 17:12:31,385 ERROR [main] org.apache.nifi.encrypt.StringEncryptor *                       migrate the flow to the new key                        *
   2020-07-24 17:12:31,385 ERROR [main] org.apache.nifi.encrypt.StringEncryptor ********************************************************************************
   2020-07-24 17:12:31,385 ERROR [main] org.apache.nifi.encrypt.StringEncryptor The nifi.sensitive.props.key password provided is invalid for algorithm NIFI_ARGON2_AES_GCM_256; must be >= 12 characters
   ```
   but then after there are two stacktraces that I think overshadow this and don't have any specifics.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] alopresto commented on a change in pull request #4427: NIFI-7638 Added PBE AEAD algorithm for flow sensitive properties

Posted by GitBox <gi...@apache.org>.
alopresto commented on a change in pull request #4427:
URL: https://github.com/apache/nifi/pull/4427#discussion_r460260816



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/encrypt/StringEncryptor.java
##########
@@ -408,27 +468,34 @@ public String decrypt(String cipherText) throws EncryptionException {
 
     private byte[] decryptPBE(byte[] cipherBytes) {
         PBECipherProvider pbecp = (PBECipherProvider) cipherProvider;
-        final EncryptionMethod encryptionMethod = EncryptionMethod.forAlgorithm(algorithm);
+        final EncryptionMethod encryptionMethod = getEncryptionMethodForAlgorithm(algorithm);
 
         // Extract salt
-        int saltLength = CipherUtility.getSaltLengthForAlgorithm(algorithm);
+        int saltLength = determineSaltLength(algorithm);
         byte[] salt = new byte[saltLength];
         System.arraycopy(cipherBytes, 0, salt, 0, saltLength);
 
-        byte[] actualCipherBytes = Arrays.copyOfRange(cipherBytes, saltLength, cipherBytes.length);
+        // Read IV if necessary (allows for future use of Argon2, PBKDF2, Bcrypt, or Scrypt)
+        byte[] ivBytes = new byte[0];

Review comment:
       The instantiation of the `byte[0]` is just to simplify the code which concatenates all the byte arrays below -- rather than having duplicate logic for IV present/not, it just appends the array whether it is populated or empty. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] asfgit closed pull request #4427: NIFI-7638 Added PBE AEAD algorithm for flow sensitive properties

Posted by GitBox <gi...@apache.org>.
asfgit closed pull request #4427:
URL: https://github.com/apache/nifi/pull/4427


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] bbende commented on a change in pull request #4427: NIFI-7638 Added PBE AEAD algorithm for flow sensitive properties

Posted by GitBox <gi...@apache.org>.
bbende commented on a change in pull request #4427:
URL: https://github.com/apache/nifi/pull/4427#discussion_r460290036



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/encrypt/StringEncryptor.java
##########
@@ -267,6 +296,16 @@ private boolean paramsAreValid() {
         return algorithmAndProviderValid && secretIsValid;
     }
 
+    private boolean customSecretIsValid(PBEKeySpec password, SecretKeySpec key, String algorithm) {
+        // Currently, the only custom algorithms use AES-G/CM with a password via Argon2
+        String rawPassword = new String(password.getPassword());
+        final boolean secretIsValid = StringUtils.isNotBlank(rawPassword) && rawPassword.trim().length() >= 12;
+        if (!secretIsValid) {
+            logger.error("The nifi.sensitive.props.key password provided is invalid for algorithm {}; must be >= 12 characters", algorithm);

Review comment:
       This message is really helpful for the user to know the problem. One minor issue is that the exception that prints to the log doesn't end up including this, it just ends with:
   ```
   
   Caused by: org.apache.nifi.encrypt.EncryptionException: Cannot initialize the StringEncryptor because some configuration values are invalid
   	at org.apache.nifi.encrypt.StringEncryptor.initialize(StringEncryptor.java:270)
   	at org.apache.nifi.encrypt.StringEncryptor.<init>(StringEncryptor.java:137)
   	at org.apache.nifi.encrypt.StringEncryptor.createEncryptor(StringEncryptor.java:236)
   	at org.apache.nifi.encrypt.StringEncryptor.createEncryptor(StringEncryptor.java:209)
   	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
   	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
   	at java.lang.reflect.Method.invoke(Method.java:498)
   	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
   	... 58 common frames omitted
   ```
   
   Was wondering if we could get that same message into the exception so its not missed and is clear what needs to be fixed. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] alopresto commented on pull request #4427: NIFI-7638 Added PBE AEAD algorithm for flow sensitive properties

Posted by GitBox <gi...@apache.org>.
alopresto commented on pull request #4427:
URL: https://github.com/apache/nifi/pull/4427#issuecomment-663699812


   This PR is ready for review & merge. 


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [nifi] alopresto commented on a change in pull request #4427: NIFI-7638 Added PBE AEAD algorithm for flow sensitive properties

Posted by GitBox <gi...@apache.org>.
alopresto commented on a change in pull request #4427:
URL: https://github.com/apache/nifi/pull/4427#discussion_r460294858



##########
File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/encrypt/StringEncryptor.java
##########
@@ -267,6 +296,16 @@ private boolean paramsAreValid() {
         return algorithmAndProviderValid && secretIsValid;
     }
 
+    private boolean customSecretIsValid(PBEKeySpec password, SecretKeySpec key, String algorithm) {
+        // Currently, the only custom algorithms use AES-G/CM with a password via Argon2
+        String rawPassword = new String(password.getPassword());
+        final boolean secretIsValid = StringUtils.isNotBlank(rawPassword) && rawPassword.trim().length() >= 12;
+        if (!secretIsValid) {
+            logger.error("The nifi.sensitive.props.key password provided is invalid for algorithm {}; must be >= 12 characters", algorithm);

Review comment:
       Great point Bryan. Fixed. 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org