diff --git a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp index b95982e6d2a729..aa4f268b21604c 100644 --- a/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp +++ b/src/app/clusters/operational-credentials-server/operational-credentials-server.cpp @@ -103,8 +103,11 @@ CHIP_ERROR OperationalCredentialsAttrAccess::ReadFabricsList(EndpointId endpoint fabricDescriptor.vendorId = fabricInfo.GetVendorId(); fabricDescriptor.fabricId = fabricInfo.GetFabricId(); - fabricDescriptor.label = fabricInfo.GetFabricLabel(); - fabricDescriptor.rootPublicKey = fabricInfo.GetRootPubkey(); + fabricDescriptor.label = fabricInfo.GetFabricLabel(); + + Credentials::P256PublicKeySpan pubKey; + ReturnErrorOnFailure(fabricInfo.GetRootPubkey(pubKey)); + fabricDescriptor.rootPublicKey = pubKey; ReturnErrorOnFailure(encoder.Encode(fabricDescriptor)); } diff --git a/src/credentials/FabricTable.cpp b/src/credentials/FabricTable.cpp index ae19040827457a..06fb786e4c2467 100644 --- a/src/credentials/FabricTable.cpp +++ b/src/credentials/FabricTable.cpp @@ -192,7 +192,14 @@ CHIP_ERROR FabricInfo::GetCompressedId(FabricId fabricId, NodeId nodeId, PeerId ReturnErrorCodeIf(compressedPeerId == nullptr, CHIP_ERROR_INVALID_ARGUMENT); uint8_t compressedFabricIdBuf[sizeof(uint64_t)]; MutableByteSpan compressedFabricIdSpan(compressedFabricIdBuf); - P256PublicKey rootPubkey(GetRootPubkey()); + P256PublicKey rootPubkey; + + { + P256PublicKeySpan rootPubkeySpan; + ReturnErrorOnFailure(GetRootPubkey(rootPubkeySpan)); + rootPubkey = rootPubkeySpan; + } + ChipLogDetail(Inet, "Generating compressed fabric ID using uncompressed fabric ID 0x" ChipLogFormatX64 " and root pubkey", ChipLogValueX64(fabricId)); ChipLogByteSpan(Inet, ByteSpan(rootPubkey.ConstBytes(), rootPubkey.Length())); @@ -332,7 +339,9 @@ CHIP_ERROR FabricInfo::GenerateDestinationID(const ByteSpan & ipk, const ByteSpa kSigmaParamRandomNumberSize + kP256_PublicKey_Length + sizeof(FabricId) + sizeof(NodeId); HMAC_sha hmac; uint8_t destinationMessage[kDestinationMessageLen]; - P256PublicKeySpan rootPubkeySpan = GetRootPubkey(); + P256PublicKeySpan rootPubkeySpan; + + ReturnErrorOnFailure(GetRootPubkey(rootPubkeySpan)); Encoding::LittleEndian::BufferWriter bbuf(destinationMessage, sizeof(destinationMessage)); diff --git a/src/credentials/FabricTable.h b/src/credentials/FabricTable.h index 0f3a3b9730bd7c..7457b2f4b28e55 100644 --- a/src/credentials/FabricTable.h +++ b/src/credentials/FabricTable.h @@ -213,18 +213,14 @@ class DLL_EXPORT FabricInfo return CHIP_NO_ERROR; } - Credentials::CertificateKeyId GetTrustedRootId() const + CHIP_ERROR GetTrustedRootId(Credentials::CertificateKeyId & skid) const { - Credentials::CertificateKeyId skid; - Credentials::ExtractSKIDFromChipCert(mRootCert, skid); - return skid; + return Credentials::ExtractSKIDFromChipCert(mRootCert, skid); } - Credentials::P256PublicKeySpan GetRootPubkey() const + CHIP_ERROR GetRootPubkey(Credentials::P256PublicKeySpan & publicKey) const { - Credentials::P256PublicKeySpan publicKey; - Credentials::ExtractPublicKeyFromChipCert(mRootCert, publicKey); - return publicKey; + return Credentials::ExtractPublicKeyFromChipCert(mRootCert, publicKey); } CHIP_ERROR VerifyCredentials(const ByteSpan & noc, const ByteSpan & icac, Credentials::ValidationContext & context, diff --git a/src/protocols/secure_channel/CASESession.cpp b/src/protocols/secure_channel/CASESession.cpp index 15df65fa573855..e88980435c9eef 100644 --- a/src/protocols/secure_channel/CASESession.cpp +++ b/src/protocols/secure_channel/CASESession.cpp @@ -534,7 +534,7 @@ CHIP_ERROR CASESession::SendSigma2() ByteSpan nocCert; ReturnErrorOnFailure(mFabricInfo->GetNOCCert(nocCert)); - mTrustedRootId = mFabricInfo->GetTrustedRootId(); + ReturnErrorOnFailure(mFabricInfo->GetTrustedRootId(mTrustedRootId)); VerifyOrReturnError(!mTrustedRootId.empty(), CHIP_ERROR_INTERNAL); // Fill in the random value @@ -915,7 +915,7 @@ CHIP_ERROR CASESession::SendSigma3() SuccessOrExit(err = mFabricInfo->GetICACert(icaCert)); SuccessOrExit(err = mFabricInfo->GetNOCCert(nocCert)); - mTrustedRootId = mFabricInfo->GetTrustedRootId(); + SuccessOrExit(err = mFabricInfo->GetTrustedRootId(mTrustedRootId)); VerifyOrExit(!mTrustedRootId.empty(), err = CHIP_ERROR_INTERNAL); // Prepare Sigma3 TBS Data Blob