-
Notifications
You must be signed in to change notification settings - Fork 919
ASN PemToDer: remove padding when AES_CBC encrypted #4911
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
Conversation
embhorn
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thanks Sean. Fix is also confirmed by customer.
| #if !defined(NO_AES) && defined(HAVE_AES_CBC) && \ | ||
| defined(HAVE_AES_DECRYPT) | ||
| if (info->cipherType == WC_CIPHER_AES_CBC) { | ||
| if (der->length > AES_BLOCK_SIZE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if der->length is a multiple of AES_BLOCK_SIZE? Will there still be padding? If not this logic isn't right. Perhaps the check should be if ((der->length % AES_BLOCK_SIZE) != 0) {?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check is to see whether there is enough bytes for at least one block - a padded block. Must have a full block of padding if the plaintext is a multiple of the block size - otherwise you don't know whether there is padding there or not.
The decryption will fail if the encrypted data isn't a multiple of the block size.
| if (info->cipherType == WC_CIPHER_AES_CBC) { | ||
| if (der->length > AES_BLOCK_SIZE) { | ||
| padVal = der->buffer[der->length-1]; | ||
| if (padVal <= AES_BLOCK_SIZE) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then use if (padVal <= der->length)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Encrypted PEM with a block cipher has padding.
Remove padding.
Fixes zd#13803
Testing
POC with customer data.
Checklist