Skip to content
Merged
Show file tree
Hide file tree
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
27 changes: 19 additions & 8 deletions HAL/keymaster/4.1/JavacardKeymaster4Device.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -1085,16 +1085,27 @@ Return<void> JavacardKeymaster4Device::begin(KeyPurpose purpose, const hidl_vec<
cborConverter_.addHardwareAuthToken(array, authToken);
std::vector<uint8_t> cborData = array.encode();

/* keyCharacteristics.hardwareEnforced is required to store algorithm, digest and padding values in operationInfo
* structure. To retrieve keyCharacteristics.hardwareEnforced, parse the keyBlob.
*/
/* TODO if keyBlob is corrupted it crashes in cbor */
std::tie(blobItem, errorCode) = cborConverter_.decodeData(std::vector<uint8_t>(keyBlob), false);
// keyCharacteristics.hardwareEnforced is required to store algorithm, digest and padding values in operationInfo
// structure. To retrieve keyCharacteristics.hardwareEnforced, call getKeyCharacateristics.
// By calling getKeyCharacateristics also helps in finding a corrupted keyblob.
hidl_vec<uint8_t> applicationId;
hidl_vec<uint8_t> applicationData;
if(getTag(inParams, Tag::APPLICATION_ID, param)) {
applicationId = param.blob;
}
if(getTag(inParams, Tag::APPLICATION_DATA, param)) {
applicationData = param.blob;
}
//Call to getKeyCharacteristics.
getKeyCharacteristics(keyBlob, applicationId, applicationData,
[&](ErrorCode error, KeyCharacteristics keyChars) {
errorCode = error;
keyCharacteristics = keyChars;
});

if(blobItem != nullptr) {
if(errorCode == ErrorCode::OK) {
errorCode = ErrorCode::UNKNOWN_ERROR;
if(cborConverter_.getKeyCharacteristics(blobItem, 3, keyCharacteristics) &&
getTag(keyCharacteristics.hardwareEnforced, Tag::ALGORITHM, param)) {
if(getTag(keyCharacteristics.hardwareEnforced, Tag::ALGORITHM, param)) {
errorCode = sendData(Instruction::INS_BEGIN_OPERATION_CMD, cborData, cborOutData);
if((errorCode == ErrorCode::OK) && (cborOutData.size() > 2)) {
//Skip last 2 bytes in cborData, it contains status.
Expand Down
10 changes: 6 additions & 4 deletions HAL/keymaster/4.1/JavacardOperationContext.cpp
Original file line numberDiff line numberDiff line change
Expand Up@@ -229,12 +229,14 @@ ErrorCode OperationContext::getBlockAlignedData(uint64_t operHandle, uint8_t* in
/*Update */
//Calculate the block sized length on combined input of both buffered data and input data.
uint32_t blockAlignedLen = ((data.buf_len + input_len)/blockSize) * blockSize;
//For symmetric ciphers, decryption operation and PKCS7 padding mode save last 16 bytes of block and send this
//block in finish operation. This is done to make sure that there will be always a 16 bytes data to finish
//operation so that javacard Applet may remove PKCS7 padding if any.
//For symmetric ciphers, decryption operation and PKCS7 padding mode or AES GCM operation save the last 16 bytes
//of block and send this block in finish operation. This is done to make sure that there will be always a 16
//bytes of data left for finish operation so that javacard Applet may remove PKCS7 padding if any or get the tag
//data for AES GCM operation for authentication purpose.
if(((operationTable[operHandle].info.alg == Algorithm::AES) ||
(operationTable[operHandle].info.alg == Algorithm::TRIPLE_DES)) &&
(operationTable[operHandle].info.pad == PaddingMode::PKCS7) &&
(operationTable[operHandle].info.pad == PaddingMode::PKCS7 ||
operationTable[operHandle].info.mode == BlockMode::GCM) &&
(operationTable[operHandle].info.purpose == KeyPurpose::DECRYPT)) {
if(blockAlignedLen >= blockSize) blockAlignedLen -= blockSize;
}
Expand Down