• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

taosdata / TDengine / #5049

11 May 2026 06:30AM UTC coverage: 73.313% (+0.09%) from 73.222%
#5049

push

travis-ci

web-flow
feat: refactor taosdump code to improve backup speed and compression ratio (#35292)

6625 of 8435 new or added lines in 28 files covered. (78.54%)

2491 existing lines in 142 files now uncovered.

281233 of 383605 relevant lines covered (73.31%)

132489999.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

67.05
/source/dnode/mnode/impl/src/mndEncryptAlgr.c
1
/*
2
 * Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
3
 *
4
 * This program is free software: you can use, redistribute, and/or modify
5
 * it under the terms of the GNU Affero General Public License, version 3
6
 * or later ("AGPL"), as published by the Free Software Foundation.
7
 *
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10
 * FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * You should have received a copy of the GNU Affero General Public License
13
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14
 */
15

16
#define MND_ENCRYPT_ALGR_VER_NUMBER 1
17
#if defined(TD_ENTERPRISE) && defined(LINUX)
18
#define MND_ENCRYPT_ALGR_LAST_ID 6
19
#else
20
#define MND_ENCRYPT_ALGR_LAST_ID 1
21
#endif
22

23
#include "audit.h"
24
#include "mndEncryptAlgr.h"
25
#include "mndMnode.h"
26
#include "mndShow.h"
27
#include "mndSync.h"
28
#include "mndTrans.h"
29
#include "tencrypt.h"
30

31
static void tFreeEncryptAlgrObj(SEncryptAlgrObj *pEncryptAlgr) {}
3,857,094✔
32

33
static int32_t tSerializeSEncryptAlgrObj(void *buf, int32_t bufLen, const SEncryptAlgrObj *pObj) {
12,976,728✔
34
  SEncoder encoder = {0};
12,976,728✔
35
  int32_t  code = 0;
12,976,728✔
36
  int32_t  lino;
37
  int32_t  tlen;
38
  tEncoderInit(&encoder, buf, bufLen);
12,976,728✔
39

40
  TAOS_CHECK_EXIT(tStartEncode(&encoder));
12,976,728✔
41
  TAOS_CHECK_EXIT(tEncodeI32(&encoder, pObj->id));
25,953,456✔
42
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->algorithm_id));
25,953,456✔
43
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->name));
25,953,456✔
44
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->desc));
25,953,456✔
45
  TAOS_CHECK_EXIT(tEncodeI16(&encoder, pObj->type));
25,953,456✔
46
  TAOS_CHECK_EXIT(tEncodeI8(&encoder, pObj->source));
25,953,456✔
47
  TAOS_CHECK_EXIT(tEncodeCStr(&encoder, pObj->ossl_algr_name));
25,953,456✔
48

49
  tEndEncode(&encoder);
12,976,728✔
50

51
_exit:
12,976,728✔
52
  if (code) {
12,976,728✔
UNCOV
53
    tlen = code;
×
54
  } else {
55
    tlen = encoder.pos;
12,976,728✔
56
  }
57
  tEncoderClear(&encoder);
12,976,728✔
58
  return tlen;
12,976,728✔
59
}
60

61
static int32_t tDeserializeSEncryptAlgrObj(void *buf, int32_t bufLen, SEncryptAlgrObj *pObj) {
3,857,094✔
62
  int32_t  code = 0;
3,857,094✔
63
  int32_t  lino;
64
  SDecoder decoder = {0};
3,857,094✔
65
  tDecoderInit(&decoder, buf, bufLen);
3,857,094✔
66

67
  TAOS_CHECK_EXIT(tStartDecode(&decoder));
3,857,094✔
68
  TAOS_CHECK_EXIT(tDecodeI32(&decoder, &pObj->id));
7,714,188✔
69
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->algorithm_id));
3,857,094✔
70
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->name));
3,857,094✔
71
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->desc));
3,857,094✔
72
  TAOS_CHECK_EXIT(tDecodeI16(&decoder, &pObj->type));
7,714,188✔
73
  TAOS_CHECK_EXIT(tDecodeI8(&decoder, &pObj->source));
7,714,188✔
74
  TAOS_CHECK_EXIT(tDecodeCStrTo(&decoder, pObj->ossl_algr_name));
3,857,094✔
75

76
  tEndDecode(&decoder);
3,857,094✔
77

78
_exit:
3,857,094✔
79
  tDecoderClear(&decoder);
3,857,094✔
80
  return code;
3,857,094✔
81
}
82

83
static SSdbRaw *mndEncryptAlgrActionEncode(SEncryptAlgrObj *pEncryptAlgr) {
6,488,364✔
84
  int32_t code = 0;
6,488,364✔
85
  int32_t lino = 0;
6,488,364✔
86
  terrno = TSDB_CODE_SUCCESS;
6,488,364✔
87

88
  void    *buf = NULL;
6,488,364✔
89
  SSdbRaw *pRaw = NULL;
6,488,364✔
90

91
  int32_t tlen = tSerializeSEncryptAlgrObj(NULL, 0, pEncryptAlgr);
6,488,364✔
92
  if (tlen < 0) {
6,488,364✔
UNCOV
93
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
94
    goto OVER;
×
95
  }
96

97
  int32_t size = sizeof(int32_t) + tlen;
6,488,364✔
98
  pRaw = sdbAllocRaw(SDB_ENCRYPT_ALGORITHMS, MND_ENCRYPT_ALGR_VER_NUMBER, size);
6,488,364✔
99
  if (pRaw == NULL) {
6,488,364✔
UNCOV
100
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
101
    goto OVER;
×
102
  }
103

104
  buf = taosMemoryMalloc(tlen);
6,488,364✔
105
  if (buf == NULL) {
6,488,364✔
UNCOV
106
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
107
    goto OVER;
×
108
  }
109

110
  tlen = tSerializeSEncryptAlgrObj(buf, tlen, pEncryptAlgr);
6,488,364✔
111
  if (tlen < 0) {
6,488,364✔
UNCOV
112
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
113
    goto OVER;
×
114
  }
115

116
  int32_t dataPos = 0;
6,488,364✔
117
  SDB_SET_INT32(pRaw, dataPos, tlen, OVER);
6,488,364✔
118
  SDB_SET_BINARY(pRaw, dataPos, buf, tlen, OVER);
6,488,364✔
119
  SDB_SET_DATALEN(pRaw, dataPos, OVER);
6,488,364✔
120

121
OVER:
6,488,364✔
122
  taosMemoryFreeClear(buf);
6,488,364✔
123
  if (terrno != TSDB_CODE_SUCCESS) {
6,488,364✔
UNCOV
124
    mError("encrypt_algr:%" PRId32 ", failed to encode to raw:%p since %s", pEncryptAlgr->id, pRaw, terrstr());
×
UNCOV
125
    sdbFreeRaw(pRaw);
×
UNCOV
126
    return NULL;
×
127
  }
128

129
  mTrace("encrypt_algr:%" PRId32 ", encode to raw:%p, row:%p", pEncryptAlgr->id, pRaw, pEncryptAlgr);
6,488,364✔
130
  return pRaw;
6,488,364✔
131
}
132

133
SSdbRow *mndEncryptAlgrActionDecode(SSdbRaw *pRaw) {
3,857,094✔
134
  int32_t      code = 0;
3,857,094✔
135
  int32_t      lino = 0;
3,857,094✔
136
  SSdbRow     *pRow = NULL;
3,857,094✔
137
  SEncryptAlgrObj *pEncryptAlgr = NULL;
3,857,094✔
138
  void        *buf = NULL;
3,857,094✔
139
  terrno = TSDB_CODE_SUCCESS;
3,857,094✔
140

141
  int8_t sver = 0;
3,857,094✔
142
  if (sdbGetRawSoftVer(pRaw, &sver) != 0) {
3,857,094✔
143
    goto OVER;
×
144
  }
145

146
  if (sver != MND_ENCRYPT_ALGR_VER_NUMBER) {
3,857,094✔
UNCOV
147
    terrno = TSDB_CODE_SDB_INVALID_DATA_VER;
×
UNCOV
148
    mError("encrypt_algr read invalid ver, data ver: %d, curr ver: %d", sver, MND_ENCRYPT_ALGR_VER_NUMBER);
×
149
    goto OVER;
×
150
  }
151

152
  pRow = sdbAllocRow(sizeof(SEncryptAlgrObj));
3,857,094✔
153
  if (pRow == NULL) {
3,857,094✔
UNCOV
154
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
155
    goto OVER;
×
156
  }
157

158
  pEncryptAlgr = sdbGetRowObj(pRow);
3,857,094✔
159
  if (pEncryptAlgr == NULL) {
3,857,094✔
UNCOV
160
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
UNCOV
161
    goto OVER;
×
162
  }
163

164
  int32_t tlen;
3,845,952✔
165
  int32_t dataPos = 0;
3,857,094✔
166
  SDB_GET_INT32(pRaw, dataPos, &tlen, OVER);
3,857,094✔
167
  buf = taosMemoryMalloc(tlen + 1);
3,857,094✔
168
  if (buf == NULL) {
3,857,094✔
UNCOV
169
    terrno = TSDB_CODE_OUT_OF_MEMORY;
×
170
    goto OVER;
×
171
  }
172
  SDB_GET_BINARY(pRaw, dataPos, buf, tlen, OVER);
3,857,094✔
173

174
  if ((terrno = tDeserializeSEncryptAlgrObj(buf, tlen, pEncryptAlgr)) < 0) {
3,857,094✔
UNCOV
175
    goto OVER;
×
176
  }
177

178
OVER:
3,857,094✔
179
  taosMemoryFreeClear(buf);
3,857,094✔
180
  if (terrno != TSDB_CODE_SUCCESS) {
3,857,094✔
UNCOV
181
    mError("encrypt_algr:%" PRId32 ", failed to decode from raw:%p since %s", pEncryptAlgr->id, pRaw, terrstr());
×
UNCOV
182
    taosMemoryFreeClear(pRow);
×
UNCOV
183
    return NULL;
×
184
  }
185

186
  mTrace("encrypt_algr:%" PRId32 ", decode from raw:%p, row:%p", pEncryptAlgr->id, pRaw, pEncryptAlgr);
3,857,094✔
187
  return pRow;
3,857,094✔
188
}
189

190
int32_t mndEncryptAlgrActionInsert(SSdb *pSdb, SEncryptAlgrObj *pEncryptAlgr) {
3,253,770✔
191
  mTrace("encrypt_algr:%" PRId32 ", perform insert action", pEncryptAlgr->id);
3,253,770✔
192
  return 0;
3,253,770✔
193
}
194

195
int32_t mndEncryptAlgrActionDelete(SSdb *pSdb, SEncryptAlgrObj *pEncryptAlgr) {
3,857,094✔
196
  mTrace("encrypt_algr:%" PRId32 ", perform delete action", pEncryptAlgr->id);
3,857,094✔
197
  tFreeEncryptAlgrObj(pEncryptAlgr);
3,857,094✔
198
  return 0;
3,857,094✔
199
}
200

201
int32_t mndEncryptAlgrActionUpdate(SSdb *pSdb, SEncryptAlgrObj *pOldEncryptAlgr, SEncryptAlgrObj *pNewEncryptAlgr) {
603,324✔
202
  mTrace("encrypt_algr:%" PRId32 ", perform update action, old row:%p new row:%p", pOldEncryptAlgr->id, pOldEncryptAlgr,
603,324✔
203
         pNewEncryptAlgr);
204

205
  return 0;
603,324✔
206
}
207

208
typedef void (*mndSetEncryptAlgrFp)(SEncryptAlgrObj *Obj);
209

210
static void mndSetSM4EncryptAlgr(SEncryptAlgrObj *Obj){
442,400✔
211
  Obj->id = 1;
442,400✔
212
  tstrncpy(Obj->algorithm_id, "SM4-CBC", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
213
  tstrncpy(Obj->name, "SM4", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
214
  tstrncpy(Obj->desc, "SM4 symmetric encryption", TSDB_ENCRYPT_ALGR_DESC_LEN);
442,400✔
215
  Obj->type = ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS;
442,400✔
216
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
442,400✔
217
  tstrncpy(Obj->ossl_algr_name, "SM4-CBC:SM4", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
218
}
442,400✔
219

220
static void mndSetAESEncryptAlgr(SEncryptAlgrObj *Obj){
442,400✔
221
  Obj->id = 2;
442,400✔
222
  tstrncpy(Obj->algorithm_id, "AES-128-CBC", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
223
  tstrncpy(Obj->name, "AES", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
224
  tstrncpy(Obj->desc, "AES symmetric encryption", TSDB_ENCRYPT_ALGR_DESC_LEN);
442,400✔
225
  Obj->type = ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS;
442,400✔
226
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
442,400✔
227
  tstrncpy(Obj->ossl_algr_name, "AES-128-CBC", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
228
}
442,400✔
229

230
static void mndSetSM3EncryptAlgr(SEncryptAlgrObj *Obj) {
442,400✔
231
  Obj->id = 3;
442,400✔
232
  tstrncpy(Obj->algorithm_id, "SM3", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
233
  tstrncpy(Obj->name, "SM3", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
234
  tstrncpy(Obj->desc, "SM3 digests", TSDB_ENCRYPT_ALGR_DESC_LEN);
442,400✔
235
  Obj->type = ENCRYPT_ALGR_TYPE__DIGEST;
442,400✔
236
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
442,400✔
237
  tstrncpy(Obj->ossl_algr_name, "SM3", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
238
}
442,400✔
239

240
static void mndSetSHAEncryptAlgr(SEncryptAlgrObj *Obj) {
442,400✔
241
  Obj->id = 4;
442,400✔
242
  tstrncpy(Obj->algorithm_id, "SHA-256", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
243
  tstrncpy(Obj->name, "SHA-256", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
244
  tstrncpy(Obj->desc, "SHA2 digests", TSDB_ENCRYPT_ALGR_DESC_LEN);
442,400✔
245
  Obj->type = ENCRYPT_ALGR_TYPE__DIGEST;
442,400✔
246
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
442,400✔
247
  tstrncpy(Obj->ossl_algr_name, "SHA-256", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
248
}
442,400✔
249

250
static void mndSetSM2EncryptAlgr(SEncryptAlgrObj *Obj) {
442,400✔
251
  Obj->id = 5;
442,400✔
252
  tstrncpy(Obj->algorithm_id, "SM2", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
253
  tstrncpy(Obj->name, "SM2", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
254
  tstrncpy(Obj->desc, "SM2 Asymmetric Cipher", TSDB_ENCRYPT_ALGR_DESC_LEN);
442,400✔
255
  Obj->type = ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS;
442,400✔
256
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
442,400✔
257
}
442,400✔
258

259
static void mndSetRSAEncryptAlgr(SEncryptAlgrObj *Obj) {
442,400✔
260
  Obj->id = 6;
442,400✔
261
  tstrncpy(Obj->algorithm_id, "RSA", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
262
  tstrncpy(Obj->name, "RSA", TSDB_ENCRYPT_ALGR_NAME_LEN);
442,400✔
263
  tstrncpy(Obj->desc, "RSA Asymmetric Cipher", TSDB_ENCRYPT_ALGR_DESC_LEN);
442,400✔
264
  Obj->type = ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS;
442,400✔
265
  Obj->source = ENCRYPT_ALGR_SOURCE_BUILTIN;
442,400✔
266
}
442,400✔
267

268
static SSdbRaw * mndCreateEncryptAlgrRaw(STrans *pTrans, SEncryptAlgrObj *Obj) {
2,654,400✔
269
  int32_t code = 0;
2,654,400✔
270

271
  SSdbRaw *pRaw = mndEncryptAlgrActionEncode(Obj);
2,654,400✔
272
  if (pRaw == NULL) {
2,654,400✔
273
    return NULL;
×
274
  }
275
  code = sdbSetRawStatus(pRaw, SDB_STATUS_READY);
2,654,400✔
276
  if (code != 0) {
2,654,400✔
277
    terrno = code;
×
278
    return NULL;
×
279
  }
280

281
  if ((code = mndTransAppendCommitlog(pTrans, pRaw)) != 0) {
2,654,400✔
UNCOV
282
    terrno = code;
×
UNCOV
283
    return NULL;
×
284
  }
285
  return pRaw;
2,654,400✔
286
}
287

288
int32_t mndSendCreateBuiltinReq(SMnode *pMnode) {
442,516✔
289
  int32_t code = 0;
442,516✔
290

291
  SRpcMsg rpcMsg = {.pCont = NULL,
442,516✔
292
                    .contLen = 0,
293
                    .msgType = TDMT_MND_BUILTIN_ENCRYPT_ALGR,
294
                    .info.ahandle = 0,
295
                    .info.notFreeAhandle = 1,
296
                    .info.refId = 0,
297
                    .info.noResp = 0,
298
                    .info.handle = 0};
299
  SEpSet  epSet = {0};
442,516✔
300

301
  mndGetMnodeEpSet(pMnode, &epSet);
442,516✔
302

303
  code = tmsgSendReq(&epSet, &rpcMsg);
442,516✔
304
  if (code != 0) {
442,516✔
UNCOV
305
    mError("failed to send builtin encrypt algr req, since %s", tstrerror(code));
×
306
  }
307
  return code;
442,516✔
308
}
309

310
static int32_t mndCreateBuiltinEncryptAlgr(SMnode *pMnode) {
442,400✔
311
  int32_t code = 0;
442,400✔
312
  STrans *pTrans = NULL;
442,400✔
313

314
  mndSetEncryptAlgrFp setFpArr[] = {mndSetSM4EncryptAlgr
442,400✔
315
#if defined(TD_ENTERPRISE) && defined(LINUX)
316
                                    ,
317
                                    mndSetAESEncryptAlgr,
318
                                    mndSetSM3EncryptAlgr,
319
                                    mndSetSHAEncryptAlgr,
320
                                    mndSetSM2EncryptAlgr,
321
                                    mndSetRSAEncryptAlgr
322
#endif
323
  };
324

325
  int32_t algrNum = sizeof(setFpArr) / sizeof(mndSetEncryptAlgrFp);
442,400✔
326

327
  pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-enc-algr");
442,400✔
328
  if (pTrans == NULL) {
442,400✔
UNCOV
329
    mError("failed to create since %s",terrstr());
×
UNCOV
330
    code = terrno;
×
UNCOV
331
    goto _OVER;
×
332
  }
333
  mInfo("trans:%d, used to create default encrypt_algr", pTrans->id);
442,400✔
334

335
  for (int32_t i = 0; i < algrNum; i++) {
3,096,800✔
336
    SEncryptAlgrObj *Obj = taosMemoryMalloc(sizeof(SEncryptAlgrObj));
2,654,400✔
337
    if (Obj == NULL) {
2,654,400✔
UNCOV
338
      goto _OVER;
×
339
    }
340
    memset(Obj, 0, sizeof(SEncryptAlgrObj));
2,654,400✔
341
    setFpArr[i](Obj);
2,654,400✔
342
    SSdbRaw *pRaw = mndCreateEncryptAlgrRaw(pTrans, Obj);
2,654,400✔
343
    taosMemoryFree(Obj);
2,654,400✔
344
    if (pRaw == NULL) {
2,654,400✔
UNCOV
345
      mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
×
346
      goto _OVER;
×
347
    }
348
  }
349

350
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
442,400✔
UNCOV
351
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
×
UNCOV
352
    goto _OVER;
×
353
  }
354

355
  code = 0;
442,400✔
356

357
_OVER:
442,400✔
358
  mndTransDrop(pTrans);
442,400✔
359
  return code;
442,400✔
360
}
361

362
static int32_t mndProcessBuiltinReq(SRpcMsg *pReq) {
442,400✔
363
  SMnode *pMnode = pReq->info.node;
442,400✔
364
  if (!mndIsLeader(pMnode)) {
442,400✔
UNCOV
365
    return TSDB_CODE_SUCCESS;
×
366
  }
367

368
  return mndCreateBuiltinEncryptAlgr(pMnode);
442,400✔
369
}
370

371
static int32_t mndProcessBuiltinRsp(SRpcMsg *pRsp) {
442,216✔
372
  mInfo("builtin rsp");
442,216✔
373
  return 0;
442,216✔
374
}
375

376
static int32_t mndUpgradeBuiltinEncryptAlgr(SMnode *pMnode, int32_t version) {
442,516✔
377
  if (version >= TSDB_MNODE_BUILTIN_DATA_VERSION) return 0;
442,516✔
378

379
  mInfo("upgrade builtin encrypt algr, current version:%d, target version:%d", version,
442,516✔
380
        TSDB_MNODE_BUILTIN_DATA_VERSION);
381
  return mndSendCreateBuiltinReq(pMnode);
442,516✔
382
}
383

384
static bool mndIsUpgradedBuiltinEncryptAlgr(SMnode *pMnode) {
1,373,902✔
385
  SEncryptAlgrObj *obj = mndAcquireEncryptAlgrById(pMnode, MND_ENCRYPT_ALGR_LAST_ID);
1,373,902✔
386
  if (obj != NULL) {
1,373,902✔
387
    mndReleaseEncryptAlgr(pMnode, obj);
495,018✔
388
    return true;
495,018✔
389
  }
390
  return false;
878,884✔
391
}
392

393
#define SYMCBC "Symmetric Ciphers CBC mode"
394
#define ASYM       "Asymmetric Ciphers"
395
#define DIGEST     "Digests"
396
#define BUILTIN "build-in"
397
#define CUSTOMIZED "customized"
398
static int32_t mndRetrieveEncryptAlgr(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows){
852✔
399
  SMnode      *pMnode = pMsg->info.node;
852✔
400
  SSdb        *pSdb = pMnode->pSdb;
852✔
401
  int32_t      code = 0;
852✔
402
  int32_t      lino = 0;
852✔
403
  int32_t      numOfRows = 0;
852✔
404
  int32_t      cols = 0;
852✔
405
  SEncryptAlgrObj *pObj = NULL;
852✔
406

407
  char tmpBuf[1000] = {0};
852✔
408

409
  while (numOfRows < rows) {
5,964✔
410
    pShow->pIter = sdbFetch(pSdb, SDB_ENCRYPT_ALGORITHMS, pShow->pIter, (void **)&pObj);
5,964✔
411
    if (pShow->pIter == NULL) break;
5,964✔
412

413
    cols = 0;
5,112✔
414
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
5,112✔
415
    COL_DATA_SET_VAL_GOTO((const char *)&pObj->id, false, pObj, pShow->pIter, _OVER);
5,112✔
416

417
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
5,112✔
418
    tstrncpy(varDataVal(tmpBuf), pObj->algorithm_id, TSDB_ENCRYPT_ALGR_NAME_LEN);
5,112✔
419
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
5,112✔
420
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
5,112✔
421

422
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
5,112✔
423
    tstrncpy(varDataVal(tmpBuf), pObj->name, TSDB_ENCRYPT_ALGR_NAME_LEN);
5,112✔
424
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
5,112✔
425
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
5,112✔
426

427
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
5,112✔
428
    tstrncpy(varDataVal(tmpBuf), pObj->desc, TSDB_ENCRYPT_ALGR_DESC_LEN);
5,112✔
429
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
5,112✔
430
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
5,112✔
431

432
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
5,112✔
433
    if(pObj->type == ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS){
5,112✔
434
      tstrncpy(varDataVal(tmpBuf), SYMCBC, strlen(SYMCBC) + 1);
1,704✔
435
    } else if (pObj->type == ENCRYPT_ALGR_TYPE__DIGEST) {
3,408✔
436
      tstrncpy(varDataVal(tmpBuf), DIGEST, strlen(DIGEST) + 1);
1,704✔
437
    } else if (pObj->type == ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS) {
1,704✔
438
      tstrncpy(varDataVal(tmpBuf), ASYM, strlen(ASYM) + 1);
1,704✔
439
    }
440
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
5,112✔
441
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
5,112✔
442

443
    memset(tmpBuf, 0, 1000);
5,112✔
444
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
5,112✔
445
    if(pObj->source == ENCRYPT_ALGR_SOURCE_BUILTIN){
5,112✔
446
      tstrncpy(varDataVal(tmpBuf), BUILTIN, strlen(BUILTIN) + 1);
5,112✔
UNCOV
447
    } else if (pObj->source == ENCRYPT_ALGR_SOURCE_CUSTOMIZED) {
×
UNCOV
448
      tstrncpy(varDataVal(tmpBuf), CUSTOMIZED, strlen(CUSTOMIZED) + 1);
×
449
    }
450
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
5,112✔
451
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
5,112✔
452

453
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
5,112✔
454
    tstrncpy(varDataVal(tmpBuf), pObj->ossl_algr_name, TSDB_ENCRYPT_ALGR_NAME_LEN);
5,112✔
455
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
5,112✔
456
    RETRIEVE_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), pObj, &lino, _OVER);
5,112✔
457

458
    sdbRelease(pSdb, pObj);
5,112✔
459
    numOfRows++;
5,112✔
460
  }
461

462
  pShow->numOfRows += numOfRows;
852✔
463

464
_OVER:
852✔
465
  if (code != 0) {
852✔
466
    mError("failed to retrieve encrypt_algr info at line %d since %s", lino, tstrerror(code));
×
UNCOV
467
    TAOS_RETURN(code);
×
468
  }
469
  return numOfRows;
852✔
470
}
471

UNCOV
472
static void mndCancelRetrieveEncryptAlgr(SMnode *pMnode, void *pIter) {
×
UNCOV
473
  SSdb *pSdb = pMnode->pSdb;
×
474
  sdbCancelFetchByType(pSdb, pIter, SDB_ENCRYPT_ALGORITHMS);
×
UNCOV
475
}
×
476

UNCOV
477
static int32_t mndProcessCreateEncryptAlgrReq(SRpcMsg *pReq) {
×
478
  SMnode               *pMnode = pReq->info.node;
×
479
  int32_t               code = 0;
×
480
  int32_t               lino = 0;
×
481
  SCreateEncryptAlgrReq createReq = {0};
×
UNCOV
482
  STrans               *pTrans = NULL;
×
483

484
  int64_t tss = taosGetTimestampMs();
×
485

486
  if (tDeserializeSCreateEncryptAlgrReq(pReq->pCont, pReq->contLen, &createReq) != 0) {
×
487
    TAOS_CHECK_GOTO(TSDB_CODE_INVALID_MSG, &lino, _OVER);
×
488
  }
489

490
  mInfo("algr:%s, start to create, ossl_name:%s", createReq.algorithmId, createReq.osslAlgrName);
×
491

492
  // TAOS_CHECK_GOTO(grantCheck(TSDB_GRANT_USER), &lino, _OVER);
493

494
  SEncryptAlgrObj *exist = mndAcquireEncryptAlgrByAId(pMnode, createReq.algorithmId);
×
495
  if (exist != NULL) {
×
496
    mndReleaseEncryptAlgr(pMnode, exist);
×
UNCOV
497
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_ALGR_EXIST, &lino, _OVER);
×
498
  }
499

500
  SEncryptAlgrObj Obj = {0};
×
501
  int32_t         id = sdbGetMaxId(pMnode->pSdb, SDB_ENCRYPT_ALGORITHMS);
×
UNCOV
502
  if (id < 100) id = 101;
×
503
  Obj.id = id;
×
504
  tstrncpy(Obj.algorithm_id, createReq.algorithmId, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
505
  tstrncpy(Obj.name, createReq.name, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
506
  tstrncpy(Obj.desc, createReq.desc, TSDB_ENCRYPT_ALGR_DESC_LEN);
×
507
  if (strncmp(createReq.type, "Symmetric_Ciphers_CBC_mode", TSDB_ENCRYPT_ALGR_TYPE_LEN) == 0) {
×
UNCOV
508
    Obj.type = ENCRYPT_ALGR_TYPE__SYMMETRIC_CIPHERS;
×
509
  } else if (strncmp(createReq.type, "Digests", TSDB_ENCRYPT_ALGR_TYPE_LEN) == 0) {
×
UNCOV
510
    Obj.type = ENCRYPT_ALGR_TYPE__DIGEST;
×
511
  } else if (strncmp(createReq.type, "Asymmetric_Ciphers", TSDB_ENCRYPT_ALGR_TYPE_LEN) == 0) {
×
512
    Obj.type = ENCRYPT_ALGR_TYPE__ASYMMETRIC_CIPHERS;
×
513
  } else {
514
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_INVALID_ENCRYPT_ALGR_TYPE, &lino, _OVER);
×
515
  }
UNCOV
516
  Obj.source = ENCRYPT_ALGR_SOURCE_CUSTOMIZED;
×
517
  tstrncpy(Obj.ossl_algr_name, createReq.osslAlgrName, TSDB_ENCRYPT_ALGR_NAME_LEN);
×
518

519
  pTrans = mndTransCreate(pMnode, TRN_POLICY_RETRY, TRN_CONFLICT_NOTHING, NULL, "create-enc-algr");
×
UNCOV
520
  if (pTrans == NULL) {
×
UNCOV
521
    mError("failed to create since %s", terrstr());
×
522
    code = terrno;
×
523
    goto _OVER;
×
524
  }
525
  mInfo("trans:%d, used to create encrypt_algr", pTrans->id);
×
526

527
  SSdbRaw *pRaw = mndCreateEncryptAlgrRaw(pTrans, &Obj);
×
UNCOV
528
  if (pRaw == NULL) {
×
UNCOV
529
    mError("trans:%d, failed to commit redo log since %s", pTrans->id, terrstr());
×
530
    goto _OVER;
×
531
  }
532

533
  if ((code = mndTransPrepare(pMnode, pTrans)) != 0) {
×
UNCOV
534
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
×
UNCOV
535
    goto _OVER;
×
536
  }
537

538
  if (tsAuditLevel >= AUDIT_LEVEL_CLUSTER) {
×
UNCOV
539
    int64_t tse = taosGetTimestampMs();
×
UNCOV
540
    double  duration = (double)(tse - tss);
×
541
    duration = duration / 1000;
×
542
    auditRecord(pReq, pMnode->clusterId, "createEncryptAlgr", "", createReq.algorithmId, createReq.sql,
×
543
                strlen(createReq.sql), duration, 0);
×
544
  }
545

UNCOV
546
  return code;
×
547
_OVER:
×
UNCOV
548
  if (code < 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
×
549
    mError("algr:%s, failed to create at line %d since %s", createReq.algorithmId, lino, tstrerror(code));
×
550
  }
551

552
  tFreeSCreateEncryptAlgrReq(&createReq);
×
553
  mndTransDrop(pTrans);
×
UNCOV
554
  TAOS_RETURN(code);
×
555
}
556

557
static int32_t mndDropEncryptAlgr(SMnode *pMnode, SRpcMsg *pReq, SEncryptAlgrObj *pAlgr) {
×
UNCOV
558
  STrans *pTrans = mndTransCreate(pMnode, TRN_POLICY_ROLLBACK, TRN_CONFLICT_NOTHING, pReq, "drop-encrypt-algr");
×
UNCOV
559
  if (pTrans == NULL) {
×
560
    mError("algr:%s, failed to drop since %s", pAlgr->algorithm_id, terrstr());
×
561
    TAOS_RETURN(terrno);
×
562
  }
563
  mInfo("trans:%d, used to drop algr:%s", pTrans->id, pAlgr->algorithm_id);
×
564

UNCOV
565
  SSdbRaw *pCommitRaw = mndEncryptAlgrActionEncode(pAlgr);
×
566
  if (pCommitRaw == NULL || mndTransAppendCommitlog(pTrans, pCommitRaw) != 0) {
×
567
    mError("trans:%d, failed to append commit log since %s", pTrans->id, terrstr());
×
UNCOV
568
    mndTransDrop(pTrans);
×
UNCOV
569
    TAOS_RETURN(terrno);
×
570
  }
571
  if (sdbSetRawStatus(pCommitRaw, SDB_STATUS_DROPPED) < 0) {
×
572
    mndTransDrop(pTrans);
×
573
    TAOS_RETURN(terrno);
×
574
  }
575

UNCOV
576
  if (mndTransPrepare(pMnode, pTrans) != 0) {
×
577
    mError("trans:%d, failed to prepare since %s", pTrans->id, terrstr());
×
UNCOV
578
    mndTransDrop(pTrans);
×
579
    TAOS_RETURN(terrno);
×
580
  }
581

UNCOV
582
  mndTransDrop(pTrans);
×
UNCOV
583
  TAOS_RETURN(0);
×
584
}
585

UNCOV
586
static int32_t mndProcessDropEncryptAlgrReq(SRpcMsg *pReq) {
×
UNCOV
587
  SMnode             *pMnode = pReq->info.node;
×
588
  int32_t             code = 0;
×
589
  int32_t             lino = 0;
×
590
  SEncryptAlgrObj    *pObj = NULL;
×
UNCOV
591
  SDropEncryptAlgrReq dropReq = {0};
×
592

593
  int64_t tss = taosGetTimestampMs();
×
594

595
  TAOS_CHECK_GOTO(tDeserializeSDropEncryptAlgrReq(pReq->pCont, pReq->contLen, &dropReq), &lino, _OVER);
×
596

597
  mInfo("algr:%s, start to drop", dropReq.algorithmId);
×
598
  // TAOS_CHECK_GOTO(mndCheckOperPrivilege(pMnode, RPC_MSG_USER(pReq), RPC_MSG_TOKEN(pReq), MND_OPER_DROP_USER), &lino, _OVER);
599

600
  if (dropReq.algorithmId[0] == 0) {
×
601
    TAOS_CHECK_GOTO(TSDB_CODE_MND_INVALID_ENCRYPT_ALGR_FORMAT, &lino, _OVER);
×
602
  }
603

604
  pObj = mndAcquireEncryptAlgrByAId(pMnode, dropReq.algorithmId);
×
UNCOV
605
  if (pObj == NULL) {
×
UNCOV
606
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_ENCRYPT_ALGR_NOT_EXIST, &lino, _OVER);
×
607
  }
608

UNCOV
609
  bool    exist = false;
×
610
  void   *pIter = NULL;
×
611
  SDbObj *pDb = NULL;
×
612
  while (1) {
UNCOV
613
    pIter = sdbFetch(pMnode->pSdb, SDB_DB, pIter, (void **)&pDb);
×
614
    if (pIter == NULL) break;
×
615

UNCOV
616
    if (pDb->cfg.encryptAlgorithm == pObj->id) {
×
617
      exist = true;
×
618
      sdbRelease(pMnode->pSdb, pDb);
×
619
      sdbCancelFetch(pMnode->pSdb, pIter);
×
620
      break;
×
621
    }
622

UNCOV
623
    sdbRelease(pMnode->pSdb, pDb);
×
624
  }
625

626
  if (exist) {
×
627
    TAOS_CHECK_GOTO(TSDB_CODE_MNODE_ENCRYPT_ALGR_IN_USE, &lino, _OVER);
×
628
  }
629

630
  TAOS_CHECK_GOTO(mndDropEncryptAlgr(pMnode, pReq, pObj), &lino, _OVER);
×
631
  if (code == 0) code = TSDB_CODE_ACTION_IN_PROGRESS;
×
632

UNCOV
633
  if (tsAuditLevel >= AUDIT_LEVEL_CLUSTER) {
×
UNCOV
634
    int64_t tse = taosGetTimestampMs();
×
UNCOV
635
    double  duration = (double)(tse - tss);
×
UNCOV
636
    duration = duration / 1000;
×
UNCOV
637
    auditRecord(pReq, pMnode->clusterId, "dropEncryptAlgr", "", dropReq.algorithmId, dropReq.sql, dropReq.sqlLen,
×
638
                duration, 0);
639
  }
640

UNCOV
641
_OVER:
×
UNCOV
642
  if (code < 0 && code != TSDB_CODE_ACTION_IN_PROGRESS) {
×
UNCOV
643
    mError("algr:%s, failed to drop at line %d since %s", dropReq.algorithmId, lino, tstrerror(code));
×
644
  }
645

UNCOV
646
  mndReleaseEncryptAlgr(pMnode, pObj);
×
UNCOV
647
  tFreeSDropEncryptAlgrReq(&dropReq);
×
UNCOV
648
  TAOS_RETURN(code);
×
649
}
650

651
static int32_t mndRetrieveEncryptStatus(SRpcMsg *pMsg, SShowObj *pShow, SSDataBlock *pBlock, int32_t rows) {
372✔
652
  int32_t code = 0;
372✔
653
  int32_t lino = 0;
372✔
654
  int32_t numOfRows = 0;
372✔
655
  int32_t cols = 0;
372✔
656
  char    tmpBuf[1000] = {0};
372✔
657

658
  // Only return data if not already retrieved
659
  if (pShow->numOfRows > 0) {
372✔
UNCOV
660
    return 0;
×
661
  }
662

663
  // Row 1: config encryption status
664
  if (numOfRows < rows) {
372✔
665
    cols = 0;
372✔
666
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
372✔
667
    tstrncpy(varDataVal(tmpBuf), "config", 32);
372✔
668
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
372✔
669
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
372✔
670

671
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
372✔
672
    tstrncpy(varDataVal(tmpBuf), taosGetEncryptAlgoName(tsCfgAlgorithm), 32);
372✔
673
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
372✔
674
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
372✔
675

676
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
372✔
677
    tstrncpy(varDataVal(tmpBuf), (tsCfgKey[0] != '\0') ? "enabled" : "disabled", 16);
372✔
678
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
372✔
679
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
372✔
680

681
    numOfRows++;
372✔
682
  }
683

684
  // Row 2: metadata encryption status
685
  if (numOfRows < rows) {
372✔
686
    cols = 0;
372✔
687
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
372✔
688
    tstrncpy(varDataVal(tmpBuf), "metadata", 32);
372✔
689
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
372✔
690
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
372✔
691

692
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
372✔
693
    tstrncpy(varDataVal(tmpBuf), taosGetEncryptAlgoName(tsMetaAlgorithm), 32);
372✔
694
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
372✔
695
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
372✔
696

697
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
372✔
698
    tstrncpy(varDataVal(tmpBuf), (tsMetaKey[0] != '\0') ? "enabled" : "disabled", 16);
372✔
699
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
372✔
700
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
372✔
701

702
    numOfRows++;
372✔
703
  }
704

705
  // Row 3: data encryption status
706
  if (numOfRows < rows) {
372✔
707
    cols = 0;
372✔
708
    SColumnInfoData *pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
372✔
709
    tstrncpy(varDataVal(tmpBuf), "data", 32);
372✔
710
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
372✔
711
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
372✔
712

713
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
372✔
714
    // Data key uses the master algorithm (usually SM4)
715
    tstrncpy(varDataVal(tmpBuf), taosGetEncryptAlgoName(tsEncryptAlgorithmType), 32);
372✔
716
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
372✔
717
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
372✔
718

719
    pColInfo = taosArrayGet(pBlock->pDataBlock, cols++);
372✔
720
    tstrncpy(varDataVal(tmpBuf), (tsDataKey[0] != '\0') ? "enabled" : "disabled", 16);
372✔
721
    varDataSetLen(tmpBuf, strlen(varDataVal(tmpBuf)));
372✔
722
    TAOS_CHECK_GOTO(colDataSetVal(pColInfo, numOfRows, (const char *)tmpBuf, false), &lino, _OVER);
372✔
723

724
    numOfRows++;
372✔
725
  }
726

727
  pShow->numOfRows += numOfRows;
372✔
728
  return numOfRows;
372✔
729

UNCOV
730
_OVER:
×
UNCOV
731
  if (code != 0) {
×
UNCOV
732
    mError("failed to retrieve encrypt status at line %d since %s", lino, tstrerror(code));
×
733
  }
UNCOV
734
  return numOfRows;
×
735
}
736

737
int32_t mndInitEncryptAlgr(SMnode *pMnode) {
542,363✔
738
  mndSetMsgHandle(pMnode, TDMT_MND_CREATE_ENCRYPT_ALGR, mndProcessCreateEncryptAlgrReq);
542,363✔
739
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS, mndRetrieveEncryptAlgr);
542,363✔
740
  mndAddShowRetrieveHandle(pMnode, TSDB_MGMT_TABLE_ENCRYPT_STATUS, mndRetrieveEncryptStatus);
542,363✔
741
  mndAddShowFreeIterHandle(pMnode, TSDB_MGMT_TABLE_ENCRYPT_ALGORITHMS, mndCancelRetrieveEncryptAlgr);
542,363✔
742
  mndSetMsgHandle(pMnode, TDMT_MND_DROP_ENCRYPT_ALGR, mndProcessDropEncryptAlgrReq);
542,363✔
743
  mndSetMsgHandle(pMnode, TDMT_MND_BUILTIN_ENCRYPT_ALGR, mndProcessBuiltinReq);
542,363✔
744
  mndSetMsgHandle(pMnode, TDMT_MND_BUILTIN_ENCRYPT_ALGR_RSP, mndProcessBuiltinRsp);
542,363✔
745

746
  SSdbTable table = {
542,363✔
747
      .sdbType = SDB_ENCRYPT_ALGORITHMS,
748
      .keyType = SDB_KEY_INT32,
749
      .upgradeFp = (SdbUpgradeFp)mndUpgradeBuiltinEncryptAlgr,
750
      .encodeFp = (SdbEncodeFp)mndEncryptAlgrActionEncode,
751
      .decodeFp = (SdbDecodeFp)mndEncryptAlgrActionDecode,
752
      .insertFp = (SdbInsertFp)mndEncryptAlgrActionInsert,
753
      .updateFp = (SdbUpdateFp)mndEncryptAlgrActionUpdate,
754
      .deleteFp = (SdbDeleteFp)mndEncryptAlgrActionDelete,
755
      .isUpgradedFp = (SdbIsUpgradedFp)mndIsUpgradedBuiltinEncryptAlgr,
756
  };
757

758
  return sdbSetTable(pMnode->pSdb, table);
542,363✔
759
}
760

761
void mndCleanupEncryptAlgr(SMnode *pMnode) { mDebug("mnd encrypt algorithms cleanup"); }
542,295✔
762

763
SEncryptAlgrObj *mndAcquireEncryptAlgrById(SMnode *pMnode, int64_t id) {
6,164,759✔
764
  SSdb        *pSdb = pMnode->pSdb;
6,164,759✔
765
  SEncryptAlgrObj *pAlgr = sdbAcquire(pSdb, SDB_ENCRYPT_ALGORITHMS, &id);
6,165,585✔
766
  if (pAlgr == NULL && terrno == TSDB_CODE_SDB_OBJ_NOT_THERE) {
6,165,585✔
767
    terrno = TSDB_CODE_SUCCESS;
5,659,837✔
768
  }
769
  return pAlgr;
6,164,759✔
770
}
771

772
void mndGetEncryptOsslAlgrNameById(SMnode *pMnode, int64_t id, char* out){
4,789,387✔
773
  SEncryptAlgrObj *obj = mndAcquireEncryptAlgrById(pMnode, id);
4,789,387✔
774
  if(obj != NULL){
4,789,387✔
775
    tstrncpy(out, obj->ossl_algr_name, TSDB_ENCRYPT_ALGR_NAME_LEN);
8,434✔
776
    mndReleaseEncryptAlgr(pMnode, obj);
8,434✔
777
  }
778
}
4,789,387✔
779

780
SEncryptAlgrObj *mndAcquireEncryptAlgrByAId(SMnode *pMnode, char* algorithm_id) {
6,389✔
781
  SSdb        *pSdb = pMnode->pSdb;
6,389✔
782
  SEncryptAlgrObj *pObj = NULL;
6,389✔
783
  void *pIter = NULL;
6,389✔
784
  while (1) {
785
    pIter = sdbFetch(pSdb, SDB_ENCRYPT_ALGORITHMS, pIter, (void **)&pObj);
17,649✔
786
    if (pIter == NULL) break;
17,649✔
787

788
    if (strncasecmp(pObj->algorithm_id, algorithm_id, TSDB_ENCRYPT_ALGR_NAME_LEN) == 0) {
15,945✔
789
      sdbCancelFetch(pSdb, pIter);
4,685✔
790
      break;
4,685✔
791
    }
792

793
    sdbRelease(pSdb, pObj);
11,260✔
794
  }
795
  return pObj;
6,389✔
796
}
797

798
void mndReleaseEncryptAlgr(SMnode *pMnode, SEncryptAlgrObj *pObj) {
504,922✔
799
  SSdb *pSdb = pMnode->pSdb;
504,922✔
800
  sdbRelease(pSdb, pObj);
504,922✔
801
  pObj = NULL;
504,922✔
802
}
504,922✔
803

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc