Пример #1
0
        /// <summary>
        /// Returns the number of keys in the package with the specified policy value
        /// </summary>
        ///
        /// <param name="KeyStream">The stream containing the VolumeKey</param>
        /// <param name="KeyPolicy">The key policy to search</param>
        ///
        /// <returns>The number of keys with that policy</returns>
        public static int KeyCount(Stream KeyStream, KeyPolicies KeyPolicy)
        {
            // get the header
            PackageKey pkey = new PackageKey(KeyStream);

            int count = 0;

            for (int i = 0; i < pkey.SubKeyID.Length; i++)
            {
                if (KeyHasPolicy(pkey.SubKeyPolicy[i], (long)KeyPolicy))
                {
                    count++;
                }
            }

            return(count);
        }
Пример #2
0
        /// <summary>
        /// KeyAuthority constructor.
        /// </summary>
        ///
        /// <param name="DomainId">Domain identity; a 16 byte field that can describe the domain, a description, or contain a secret shared by a group</param>
        /// <param name="OriginId">Origin identity; a unique 16 byte value identifying the node that created this key</param>
        /// <param name="PackageId">A unique 16 byte field used for storage or as identity of this package</param>
        /// <param name="PackageTag">A 32 byte field containing an optional package description or authentication code</param>
        /// <param name="KeyPolicy">A <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.KeyPolicies">KeyPolicy</see> master flag that contains the policy flags applied to each subkey set</param>
        /// <param name="OptionFlag">Used by KeyPolicy if the flag is set to <see cref="VTDev.Libraries.CEXEngine.Crypto.Enumeration.KeyPolicies.Volatile">Volatile</see>, set as the key expiration date/time in Ticks</param>
        /// <param name="TargetId">The hashed value of the targets origin id field, used to authenticate a target installation. A null value generates zeros.</param>
        public KeyAuthority(byte[] DomainId, byte[] OriginId, byte[] PackageId, byte[] PackageTag, KeyPolicies KeyPolicy, int OptionFlag = 0, byte[] TargetId = null)
        {
            this.DomainId = new byte[DOMAINID_SIZE];
            Array.Copy(DomainId, 0, this.DomainId, 0, DomainId.Length < DOMAINID_SIZE ? DomainId.Length : DOMAINID_SIZE);

            this.OriginId = new byte[ORIGINID_SIZE];
            Array.Copy(OriginId, 0, this.OriginId, 0, OriginId.Length < ORIGINID_SIZE ? OriginId.Length : ORIGINID_SIZE);

            this.TargetId = new byte[TARGETID_SIZE];
            if (TargetId != null)
            {
                Array.Copy(TargetId, 0, this.TargetId, 0, TargetId.Length < TARGETID_SIZE ? TargetId.Length : TARGETID_SIZE);
            }

            this.PackageId = new byte[PACKGID_SIZE];
            Array.Copy(PackageId, 0, this.PackageId, 0, PackageId.Length < PACKGID_SIZE ? PackageId.Length : PACKGID_SIZE);

            this.PackageTag = new byte[PACKGTAG_SIZE];
            Array.Copy(PackageTag, 0, this.PackageTag, 0, PackageTag.Length < PACKGTAG_SIZE ? PackageTag.Length : PACKGTAG_SIZE);

            this.KeyPolicy  = (int)KeyPolicy;
            this.OptionFlag = OptionFlag;
        }
Пример #3
0
        /// <summary>
        /// Returns the number of keys in the package with the specified policy value
        /// </summary>
        /// 
        /// <param name="KeyStream">The stream containing the VolumeKey</param>
        /// <param name="KeyPolicy">The key policy to search</param>
        /// 
        /// <returns>The number of keys with that policy</returns>
        public static int KeyCount(Stream KeyStream, KeyPolicies KeyPolicy)
        {
            // get the header
            PackageKey pkey = new PackageKey(KeyStream);

            int count = 0;
            for (int i = 0; i < pkey.SubKeyID.Length; i++)
            {
                if (KeyHasPolicy(pkey.SubKeyPolicy[i], (long)KeyPolicy))
                    count++;
            }

            return count;
        }
Пример #4
0
 private bool HasFlag(long Flags, KeyPolicies Policy)
 {
     return((Flags & (long)Policy) == (long)Policy);
 }
Пример #5
0
 private bool HasFlag(long Flags, KeyPolicies Policy)
 {
     return ((Flags & (long)Policy) == (long)Policy);
 }
Пример #6
0
 private void ClearPolicy(KeyPolicies KeyPolicy)
 {
     if (HasPolicy(KeyPolicy))
         _container.Authority.KeyPolicy &= ~(long)KeyPolicy;
 }
Пример #7
0
 private bool HasPolicy(KeyPolicies KeyPolicy)
 {
     return ((_container.Authority.KeyPolicy & (long)KeyPolicy) == (long)KeyPolicy);
 }
Пример #8
0
 private void SetPolicy(KeyPolicies KeyPolicy)
 {
     if (!HasPolicy(KeyPolicy))
         _container.Authority.KeyPolicy |= (long)KeyPolicy;
 }
Пример #9
0
        /// <summary>
        /// KeyAuthority constructor.
        /// </summary>
        /// 
        /// <param name="DomainId">Domain identity; a 16 byte field that can describe the domain, a description, or contain a secret shared by a group</param>
        /// <param name="OriginId">Origin identity; a unique 16 byte value identifying the node that created this key</param>
        /// <param name="PackageId">A unique 16 byte field used for storage or as identity of this package</param>
        /// <param name="PackageTag">A 32 byte field containing an optional package description or authentication code</param>
        /// <param name="KeyPolicy">A <see cref="KeyPolicies">KeyPolicy</see> master flag that contains the policy flags applied to each subkey set</param>
        /// <param name="OptionFlag">Used by KeyPolicy if the flag is set to <see cref="KeyPolicies.Volatile">Volatile</see>, set as the key expiration date/time in Ticks</param>
        /// <param name="TargetId">The hashed value of the targets origin id field, used to authenticate a target installation. A null value generates zeros.</param>
        public KeyAuthority(byte[] DomainId, byte[] OriginId, byte[] PackageId, byte[] PackageTag, KeyPolicies KeyPolicy, int OptionFlag = 0, byte[] TargetId = null)
        {
            this.DomainId = new byte[DOMAINID_SIZE];
            Array.Copy(DomainId, 0, this.DomainId, 0, DomainId.Length < DOMAINID_SIZE ? DomainId.Length : DOMAINID_SIZE);

            this.OriginId = new byte[ORIGINID_SIZE];
            Array.Copy(OriginId, 0, this.OriginId, 0, OriginId.Length < ORIGINID_SIZE ? OriginId.Length : ORIGINID_SIZE);

            this.TargetId = new byte[TARGETID_SIZE];
            if (TargetId != null)
                Array.Copy(TargetId, 0, this.TargetId, 0, TargetId.Length < TARGETID_SIZE ? TargetId.Length : TARGETID_SIZE);

            this.PackageId = new byte[PACKGID_SIZE];
            Array.Copy(PackageId, 0, this.PackageId, 0, PackageId.Length < PACKGID_SIZE ? PackageId.Length : PACKGID_SIZE);

            this.PackageTag = new byte[PACKGTAG_SIZE];
            Array.Copy(PackageTag, 0, this.PackageTag, 0, PackageTag.Length < PACKGTAG_SIZE ? PackageTag.Length : PACKGTAG_SIZE);

            this.KeyPolicy = (int)KeyPolicy;
            this.OptionFlag = OptionFlag;
        }