Ejemplo n.º 1
0
 /// <summary>
 ///   Creates a new instance of the DsRecord class
 /// </summary>
 /// <param name="key"> The key, that should be covered </param>
 /// <param name="timeToLive"> Seconds the record should be cached at most </param>
 /// <param name="digestType"> Type of the digest </param>
 public DsRecord(DnsKeyRecord key, int timeToLive, DnsSecDigestType digestType)
     : base(key.Name, RecordType.Ds, key.RecordClass, timeToLive)
 {
     KeyTag     = key.CalculateKeyTag();
     Algorithm  = key.Algorithm;
     DigestType = digestType;
     Digest     = CalculateKeyHash(key);
 }
Ejemplo n.º 2
0
        internal bool IsCovering(DnsKeyRecord dnsKeyRecord)
        {
            if (dnsKeyRecord.Algorithm != Algorithm)
            {
                return(false);
            }

            if (dnsKeyRecord.CalculateKeyTag() != KeyTag)
            {
                return(false);
            }

            byte[] hash = CalculateKeyHash(dnsKeyRecord);

            return(StructuralComparisons.StructuralEqualityComparer.Equals(hash, Digest));
        }
Ejemplo n.º 3
0
        private byte[] CalculateKeyHash(DnsKeyRecord dnsKeyRecord)
        {
            byte[] buffer = new byte[dnsKeyRecord.Name.MaximumRecordDataLength + 2 + dnsKeyRecord.MaximumRecordDataLength];

            int currentPosition = 0;

            DnsMessageBase.EncodeDomainName(buffer, 0, ref currentPosition, dnsKeyRecord.Name, null, true);
            dnsKeyRecord.EncodeRecordData(buffer, 0, ref currentPosition, null, true);

            var hashAlgorithm = GetHashAlgorithm();

            hashAlgorithm.BlockUpdate(buffer, 0, currentPosition);

            byte[] hash = new byte[hashAlgorithm.GetDigestSize()];

            hashAlgorithm.DoFinal(hash, 0);
            return(hash);
        }
Ejemplo n.º 4
0
        internal RrSigRecord(List <DnsRecordBase> records, DnsKeyRecord key, DateTime inception, DateTime expiration)
            : base(records[0].Name, RecordType.RrSig, records[0].RecordClass, records[0].TimeToLive)
        {
            TypeCovered         = records[0].RecordType;
            Algorithm           = key.Algorithm;
            Labels              = (byte)(records[0].Name.Labels[0] == DomainName.Asterisk.Labels[0] ? records[0].Name.LabelCount - 1 : records[0].Name.LabelCount);
            OriginalTimeToLive  = records[0].TimeToLive;
            SignatureExpiration = expiration;
            SignatureInception  = inception;
            KeyTag              = key.CalculateKeyTag();
            SignersName         = key.Name;
            Signature           = new byte[] { };

            byte[] signBuffer;
            int    signBufferLength;

            EncodeSigningBuffer(records, out signBuffer, out signBufferLength);

            Signature = key.Sign(signBuffer, signBufferLength);
        }
Ejemplo n.º 5
0
        public static RrSigRecord SignRecord(List <DnsRecordBase> records, DnsKeyRecord key, DateTime inception, DateTime expiration)
        {
            RrSigRecord record = new RrSigRecord(records, key, inception, expiration);

            record.TypeCovered         = records[0].RecordType;
            record.Algorithm           = key.Algorithm;
            record.Labels              = (byte)(records[0].Name.Labels[0] == DomainName.Asterisk.Labels[0] ? records[0].Name.LabelCount - 1 : records[0].Name.LabelCount);
            record.OriginalTimeToLive  = records[0].TimeToLive;
            record.SignatureExpiration = expiration;
            record.SignatureInception  = inception;
            record.KeyTag              = key.CalculateKeyTag();
            record.SignersName         = key.Name;
            record.Signature           = new byte[] { };

            // byte[] signBuffer;
            // int signBufferLength;
            record.EncodeSigningBuffer(records, out byte[] signBuffer, out int signBufferLength);
            record.Signature = key.Sign(signBuffer, signBufferLength);

            return(record);
        }
Ejemplo n.º 6
0
		/// <summary>
		///   Creates a new instance of the DsRecord class
		/// </summary>
		/// <param name="key"> The key, that should be covered </param>
		/// <param name="timeToLive"> Seconds the record should be cached at most </param>
		/// <param name="digestType"> Type of the digest </param>
		public DsRecord(DnsKeyRecord key, int timeToLive, DnsSecDigestType digestType)
			: base(key.Name, RecordType.Ds, key.RecordClass, timeToLive)
		{
			KeyTag = key.CalculateKeyTag();
			Algorithm = key.Algorithm;
			DigestType = digestType;
			Digest = CalculateKeyHash(key);
		}
Ejemplo n.º 7
0
		private byte[] CalculateKeyHash(DnsKeyRecord dnsKeyRecord)
		{
			byte[] buffer = new byte[dnsKeyRecord.Name.MaximumRecordDataLength + 2 + dnsKeyRecord.MaximumRecordDataLength];

			int currentPosition = 0;

			DnsMessageBase.EncodeDomainName(buffer, 0, ref currentPosition, dnsKeyRecord.Name, null, true);
			dnsKeyRecord.EncodeRecordData(buffer, 0, ref currentPosition, null, true);

			var hashAlgorithm = GetHashAlgorithm();

			hashAlgorithm.BlockUpdate(buffer, 0, currentPosition);

			byte[] hash = new byte[hashAlgorithm.GetDigestSize()];

			hashAlgorithm.DoFinal(hash, 0);
			return hash;
		}
Ejemplo n.º 8
0
		internal bool IsCovering(DnsKeyRecord dnsKeyRecord)
		{
			if (dnsKeyRecord.Algorithm != Algorithm)
				return false;

			if (dnsKeyRecord.CalculateKeyTag() != KeyTag)
				return false;

			byte[] hash = CalculateKeyHash(dnsKeyRecord);

			return StructuralComparisons.StructuralEqualityComparer.Equals(hash, Digest);
		}