refactor
This commit is contained in:
parent
239acea831
commit
5f31575624
|
@ -58,7 +58,7 @@ typedef struct {
|
||||||
int64_t segSize;
|
int64_t segSize;
|
||||||
EWalType level; // wal level
|
EWalType level; // wal level
|
||||||
int32_t encryptAlgorithm;
|
int32_t encryptAlgorithm;
|
||||||
char encryptKey[17];
|
char encryptKey[ENCRYPT_KEY_LEN + 1];
|
||||||
} SWalCfg;
|
} SWalCfg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -376,13 +376,13 @@ int mainWindows(int argc, char **argv) {
|
||||||
dError("failed to generate encrypt code since taosd is running, please stop it first");
|
dError("failed to generate encrypt code since taosd is running, please stop it first");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
int ret = updateEncryptKey(global.encryptKey);
|
int ret = dmUpdateEncryptKey(global.encryptKey);
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(getEncryptKey() != 0){
|
if(dmGetEncryptKey() != 0){
|
||||||
dError("failed to start since failed to get encrypt key");
|
dError("failed to start since failed to get encrypt key");
|
||||||
taosCloseLog();
|
taosCloseLog();
|
||||||
taosCleanupArgs();
|
taosCleanupArgs();
|
||||||
|
|
|
@ -233,7 +233,7 @@ int32_t dmProcessCreateEncryptKeyReq(SDnodeMgmt *pMgmt, SRpcMsg *pMsg) {
|
||||||
goto _exit;
|
goto _exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
code = updateEncryptKey(cfgReq.value);
|
code = dmUpdateEncryptKey(cfgReq.value);
|
||||||
if(code == 0) {
|
if(code == 0) {
|
||||||
tsEncryptionKeyChksum = taosCalcChecksum(0, cfgReq.value, strlen(cfgReq.value));
|
tsEncryptionKeyChksum = taosCalcChecksum(0, cfgReq.value, strlen(cfgReq.value));
|
||||||
tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;
|
tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;
|
||||||
|
|
|
@ -193,8 +193,8 @@ void dmSetMnodeEpSet(SDnodeData *pData, SEpSet *pEpSet);
|
||||||
bool dmUpdateDnodeInfo(void *pData, int32_t *dnodeId, int64_t *clusterId, char *fqdn, uint16_t *port);
|
bool dmUpdateDnodeInfo(void *pData, int32_t *dnodeId, int64_t *clusterId, char *fqdn, uint16_t *port);
|
||||||
void dmRemoveDnodePairs(SDnodeData *pData);
|
void dmRemoveDnodePairs(SDnodeData *pData);
|
||||||
void dmGetDnodeEp(void *pData, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort);
|
void dmGetDnodeEp(void *pData, int32_t dnodeId, char *pEp, char *pFqdn, uint16_t *pPort);
|
||||||
int32_t updateEncryptKey(char *key);
|
int32_t dmUpdateEncryptKey(char *key);
|
||||||
int32_t getEncryptKey();
|
int32_t dmGetEncryptKey();
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include "tchecksum.h"
|
#include "tchecksum.h"
|
||||||
|
|
||||||
#define MAXLEN 1024
|
#define MAXLEN 1024
|
||||||
#define DM_KEY_INDICATOR "this indicator!"
|
#define DM_KEY_INDICATOR "this indicator!"
|
||||||
#define DM_ENCRYPT_CODE_FILE "encryptCode.cfg"
|
#define DM_ENCRYPT_CODE_FILE "encryptCode.cfg"
|
||||||
#define DM_CHECK_CODE_FILE "checkCode.bin"
|
#define DM_CHECK_CODE_FILE "checkCode.bin"
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ TdFilePtr dmCheckRunning(const char *dataDir) {
|
||||||
|
|
||||||
extern int32_t generateEncryptCode(const char *key, const char *machineId, char **encryptCode);
|
extern int32_t generateEncryptCode(const char *key, const char *machineId, char **encryptCode);
|
||||||
|
|
||||||
static int32_t writeCheckCode(char* file, char* realfile, char* key){
|
static int32_t dmWriteCheckCodeFile(char* file, char* realfile, char* key){
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
char *result = NULL;
|
char *result = NULL;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
|
@ -220,7 +220,7 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t writeEncryptCode(char* file, char* realfile, char* encryptCode){
|
static int32_t dmWriteEncryptCodeFile(char* file, char* realfile, char* encryptCode){
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int32_t compareCheckCode(char* file, char* key){
|
static int32_t dmCompareEncryptKey(char* file, char* key){
|
||||||
char *content = NULL;
|
char *content = NULL;
|
||||||
int64_t size = 0;
|
int64_t size = 0;
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
|
@ -304,7 +304,7 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t updateEncryptKey(char *key) {
|
int32_t dmUpdateEncryptKey(char *key) {
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
char *machineId = NULL;
|
char *machineId = NULL;
|
||||||
char *encryptCode = NULL;
|
char *encryptCode = NULL;
|
||||||
|
@ -332,7 +332,7 @@ int32_t updateEncryptKey(char *key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if(taosCheckExistFile(realCheckFile)){
|
if(taosCheckExistFile(realCheckFile)){
|
||||||
if(compareCheckCode(realCheckFile, key) != 0){
|
if(dmCompareEncryptKey(realCheckFile, key) != 0){
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -346,11 +346,11 @@ int32_t updateEncryptKey(char *key) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(writeEncryptCode(encryptFile, realEncryptFile, encryptCode) != 0){
|
if(dmWriteEncryptCodeFile(encryptFile, realEncryptFile, encryptCode) != 0){
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(writeCheckCode(checkFile, realCheckFile, key) != 0){
|
if(dmWriteCheckCodeFile(checkFile, realCheckFile, key) != 0){
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -367,7 +367,7 @@ _OVER:
|
||||||
|
|
||||||
extern int32_t checkAndGetCryptKey(const char *encryptCode, const char *machineId, char **key);
|
extern int32_t checkAndGetCryptKey(const char *encryptCode, const char *machineId, char **key);
|
||||||
|
|
||||||
static int32_t readEncryptCode(char* file, char** output){
|
static int32_t dmReadEncryptCodeFile(char* file, char** output){
|
||||||
TdFilePtr pFile = NULL;
|
TdFilePtr pFile = NULL;
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
char *content = NULL;
|
char *content = NULL;
|
||||||
|
@ -410,7 +410,7 @@ _OVER:
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getEncryptKey(){
|
int32_t dmGetEncryptKey(){
|
||||||
int32_t code = -1;
|
int32_t code = -1;
|
||||||
char encryptFile[PATH_MAX] = {0};
|
char encryptFile[PATH_MAX] = {0};
|
||||||
char checkFile[PATH_MAX] = {0};
|
char checkFile[PATH_MAX] = {0};
|
||||||
|
@ -426,7 +426,7 @@ int32_t getEncryptKey(){
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(readEncryptCode(encryptFile, &content) != 0){
|
if(dmReadEncryptCodeFile(encryptFile, &content) != 0){
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,7 +448,7 @@ int32_t getEncryptKey(){
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(compareCheckCode(checkFile, encryptKey) != 0){
|
if(dmCompareEncryptKey(checkFile, encryptKey) != 0){
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -304,7 +304,6 @@ struct SVnodeCfg {
|
||||||
int8_t isRsma;
|
int8_t isRsma;
|
||||||
int8_t hashMethod;
|
int8_t hashMethod;
|
||||||
int8_t standby;
|
int8_t standby;
|
||||||
int8_t encryptAlgorithm;
|
|
||||||
STsdbCfg tsdbCfg;
|
STsdbCfg tsdbCfg;
|
||||||
SWalCfg walCfg;
|
SWalCfg walCfg;
|
||||||
SSyncCfg syncCfg;
|
SSyncCfg syncCfg;
|
||||||
|
|
|
@ -395,6 +395,7 @@ void SMS4_CBC_DecryptionEx(unsigned char ciphertext[16], unsigned int key[32], u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
int SM4_ECB_Encrypt( unsigned char *pKey,
|
int SM4_ECB_Encrypt( unsigned char *pKey,
|
||||||
unsigned int KeyLen,
|
unsigned int KeyLen,
|
||||||
unsigned char *pInData,
|
unsigned char *pInData,
|
||||||
|
@ -461,7 +462,7 @@ int SM4_ECB_Decrypt( unsigned char *pKey,
|
||||||
*pOutDataLen = inDataLen;
|
*pOutDataLen = inDataLen;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
int SM4_CBC_Encrypt( unsigned char *pKey,
|
int SM4_CBC_Encrypt( unsigned char *pKey,
|
||||||
unsigned int KeyLen,
|
unsigned int KeyLen,
|
||||||
unsigned char *pIV,
|
unsigned char *pIV,
|
||||||
|
|
|
@ -394,7 +394,7 @@ struct STDB {
|
||||||
#endif
|
#endif
|
||||||
int64_t txnId;
|
int64_t txnId;
|
||||||
int32_t encryptAlgorithm;
|
int32_t encryptAlgorithm;
|
||||||
char encryptKey[ENCRYPT_KEY_LEN];
|
char encryptKey[ENCRYPT_KEY_LEN + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
struct SPager {
|
struct SPager {
|
||||||
|
|
Loading…
Reference in New Issue