Skip to content

Commit

Permalink
Added IM commands porting
Browse files Browse the repository at this point in the history
  • Loading branch information
sharadb-amazon committed May 3, 2024
1 parent 1663b88 commit b87a799
Show file tree
Hide file tree
Showing 9 changed files with 695 additions and 2,154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
39DB29E82B9A3B1D0071334A /* MCCommandPayloads.h */,
39DB29EA2B9A3B2D0071334A /* MCCommandPayloads.mm */,
399049A62B9FC4ED000C91F0 /* MCCommandPayloads_Internal.h */,
3C4F521F2B507C4A00BB8A10 /* MCEndpointClusterType.h */,
);
path = "zap-generated";
sourceTree = "<group>";
Expand Down Expand Up @@ -294,7 +295,6 @@
3C621CA42B605A6A005CDBA3 /* MCAttribute.h */,
3C621CA82B605C52005CDBA3 /* MCAttribute_Internal.h */,
3C621CAA2B605C6E005CDBA3 /* MCAttribute.mm */,
3C4F521F2B507C4A00BB8A10 /* MCEndpointClusterType.h */,
3C4F52132B4F31DC00BB8A10 /* MCDeviceTypeStruct.h */,
3C4F52152B4F31FA00BB8A10 /* MCDeviceTypeStruct.m */,
3C0474052B3F7E5F0012AE95 /* MCEndpointFilter.h */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@ - (instancetype _Nonnull)initWithCppCastingPlayer:(matter::casting::memory::Stro
return self;
}

+ (MCCastingPlayer *_Nullable)getTargetCastingPlayer
{
ChipLogProgress(AppServer, "MCCastingPlayer.getTargetCastingPlayer called");
VerifyOrReturnValue([[MCCastingApp getSharedInstance] isRunning], nil, ChipLogError(AppServer, "MCCastingApp NOT running"));
__block MCCastingPlayer * castingPlayer = nil;
dispatch_sync([[MCCastingApp getSharedInstance] getWorkQueue], ^{
matter::casting::core::CastingPlayer *cppCastingPlayer = matter::casting::core::CastingPlayer::GetTargetCastingPlayer();
if(cppCastingPlayer != nullptr) {
castingPlayer = [[MCCastingPlayer alloc] initWithCppCastingPlayer:std::make_shared<matter::casting::core::CastingPlayer>(cppCastingPlayer)];
}
});
return castingPlayer;
}

- (NSString * _Nonnull)description
{
return [NSString stringWithFormat:@"%@ with Product ID: %hu and Vendor ID: %hu. Resolved IPAddr?: %@",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

- (instancetype _Nonnull)initWithCppCastingPlayer:(matter::casting::memory::Strong<matter::casting::core::CastingPlayer>)cppCastingPlayer;

+ (MCCastingPlayer *_Nullable)getTargetCastingPlayer;

@end

#endif /* MCCastingPlayer_Internal_h */
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

#import "MCCastingPlayer.h"
#import "MCCluster.h"
#import "MCEndpointClusterType.h"
#import "zap-generated/MCEndpointClusterType.h"

#import <Foundation/Foundation.h>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ FOUNDATION_EXPORT const unsigned char MatterTvCastingBridgeVersionString[];
#import "MCCryptoUtils.h"
#import "MCDataSource.h"
#import "MCDeviceAttestationCredentials.h"
#import "MCEndpointClusterType.h"
#import "zap-generated/MCEndpointClusterType.h"
#import "MCEndpointFilter.h"
#import "MCObserver.h"
#import "zap-generated/MCAttributeObjects.h"
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#import "MCCommissionableData.h"
#import "MCDeviceAttestationCredentials.h"
#import "MCErrorUtils.h"
#import "MCCryptoUtils.h"

#include <app/data-model/ListLargeSystemExtensions.h>
#include <credentials/DeviceAttestationCredsProvider.h>
Expand Down Expand Up @@ -91,6 +92,47 @@ - (MCDeviceAttestationCredentials *)castingAppDidReceiveRequestForDeviceAttestat
}

- (MatterError *)castingApp:(id)sender didReceiveRequestToSignCertificateRequest:(NSData *)csrData outRawSignature:(NSData * _Nonnull * _Nonnull)outRawSignature
{
NSLog(@"castingApp didReceiveRequestToSignCertificateRequest");

if (self.dacHolder != nil) {
CHIP_ERROR result = CHIP_NO_ERROR;

// Get the private SecKey from dacHolder
SecKeyRef privateSecKey = [self.dacHolder getDeviceAttestationCertPrivateKeyRef];

if (privateSecKey == nil) {
NSLog(@"Failed to retrieve private key from dacHolder.");
return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INVALID_ARGUMENT];
}

// Sign csrData to get asn1SignatureData
CFErrorRef error = nil;
CFDataRef asn1SignatureData = SecKeyCreateSignature(privateSecKey, kSecKeyAlgorithmECDSASignatureMessageX962SHA256, (__bridge CFDataRef)csrData, &error);
if (error != nil || asn1SignatureData == nil)
{
NSLog(@"Failed to sign message. Error: %@", error);
return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INVALID_ARGUMENT];
}

// Convert ASN.1 DER signature to SEC1 raw format
MatterError * conversionError = [MCCryptoUtils ecdsaAsn1SignatureToRawWithFeLengthBytes:32
asn1Signature:asn1SignatureData
outRawSignature:outRawSignature];

if (conversionError != MATTER_NO_ERROR)
{
NSLog(@"Failed to convert to raw signature.");
return conversionError;
}

return [MCErrorUtils MatterErrorFromChipError:result];
}

return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE];
}

/*- (MatterError *)castingApp:(id)sender didReceiveRequestToSignCertificateRequest:(NSData *)csrData outRawSignature:(NSData * _Nonnull * _Nonnull)outRawSignature
{
ChipLogProgress(AppServer, "DataSourceCompat::didReceiveRequestToSignCertificateRequest called");
Expand Down Expand Up @@ -150,5 +192,5 @@ - (MatterError *)castingApp:(id)sender didReceiveRequestToSignCertificateRequest
}
return [MCErrorUtils MatterErrorFromChipError:CHIP_ERROR_INCORRECT_STATE];
}
}*/
@end

0 comments on commit b87a799

Please sign in to comment.