@@ -25,14 +25,15 @@ public class Fabric : OperationalCertificate
2525
2626 private Dictionary < ulong , OperationalCertificate > nodes = new Dictionary < ulong , OperationalCertificate > ( ) ;
2727
28- public Fabric ( ulong rcac , ulong fabricId , byte [ ] ipk ) : base ( )
28+ public Fabric ( string fabricName , ulong fabricId , byte [ ] ipk ) : base ( )
2929 {
3030 if ( fabricId == 0 )
3131 throw new ArgumentException ( "Invalid Fabric ID" ) ;
3232 if ( ipk . Length != 16 )
3333 throw new ArgumentException ( "Epoch Key must be 16 bytes" ) ;
34- this . RCAC = rcac ;
34+ this . RCAC = ( ulong ) Random . Shared . NextInt64 ( ) ;
3535 this . FabricID = fabricId ;
36+ this . CommonName = fabricName ;
3637 EpochKey = ipk ;
3738 X500DistinguishedNameBuilder builder = new X500DistinguishedNameBuilder ( ) ;
3839 builder . Add ( OID_RCAC , $ "{ RCAC : X16} ", UniversalTagNumber . UTF8String ) ;
@@ -45,17 +46,17 @@ public Fabric(ulong rcac, ulong fabricId, byte[] ipk) : base()
4546 req . CertificateExtensions . Add ( subjectKeyIdentifier ) ;
4647 req . CertificateExtensions . Add ( X509AuthorityKeyIdentifierExtension . CreateFromSubjectKeyIdentifier ( subjectKeyIdentifier ) ) ;
4748 this . cert = req . CreateSelfSigned ( DateTime . Now . Subtract ( TimeSpan . FromSeconds ( 30 ) ) , DateTime . Now . AddYears ( 10 ) ) ;
48- byte [ ] fabricIDBytes = new byte [ 8 ] ;
49- BinaryPrimitives . WriteUInt64BigEndian ( fabricIDBytes , FabricID ) ;
50- CompressedFabricID = Crypto . KDF ( PublicKey . AsSpan ( 1 ) , fabricIDBytes , COMPRESSED_FABRIC_INFO , 64 ) ;
51- OperationalIdentityProtectionKey = Crypto . KDF ( EpochKey , CompressedFabricID , Encoding . ASCII . GetBytes ( "GroupKey v1.0" ) , Crypto . SYMMETRIC_KEY_LENGTH_BITS ) ;
49+ GenerateIDs ( ) ;
5250 }
5351
54- protected Fabric ( X509Certificate2 cert , byte [ ] ipk )
52+ protected Fabric ( X509Certificate2 cert , byte [ ] ipk ) : base ( cert )
5553 {
56- this . cert = cert ;
5754 EpochKey = ipk ;
58- ParseCert ( ) ;
55+ GenerateIDs ( ) ;
56+ }
57+
58+ private void GenerateIDs ( )
59+ {
5960 byte [ ] fabricIDBytes = new byte [ 8 ] ;
6061 BinaryPrimitives . WriteUInt64BigEndian ( fabricIDBytes , FabricID ) ;
6162 CompressedFabricID = Crypto . KDF ( PublicKey . AsSpan ( 1 ) , fabricIDBytes , COMPRESSED_FABRIC_INFO , 64 ) ;
@@ -179,9 +180,9 @@ public byte[] ComputeDestinationID(byte[] random, ulong nodeId)
179180 return Crypto . HMAC ( OperationalIdentityProtectionKey , message ) ;
180181 }
181182
182- public byte [ ] CompressedFabricID { get ; init ; }
183+ public byte [ ] CompressedFabricID { get ; set ; }
183184 public OperationalCertificate ? Commissioner { get ; private set ; }
184- public byte [ ] OperationalIdentityProtectionKey { get ; init ; }
185+ public byte [ ] OperationalIdentityProtectionKey { get ; set ; }
185186 public byte [ ] EpochKey { get ; init ; }
186187 }
187188}
0 commit comments