char *loadPrefFile() { if(!checkFileExist(SETTINGS_FILE) && checkFileExist(SETTINGS_FILE".tmp")) rename(SETTINGS_FILE".tmp", SETTINGS_FILE); size_t filesize = getFileSize(SETTINGS_FILE); if(filesize == 0) return NULL; char * output = calloc(filesize + 10, sizeof(char)); if(output == NULL) return NULL; AESDecrypt(SETTINGS_PASSWORD, SETTINGS_FILE, output, OUTPUT_IN_MEMORY); if(output[0] != '<') { #ifdef EXTENSIVE_LOGGING logR("Incorrect settings decryption: %s", output); #else logR("Incorrect settings decryption"); #endif free(output); output = NULL; } return output; }
int main(int argc, char *argv[]) { std::string en_key(DSP_DES_CBC_KEY); std::string in("code_id=bSkL81c10018&os_ver=4.3&app_ver=1.0.0&android_id=504340280EA00B10&imei=860372032982284&mac=00:db:df:87:5a:7d&sw=375&sh=667&ot=3&ct=4&ip=180.173.15.245&device_type=1&os_type=1&vendor=vivo&model=x9+plus"); std::string out = AESEncrypt(en_key, in); std::string res = AESDecrypt(DSP_DES_CBC_KEY, out); printf("%s\n", res.c_str()); return 0; }
VOS_UINT32 USIMM_VsimGetRealKiOpc(VOS_UINT8 *pucKi, VOS_UINT8 *pucOpc) { VOS_UINT8 aucKey[VSIM_DH_AGREE_KEY] = {0}; VOS_UINT8 aucKi[USIMM_VSIM_SECUR_MAX_LEN]; VOS_UINT8 aucOpc[USIMM_VSIM_SECUR_MAX_LEN]; NVIM_VSIM_HVSDH_NV_STRU stNVDHKey; DH_KEY stDHPara; VSIM_KEYDATA_STRU stCPrivateKey; /* 单板私钥 */ VOS_MemSet(&stDHPara, 0, sizeof(stDHPara)); if(VOS_NULL == g_stUSIMMVSimAuthInfo.ucKILen) { USIMM_ERROR_LOG("USIMM_VsimGetRealKiOpc: Ki Len is 0"); return VOS_ERR; } if(NV_OK != NV_Read(en_NV_Item_VSIM_HVSDH_INFO, &stNVDHKey, sizeof(NVIM_VSIM_HVSDH_NV_STRU))) { USIMM_ERROR_LOG("USIMM_VsimGetRealKiOpc: NV Read Key is Failed"); return VOS_ERR; } if(VSIM_ALGORITHM_NULL == stNVDHKey.enAlgorithm) { USIMM_WARNING_LOG("USIMM_VsimGetRealKiOpc: Algorithm is OFF"); VOS_MemCpy(pucKi, g_stUSIMMVSimAuthInfo.aucKi, USIMM_AUTH_KI_LEN); VOS_MemCpy(pucOpc, g_stUSIMMVSimAuthInfo.aucOpc, USIMM_AUTH_OPC_LEN); return VOS_OK; } /* [false alarm]:fortify */ if(VOS_OK != USIMM_VsimHUKDecode(stNVDHKey.stCPrivateKey.aucKey, VSIM_DH_PRIVATE_KEY, stCPrivateKey.aucKey, &stCPrivateKey.ulKeyLen)) { USIMM_ERROR_LOG("USIMM_VsimGetRealKiOpc: USIMM_VsimHUKDecode is Failed");/* [false alarm]:fortify */ return VOS_ERR; } VOS_MemCpy(stDHPara.privateValue, stCPrivateKey.aucKey, VSIM_DH_PRIVATE_KEY); stDHPara.priVallen = VSIM_DH_PRIVATE_KEY; DH_FillFixParams(&stDHPara); if(VOS_OK != DH_ComputeAgreedKey(aucKey, stNVDHKey.stSPublicKey.aucKey, &stDHPara)) { USIMM_ERROR_LOG("USIMM_VsimGetRealKiOpc: DH_ComputeAgreedKey is Failed"); return VOS_ERR; } /* coverity[uninit_use_in_call] */ if(VOS_FALSE == AESDecrypt(g_stUSIMMVSimAuthInfo.aucKi, g_stUSIMMVSimAuthInfo.ucKILen, aucKey, sizeof(aucKey), aucKi, sizeof(aucKi))) { USIMM_ERROR_LOG("USIMM_VsimGetRealKiOpc: AESDecrypt Ki is Failed"); return VOS_ERR; } VOS_MemCpy(pucKi, aucKi, USIMM_AUTH_KI_LEN); if(VOS_NULL == g_stUSIMMVSimAuthInfo.ucOpcLen) { USIMM_NORMAL_LOG("USIMM_VsimGetRealKiOpc: Only get Ki Data"); return VOS_OK; } /* coverity[uninit_use_in_call] */ if(VOS_FALSE == AESDecrypt(g_stUSIMMVSimAuthInfo.aucOpc, g_stUSIMMVSimAuthInfo.ucOpcLen, aucKey, sizeof(aucKey), aucOpc, sizeof(aucOpc))) { USIMM_ERROR_LOG("USIMM_VsimGetRealKiOpc: AESDecrypt Opc is Failed"); return VOS_ERR; } /* coverity[uninit_use_in_call] */ VOS_MemCpy(pucOpc, aucOpc, USIMM_AUTH_OPC_LEN); USIMM_NORMAL_LOG("USIMM_VsimGetRealKiOpc: Get Ki and Opc Data"); return VOS_OK; }