Skip to content

Commit c526289

Browse files
committed
WL#15204 TDE: Generate, store and share Node Master Key
Bug#34417282 No program to inspect secrets file, extract key for manual usage of tools. Post push fix. Make secretsfile endianness safe. Although not critical to have secretsfile endian safe since we do not support copying data node filesystem between system of different endianness it can be nice if ndb_secretsfile_reader tool can read the secretesfile from systems with the other endianness. This change always store the key length in secretsfile using little endian. Change-Id: I63a9cf286675e15e8f403028185320c0dbae17ad
1 parent 5ae19c3 commit c526289

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

storage/ndb/src/kernel/blocks/ndbcntr/NdbcntrMain.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#define NDBCNTR_C
2626
#include "Ndbcntr.hpp"
2727

28+
#include "config.h" // WORDS_BIGENDIAN
2829
#include <cstring>
2930
#include <ndb_limits.h>
3031
#include <ndb_version.h>
@@ -84,6 +85,7 @@
8485
#include "../backup/BackupFormat.hpp"
8586

8687
#include <NdbGetRUsage.h>
88+
#include "util/ndb_ndbxfrm1.h" // ndb_ndbxfrm1::toggle_endian
8789
#include <EventLogger.hpp>
8890

8991
#define JAM_FILE_ID 458
@@ -6447,8 +6449,13 @@ void Ndbcntr::write_secretsfile(Signal *signal)
64476449
Uint32 cnt=0;
64486450
memcpy(&c_secretsfile.m_data[cnt], "NDBSCRT1", 8);
64496451
cnt += ndb_ceil_div<Uint32>(8, sizeof(Uint32));
6452+
auto key_len_le = globalData.nodeMasterKeyLength;
6453+
#ifdef WORDS_BIGENDIAN
6454+
// key length should be stored in little endian
6455+
ndb_ndbxfrm1::toggle_endian32(&key_len_le);
6456+
#endif
64506457
memcpy(&c_secretsfile.m_data[cnt],
6451-
&globalData.nodeMasterKeyLength,
6458+
&key_len_le,
64526459
sizeof(globalData.nodeMasterKeyLength));
64536460
cnt += ndb_ceil_div<Uint32>(sizeof(globalData.nodeMasterKeyLength),sizeof(Uint32));
64546461

@@ -6553,6 +6560,10 @@ void Ndbcntr::read_secretsfile_data(Signal *signal)
65536560
cnt += sizeof(magic);
65546561
Uint32 key_len;
65556562
memcpy(&key_len, ptr+cnt, sizeof(key_len));
6563+
#ifdef WORDS_BIGENDIAN
6564+
// key length is always stored in little endian
6565+
ndb_ndbxfrm1::toggle_endian32(&key_len);
6566+
#endif
65566567
assert(key_len == c_nodeMasterKeyLength);
65576568
cnt += sizeof(key_len);
65586569
memset(globalData.nodeMasterKey, 0, MAX_NODE_MASTER_KEY_LENGTH);

storage/ndb/tools/ndb_secretsfile_reader.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2323
*/
2424

25+
#include "config.h" // WORDS_BIGENDIAN
2526
#include "util/require.h"
2627
#include <stdio.h>
2728
#include <string.h>
@@ -32,6 +33,7 @@
3233
#include "util/ndb_opts.h"
3334
#include "util/ndbxfrm_iterator.h"
3435
#include "util/ndbxfrm_file.h"
36+
#include "util/ndb_ndbxfrm1.h" // ndb_ndbxfrm1::toggle_endian
3537
#include "util/ndb_openssl_evp.h"
3638

3739
using byte = unsigned char;
@@ -179,6 +181,10 @@ int read_secrets_file(const char filename[])
179181

180182
Uint32 key_len;
181183
memcpy(&key_len, &buffer[8], 4);
184+
#ifdef WORDS_BIGENDIAN
185+
// key length is always stored in little endian
186+
ndb_ndbxfrm1::toggle_endian32(&key_len);
187+
#endif
182188
if(bytes_available < key_len)
183189
{
184190
fprintf(stderr, "Error: Failed to read secrets file, "

0 commit comments

Comments
 (0)