Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.1 kB
3
Indexable
Never
case CMD_GENERATE_EC_SERVICE_KEY_V1 :
    if (keyType == KEY_TYPE_NONE) {
        keyType = KEY_TYPE_EC;
    }
    memcpy(&dataLen, inData + inDataLen - sizeof(uint32_t), sizeof(dataLen));
    if (dataLen > inDataLen) {
        LOGE("In data length is not proper - %d %d.", dataLen, inDataLen);
        return ERR_TA_BUFFER_OVERFLOW;
    }

    pTlv = (Tlv_t *)inData;
    if (pTlv->tag == KEYBLOB_TAG_TA_NAME) {
        if ((tidLen = pTlv->dataLen) > MAX_TID_SIZE) {
            LOGE("Invalid TID length: %d", tidLen);
            return ERR_TA_INVALID_ARGUMENT;
        }
        pTlv = (Tlv_t *)(pTlv->data + pTlv->dataLen);
        pos += tidLen;
    }

    if (pTlv->tag == KEYBLOB_TAG_ATTRS) {
        attrsLen = pTlv->dataLen;
        pAttrs = pTlv->data;
        
        // Length validation for attrsLen
        if (attrsLen == 0 || attrsLen > (dataLen - pos)) {
            LOGE("Invalid attribute length: %d", attrsLen);
            return ERR_TA_BUFFER_OVERFLOW;
        }

        if ((dataLen > attrsLen) && (pos < dataLen - attrsLen)) {
            pTlv = (Tlv_t *)(pTlv->data + pTlv->dataLen);
            pos += attrsLen;
        } else {
            LOGE("Inserted data is too big - %d %d", tidLen, attrsLen);
            return ERR_TA_BUFFER_OVERFLOW;
        }
    }

    // Ensure there is enough data for KeyInfo
    if ((dataLen > sizeof(struct KeyInfo)) && (pos < dataLen - sizeof(struct KeyInfo))) {
        pKeyInfo = (uint8_t *)pTlv;
        pos += sizeof(struct KeyInfo);

        memcpy(&wrappedKeyLenV1, inData + inDataLen - sizeof(uint32_t) * 2, sizeof(wrappedKeyLenV1));

        if ((dataLen > wrappedKeyLenV1) && (pos < dataLen - wrappedKeyLenV1)) {
            pWrappedKey = pKeyInfo + sizeof(struct KeyInfo);

            LOGD("dataLen = %d, tidLen = %d, attrsLen = %d, drkKeyLen = %d", dataLen, tidLen, attrsLen, wrappedKeyLenV1);

            ret = generateServiceKeyV1((struct KeyInfo *)pKeyInfo, pWrappedKey, wrappedKeyLenV1,
                                       outData, outDataLen, pAttrs, attrsLen, keyType);
        }
    }
    break;
Leave a Comment