Skip to content

Fail if record cannot be decrypted with any keys in multi-decryptor#2632

Closed
justincormack wants to merge 1 commit intomoby:masterfrom
justincormack:fail-multidecrypt
Closed

Fail if record cannot be decrypted with any keys in multi-decryptor#2632
justincormack wants to merge 1 commit intomoby:masterfrom
justincormack:fail-multidecrypt

Conversation

@justincormack
Copy link
Contributor

Previously this would return nil, nil in the final fallthrough case.

Signed-off-by: Justin Cormack justin.cormack@docker.com

cc @cyli

Previously this would return nil, nil in the final fallthrough case.

Signed-off-by: Justin Cormack <justin.cormack@docker.com>
@codecov
Copy link

codecov bot commented May 17, 2018

Codecov Report

Merging #2632 into master will decrease coverage by 0.6%.
The diff coverage is 60%.

@@            Coverage Diff             @@
##           master    #2632      +/-   ##
==========================================
- Coverage   62.59%   61.98%   -0.61%     
==========================================
  Files          51      134      +83     
  Lines        7180    21822   +14642     
==========================================
+ Hits         4494    13526    +9032     
- Misses       2231     6839    +4608     
- Partials      455     1457    +1002

@cyli
Copy link
Contributor

cyli commented May 17, 2018

Thanks! I definitely do not have a test for this case. I'm not entirely sure I see where it'd be nil, nil though, apologies - would you mind adding a test case that triggers this?

These were the two test cases I could think of:

diff --git a/manager/encryption/encryption_test.go b/manager/encryption/encryption_test.go
index 2556ef8a..1b566b21 100644
--- a/manager/encryption/encryption_test.go
+++ b/manager/encryption/encryption_test.go
@@ -107,6 +107,15 @@ func TestMultiDecryptor(t *testing.T) {
                        require.IsType(t, ErrCannotDecrypt{}, err)
                }
        }
+
+       // Test multidecryptor where it does not have a decryptor with the right key
+       for _, d := range []MultiDecrypter{m, NewMultiDecrypter()} {
+               plaintext := []byte("message")
+               ciphertext, err := Encrypt(plaintext, NewNACLSecretbox([]byte("other")))
+               require.NoError(t, err)
+               _, err = Decrypt(ciphertext, d)
+               require.IsType(t, ErrCannotDecrypt{}, err)
+       }
 }

The first one returns decryption error using NACL secretbox and the second one returns cannot decrypt record encrypted using SECRETBOX_SALSA20_POLY1305.

The error returned in your change is much more friendly, however.

@justincormack
Copy link
Contributor Author

Oh, actually I am being confused, yes it will error...

@cyli
Copy link
Contributor

cyli commented May 17, 2018

@justincormack I actually find named return vars kinda confusing - I'm not sure why I used it. I'll submit a new PR with the test and with explicit returns instead, and your much nicer error. Thanks again!

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