openwallet-foundation / askar

Secure storage designed for Hyperledger Aries agents.
Apache License 2.0
63 stars 51 forks source link

Error handling in crypto box #213

Closed angellllk closed 10 months ago

angellllk commented 10 months ago

Hi. I'm submitting this issue in regard to crypto_box_seal_open. Passing a [u8], with length less than 32 as ciphertext, results in a panic (range end index 32 out of range for slice).

let ephem_pk = X25519KeyPair::from_public_bytes(&ciphertext[..CBOX_KEY_LENGTH])?;

It should be checked if the array has the correct length, as it is checked in crypto_box_open:

if buf_len < CBOX_TAG_LENGTH {
        return Err(err_msg!(Encryption, "Invalid size for encrypted data"));
}