This commit is contained in:
dmchen 2024-04-01 09:39:29 +00:00
parent 0a4556984c
commit a1b7444a48
4 changed files with 14 additions and 23 deletions

View File

@ -337,7 +337,6 @@ int32_t updateEncryptKey(char *key) {
} }
} }
//TODO: dmchen parse key from code
if (!(machineId = tGetMachineId())) { if (!(machineId = tGetMachineId())) {
terrno = TSDB_CODE_OUT_OF_MEMORY; terrno = TSDB_CODE_OUT_OF_MEMORY;
goto _OVER; goto _OVER;
@ -436,33 +435,31 @@ int32_t getEncryptKey(){
} }
char *encryptKey = NULL; char *encryptKey = NULL;
//TODO: dmchen parse key from code
if(checkAndGetCryptKey(content, machineId, &encryptKey) != 0){ if(checkAndGetCryptKey(content, machineId, &encryptKey) != 0){
goto _OVER; goto _OVER;
} }
strncpy(tsEncryptKey, encryptKey, ENCRYPT_KEY_LEN);
taosMemoryFreeClear(encryptKey);
//TODO: dmchen checksum
tsEncryptionKeyChksum = taosCalcChecksum(0, tsEncryptKey, ENCRYPT_KEY_LEN);
tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;
taosMemoryFreeClear(content); taosMemoryFreeClear(content);
if(tsEncryptKey[0] == '\0'){ if(encryptKey[0] == '\0'){
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY; terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
dError("failed to read key since %s", terrstr()); dError("failed to read key since %s", terrstr());
goto _OVER; goto _OVER;
} }
if(compareCheckCode(checkFile, tsEncryptKey) != 0){ if(compareCheckCode(checkFile, encryptKey) != 0){
goto _OVER; goto _OVER;
} }
strncpy(tsEncryptKey, encryptKey, ENCRYPT_KEY_LEN);
taosMemoryFreeClear(encryptKey);
tsEncryptionKeyChksum = taosCalcChecksum(0, tsEncryptKey, ENCRYPT_KEY_LEN);
tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;
code = 0; code = 0;
_OVER: _OVER:
if (content != NULL) taosMemoryFree(content); if (content != NULL) taosMemoryFree(content);
if (encryptKey != NULL) taosMemoryFree(encryptKey);
if (code != 0) { if (code != 0) {
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno); if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
dError("failed to get encrypt key since %s", terrstr()); dError("failed to get encrypt key since %s", terrstr());

View File

@ -273,8 +273,7 @@ struct STsdbCfg {
int32_t keepTimeOffset; // just for save config, use STsdbKeepCfg in STsdb instead int32_t keepTimeOffset; // just for save config, use STsdbKeepCfg in STsdb instead
SRetention retentions[TSDB_RETENTION_MAX]; SRetention retentions[TSDB_RETENTION_MAX];
int32_t encryptAlgorithm; int32_t encryptAlgorithm;
//TODO dmchen len char encryptKey[ENCRYPT_KEY_LEN + 1];
char encryptKey[17];
}; };
typedef struct { typedef struct {

View File

@ -154,8 +154,7 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) {
// validate body // validate body
int32_t cryptedBodyLen = logContent->head.bodyLen; int32_t cryptedBodyLen = logContent->head.bodyLen;
//TODO: dmchen enum if(pWal->cfg.encryptAlgorithm == DND_CA_SM4){
if(pWal->cfg.encryptAlgorithm == 1){
cryptedBodyLen = ENCRYPTED_LEN(cryptedBodyLen); cryptedBodyLen = ENCRYPTED_LEN(cryptedBodyLen);
} }
recordLen = walCkHeadSz + cryptedBodyLen; recordLen = walCkHeadSz + cryptedBodyLen;
@ -627,8 +626,7 @@ int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
int32_t plainBodyLen = ckHead.head.bodyLen; int32_t plainBodyLen = ckHead.head.bodyLen;
int32_t cryptedBodyLen = plainBodyLen; int32_t cryptedBodyLen = plainBodyLen;
//TODO: dmchen enum if(pWal->cfg.encryptAlgorithm == DND_CA_SM4){
if(pWal->cfg.encryptAlgorithm == 1){
cryptedBodyLen = ENCRYPTED_LEN(cryptedBodyLen); cryptedBodyLen = ENCRYPTED_LEN(cryptedBodyLen);
} }
idxEntry.offset += sizeof(SWalCkHead) + cryptedBodyLen; idxEntry.offset += sizeof(SWalCkHead) + cryptedBodyLen;

View File

@ -528,8 +528,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
char* newBody = NULL; char* newBody = NULL;
char* newBodyEncrypted = NULL; char* newBodyEncrypted = NULL;
//TODO: dmchen enum if(pWal->cfg.encryptAlgorithm == DND_CA_SM4){
if(pWal->cfg.encryptAlgorithm == 1){
cyptedBodyLen = ENCRYPTED_LEN(cyptedBodyLen); cyptedBodyLen = ENCRYPTED_LEN(cyptedBodyLen);
char* newBody = taosMemoryMalloc(cyptedBodyLen); char* newBody = taosMemoryMalloc(cyptedBodyLen);
if(newBody == NULL){ if(newBody == NULL){
@ -571,16 +570,14 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal), wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal),
strerror(errno)); strerror(errno));
code = -1; code = -1;
//TODO: dmchen enum if(pWal->cfg.encryptAlgorithm == DND_CA_SM4){
if(pWal->cfg.encryptAlgorithm == 1){
taosMemoryFree(newBody); taosMemoryFree(newBody);
taosMemoryFree(newBodyEncrypted); taosMemoryFree(newBodyEncrypted);
} }
goto END; goto END;
} }
//TODO: dmchen enum if(pWal->cfg.encryptAlgorithm == DND_CA_SM4){
if(pWal->cfg.encryptAlgorithm == 1){
taosMemoryFree(newBody); taosMemoryFree(newBody);
taosMemoryFree(newBodyEncrypted); taosMemoryFree(newBodyEncrypted);
wInfo("vgId:%d, free newBody newBodyEncrypted %s", wInfo("vgId:%d, free newBody newBodyEncrypted %s",