Skip to content

Commit

Permalink
Bump copyright year
Browse files Browse the repository at this point in the history
  • Loading branch information
jdomnitz committed Jan 1, 2025
1 parent f8626ec commit ef2901c
Show file tree
Hide file tree
Showing 62 changed files with 115 additions and 97 deletions.
2 changes: 1 addition & 1 deletion Generator/ClassGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Generator/ClusterGenerator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Generator/DataType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Generator/Generator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Generator/GeneratorUtil.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Generator/StructParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion Generator/Tag.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Clusters/ClusterBase.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Clusters/UnknownCluster.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public UnknownCluster(uint cluster, ushort endPoint) : base(cluster, endPoint)

public override string ToString()
{
return $"Unknown Cluster: 0x{cluster:X2}";
return $"Unknown Cluster: 0x{cluster:X4}";
}
}
}
2 changes: 1 addition & 1 deletion MatterDotNet/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Messages/MCSP/MessageCounterSyncRequest.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Messages/MCSP/MessageCounterSyncResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
29 changes: 13 additions & 16 deletions MatterDotNet/PKI/Fabric.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand All @@ -13,7 +13,6 @@
using MatterDotNet.Protocol.Cryptography;
using System.Buffers.Binary;
using System.Formats.Asn1;
using System.Globalization;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
Expand All @@ -30,6 +29,8 @@ public Fabric(ulong rcac, ulong fabricId, byte[] ipk) : base()
{
if (fabricId == 0)
throw new ArgumentException("Invalid Fabric ID");
if (ipk.Length != 16)
throw new ArgumentException("Epoch Key must be 16 bytes");
this.RCAC = rcac;
this.FabricID = fabricId;
EpochKey = ipk;
Expand All @@ -54,20 +55,7 @@ protected Fabric(X509Certificate2 cert, byte[] ipk)
{
this.cert = cert;
EpochKey = ipk;
foreach (X500RelativeDistinguishedName dn in cert.SubjectName.EnumerateRelativeDistinguishedNames(false))
{
switch (dn.GetSingleElementType().Value)
{
case OID_RCAC:
if (ulong.TryParse(dn.GetSingleElementValue()!, NumberStyles.HexNumber, null, out ulong rcac))
RCAC = rcac;
break;
case OID_FabricID:
if (ulong.TryParse(dn.GetSingleElementValue()!, NumberStyles.HexNumber, null, out ulong fabric))
FabricID = fabric;
break;
}
}
ParseCert();
byte[] fabricIDBytes = new byte[8];
BinaryPrimitives.WriteUInt64BigEndian(fabricIDBytes, FabricID);
CompressedFabricID = Crypto.KDF(PublicKey.AsSpan(1), fabricIDBytes, COMPRESSED_FABRIC_INFO, 64);
Expand Down Expand Up @@ -172,6 +160,15 @@ public bool ContainsNOC(ulong nodeId)
return null;
}

public IEnumerable<OperationalCertificate> GetNodes()
{
foreach (OperationalCertificate node in nodes.Values)
{
if (node != Commissioner)
yield return node;
}
}

public byte[] ComputeDestinationID(byte[] random, ulong nodeId)
{
byte[] message = new byte[113];
Expand Down
59 changes: 40 additions & 19 deletions MatterDotNet/PKI/OperationalCertificate.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -55,7 +55,7 @@ internal OperationalCertificate(X509Certificate2 cert)
ParseCert();
}

private void ParseCert()
protected void ParseCert()
{
foreach (X500RelativeDistinguishedName dn in cert.SubjectName.EnumerateRelativeDistinguishedNames(false))
{
Expand Down Expand Up @@ -243,6 +243,10 @@ private static List<DnAttribute> GetDNs(X500DistinguishedName subject)
return attrs;
}

/// <summary>
/// Convert an operational certificate into a matter certificate
/// </summary>
/// <returns></returns>
public MatterCertificate ToMatterCertificate()
{
List<Extension> extensions = new List<Extension>();
Expand Down Expand Up @@ -280,6 +284,10 @@ public MatterCertificate ToMatterCertificate()
};
}

/// <summary>
/// Convert an operational certificate into a matter certificate (in byte[] form)
/// </summary>
/// <returns></returns>
public byte[] GetMatterCertBytes()
{
PayloadWriter payload = new PayloadWriter(600);
Expand All @@ -292,45 +300,58 @@ internal X509Certificate2 GetRaw()
return cert;
}

public byte[]? GetPrivateKey()
{
if (!cert.HasPrivateKey)
return null;
return cert.GetECDsaPrivateKey()?.ExportParameters(true).D;
}

/// <summary>
/// Compute an ECDsa Signature
/// </summary>
/// <param name="message"></param>
/// <returns></returns>
public byte[]? SignData(byte[] message)
{
if (!cert.HasPrivateKey)
return null;
return cert.GetECDsaPrivateKey()?.SignData(message, HashAlgorithmName.SHA256);
}

/// <summary>
/// Verify an ECDsa Signature
/// </summary>
/// <param name="message"></param>
/// <param name="signature"></param>
/// <returns></returns>
public bool VerifyData(byte[] message, byte[] signature)
{
return cert.GetECDsaPublicKey()?.VerifyData(message, signature, HashAlgorithmName.SHA256) ?? false;
}

public string IssuerName { get; set; } = string.Empty;
public string IssuerName { get; private set; } = string.Empty;

public string CommonName { get; set; } = string.Empty;
public string CommonName { get; private set; } = string.Empty;

public ulong NodeID { get; set; }
public ulong NodeID { get; private set; }

public ulong FirmwareSigningID { get; set; }
public ulong FirmwareSigningID { get; private set; }

public ulong ICAC { get; set; }
public ulong ICAC { get; private set; }

public ulong RCAC { get; set; }
public ulong RCAC { get; protected set; }

public ulong FabricID { get; set; }
public ulong FabricID { get; protected set; }

public List<CASEAuthenticatedTag> Cats { get; set; } = [];
public List<CASEAuthenticatedTag> Cats { get; private set; } = [];

public uint VendorID { get; set; }
/// <summary>
/// Node Vendor ID
/// </summary>
public uint VendorID { get; private set; }

public uint ProductID { get; set; }
/// <summary>
/// Node Product ID
/// </summary>
public uint ProductID { get; private set; }

/// <summary>
/// Public ECDsa Key
/// </summary>
public byte[] PublicKey { get { return cert.GetPublicKey(); } }
}
}
2 changes: 1 addition & 1 deletion MatterDotNet/PayloadParser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Connection/IConnection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
6 changes: 3 additions & 3 deletions MatterDotNet/Protocol/Connection/MRPConnection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down Expand Up @@ -106,8 +106,8 @@ public async Task SendFrame(Exchange exchange, Frame frame, bool reliable)
public async Task SendAck(SessionContext? session, ushort exchange, uint counter, bool initiator)
{
Frame ack = new Frame(null, (byte)SecureOpCodes.MRPStandaloneAcknowledgement);
ack.SessionID = session?.RemoteSessionID ?? 0;
ack.Counter = session!.GetSessionCounter();
ack.SessionID = session!.RemoteSessionID;
ack.Counter = session.GetSessionCounter();
ack.Message.ExchangeID = exchange;
ack.Message.Flags = ExchangeFlags.Acknowledgement;
if (initiator)
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Connection/Retransmission.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Connection/TCPConnection.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Cryptography/AesCtr.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Cryptography/BigIntegerPoint.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Cryptography/CTR_DRBG.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Cryptography/Crypto.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Cryptography/SPAKE2Plus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Cryptography/SecP256.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/Flags/ExchangeFlags.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/Flags/MessageFlags.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/Flags/SecurityFlags.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/Frame.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/IPayload.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/OpCodes/BDXOpCodes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/OpCodes/IMOpCodes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/OpCodes/SecureOpCodes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/OpCodes/UDCOpCodes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/PayloadWriter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/ProtocolType.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
2 changes: 1 addition & 1 deletion MatterDotNet/Protocol/Payloads/Status/BDXStatusCodes.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// MatterDotNet Copyright (C) 2024
// MatterDotNet Copyright (C) 2025
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
Expand Down
Loading

0 comments on commit ef2901c

Please sign in to comment.