Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

feat: Legacy encrypt (current aries RFC 19), compatible with ACA-Py #292

Merged
merged 1 commit into from
Sep 20, 2019

Conversation

Moopli
Copy link
Contributor

@Moopli Moopli commented Sep 19, 2019

Implements legacy encrypter for compatibility with ACA-Py.

Closes #139

Signed-off-by: Filip Burlacu [email protected]

@codecov-io
Copy link

codecov-io commented Sep 19, 2019

Codecov Report

Merging #292 into master will decrease coverage by 0.04%.
The diff coverage is 88.07%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #292      +/-   ##
==========================================
- Coverage   88.75%   88.71%   -0.05%     
==========================================
  Files          39       42       +3     
  Lines        1975     2126     +151     
==========================================
+ Hits         1753     1886     +133     
- Misses        122      131       +9     
- Partials      100      109       +9
Impacted Files Coverage Δ
pkg/didcomm/crypto/legacy/authcrypt/authcrypt.go 86.44% <86.44%> (ø)
pkg/didcomm/crypto/legacy/authcrypt/decrypt.go 87.5% <87.5%> (ø)
pkg/didcomm/crypto/legacy/authcrypt/encrypt.go 89.47% <89.47%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 58db8d1...ad1a464. Read the comment docs.

@fqutishat
Copy link
Contributor

code coverage is low

return encodedRecipients, nil
}

// Note: the spec is incorrect with the parameters for encrypted_key: the CEK is the message to encrypt
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you raise an issue on aries-rfcs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The spec in question is being amended to a JWE format (that @Baha-sk is working on) anyway - perhaps we should request it be split to keep a spec for the legacy format for backwards-compatibility, and amend that.

Copy link
Contributor

@llorllale llorllale left a comment

Choose a reason for hiding this comment

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

I'm concerned that most of the tests just consist of a) checking that there is no error, and b) the output is not empty.

It would be better if we tested actual results against expected, verifiable values.

pkg/didcomm/crypto/legacy/authcrypt/authcrypt.go Outdated Show resolved Hide resolved
pkg/didcomm/crypto/legacy/authcrypt/authcrypt.go Outdated Show resolved Hide resolved
pkg/didcomm/crypto/legacy/authcrypt/authcrypt.go Outdated Show resolved Hide resolved
pkg/didcomm/crypto/legacy/authcrypt/encrypt.go Outdated Show resolved Hide resolved
recipient1Key, err := randCurveKeyPair(rand.Reader)
require.NoError(t, err)

t.Run("Generate a box_seal message to compare to ACA-Py:", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

where is the comparison to ACA-Py's output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Randomness (for nonces, CEKs) keeps me from generating encrypted envelopes in ACA-Py to compare against my own output. Right now I generate test data which can be pasted into a python test script to verify using ACA-Py decrypt, but once I have decrypt implemented I can create test data in ACA-Py that can be part of test cases here, testing decrypt, and I can also have test cases for my encrypt against my decrypt.

In essence, verification of correctness needs to happen on the decrypt side. I could work on making encrypt take a Reader as parameter for the randomness source, with the wallet being relied on to submit a CSPRNG.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My above concern should be solved now. You should soon see more tests like what you want to see.

TODO: use Ed25519 keys, convert to curve25519 internally, encode the Ed25519 form for message packing
*/

t.Run("Success test case: given keys, generate envelope", func(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be good to compare the actual result to an expected value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Now that I can run the crypter using a deterministic rand source, I have a few tests which do this. Got some ideas on more I can do though.

pkg/didcomm/crypto/legacy/authcrypt/encrypt.go Outdated Show resolved Hide resolved
@Moopli Moopli force-pushed the issue-139 branch 2 times, most recently from 8e7eca5 to 9522538 Compare September 19, 2019 21:35
@Moopli
Copy link
Contributor Author

Moopli commented Sep 19, 2019

I'm concerned that most of the tests just consist of a) checking that there is no error, and b) the output is not empty.

It would be better if we tested actual results against expected, verifiable values.

I just pushed fixes to most of what's been brought up, some improvements to test coverage, and I made the crypter deterministic, taking an RNG as a parameter - crypto/rand.Reader under production conditions, but can take a seeded RNG for tests. I verified with a test using an empty payload, and I'll add more tests that I can now do, with a deterministic crypter.

go.mod Outdated Show resolved Hide resolved
@Moopli Moopli changed the title Legacy encrypt (current aries RFC 19), compatible with ACA-Py feat: Legacy encrypt (current aries RFC 19), compatible with ACA-Py Sep 20, 2019
@Moopli Moopli force-pushed the issue-139 branch 4 times, most recently from d6d121f to 3417002 Compare September 20, 2019 19:04
@Moopli Moopli force-pushed the issue-139 branch 2 times, most recently from 7cb4451 to 31a15a1 Compare September 20, 2019 19:53
@Moopli Moopli force-pushed the issue-139 branch 3 times, most recently from a50249a to fadbb35 Compare September 20, 2019 22:13
@Moopli
Copy link
Contributor Author

Moopli commented Sep 20, 2019

@fqutishat every live code path is now exercised - only future regressions or cosmic rays will make errors happen in the few error cases that aren't tested.

return c, nil
}

func (c *Crypter) setRandSource(source io.Reader) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This method is unused

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's used in tests, but I can replace it with direct access to the Crypter.

Copy link
Contributor

@llorllale llorllale left a comment

Choose a reason for hiding this comment

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

PR way too big. Please don't do this again.

@llorllale llorllale merged commit 0bdac24 into hyperledger-archives:master Sep 20, 2019
@Moopli Moopli deleted the issue-139 branch September 23, 2019 14:25
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Create package to support legacy envelope encryption format
6 participants