|
@@ -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, "%s", "math guid failed, current format is not surpport!");
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_ERROR, "%s", "math guid failed, current format is not surpport!");
|
|
|
fclose(pDestFile);
|
|
|
return iret;
|
|
|
}
|
|
@@ -102,7 +102,7 @@ static int encrypt_mp4_file(char* poutfilename, char* phead, uint32_t uheaderlen
|
|
|
if (0 == unoencryptlen) {
|
|
|
return iret;
|
|
|
}
|
|
|
- safe_log(pcallback, "not encrypt file length is %u.", unoencryptlen);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_DEBUG, "not encrypt file length is %u.", unoencryptlen);
|
|
|
|
|
|
FILE* pDestFile = fopen(poutfilename, "wb");
|
|
|
if (NULL == pDestFile) {
|
|
@@ -113,7 +113,7 @@ static int encrypt_mp4_file(char* poutfilename, char* phead, uint32_t uheaderlen
|
|
|
fseek(pSrcFile, 0, SEEK_END);
|
|
|
unsigned int usrcfilelen = ftell(pSrcFile);
|
|
|
rewind(pSrcFile);
|
|
|
- safe_log(pcallback, "src file length is %u.", usrcfilelen);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_DEBUG, "src file length is %u.", usrcfilelen);
|
|
|
|
|
|
//1. 新增自定义文件头
|
|
|
fwrite(phead, 1, uheaderlen, pDestFile);
|
|
@@ -147,7 +147,7 @@ static int encrypt_mp4_file(char* poutfilename, char* phead, uint32_t uheaderlen
|
|
|
int32_t iencdatalen = umoovboxlen + SM4ENC_BLOCK_SIZE;
|
|
|
unsigned char* pobjdataenc = (unsigned char*)malloc(iencdatalen);
|
|
|
SM4EncECBMode(pstrkey, pmoovboxdata, umoovboxlen, pobjdataenc, &iencdatalen);
|
|
|
- safe_log(pcallback, "after encode, moov box length is %u.", iencdatalen);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_DEBUG, "after encode, moov box length is %u.", iencdatalen);
|
|
|
|
|
|
//3. 填充加密后的moov box长度
|
|
|
fwrite(&iencdatalen, 1, sizeof(uint32_t), pDestFile);
|
|
@@ -268,7 +268,7 @@ static int decrypt_mp4_file(char* poutfilename, FILE* pSrcFile, unsigned char* p
|
|
|
if (0 == unoencryptlen) {
|
|
|
return iret;
|
|
|
}
|
|
|
- safe_log(pcallback, "not encrypt file length is %u.", unoencryptlen);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_DEBUG, "not encrypt file length is %u.", unoencryptlen);
|
|
|
|
|
|
//1. 填充ftyp, free, mdat box
|
|
|
char* data_buffer = (char*)malloc(RVC_READ_BUFFER_SIZE);
|
|
@@ -289,7 +289,7 @@ static int decrypt_mp4_file(char* poutfilename, FILE* pSrcFile, unsigned char* p
|
|
|
//2. 获取加密后的moov box大小
|
|
|
int32_t uencryptboxsize = 0;
|
|
|
fread(&uencryptboxsize, 1, sizeof(uint32_t), pSrcFile);
|
|
|
- safe_log(pcallback, "encrypt moov box size is = %d.", uencryptboxsize);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_DEBUG, "encrypt moov box size is = %d.", uencryptboxsize);
|
|
|
|
|
|
//3. 读取加密后的moov box
|
|
|
unsigned char* pmoovboxdata = (unsigned char*)malloc(uencryptboxsize);
|
|
@@ -299,7 +299,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, "decrypt moov box size is = %d.", ioutlen);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_DEBUG, "decrypt moov box size is = %d.", ioutlen);
|
|
|
|
|
|
//5. 填充解密后的moov box
|
|
|
fwrite(pdecmoovboxdata, 1, ioutlen, pDestFile);
|
|
@@ -320,20 +320,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,"%s","invalid encryption version param.");
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_ERROR, "%s","invalid encryption version param.");
|
|
|
return iret;
|
|
|
}
|
|
|
|
|
|
FILE* pSrcFile = fopen(pfilename, "rb");
|
|
|
if (NULL == pSrcFile){
|
|
|
- safe_log(pcallback,"open file %s failed!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_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,"file %s is not encryption!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_INFO, "file %s is not encryption!",pfilename);
|
|
|
fclose(pSrcFile);
|
|
|
return iret;
|
|
|
}
|
|
@@ -346,7 +346,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,"file %s encryption and decryption version is not matched!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_ERROR, "file %s encryption and decryption version is not matched!",pfilename);
|
|
|
}
|
|
|
fclose(pSrcFile);
|
|
|
return iret;
|
|
@@ -383,7 +383,7 @@ bool is_file_encrypted(const char* pfilename, const filecryption_callback_t* pca
|
|
|
|
|
|
FILE* pSrcFile = fopen(pfilename, "rb");
|
|
|
if (NULL == pSrcFile){
|
|
|
- safe_log(pcallback,"open file %s failed!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_ERROR, "open file %s failed!",pfilename);
|
|
|
return bret;
|
|
|
}
|
|
|
|
|
@@ -393,7 +393,7 @@ bool is_file_encrypted(const char* pfilename, const filecryption_callback_t* pca
|
|
|
bret = true;
|
|
|
}
|
|
|
else{
|
|
|
- safe_log(pcallback,"file %s is not encryption!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_INFO, "file %s is not encryption!",pfilename);
|
|
|
}
|
|
|
}
|
|
|
fclose(pSrcFile);
|
|
@@ -411,13 +411,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,"%s","invalid cryption version param.");
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_ERROR, "%s","invalid cryption version param.");
|
|
|
return iret;
|
|
|
}
|
|
|
|
|
|
FILE* pSrcFile = fopen(pfilename, "rb");
|
|
|
if (NULL == pSrcFile){
|
|
|
- safe_log(pcallback,"open file %s failed!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_ERROR, "open file %s failed!",pfilename);
|
|
|
return iret;
|
|
|
}
|
|
|
|
|
@@ -427,7 +427,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,"file %s is not encrypted!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_INFO, "file %s is not encrypted!",pfilename);
|
|
|
*pdechead = NULL;
|
|
|
*udecheadlen = 0;
|
|
|
*ioffset = 0;
|
|
@@ -444,7 +444,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,"file %s encryption and decrption version is not matched!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_ERROR, "file %s encryption and decrption version is not matched!",pfilename);
|
|
|
}
|
|
|
safe_free(prvcbuffer);
|
|
|
fclose(pSrcFile);
|
|
@@ -459,7 +459,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,"get_file_json_infos_from_rvc_header success!");
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_DEBUG, "get_file_json_infos_from_rvc_header success!");
|
|
|
}
|
|
|
safe_free(prvcbuffer);
|
|
|
}
|
|
@@ -467,7 +467,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,"file %s is current not surrport format!",pfilename);
|
|
|
+ safe_log(pcallback, FILECRYPT_LOG_ERROR, "file %s is current not surrport format!",pfilename);
|
|
|
fclose(pSrcFile);
|
|
|
return iret;
|
|
|
}
|