Skip to content

Commit 28a21a1

Browse files
authored
Return CHIP_ERROR_WELL_UNINITIALIZED when not initialized (#21827)
1 parent 7848b51 commit 28a21a1

9 files changed

+30
-30
lines changed

examples/platform/linux/LinuxCommissionableDataProvider.cpp

+6-6
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ CHIP_ERROR LinuxCommissionableDataProvider::Init(chip::Optional<std::vector<uint
4242
chip::Optional<std::vector<uint8_t>> spake2pSalt, uint32_t spake2pIterationCount,
4343
chip::Optional<uint32_t> setupPasscode, uint16_t discriminator)
4444
{
45-
VerifyOrReturnError(mIsInitialized == false, CHIP_ERROR_INCORRECT_STATE);
45+
VerifyOrReturnError(mIsInitialized == false, CHIP_ERROR_WELL_UNINITIALIZED);
4646

4747
if (discriminator > chip::kMaxDiscriminatorValue)
4848
{
@@ -174,21 +174,21 @@ CHIP_ERROR LinuxCommissionableDataProvider::Init(chip::Optional<std::vector<uint
174174

175175
CHIP_ERROR LinuxCommissionableDataProvider::GetSetupDiscriminator(uint16_t & setupDiscriminator)
176176
{
177-
VerifyOrReturnError(mIsInitialized == true, CHIP_ERROR_INCORRECT_STATE);
177+
VerifyOrReturnError(mIsInitialized == true, CHIP_ERROR_WELL_UNINITIALIZED);
178178
setupDiscriminator = mDiscriminator;
179179
return CHIP_NO_ERROR;
180180
}
181181

182182
CHIP_ERROR LinuxCommissionableDataProvider::GetSpake2pIterationCount(uint32_t & iterationCount)
183183
{
184-
VerifyOrReturnError(mIsInitialized == true, CHIP_ERROR_INCORRECT_STATE);
184+
VerifyOrReturnError(mIsInitialized == true, CHIP_ERROR_WELL_UNINITIALIZED);
185185
iterationCount = mPaseIterationCount;
186186
return CHIP_NO_ERROR;
187187
}
188188

189189
CHIP_ERROR LinuxCommissionableDataProvider::GetSpake2pSalt(chip::MutableByteSpan & saltBuf)
190190
{
191-
VerifyOrReturnError(mIsInitialized == true, CHIP_ERROR_INCORRECT_STATE);
191+
VerifyOrReturnError(mIsInitialized == true, CHIP_ERROR_WELL_UNINITIALIZED);
192192

193193
VerifyOrReturnError(saltBuf.size() >= kSpake2p_Max_PBKDF_Salt_Length, CHIP_ERROR_BUFFER_TOO_SMALL);
194194
memcpy(saltBuf.data(), mPaseSalt.data(), mPaseSalt.size());
@@ -199,7 +199,7 @@ CHIP_ERROR LinuxCommissionableDataProvider::GetSpake2pSalt(chip::MutableByteSpan
199199

200200
CHIP_ERROR LinuxCommissionableDataProvider::GetSpake2pVerifier(chip::MutableByteSpan & verifierBuf, size_t & outVerifierLen)
201201
{
202-
VerifyOrReturnError(mIsInitialized == true, CHIP_ERROR_INCORRECT_STATE);
202+
VerifyOrReturnError(mIsInitialized == true, CHIP_ERROR_WELL_UNINITIALIZED);
203203

204204
// By now, serialized verifier from Init should be correct size
205205
VerifyOrReturnError(mSerializedPaseVerifier.size() == kSpake2p_VerifierSerialized_Length, CHIP_ERROR_INTERNAL);
@@ -214,7 +214,7 @@ CHIP_ERROR LinuxCommissionableDataProvider::GetSpake2pVerifier(chip::MutableByte
214214

215215
CHIP_ERROR LinuxCommissionableDataProvider::GetSetupPasscode(uint32_t & setupPasscode)
216216
{
217-
VerifyOrReturnError(mIsInitialized == true, CHIP_ERROR_INCORRECT_STATE);
217+
VerifyOrReturnError(mIsInitialized == true, CHIP_ERROR_WELL_UNINITIALIZED);
218218

219219
// Pretend not implemented if we don't have a passcode value externally set
220220
if (!mSetupPasscode.HasValue())

src/controller/ExampleOperationalCredentialsIssuer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ CHIP_ERROR ExampleOperationalCredentialsIssuer::GenerateNOCChain(const ByteSpan
188188
const ByteSpan & PAI,
189189
Callback::Callback<OnNOCChainGeneration> * onCompletion)
190190
{
191-
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
191+
VerifyOrReturnError(mInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
192192
// At this point, Credential issuer may wish to validate the CSR information
193193
(void) attestationChallenge;
194194
(void) csrNonce;

src/credentials/DeviceAttestationVendorReserved.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class DeviceAttestationVendorReservedDeconstructor
8888
*/
8989
CHIP_ERROR GetNextVendorReservedElement(struct VendorReservedElement & element)
9090
{
91-
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
91+
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
9292
if (mIsDone)
9393
{
9494
return CHIP_END_OF_TLV;

src/crypto/CHIPCryptoPALOpenSSL.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ CHIP_ERROR P256Keypair::ECDSA_sign_msg(const uint8_t * msg, const size_t msg_len
700700
ERR_clear_error();
701701

702702
static_assert(P256ECDSASignature::Capacity() >= kP256_ECDSA_Signature_Length_Raw, "P256ECDSASignature must be large enough");
703-
VerifyOrExit(mInitialized, error = CHIP_ERROR_INCORRECT_STATE);
703+
VerifyOrExit(mInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
704704
nid = _nidForCurve(MapECName(mPublicKey.Type()));
705705
VerifyOrExit(nid != NID_undef, error = CHIP_ERROR_INVALID_ARGUMENT);
706706

@@ -919,7 +919,7 @@ CHIP_ERROR P256Keypair::ECDH_derive_secret(const P256PublicKey & remote_public_k
919919
EC_KEY * ec_key = EC_KEY_dup(to_const_EC_KEY(&mKeypair));
920920
VerifyOrExit(ec_key != nullptr, error = CHIP_ERROR_INTERNAL);
921921

922-
VerifyOrExit(mInitialized, error = CHIP_ERROR_INCORRECT_STATE);
922+
VerifyOrExit(mInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
923923

924924
local_key = EVP_PKEY_new();
925925
VerifyOrExit(local_key != nullptr, error = CHIP_ERROR_INTERNAL);
@@ -1199,7 +1199,7 @@ CHIP_ERROR P256Keypair::NewCertificateSigningRequest(uint8_t * out_csr, size_t &
11991199
X509_NAME * subject = X509_NAME_new();
12001200
VerifyOrExit(subject != nullptr, error = CHIP_ERROR_INTERNAL);
12011201

1202-
VerifyOrExit(mInitialized, error = CHIP_ERROR_INCORRECT_STATE);
1202+
VerifyOrExit(mInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
12031203

12041204
result = X509_REQ_set_version(x509_req, 0);
12051205
VerifyOrExit(result == 1, error = CHIP_ERROR_INTERNAL);

src/crypto/CHIPCryptoPALTinyCrypt.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ static inline const mbedtls_uecc_keypair * to_const_keypair(const P256KeypairCon
513513

514514
CHIP_ERROR P256Keypair::ECDSA_sign_msg(const uint8_t * msg, const size_t msg_length, P256ECDSASignature & out_signature) const
515515
{
516-
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
516+
VerifyOrReturnError(mInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
517517
VerifyOrReturnError((msg != nullptr) && (msg_length > 0), CHIP_ERROR_INVALID_ARGUMENT);
518518

519519
uint8_t digest[kSHA256_Hash_Length];
@@ -581,7 +581,7 @@ CHIP_ERROR P256Keypair::ECDH_derive_secret(const P256PublicKey & remote_public_k
581581

582582
const mbedtls_uecc_keypair * keypair = to_const_keypair(&mKeypair);
583583

584-
VerifyOrExit(mInitialized, error = CHIP_ERROR_INCORRECT_STATE);
584+
VerifyOrExit(mInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
585585

586586
// Fully padded raw uncompressed points expected, first byte is always 0x04 i.e uncompressed
587587
result = uECC_shared_secret(remote_public_key.ConstBytes() + 1, keypair->private_key, Uint8::to_uchar(out_secret));
@@ -737,7 +737,7 @@ CHIP_ERROR P256Keypair::NewCertificateSigningRequest(uint8_t * out_csr, size_t &
737737
pk.CHIP_CRYPTO_PAL_PRIVATE(pk_ctx) = to_keypair(&mKeypair);
738738
VerifyOrExit(pk.CHIP_CRYPTO_PAL_PRIVATE(pk_info) != nullptr, error = CHIP_ERROR_INTERNAL);
739739

740-
VerifyOrExit(mInitialized, error = CHIP_ERROR_INCORRECT_STATE);
740+
VerifyOrExit(mInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
741741

742742
mbedtls_x509write_csr_set_key(&csr, &pk);
743743

src/crypto/CHIPCryptoPALmbedTLS.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ static inline const mbedtls_ecp_keypair * to_const_keypair(const P256KeypairCont
508508

509509
CHIP_ERROR P256Keypair::ECDSA_sign_msg(const uint8_t * msg, const size_t msg_length, P256ECDSASignature & out_signature) const
510510
{
511-
VerifyOrReturnError(mInitialized, CHIP_ERROR_INCORRECT_STATE);
511+
VerifyOrReturnError(mInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
512512
VerifyOrReturnError((msg != nullptr) && (msg_length > 0), CHIP_ERROR_INVALID_ARGUMENT);
513513

514514
uint8_t digest[kSHA256_Hash_Length];
@@ -651,7 +651,7 @@ CHIP_ERROR P256Keypair::ECDH_derive_secret(const P256PublicKey & remote_public_k
651651

652652
const mbedtls_ecp_keypair * keypair = to_const_keypair(&mKeypair);
653653

654-
VerifyOrExit(mInitialized, error = CHIP_ERROR_INCORRECT_STATE);
654+
VerifyOrExit(mInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
655655

656656
result = mbedtls_ecp_group_load(&ecp_grp, MapECPGroupId(remote_public_key.Type()));
657657
VerifyOrExit(result == 0, error = CHIP_ERROR_INTERNAL);
@@ -845,7 +845,7 @@ CHIP_ERROR P256Keypair::NewCertificateSigningRequest(uint8_t * out_csr, size_t &
845845
pk.CHIP_CRYPTO_PAL_PRIVATE(pk_ctx) = to_keypair(&mKeypair);
846846
VerifyOrExit(pk.CHIP_CRYPTO_PAL_PRIVATE(pk_info) != nullptr, error = CHIP_ERROR_INTERNAL);
847847

848-
VerifyOrExit(mInitialized, error = CHIP_ERROR_INCORRECT_STATE);
848+
VerifyOrExit(mInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
849849

850850
mbedtls_x509write_csr_set_key(&csr, &pk);
851851

src/platform/EFR32/CHIPCryptoPALPsaEfr32.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ CHIP_ERROR P256Keypair::ECDSA_sign_msg(const uint8_t * msg, const size_t msg_len
628628
size_t output_length = 0;
629629
const psa_plaintext_ecp_keypair * keypair = to_const_keypair(&mKeypair);
630630

631-
VerifyOrExit(mInitialized, error = CHIP_ERROR_INCORRECT_STATE);
631+
VerifyOrExit(mInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
632632
VerifyOrExit((msg != nullptr) && (msg_length > 0), error = CHIP_ERROR_INVALID_ARGUMENT);
633633

634634
psa_crypto_init();
@@ -722,7 +722,7 @@ CHIP_ERROR P256Keypair::ECDH_derive_secret(const P256PublicKey & remote_public_k
722722
size_t output_length = 0;
723723
const psa_plaintext_ecp_keypair * keypair = to_const_keypair(&mKeypair);
724724

725-
VerifyOrExit(mInitialized, error = CHIP_ERROR_INCORRECT_STATE);
725+
VerifyOrExit(mInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
726726

727727
// Step 1: import plaintext key as volatile for ECDH
728728
psa_crypto_init();
@@ -839,7 +839,7 @@ CHIP_ERROR P256Keypair::Serialize(P256SerializedKeypair & output) const
839839
size_t len = output.Length() == 0 ? output.Capacity() : output.Length();
840840
Encoding::BufferWriter bbuf(output, len);
841841

842-
VerifyOrExit(mInitialized, error = CHIP_ERROR_INCORRECT_STATE);
842+
VerifyOrExit(mInitialized, error = CHIP_ERROR_WELL_UNINITIALIZED);
843843

844844
bbuf.Put(mPublicKey, mPublicKey.Length());
845845

src/platform/EFR32/Efr32PsaOperationalKeystore.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ CHIP_ERROR Efr32PsaOperationalKeystore::NewOpKeypairForFabric(FabricIndex fabric
185185
MutableByteSpan & outCertificateSigningRequest)
186186
{
187187
CHIP_ERROR error = CHIP_NO_ERROR;
188-
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
188+
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
189189
VerifyOrReturnError(IsValidFabricIndex(fabricIndex), CHIP_ERROR_INVALID_FABRIC_INDEX);
190190

191191
// If a key is pending, we cannot generate for a different fabric index until we commit or revert.
@@ -267,7 +267,7 @@ CHIP_ERROR Efr32PsaOperationalKeystore::NewOpKeypairForFabric(FabricIndex fabric
267267
CHIP_ERROR Efr32PsaOperationalKeystore::ActivateOpKeypairForFabric(FabricIndex fabricIndex,
268268
const Crypto::P256PublicKey & nocPublicKey)
269269
{
270-
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
270+
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
271271
VerifyOrReturnError(mPendingKeypair != nullptr, CHIP_ERROR_INVALID_FABRIC_INDEX);
272272
VerifyOrReturnError(IsValidFabricIndex(fabricIndex) && (fabricIndex == mPendingFabricIndex), CHIP_ERROR_INVALID_FABRIC_INDEX);
273273

@@ -281,7 +281,7 @@ CHIP_ERROR Efr32PsaOperationalKeystore::ActivateOpKeypairForFabric(FabricIndex f
281281

282282
CHIP_ERROR Efr32PsaOperationalKeystore::CommitOpKeypairForFabric(FabricIndex fabricIndex)
283283
{
284-
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
284+
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
285285
VerifyOrReturnError(mPendingKeypair != nullptr, CHIP_ERROR_INVALID_FABRIC_INDEX);
286286
VerifyOrReturnError(IsValidFabricIndex(fabricIndex) && (fabricIndex == mPendingFabricIndex), CHIP_ERROR_INVALID_FABRIC_INDEX);
287287
VerifyOrReturnError(mIsPendingKeypairActive == true, CHIP_ERROR_INCORRECT_STATE);
@@ -329,7 +329,7 @@ CHIP_ERROR Efr32PsaOperationalKeystore::CommitOpKeypairForFabric(FabricIndex fab
329329

330330
CHIP_ERROR Efr32PsaOperationalKeystore::RemoveOpKeypairForFabric(FabricIndex fabricIndex)
331331
{
332-
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
332+
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
333333
VerifyOrReturnError(IsValidFabricIndex(fabricIndex), CHIP_ERROR_INVALID_FABRIC_INDEX);
334334

335335
// Remove pending keypair if we have it and the fabric ID matches
@@ -396,7 +396,7 @@ void Efr32PsaOperationalKeystore::RevertPendingKeypair()
396396
CHIP_ERROR Efr32PsaOperationalKeystore::SignWithOpKeypair(FabricIndex fabricIndex, const ByteSpan & message,
397397
Crypto::P256ECDSASignature & outSignature) const
398398
{
399-
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
399+
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
400400
VerifyOrReturnError(IsValidFabricIndex(fabricIndex), CHIP_ERROR_INVALID_FABRIC_INDEX);
401401

402402
// Check to see whether the key is an activated pending key

src/platform/Tizen/ThreadStackManagerImpl.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ CHIP_ERROR ThreadStackManagerImpl::_SetThreadProvision(ByteSpan netInfo)
209209
{
210210
int threadErr = THREAD_ERROR_NONE;
211211

212-
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
212+
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
213213
VerifyOrReturnError(Thread::OperationalDataset::IsValid(netInfo), CHIP_ERROR_INVALID_ARGUMENT);
214214

215215
threadErr = thread_network_set_active_dataset_tlvs(mThreadInstance, netInfo.data(), netInfo.size());
@@ -236,7 +236,7 @@ CHIP_ERROR ThreadStackManagerImpl::_GetThreadProvision(Thread::OperationalDatase
236236
uint8_t * tlvsData = nullptr;
237237
int tlvsLen;
238238

239-
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
239+
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
240240

241241
threadErr = thread_network_get_active_dataset_tlvs(mThreadInstance, &tlvsData, &tlvsLen);
242242
VerifyOrExit(threadErr == THREAD_ERROR_NONE, ChipLogError(DeviceLayer, "FAIL: get active dataset tlvs"));
@@ -285,7 +285,7 @@ CHIP_ERROR ThreadStackManagerImpl::_SetThreadEnabled(bool val)
285285
{
286286
int threadErr = THREAD_ERROR_NONE;
287287

288-
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
288+
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
289289
bool isEnabled = sInstance._IsThreadEnabled();
290290

291291
if (val && !isEnabled)
@@ -362,7 +362,7 @@ CHIP_ERROR ThreadStackManagerImpl::_SetThreadDeviceType(ConnectivityManager::Thr
362362
int threadErr = THREAD_ERROR_NONE;
363363
thread_device_type_e devType;
364364

365-
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
365+
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
366366

367367
switch (deviceType)
368368
{
@@ -507,7 +507,7 @@ CHIP_ERROR ThreadStackManagerImpl::_AddSrpService(const char * aInstanceName, co
507507
CHIP_ERROR error = CHIP_NO_ERROR;
508508
int threadErr = THREAD_ERROR_NONE;
509509

510-
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_INCORRECT_STATE);
510+
VerifyOrReturnError(mIsInitialized, CHIP_ERROR_WELL_UNINITIALIZED);
511511
VerifyOrExit(aInstanceName, error = CHIP_ERROR_INVALID_ARGUMENT);
512512
VerifyOrExit(aName, error = CHIP_ERROR_INVALID_ARGUMENT);
513513

0 commit comments

Comments
 (0)