Skip to content

private key and phone number leaked in enclave code #1

Description

@jmp0x7c00

hi,sir
I think there is a security issue in your enclave code, in file Server/Enclave/Enclave.cpp

sgx_status_t ecall_decrypt_secret(sgx_ra_context_t context,
        const uint8_t *p_src, uint32_t src_len, 
        const sgx_aes_gcm_128bit_tag_t *p_in_mac)
{   
    if (contextid_accid_map.find(context) == contextid_accid_map.end())
    {
        return SGX_ERROR_UNEXPECTED;
    }

    sgx_status_t sgx_status = SGX_SUCCESS;
    sgx_ra_key_128_t ra_key;
    string phone_num;

    sgx_status = sgx_ra_get_keys(context, SGX_RA_KEY_SK, &ra_key);
    if (SGX_SUCCESS != sgx_status)
    {
        return sgx_status;
    }

    feprintf("ra key:%s\n", hexstring(&ra_key, sizeof(ra_key))); //  ========>  ra_key is leaked...
    
    uint8_t *p_iv = (uint8_t*)malloc(SGX_AESGCM_IV_SIZE);
    memset(p_iv, 0, SGX_AESGCM_IV_SIZE);
    uint8_t *p_dst = (uint8_t*)malloc(src_len);
    memset(p_dst, 0, src_len);
    sgx_status = sgx_rijndael128GCM_decrypt(&ra_key, p_src,
            src_len, p_dst, p_iv, SGX_AESGCM_IV_SIZE, NULL, 0, p_in_mac);

    if (SGX_SUCCESS != sgx_status)
    {
        sgx_status = SGX_ERROR_UNEXPECTED;
        goto cleanup;
    }

    phone_num = string(hexstring(p_dst, src_len));
    phone_num = phone_num.substr(0, 11);
    accid_phone_map[contextid_accid_map[context]] = phone_num;

    feprintf("Phone number:%s\n", accid_phone_map[contextid_accid_map[context]]); // ========> phone number is leaked

private key and phone number can be leaked by invoking ocall void ocall_eprint_string([in, string] const char *str);

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions