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

Add AD mode to Transit's AEAD ciphers #17638

Merged
merged 4 commits into from
Oct 24, 2022
Merged

Conversation

cipherboy
Copy link
Contributor

Project I started during hack week, but didn't quite finish... (something something, tests) :-)

This adds a new parameter, associated_data to be passed when using an AEAD cipher (AES+GCM, ChaCha20+Poly1305). This is authenticated, but need not be transited in ciphertext.

var factory interface{}

if item.AssociatedData != "" {
isAEAD := p.Type.String() == "aes128-gcm96" || p.Type.String() == "aes192-gcm96" || p.Type.String() == "aes256-gcm96" || p.Type.String() == "chacha20-poly1305"
Copy link
Contributor

Choose a reason for hiding this comment

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

Could we switch this to use the existing pattern of adding this test on the KeyType type in policy.go around line 146, instead of using string tests? For example we seem to have added an "impossible" key type value in this test of aes192-gcm96

func (kt KeyType) AEADSupported() bool {
	switch kt {
	case KeyType_AES128_GCM96, KeyType_AES256_GCM96, KeyType_ChaCha20_Poly1305:
		return true
	}
	return false
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I added it intentionally so we don't fail if we later introduce AES-192... This does seem cleaner since the change should be localized to KeyType.

This allows the high-level, algorithm-agnostic Encrypt/Decrypt with
Factory to pass in AssociatedData, and potentially take multiple
factories (to allow KMS keys to work). On AEAD ciphers with a relevant
factory, an AssociatedData factory will be used to populate the
AdditionalData field of the SymmetricOpts struct, using it in the AEAD
Seal process.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
This allows passing the associated_data (the last AD in AEAD) to
Transit's encrypt/decrypt when using an AEAD cipher (currently
aes128-gcm96, aes256-gcm96, and chacha20-poly1305). We err if this
parameter is passed on non-AEAD ciphers presently.

This associated data can be safely transited in plaintext, without risk
of modifications. In the event of tampering with either the ciphertext
or the associated data, decryption will fail.

Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Signed-off-by: Alexander Scheel <alex.scheel@hashicorp.com>
Copy link
Contributor

@stevendpclark stevendpclark left a comment

Choose a reason for hiding this comment

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

Looks good to me, but will defer to others in the team to sign off on the new transit feature.

Copy link
Collaborator

@sgmiller sgmiller left a comment

Choose a reason for hiding this comment

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

Awesome!

@cipherboy cipherboy enabled auto-merge (squash) October 24, 2022 17:23
@cipherboy cipherboy merged commit fc2bdc3 into main Oct 24, 2022
@cipherboy cipherboy deleted the cipherboy-add-transit-aad-mode branch December 1, 2022 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants