[GitHub] accumulo pull request #163: ACCUMULO-2278 Return value from in.read() should...

2016-10-14 Thread asfgit
Github user asfgit closed the pull request at:

https://github.com/apache/accumulo/pull/163


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] accumulo pull request #163: ACCUMULO-2278 Return value from in.read() should...

2016-10-13 Thread mm376
Github user mm376 commented on a diff in the pull request:

https://github.com/apache/accumulo/pull/163#discussion_r83207379
  
--- Diff: 
core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java
 ---
@@ -81,7 +81,10 @@ private void doKeyEncryptionOperation(int 
encryptionMode, CryptoModuleParameters
   Cipher cipher = 
DefaultCryptoModuleUtils.getCipher(params.getAllOptions().get(Property.CRYPTO_DEFAULT_KEY_STRATEGY_CIPHER_SUITE.getKey()));
 
   try {
-cipher.init(encryptionMode, new SecretKeySpec(keyEncryptionKey, 
params.getAlgorithmName()));
+   if (keyEncryptionKey.length > 0)
--- End diff --

Chris, Josh: I made the code change and pushed it into repository, take a 
look at it when you get a chance.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] accumulo pull request #163: ACCUMULO-2278 Return value from in.read() should...

2016-10-12 Thread ctubbsii
Github user ctubbsii commented on a diff in the pull request:

https://github.com/apache/accumulo/pull/163#discussion_r83102811
  
--- Diff: 
core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java
 ---
@@ -81,7 +81,10 @@ private void doKeyEncryptionOperation(int 
encryptionMode, CryptoModuleParameters
   Cipher cipher = 
DefaultCryptoModuleUtils.getCipher(params.getAllOptions().get(Property.CRYPTO_DEFAULT_KEY_STRATEGY_CIPHER_SUITE.getKey()));
 
   try {
-cipher.init(encryptionMode, new SecretKeySpec(keyEncryptionKey, 
params.getAlgorithmName()));
+   if (keyEncryptionKey.length > 0)
--- End diff --

The original reported issue is that the return value of the read is not 
captured or checked. The conditional being checked here only verifies that the 
allocated array was larger than an empty array. What it actually needs to check 
is that the number of bytes read into the array is the same as the value of the 
length field, regardless of what else we want to check. The conditional in this 
patch is sufficient only if we switch to using `readFully` instead of `read`, 
which throws an EOFException if the number of bytes read from the input stream 
isn't enough to fill the buffer (e.g. doesn't match the expected 
keyEncryptionKeyLength).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] accumulo pull request #163: ACCUMULO-2278 Return value from in.read() should...

2016-10-12 Thread joshelser
Github user joshelser commented on a diff in the pull request:

https://github.com/apache/accumulo/pull/163#discussion_r83087033
  
--- Diff: 
core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java
 ---
@@ -81,7 +81,10 @@ private void doKeyEncryptionOperation(int 
encryptionMode, CryptoModuleParameters
   Cipher cipher = 
DefaultCryptoModuleUtils.getCipher(params.getAllOptions().get(Property.CRYPTO_DEFAULT_KEY_STRATEGY_CIPHER_SUITE.getKey()));
 
   try {
-cipher.init(encryptionMode, new SecretKeySpec(keyEncryptionKey, 
params.getAlgorithmName()));
+   if (keyEncryptionKey.length > 0)
--- End diff --

> The SecretKeySpec constructor would throw IllegalArgumentException

> adding this check probably caused the rest of the code to be executed 
resulting in a null exception in another part of the code.

Sounds to me like we would want to throw our own IllegalArgumentException 
(or some unchecked exception) in an `else` branch to the conditional you added. 
Care to update the pull request with that change?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] accumulo pull request #163: ACCUMULO-2278 Return value from in.read() should...

2016-10-12 Thread mm376
Github user mm376 commented on a diff in the pull request:

https://github.com/apache/accumulo/pull/163#discussion_r83072563
  
--- Diff: 
core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java
 ---
@@ -81,7 +81,10 @@ private void doKeyEncryptionOperation(int 
encryptionMode, CryptoModuleParameters
   Cipher cipher = 
DefaultCryptoModuleUtils.getCipher(params.getAllOptions().get(Property.CRYPTO_DEFAULT_KEY_STRATEGY_CIPHER_SUITE.getKey()));
 
   try {
-cipher.init(encryptionMode, new SecretKeySpec(keyEncryptionKey, 
params.getAlgorithmName()));
+   if (keyEncryptionKey.length > 0)
--- End diff --

Code was throwing an exception even before the if check was added, adding 
this check probably caused the rest of the code to be executed resulting in a 
null exception in another part of the code.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] accumulo pull request #163: ACCUMULO-2278 Return value from in.read() should...

2016-10-12 Thread mstair
Github user mstair commented on a diff in the pull request:

https://github.com/apache/accumulo/pull/163#discussion_r83072327
  
--- Diff: 
core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java
 ---
@@ -81,7 +81,10 @@ private void doKeyEncryptionOperation(int 
encryptionMode, CryptoModuleParameters
   Cipher cipher = 
DefaultCryptoModuleUtils.getCipher(params.getAllOptions().get(Property.CRYPTO_DEFAULT_KEY_STRATEGY_CIPHER_SUITE.getKey()));
 
   try {
-cipher.init(encryptionMode, new SecretKeySpec(keyEncryptionKey, 
params.getAlgorithmName()));
+   if (keyEncryptionKey.length > 0)
--- End diff --

The SecretKeySpec constructor would throw IllegalArgumentException


https://docs.oracle.com/javase/7/docs/api/javax/crypto/spec/SecretKeySpec.html 



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] accumulo pull request #163: ACCUMULO-2278 Return value from in.read() should...

2016-10-11 Thread ctubbsii
Github user ctubbsii commented on a diff in the pull request:

https://github.com/apache/accumulo/pull/163#discussion_r82935160
  
--- Diff: 
core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java
 ---
@@ -81,7 +81,10 @@ private void doKeyEncryptionOperation(int 
encryptionMode, CryptoModuleParameters
   Cipher cipher = 
DefaultCryptoModuleUtils.getCipher(params.getAllOptions().get(Property.CRYPTO_DEFAULT_KEY_STRATEGY_CIPHER_SUITE.getKey()));
 
   try {
-cipher.init(encryptionMode, new SecretKeySpec(keyEncryptionKey, 
params.getAlgorithmName()));
+   if (keyEncryptionKey.length > 0)
--- End diff --

This makes me wonder what the API contract is on `read()`. Will the return 
value from this always be equal to the length of the byte array? If it's not, 
should we explicitly throw an `InvalidKeyException`? Should we use some 
`readFully()` method to populate the read buffer instead of `read()`?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] accumulo pull request #163: ACCUMULO-2278 Return value from in.read() should...

2016-10-11 Thread joshelser
Github user joshelser commented on a diff in the pull request:

https://github.com/apache/accumulo/pull/163#discussion_r82929101
  
--- Diff: 
core/src/main/java/org/apache/accumulo/core/security/crypto/NonCachingSecretKeyEncryptionStrategy.java
 ---
@@ -81,7 +81,10 @@ private void doKeyEncryptionOperation(int 
encryptionMode, CryptoModuleParameters
   Cipher cipher = 
DefaultCryptoModuleUtils.getCipher(params.getAllOptions().get(Property.CRYPTO_DEFAULT_KEY_STRATEGY_CIPHER_SUITE.getKey()));
 
   try {
-cipher.init(encryptionMode, new SecretKeySpec(keyEncryptionKey, 
params.getAlgorithmName()));
+   if (keyEncryptionKey.length > 0)
--- End diff --

It looks like this change might actually change the code flow. When the 
keyEncryptionKey was of length `0`, would `cipher.init(...)` have thrown an 
`InvalidKeyException`? I would assume that when the key is empty, we would want 
to throw a `RuntimeException`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] accumulo pull request #163: ACCUMULO-2278 Return value from in.read() should...

2016-10-11 Thread mm376
GitHub user mm376 opened a pull request:

https://github.com/apache/accumulo/pull/163

ACCUMULO-2278 Return value from in.read() should be checked in

NonCachingSecretKeyEn.cryptionStrategy#doKeyEncryptionOperation()

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/mm376/accumulo ACCUMULO-2278

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/accumulo/pull/163.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #163


commit ca3b8f1414fc4536e9c42921e8b8271025874912
Author: mm376k 
Date:   2016-10-11T23:29:03Z

ACCUMULO-2278 Return value from in.read() should be checked in
NonCachingSecretKeyEn.cryptionStrategy#doKeyEncryptionOperation()




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---