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

fix decryptRaw issue for nil/empty data #4532

Merged
merged 1 commit into from
Oct 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions internal/blsgen/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"crypto/md5"
"crypto/rand"
"encoding/hex"
"fmt"
"io"
"io/ioutil"
"os"
Expand Down Expand Up @@ -136,6 +137,9 @@ func decrypt(encrypted []byte, passphrase string) (decrypted []byte, err error)
}

func decryptRaw(data []byte, passphrase string) ([]byte, error) {
if len(data) == 0 {
return nil, fmt.Errorf("unable to decrypt raw data with the provided passphrase; the data is empty")
}
var err error
key := []byte(createHash(passphrase))
block, err := aes.NewCipher(key)
Expand All @@ -147,6 +151,9 @@ func decryptRaw(data []byte, passphrase string) ([]byte, error) {
return nil, err
}
nonceSize := gcm.NonceSize()
if len(data) < nonceSize {
return nil, fmt.Errorf("failed to decrypt raw data with the provided passphrase; the data size is invalid")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, fmt.Errorf("failed to decrypt raw data with the provided passphrase; the data size is invalid")
return nil, fmt.Errorf("failed to decrypt raw data with the provided passphrase; expected at least %d, got %d", nonceSize, len(data))

}
nonce, ciphertext := data[:nonceSize], data[nonceSize:]
plaintext, err := gcm.Open(nil, nonce, ciphertext, nil)
return plaintext, err
Expand Down