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

validate cipher length before decrypting #14098

Merged
merged 2 commits into from
Feb 18, 2022

Conversation

swayne275
Copy link
Contributor

This addresses TOB-016.

I'm not sure if erroring when the len(ciphertext) < 4 is revealing any important information to a potential attacker, so please let me know. As is, it would panic (which is less directly revealing the same information).

This will be backported back to 1.7.x

@swayne275 swayne275 requested review from a team February 16, 2022 14:59
Copy link
Contributor

@cipherboy cipherboy left a comment

Choose a reason for hiding this comment

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

Do we also need b.decrypt to check length? It kinda looks like it doesn't:

vault/vault/barrier_aes_gcm.go

Lines 1015 to 1035 in fe5c8db

// decrypt is used to decrypt a value using the keyring
func (b *AESGCMBarrier) decrypt(path string, gcm cipher.AEAD, cipher []byte) ([]byte, error) {
// Capture the parts
nonce := cipher[5 : 5+gcm.NonceSize()]
raw := cipher[5+gcm.NonceSize():]
out := make([]byte, 0, len(raw)-gcm.NonceSize())
// Attempt to open
switch cipher[4] {
case AESGCMVersion1:
return gcm.Open(out, nonce, raw, nil)
case AESGCMVersion2:
aad := []byte(nil)
if path != "" {
aad = []byte(path)
}
return gcm.Open(out, nonce, raw, aad)
default:
return nil, fmt.Errorf("version bytes mis-match")
}
}

@swayne275
Copy link
Contributor Author

swayne275 commented Feb 16, 2022

@cipherboy it looks like it should as well

edit: 951390b

@vercel vercel bot temporarily deployed to Preview – vault February 16, 2022 15:14 Inactive
@vercel vercel bot temporarily deployed to Preview – vault-storybook February 16, 2022 15:14 Inactive
@swayne275 swayne275 requested review from cipherboy and a team February 16, 2022 15:15
@swayne275 swayne275 merged commit a6f8bdc into main Feb 18, 2022
@swayne275 swayne275 deleted the vault-5099/add-cipher-length-validation branch February 18, 2022 14:37
swayne275 added a commit that referenced this pull request Feb 18, 2022
* validate cipher length before decrypting

* also protect decrypt from short cipher
swayne275 added a commit that referenced this pull request Feb 18, 2022
* validate cipher length before decrypting

* also protect decrypt from short cipher
swayne275 added a commit that referenced this pull request Feb 18, 2022
* validate cipher length before decrypting

* also protect decrypt from short cipher
swayne275 added a commit that referenced this pull request Feb 18, 2022
* validate cipher length before decrypting

* also protect decrypt from short cipher
swayne275 added a commit that referenced this pull request Feb 18, 2022
* validate cipher length before decrypting

* also protect decrypt from short cipher
swayne275 added a commit that referenced this pull request Feb 18, 2022
* validate cipher length before decrypting

* also protect decrypt from short cipher
@mladlow
Copy link
Collaborator

mladlow commented Feb 23, 2022

@swayne275 if you'd like you can use backport-assistant to automatically create the backport PRs for stuff like this in the future. There's a google doc on how to do this, which I'll eventually move to the wiki.

@swayne275
Copy link
Contributor Author

@mladlow oh awesome! last i'd heard my understanding was that was only for docs changes. i had been using https://docs.google.com/document/d/1uQDcq2gd-rO4PHeK9fEEZ5qauGJVsEUrG57il3mOcQw/edit#heading=h.1n8tmqhs7xas

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.

4 participants