Beispiel #1
0
        public override void CopyTo(PACSAMKeyRecord to, bool includeKey = false)
        {
            base.CopyTo(to);

            if (includeKey)
            {
                if (IAKey == null)
                {
                    throw new ApplicationException(@"The 'IAKey' element of an initialised key is missing.");
                }

                if (IAKey.P == null ||
                    IAKey.Q == null ||
                    IAKey.PQ == null ||
                    IAKey.DP == null ||
                    IAKey.DQ == null ||
                    IAKey.Modulus == null ||
                    IAKey.Exponent == null)
                {
                    throw new ApplicationException(@"One or more 'IAKey' sub-elements of an initialised key are missing.");
                }

                if (FAKey == null)
                {
                    throw new ApplicationException(@"The 'FAKey' element of an initialised key is missing.");
                }

                (to as PACSAMPlaidKeyRecord).IAKey = new RSAKey(IAKey);
                (to as PACSAMPlaidKeyRecord).FAKey = FAKey.ToArray();
            }
        }
Beispiel #2
0
        public override void ImportParts(params PACSAMKeyRecord[] parts)
        {
            // There must be at least 3 or more parts
            if (parts.Length < 3)
            {
                throw new ArgumentException(@"ExportParts: There must be at 3 or more parts to export to!");
            }

            for (int i = 1; i < parts.Length; i++)
            {
                // Validate each part has the same hash
                if (!parts[i].Hash.SequenceEqual(parts[0].Hash))
                {
                    throw new InvalidDataException(@"ImportParts: Hash values do not match for supplied key parts");
                }
            }

            // Copy the basic information from the first part
            parts[0].CopyTo(this);

            var p0 = (parts[0] as PACSAMKeyFile);

            for (int i = 0; i < p0.Records.Count; i++)
            {
                PACSAMKeyRecord   record   = p0.Records[i].Clone();
                PACSAMKeyRecord[] keyParts = new PACSAMKeyRecord[parts.Length];

                for (int j = 0; j < parts.Length; j++)
                {
                    keyParts[j] = (parts[j] as PACSAMKeyFile).Records[i];

                    if (!keyParts[j].Name.Equals(record.Name))
                    {
                        throw new InvalidDataException(@"Key name mismatch while importing '" + record.Name + "' (possibly out of order).");
                    }
                }

                // Import
                try
                {
                    record.ImportParts(keyParts);
                }
                catch (Exception ex)
                {
                    throw new InvalidDataException(ex.Message + " (Key Name: " + record.Name + ")");
                }

                // Add
                Records.Add(record);
            }

            // Import the SystemIdentifier
            for (int i = 1; i < parts.Length; i++)
            {
                var pI = (parts[i] as PACSAMKeyFile);
                SystemDiversifier = Crypto.XorArray(SystemDiversifier, pI.SystemDiversifier);
            }
        }
Beispiel #3
0
        public override void CopyTo(PACSAMKeyRecord to, bool includeKey = false)
        {
            base.CopyTo(to);

            if (includeKey)
            {
                (to as PACSAMTDEA2KeyRecord).Value = Value.ToArray();
            }
        }
Beispiel #4
0
 public virtual void CopyTo(PACSAMKeyRecord to, bool includeKey = false)
 {
     to.Id      = Id;
     to.Version = Version;
     to.Name    = Name;
     to.Hash    = Hash.ToArray();
     if (Attributes != null)
     {
         to.Attributes = Attributes;
     }
 }
Beispiel #5
0
        public override void CopyTo(PACSAMKeyRecord to, bool includeKey = false)
        {
            base.CopyTo(to);

            (to as PACSAMKeyFile).Part              = Part;
            (to as PACSAMKeyFile).PartCount         = PartCount;
            (to as PACSAMKeyFile).SystemDiversifier = SystemDiversifier.ToArray();

            // Overwrite the attribute field to None (doesn't apply)
            (to as PACSAMKeyFile).Attributes = PACSAMKeyAttribute.None;
        }
Beispiel #6
0
        public override void ExportParts(params PACSAMKeyRecord[] parts)
        {
            // There must be at least 3 or more parts
            if (parts.Length < 3)
            {
                throw new ArgumentException(@"ExportParts: There must be at 3 or more parts to export to!");
            }

            // Create the resulting keyfile parts
            for (int i = 0; i < parts.Length; i++)
            {
                // Generate the part
                parts[i] = new PACSAMKeyFile(this);
            }

            // Export each key
            foreach (var record in Records)
            {
                PACSAMKeyRecord[] keyParts = new PACSAMKeyRecord[parts.Length];

                // Generate the key parts
                record.ExportParts(keyParts);
                for (int i = 0; i < parts.Length; i++)
                {
                    var pI = (parts[i] as PACSAMKeyFile);
                    pI.Records.Add(keyParts[i]);
                }
            }

            // Export the SystemIdentifier
            for (int i = 1; i < parts.Length; i++)
            {
                var pI = (parts[i] as PACSAMKeyFile);
                var p0 = (parts[0] as PACSAMKeyFile);

                pI.SystemDiversifier = Crypto.CreateRandomEntropy(SystemDiversifier.Length);
                p0.SystemDiversifier = Crypto.XorArray(p0.SystemDiversifier, pI.SystemDiversifier);
            }

            // Set the Part and PartCount values
            for (int i = 0; i < parts.Length; i++)
            {
                (parts[i] as PACSAMKeyFile).Part      = (i + 1);
                (parts[i] as PACSAMKeyFile).PartCount = parts.Length;
            }
        }