|
@@ -48,7 +48,7 @@ static int encrypt_asf_file(char* poutfilename, char* phead, uint32_t uheaderlen
|
|
|
char strGuid[HEADER_OBJECT_GUID_LEN] = { 0 };
|
|
|
fread(strGuid, 1, HEADER_OBJECT_GUID_LEN, pSrcFile);
|
|
|
if (0 != memcmp(strGuid, ASF_Header_GUID, HEADER_OBJECT_GUID_LEN)) {
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "%s", "math guid failed, current format is not surpport!");
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "%s", "math guid failed, current format is not surpport!");
|
|
|
fclose(pDestFile);
|
|
|
return iret;
|
|
|
}
|
|
@@ -100,22 +100,22 @@ static int encrypt_mp4_file(char* poutfilename, char* phead, uint32_t uheaderlen
|
|
|
|
|
|
unsigned int unoencryptlen = get_noencrypt_boxs_size(pSrcFile, pcallback, true);
|
|
|
if (0 == unoencryptlen) {
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "get not encrypt boxs size failed.");
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "get not encrypt boxs size failed.");
|
|
|
return iret;
|
|
|
}
|
|
|
- //safe_log(pcallback, FILECRYPT_LOG_DEBUG, "not encrypt file length is %u.", unoencryptlen);
|
|
|
+ //safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "not encrypt file length is %u.", unoencryptlen);
|
|
|
|
|
|
FILE* pDestFile = fopen(poutfilename, "wb");
|
|
|
if (NULL == pDestFile) {
|
|
|
fclose(pSrcFile);
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "open output file failed.");
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "open output file failed.");
|
|
|
return iret;
|
|
|
}
|
|
|
|
|
|
fseek(pSrcFile, 0, SEEK_END);
|
|
|
uint32_t usrcfilelen = (uint32_t)ftell(pSrcFile);
|
|
|
rewind(pSrcFile);
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_DEBUG, "src file length is %u.", usrcfilelen);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "src file length is %u.", usrcfilelen);
|
|
|
|
|
|
//1. 新增自定义文件头
|
|
|
fwrite(phead, 1, uheaderlen, pDestFile);
|
|
@@ -150,7 +150,7 @@ static int encrypt_mp4_file(char* poutfilename, char* phead, uint32_t uheaderlen
|
|
|
unsigned char* pobjdataenc = (unsigned char*)malloc(iencdatalen);
|
|
|
|
|
|
if (0 == SM4EncECBMode(pstrkey, pmoovboxdata, umoovboxlen, pobjdataenc, &iencdatalen)) {
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_DEBUG, "after encode, moov box length is %u.", iencdatalen);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "after encode, moov box length is %u.", iencdatalen);
|
|
|
if (iencdatalen > 0) {
|
|
|
//3. 填充加密后的moov box长度
|
|
|
fwrite(&iencdatalen, 1, sizeof(uint32_t), pDestFile);
|
|
@@ -161,7 +161,7 @@ static int encrypt_mp4_file(char* poutfilename, char* phead, uint32_t uheaderlen
|
|
|
}
|
|
|
|
|
|
if(0 != iret){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "SM4 encrypt moovbox failed, and src moovbox len is %d.", umoovboxlen);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "SM4 encrypt moovbox failed, and src moovbox len is %d.", umoovboxlen);
|
|
|
}
|
|
|
|
|
|
fclose(pDestFile);
|
|
@@ -273,7 +273,7 @@ static int decrypt_mp4_file(char* poutfilename, FILE* pSrcFile, unsigned char* p
|
|
|
if (0 == unoencryptlen) {
|
|
|
return iret;
|
|
|
}
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_DEBUG, "not encrypt file length is %u.", unoencryptlen);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "not encrypt file length is %u.", unoencryptlen);
|
|
|
|
|
|
//1. 填充ftyp, free, mdat box
|
|
|
char* data_buffer = (char*)malloc(RVC_READ_BUFFER_SIZE);
|
|
@@ -294,7 +294,7 @@ static int decrypt_mp4_file(char* poutfilename, FILE* pSrcFile, unsigned char* p
|
|
|
//2. 获取加密后的moov box大小
|
|
|
uint32_t uencryptboxsize = 0;
|
|
|
fread(&uencryptboxsize, 1, sizeof(uint32_t), pSrcFile);
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_DEBUG, "encrypt moov box size is = %d.", uencryptboxsize);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "encrypt moov box size is = %d.", uencryptboxsize);
|
|
|
|
|
|
if (uencryptboxsize > 0) {
|
|
|
//3. 读取加密后的moov box
|
|
@@ -305,7 +305,7 @@ static int decrypt_mp4_file(char* poutfilename, FILE* pSrcFile, unsigned char* p
|
|
|
|
|
|
//4. 解密moov box
|
|
|
SM4DecECBMode(pstrkey, pmoovboxdata, uencryptboxsize, pdecmoovboxdata, &ioutlen);
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_DEBUG, "decrypt moov box size is = %d.", ioutlen);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "decrypt moov box size is = %d.", ioutlen);
|
|
|
|
|
|
//5. 填充解密后的moov box
|
|
|
fwrite(pdecmoovboxdata, 1, ioutlen, pDestFile);
|
|
@@ -316,7 +316,7 @@ static int decrypt_mp4_file(char* poutfilename, FILE* pSrcFile, unsigned char* p
|
|
|
iret = 0;
|
|
|
}
|
|
|
else {
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "get encrypt moovbox failed, decrypt failed!");
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "get encrypt moovbox failed, decrypt failed!");
|
|
|
}
|
|
|
|
|
|
fclose(pDestFile);
|
|
@@ -330,20 +330,20 @@ int decryption_file(char* poutfile, uint32_t uoutlen, const char* pfilename, con
|
|
|
int iret = -1;
|
|
|
|
|
|
if (NULL == pfilename || eversion >= sizeof(cryption_ver_flag_table)/sizeof(char*) || eversion < 0){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "%s","invalid encryption version param.");
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "%s","invalid encryption version param.");
|
|
|
return iret;
|
|
|
}
|
|
|
|
|
|
FILE* pSrcFile = fopen(pfilename, "rb");
|
|
|
if (NULL == pSrcFile){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "open file %s failed!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "open file %s failed!",pfilename);
|
|
|
return iret;
|
|
|
}
|
|
|
|
|
|
char strrvcflag[RVC_FILE_HEADER_FLAG_LEN] = {0};
|
|
|
fread(strrvcflag,1, RVC_FILE_HEADER_FLAG_LEN, pSrcFile);
|
|
|
if (0 != memcmp(strrvcflag, rvc_header, RVC_FILE_HEADER_FLAG_LEN)){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_INFO, "file %s is not encryption!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_INFO, "file %s is not encryption!",pfilename);
|
|
|
fclose(pSrcFile);
|
|
|
return iret;
|
|
|
}
|
|
@@ -356,7 +356,7 @@ int decryption_file(char* poutfile, uint32_t uoutlen, const char* pfilename, con
|
|
|
|
|
|
if (0 != memcmp(prvcbuffer+sizeof(uint32_t), cryption_ver_flag_table[eversion], RVC_CRYPTION_VER_FLAG_LEN)){
|
|
|
if (0 == memcmp(prvcbuffer+sizeof(uint32_t), cryption_ver_flag_table[eversion], RVC_CRYPTION_VER_FLAG_LEN-1)){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "file %s is encrypt but decrypt version is not matched!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "file %s is encrypt but decrypt version is not matched!",pfilename);
|
|
|
}
|
|
|
fclose(pSrcFile);
|
|
|
safe_free(prvcbuffer);
|
|
@@ -397,7 +397,7 @@ bool is_file_encrypted(const char* pfilename, const filecryption_callback_t* pca
|
|
|
|
|
|
FILE* pSrcFile = fopen(pfilename, "rb");
|
|
|
if (NULL == pSrcFile){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "open file %s failed!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "open file %s failed!",pfilename);
|
|
|
return bret;
|
|
|
}
|
|
|
|
|
@@ -407,7 +407,7 @@ bool is_file_encrypted(const char* pfilename, const filecryption_callback_t* pca
|
|
|
bret = true;
|
|
|
}
|
|
|
else{
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_INFO, "file %s is not encryption!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_INFO, "file %s is not encryption!",pfilename);
|
|
|
}
|
|
|
}
|
|
|
fclose(pSrcFile);
|
|
@@ -425,13 +425,13 @@ int rvc_file_decrypt(unsigned char** pdechead, uint32_t* udecheadlen, int* ioffs
|
|
|
{
|
|
|
int iret = -1;
|
|
|
if (NULL == pfilename || eversion >= sizeof(cryption_ver_flag_table)/sizeof(char*) || eversion < 0){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "%s","invalid cryption version param.");
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "%s","invalid cryption version param.");
|
|
|
return iret;
|
|
|
}
|
|
|
|
|
|
FILE* pSrcFile = fopen(pfilename, "rb");
|
|
|
if (NULL == pSrcFile){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "open file %s failed!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "open file %s failed!",pfilename);
|
|
|
return iret;
|
|
|
}
|
|
|
|
|
@@ -441,7 +441,7 @@ int rvc_file_decrypt(unsigned char** pdechead, uint32_t* udecheadlen, int* ioffs
|
|
|
char strrvcflag[RVC_FILE_HEADER_FLAG_LEN] = {0};
|
|
|
fread(strrvcflag,1, RVC_FILE_HEADER_FLAG_LEN, pSrcFile);
|
|
|
if (0 != memcmp(strrvcflag, rvc_header, RVC_FILE_HEADER_FLAG_LEN)){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_INFO, "file %s is not encrypted!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_INFO, "file %s is not encrypted!",pfilename);
|
|
|
*pdechead = NULL;
|
|
|
*udecheadlen = 0;
|
|
|
*ioffset = 0;
|
|
@@ -458,7 +458,7 @@ int rvc_file_decrypt(unsigned char** pdechead, uint32_t* udecheadlen, int* ioffs
|
|
|
|
|
|
if (0 != memcmp(prvcbuffer+sizeof(uint32_t), cryption_ver_flag_table[eversion], RVC_CRYPTION_VER_FLAG_LEN)){
|
|
|
if (0 == memcmp(prvcbuffer+sizeof(uint32_t), cryption_ver_flag_table[eversion], RVC_CRYPTION_VER_FLAG_LEN-1)){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "file %s encryption and decrption version is not matched!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "file %s encryption and decrption version is not matched!",pfilename);
|
|
|
}
|
|
|
safe_free(prvcbuffer);
|
|
|
fclose(pSrcFile);
|
|
@@ -473,7 +473,7 @@ int rvc_file_decrypt(unsigned char** pdechead, uint32_t* udecheadlen, int* ioffs
|
|
|
|
|
|
int ijson = get_file_json_infos_from_rvc_header(pstrjson, ujsonlen, prvcbuffer, irvcheadlen - RVC_FILE_HEADER_FLAG_LEN - sizeof(uint32_t));
|
|
|
if (0 == ijson){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_DEBUG, "get_file_json_infos_from_rvc_header success!");
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_DEBUG, "get_file_json_infos_from_rvc_header success!");
|
|
|
}
|
|
|
safe_free(prvcbuffer);
|
|
|
}
|
|
@@ -481,7 +481,7 @@ int rvc_file_decrypt(unsigned char** pdechead, uint32_t* udecheadlen, int* ioffs
|
|
|
char strasfheader[ASF_HEADER_GUID_LEN] = {0};
|
|
|
if (ASF_HEADER_GUID_LEN == fread(strasfheader, 1, ASF_HEADER_GUID_LEN, pSrcFile)){
|
|
|
if (0 != memcmp(strasfheader, ASF_Header_GUID, ASF_HEADER_GUID_LEN)){
|
|
|
- safe_log(pcallback, FILECRYPT_LOG_ERROR, "file %s is current not surrport format!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LEVEL_ERROR, "file %s is current not surrport format!",pfilename);
|
|
|
fclose(pSrcFile);
|
|
|
return iret;
|
|
|
}
|