Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: return generic errors for aes256cbc encrypt and decrypt #509

Merged
merged 10 commits into from
Feb 2, 2020

Conversation

developerfred
Copy link
Contributor

@developerfred developerfred commented Jan 5, 2020

fixes #499

Copy link
Member

@robdefeo robdefeo left a comment

Choose a reason for hiding this comment

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

Thanks @developerfred for the PR 😄 there are a few more errors that need to be returned by the Encrypt(message mc.PlainContent) (mc.EncryptedContent, error) and decryptEncryptedData(d.privateKey, encryptedData) as they still return other errors that would make it back to the end user.
Thanks

crypto/cipher/aes256cbc/decrypter.go Show resolved Hide resolved
crypto/cipher/aes256cbc/encrypter.go Show resolved Hide resolved
Copy link
Member

@robdefeo robdefeo left a comment

Choose a reason for hiding this comment

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

thanks @developerfred these changes were exactly what I had asked for. I missed one method though decryptEncryptedData(d.privateKey, encryptedData) can you also do the same with that one

crypto/cipher/aes256cbc/decrypter.go Show resolved Hide resolved
Copy link
Member

@robdefeo robdefeo left a comment

Choose a reason for hiding this comment

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

Thanks @developerfred looks great 😄 changes are good to merge 👍

}

macKey, encryptionKey := generateMacKeyAndEncryptionKey(sharedSecret)
mac, err := generateMac(macKey, data.InitializationVector, *ephemeralPublicKey, data.Ciphertext)

if err != nil {
return nil, errors.WithMessage(err, "generateMac failed")

Choose a reason for hiding this comment

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

I don't think it's a good idea to mask all errors with the same error. It's okay to return the same error type, but it should not be the same error message for different types of errors, the actual error is getting masked here. It'll be harder to debug the reason just by seeing "error in decryption".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe that in the future we will create a variable for each type of error, making the code more maintainable.

Copy link
Member

Choose a reason for hiding this comment

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

@hasitpbhatt thank you for taking the time to leave a review on this PR. Sorry for the delay getting back to you I was off for a while. I would love to hear about how you found out about Mailchain and if there is anything I can do to help you. Please feel free to comment here or join our slack channel

You raise an excellent point about the outcome from a developer perspective. The reason for masking the error is to reduce the information an attacker might get from an error. This does need more thought overall so I have opened an issues #532 to discuss this.

In the meantime @developerfred I will merge this change as it resolves the issue as originally defined. Once #532 is resolved we will come back to this

@robdefeo robdefeo merged commit 8232fa2 into mailchain:master Feb 2, 2020
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.

return generic errors for aes256cbc encrypt and decrypt
3 participants