Skip to content

Commit

Permalink
Remove CHIPP256KeypairNativeBridge. (#20243)
Browse files Browse the repository at this point in the history
We don't need the complicated indirection here, as long as we compile
libCHIP with RTTI enabled on Mac, like the framework code that's
trying to use it.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Jan 19, 2024
1 parent bdea40d commit 1569628
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 133 deletions.
2 changes: 1 addition & 1 deletion build/config/compiler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ config("coverage_default") {

declare_args() {
# Enable Runtime Type Information (RTTI)
enable_rtti = false
enable_rtti = current_os == "mac" || current_os == "ios"
}

config("no_rtti") {
Expand Down
3 changes: 1 addition & 2 deletions src/darwin/Framework/CHIP/MTRCertificates.mm
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,10 @@ + (nullable NSData *)generateCertificateSigningRequest:(id<MTRKeypair>)keypair
if (err != CHIP_NO_ERROR) {
break;
}
CHIPP256KeypairNativeBridge nativeKeypair(keypairBridge);

uint8_t buf[kMAX_CSR_Length];
MutableByteSpan csr(buf);
err = GenerateCertificateSigningRequest(&nativeKeypair, csr);
err = GenerateCertificateSigningRequest(&keypairBridge, csr);
if (err != CHIP_NO_ERROR) {
break;
}
Expand Down
12 changes: 5 additions & 7 deletions src/darwin/Framework/CHIP/MTRDeviceController.mm
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ @interface MTRDeviceController ()
@property (readonly) MTROperationalCredentialsDelegate * operationalCredentialsDelegate;
@property (readonly) MTRP256KeypairBridge signingKeypairBridge;
@property (readonly) MTRP256KeypairBridge operationalKeypairBridge;
@property (readonly) chip::Optional<chip::CHIPP256KeypairNativeBridge> operationalKeypairNativeBridge;
@property (readonly) MTRDeviceAttestationDelegateBridge * deviceAttestationDelegateBridge;
@property (readonly) MTRControllerFactory * factory;
@end
Expand Down Expand Up @@ -193,16 +192,16 @@ - (BOOL)startup:(MTRDeviceControllerStartupParamsInternal *)startupParams
CHIP_ERROR errorCode = CHIP_ERROR_INCORRECT_STATE;

// create a MTRP256KeypairBridge here and pass it to the operationalCredentialsDelegate
std::unique_ptr<chip::Crypto::CHIPP256KeypairNativeBridge> nativeBridge;
chip::Crypto::P256Keypair * signingKeypair = nullptr;
if (startupParams.nocSigner) {
errorCode = _signingKeypairBridge.Init(startupParams.nocSigner);
if ([self checkForStartError:(CHIP_NO_ERROR == errorCode) logMsg:kErrorSigningKeypairInit]) {
return;
}
nativeBridge = std::make_unique<chip::Crypto::CHIPP256KeypairNativeBridge>(_signingKeypairBridge);
signingKeypair = &_signingKeypairBridge;
}
errorCode = _operationalCredentialsDelegate->Init(_factory.storageDelegateBridge, std::move(nativeBridge),
startupParams.ipk, startupParams.rootCertificate, startupParams.intermediateCertificate);
errorCode = _operationalCredentialsDelegate->Init(_factory.storageDelegateBridge, signingKeypair, startupParams.ipk,
startupParams.rootCertificate, startupParams.intermediateCertificate);
if ([self checkForStartError:(CHIP_NO_ERROR == errorCode) logMsg:kErrorOperationalCredentialsInit]) {
return;
}
Expand Down Expand Up @@ -231,8 +230,7 @@ - (BOOL)startup:(MTRDeviceControllerStartupParamsInternal *)startupParams
if ([self checkForStartError:(CHIP_NO_ERROR == errorCode) logMsg:kErrorOperationalKeypairInit]) {
return;
}
_operationalKeypairNativeBridge.Emplace(_operationalKeypairBridge);
commissionerParams.operationalKeypair = &_operationalKeypairNativeBridge.Value();
commissionerParams.operationalKeypair = &_operationalKeypairBridge;
commissionerParams.hasExternallyOwnedOperationalKeypair = true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
#include <controller/OperationalCredentialsDelegate.h>
#include <crypto/CHIPCryptoPAL.h>
#include <lib/core/CASEAuthTag.h>
#include <platform/Darwin/CHIPP256KeypairNativeBridge.h>

NS_ASSUME_NONNULL_BEGIN

class MTROperationalCredentialsDelegate : public chip::Controller::OperationalCredentialsDelegate {
public:
using ChipP256KeypairPtr = std::unique_ptr<chip::Crypto::P256Keypair>;
using ChipP256KeypairPtr = chip::Crypto::P256Keypair *;

~MTROperationalCredentialsDelegate() {}

Expand Down
11 changes: 4 additions & 7 deletions src/darwin/Framework/CHIP/MTROperationalCredentialsDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

mStorage = storage;

mIssuerKey = std::move(nocSigner);
mIssuerKey = nocSigner;

if ([ipk length] != mIPK.Length()) {
MTR_LOG_ERROR("MTROperationalCredentialsDelegate::init provided IPK is wrong size");
Expand Down Expand Up @@ -203,7 +203,6 @@ uint64_t GetIssuerId(NSNumber * _Nullable providedIssuerId)
*rootCert = nil;
MTRP256KeypairBridge keypairBridge;
ReturnErrorOnFailure(keypairBridge.Init(keypair));
CHIPP256KeypairNativeBridge nativeKeypair(keypairBridge);

ChipDN rcac_dn;
ReturnErrorOnFailure(rcac_dn.AddAttribute_MatterRCACId(GetIssuerId(issuerId)));
Expand All @@ -229,7 +228,7 @@ uint64_t GetIssuerId(NSNumber * _Nullable providedIssuerId)
uint8_t rcacBuffer[Controller::kMaxCHIPDERCertLength];
MutableByteSpan rcac(rcacBuffer);
X509CertRequestParams rcac_request = { 0, validityStart, validityEnd, rcac_dn, rcac_dn };
ReturnErrorOnFailure(NewRootX509Cert(rcac_request, nativeKeypair, rcac));
ReturnErrorOnFailure(NewRootX509Cert(rcac_request, keypairBridge, rcac));
*rootCert = AsData(rcac);
return CHIP_NO_ERROR;
}
Expand All @@ -247,7 +246,6 @@ uint64_t GetIssuerId(NSNumber * _Nullable providedIssuerId)

MTRP256KeypairBridge keypairBridge;
ReturnErrorOnFailure(keypairBridge.Init(rootKeypair));
CHIPP256KeypairNativeBridge nativeRootKeypair(keypairBridge);

ByteSpan rcac = AsByteSpan(rootCertificate);

Expand Down Expand Up @@ -280,7 +278,7 @@ uint64_t GetIssuerId(NSNumber * _Nullable providedIssuerId)
uint8_t icacBuffer[Controller::kMaxCHIPDERCertLength];
MutableByteSpan icac(icacBuffer);
X509CertRequestParams icac_request = { 0, validityStart, validityEnd, icac_dn, rcac_dn };
ReturnErrorOnFailure(NewICAX509Cert(icac_request, pubKey, nativeRootKeypair, icac));
ReturnErrorOnFailure(NewICAX509Cert(icac_request, pubKey, keypairBridge, icac));
*intermediateCert = AsData(icac);
return CHIP_NO_ERROR;
}
Expand Down Expand Up @@ -308,7 +306,6 @@ uint64_t GetIssuerId(NSNumber * _Nullable providedIssuerId)

MTRP256KeypairBridge keypairBridge;
ReturnErrorOnFailure(keypairBridge.Init(signingKeypair));
CHIPP256KeypairNativeBridge nativeSigningKeypair(keypairBridge);

P256PublicKey pubKey;
ReturnErrorOnFailure(MTRP256KeypairBridge::MatterPubKeyFromSecKeyRef(operationalPublicKey, &pubKey));
Expand All @@ -323,7 +320,7 @@ uint64_t GetIssuerId(NSNumber * _Nullable providedIssuerId)

uint8_t nocBuffer[Controller::kMaxCHIPDERCertLength];
MutableByteSpan noc(nocBuffer);
ReturnErrorOnFailure(GenerateNOC(nativeSigningKeypair, signingCertificate, node, fabric, cats, pubKey, noc));
ReturnErrorOnFailure(GenerateNOC(keypairBridge, signingCertificate, node, fabric, cats, pubKey, noc));

*operationalCert = AsData(noc);
return CHIP_NO_ERROR;
Expand Down
2 changes: 1 addition & 1 deletion src/darwin/Framework/CHIP/MTRP256KeypairBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

NS_ASSUME_NONNULL_BEGIN

class MTRP256KeypairBridge : public chip::Crypto::P256KeypairBase
class MTRP256KeypairBridge : public chip::Crypto::P256Keypair
{
public:
~MTRP256KeypairBridge(){};
Expand Down
2 changes: 0 additions & 2 deletions src/platform/Darwin/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ static_library("Darwin") {
"BlePlatformConfig.h",
"CHIPDevicePlatformConfig.h",
"CHIPDevicePlatformEvent.h",
"CHIPP256KeypairNativeBridge.cpp",
"CHIPP256KeypairNativeBridge.h",
"CHIPPlatformConfig.h",
"ConfigurationManagerImpl.cpp",
"ConfigurationManagerImpl.h",
Expand Down
54 changes: 0 additions & 54 deletions src/platform/Darwin/CHIPP256KeypairNativeBridge.cpp

This file was deleted.

57 changes: 0 additions & 57 deletions src/platform/Darwin/CHIPP256KeypairNativeBridge.h

This file was deleted.

0 comments on commit 1569628

Please sign in to comment.