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

Authcrypt Decrypt Using (X)Chacha20Poly1035 #230

Merged
merged 1 commit into from
Sep 12, 2019

Conversation

baha-ai
Copy link
Contributor

@baha-ai baha-ai commented Sep 9, 2019

Closes #122

@codecov-io
Copy link

codecov-io commented Sep 9, 2019

Codecov Report

Merging #230 into master will increase coverage by 0.02%.
The diff coverage is 89.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #230      +/-   ##
==========================================
+ Coverage   87.34%   87.36%   +0.02%     
==========================================
  Files          36       36              
  Lines        1643     1726      +83     
==========================================
+ Hits         1435     1508      +73     
- Misses        115      120       +5     
- Partials       93       98       +5
Impacted Files Coverage Δ
pkg/didcomm/crypto/jwe/authcrypt/authcrypt.go 100% <100%> (ø) ⬆️
pkg/didcomm/crypto/jwe/authcrypt/decrypt.go 86.73% <88.88%> (+15.9%) ⬆️
pkg/didcomm/crypto/jwe/authcrypt/encrypt.go 76.15% <89.09%> (+0.03%) ⬆️

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 555861a...0354cec. Read the comment docs.

@troyronda
Copy link
Contributor

@Baha-sk Test coverage looks low?

@baha-ai baha-ai force-pushed the issue-122 branch 3 times, most recently from f2e2f5d to 884e84e Compare September 10, 2019 20:42
@baha-ai
Copy link
Contributor Author

baha-ai commented Sep 10, 2019

@Baha-sk Test coverage looks low?

@troyronda coverage is now increased

require.NoError(t, err)
require.NotEmpty(t, dec)

// TODO fix try to decrypt the reference payload
Copy link
Contributor

Choose a reason for hiding this comment

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

How do we know this PR is working?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

working on php interoperable decryption/encryption..

Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this line commented out then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

encryption/decryption fully works in Go.. testing with a JWE generated in another language (PHP) is still failing, but doesn't block Pack/Unpack for now.. so we can go ahead and merge this PR and a new PR will deal with interoperability updates.

@sandrask
Copy link
Contributor

As discussed, please remove senderKey and recipient public keys from New(). You don't need to specify sender key if you are only using Decrypt() function.

@baha-ai
Copy link
Contributor Author

baha-ai commented Sep 12, 2019

As discussed, please remove senderKey and recipient public keys from New(). You don't need to specify sender key if you are only using Decrypt() function.

I will refactor to extract keys out of New() and move them to Encrypt()/Decrypt() accordingly.

pld := []byte("lorem ipsum dolor sit amet")
enc, e := crypter.Encrypt(pld)
require.NoError(t, e)
require.NotEmpty(t, enc)
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume the correctness check isn't being done due to a non-deterministic nonce?

Seems like the testing should be setting deterministic values and comparing actual results. !Empty checks seem insufficient.

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, probably by hardcoding values into RandReader for tests .. I'll see how this can be done..

@baha-ai baha-ai force-pushed the issue-122 branch 2 times, most recently from 098e039 to 335fe65 Compare September 12, 2019 18:39
@fqutishat fqutishat requested a review from sandrask September 12, 2019 18:56
Copy link
Contributor

@Moopli Moopli left a comment

Choose a reason for hiding this comment

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

👍

@@ -31,17 +30,27 @@ const XC20P = ContentEncryption("XC20P") // XChacha20 encryption + Poly1035 auth
//nolint:gochecknoglobals
var randReader = rand.Reader

// ErrEmptyRecipients is used when recipients list is empty
var ErrEmptyRecipients = errors.New("empty recipients")
Copy link
Contributor

@troyronda troyronda Sep 12, 2019

Choose a reason for hiding this comment

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

I think you should only create exported Error values for things you expect the consumer of the library to check. i.e., expected errors.

Are you suggesting implementations need to check for these specific errors? Most don't seem like runtime issues... If they aren't expected to be checked, then don't export the errors.

Even more explicitly, if you don't expect someone to call errors.Is then there is no need for this error value to show up in the API.

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 user of the Crypter can miss adding recipients when calling Encrypt/Decrypt... but this will probably be internal (used by the wallet API).. I can un export these error types

	Using RawURLEncoding for Base64 encoding to
	allow interoperability with non Go agents

Signed-off-by: Baha Shaaban <[email protected]>
@fqutishat fqutishat merged commit 0efa055 into hyperledger-archives:master Sep 12, 2019
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.

Decrypt (X)Chacha20Poly1035 envelop
6 participants