Skip to content

Commit

Permalink
[Chip-Cert] Avoid Serialized packet loss (chip-cert genCert - Chip_Ba…
Browse files Browse the repository at this point in the history
…se64) (#13853)

* Avoid serializedKeyPair packet loss in keyFormat_Chip_Base64 mode

* Restyled by clang-format

Co-authored-by: Restyled.io <commits@restyled.io>
  • Loading branch information
2 people authored and pull[bot] committed Nov 15, 2023
1 parent df4e734 commit 1268592
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/tools/chip-cert/KeyUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,15 +240,15 @@ bool GenerateKeyPair(EVP_PKEY * key)

bool WritePrivateKey(const char * fileName, EVP_PKEY * key, KeyFormat keyFmt)
{
bool res = true;
FILE * file = nullptr;
uint8_t * keyToWrite = nullptr;
uint32_t keyToWriteLen = 0;
uint32_t chipKeyLen = kP256_PublicKey_Length + kP256_PrivateKey_Length;
bool res = true;
FILE * file = nullptr;
uint8_t * keyToWrite = nullptr;
uint32_t keyToWriteLen = 0;
P256SerializedKeypair serializedKeypair;
uint32_t chipKeyLen = sizeof(serializedKeypair);
uint32_t chipKeyBase64Len = BASE64_ENCODED_LEN(chipKeyLen);
std::unique_ptr<uint8_t[]> chipKey(new uint8_t[chipKeyLen]);
std::unique_ptr<uint8_t[]> chipKeyBase64(new uint8_t[chipKeyBase64Len]);
P256SerializedKeypair serializedKeypair;

VerifyOrExit(key != nullptr, res = false);

Expand Down Expand Up @@ -282,7 +282,7 @@ bool WritePrivateKey(const char * fileName, EVP_PKEY * key, KeyFormat keyFmt)

if (keyFmt == kKeyFormat_Chip_Base64)
{
res = Base64Encode(serializedKeypair, static_cast<uint32_t>(serializedKeypair.Length()), chipKeyBase64.get(),
res = Base64Encode(serializedKeypair, static_cast<uint32_t>(sizeof(serializedKeypair)), chipKeyBase64.get(),
chipKeyBase64Len, chipKeyBase64Len);
VerifyTrueOrExit(res);

Expand Down

0 comments on commit 1268592

Please sign in to comment.