Untitled

 avatar
unknown
plain_text
10 months ago
1.5 kB
7
Indexable
int32_t generateServiceKeyV1(struct KeyInfo *keyInfo, const uint8_t *drkBlob, const uint32_t drkBlobLen,
        uint8_t *serviceBlob, uint32_t *serviceBlobLen, const uint8_t *attrs, const uint32_t attrsLen, KeyType_t keyType)
{
    int32_t ret = NOT_ERROR;
    ServiceKeyInfo_t serviceKeyInfo;
    uint8_t plainBlob[MAX_SKM_BUF_SIZE], targetTid[MAX_TID_SIZE];
    uint32_t plainBlobLen = sizeof(plainBlob), targetTidLen = sizeof(targetTid);
    
    LOGI("%s start...", __func__);

    if (keyInfo == NULL) {
        LOGE("%s : Invalid argument. keyInfo is NULL.", __func__);
        return ERR_TA_INVALID_ARGUMENT;
    }

    // Check for NULL pointers within keyInfo before dereferencing
    if (keyInfo->serviceName == NULL || keyInfo->model == NULL || keyInfo->serialno == NULL) {
        LOGE("%s : Invalid KeyInfo structure. One of the fields is NULL.", __func__);
        return ERR_TA_INVALID_ARGUMENT;
    }

    memset(plainBlob, 0, sizeof(plainBlob));
    memset(&serviceKeyInfo, 0, sizeof(serviceKeyInfo));

    // Now it's safe to use the keyInfo members
    memcpy(serviceKeyInfo.serviceName, keyInfo->serviceName, MAX_SERVICE_NAME);
    serviceKeyInfo.serviceName[MAX_SERVICE_NAME] = '\0';    
    memcpy(serviceKeyInfo.model, keyInfo->model, sizeof(serviceKeyInfo.model));
    memcpy(serviceKeyInfo.serialNo, keyInfo->serialno, sizeof(serviceKeyInfo.serialNo));
    serviceKeyInfo.keyLength = keyInfo->keyLen;
    serviceKeyInfo.keyType = keyType;

    // Additional logic here...

    return ret;
}
Editor is loading...
Leave a Comment