Commit f3ded302 authored by Brickner_cp's avatar Brickner_cp

DNS

parent c775ec22
...@@ -312,6 +312,11 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -312,6 +312,11 @@ namespace PcapDotNet.Packets.TestUtils
return new DnsResourceDataUri(random.NextUShort(), random.NextUShort(), return new DnsResourceDataUri(random.NextUShort(), random.NextUShort(),
((Func<DataSegment>)(() => random.NextDataSegment(random.NextInt(0, 100)))).GenerateArray(random.NextInt(0, 10))); ((Func<DataSegment>)(() => random.NextDataSegment(random.NextInt(0, 100)))).GenerateArray(random.NextInt(0, 10)));
case DnsType.Caa:
return new DnsResourceDataCertificationAuthorityAuthorization(random.NextFlags<DnsCertificationAuthorityAuthorizationFlags>(),
random.NextDataSegment(random.NextInt(0, 16)),
random.NextDataSegment(random.NextInt(0, 100)));
default: default:
return new DnsResourceDataAnything(random.NextDataSegment(random.Next(100))); return new DnsResourceDataAnything(random.NextDataSegment(random.Next(100)));
} }
......
...@@ -6618,4 +6618,118 @@ namespace PcapDotNet.Packets.Dns ...@@ -6618,4 +6618,118 @@ namespace PcapDotNet.Packets.Dns
return new DnsResourceDataUri(priority, weight, target); return new DnsResourceDataUri(priority, weight, target);
} }
} }
[Flags]
public enum DnsCertificationAuthorityAuthorizationFlags : byte
{
/// <summary>
/// If set, the critical flag is asserted and the property must be understood if the CAA record is to be correctly processed by a certificate issuer.
/// A Certification Authority must not issue certificates for any Domain that contains a CAA critical property for an unknown or unsupported property type that has the issuer flag set.
/// </summary>
Critical = 0x80,
}
/// <summary>
/// Hallam-Baker.
/// <pre>
/// +-----+----------+----------+------------+
/// | bit | 0 | 1-7 | 8-15 |
/// +-----+----------+----------+------------+
/// | 0 | Critical | Reserved | Tag Length |
/// +-----+----------+----------+------------+
/// | 16 | Tag |
/// | ... | |
/// +-----+----------------------------------+
/// | ... | Value |
/// +-----+----------------------------------+
/// </pre>
/// </summary>
[DnsTypeRegistration(Type = DnsType.Caa)]
public sealed class DnsResourceDataCertificationAuthorityAuthorization : DnsResourceDataSimple, IEquatable<DnsResourceDataCertificationAuthorityAuthorization>
{
private static class Offset
{
public const int Flags = 0;
public const int TagLength = Flags + sizeof(byte);
public const int Tag = TagLength + sizeof(byte);
}
private const int ConstantPartLength = Offset.Tag;
public DnsResourceDataCertificationAuthorityAuthorization(DnsCertificationAuthorityAuthorizationFlags flags, DataSegment tag, DataSegment value)
{
if (tag.Length > byte.MaxValue)
throw new ArgumentOutOfRangeException("tag", tag.Length, string.Format("Cannot be longer than {0}", byte.MaxValue));
Flags = flags;
Tag = tag;
Value = value;
}
/// <summary>
/// Flags of the record.
/// </summary>
public DnsCertificationAuthorityAuthorizationFlags Flags { get; private set; }
/// <summary>
/// The property identifier, a sequence of ASCII characters.
/// Tag values may contain ASCII characters a through z and the numbers 0 through 9.
/// Tag values must not contain any other characters.
/// Matching of tag values is case insensitive.
/// </summary>
public DataSegment Tag { get; private set; }
/// <summary>
/// Represents the property value.
/// Property values are encoded as binary values and may employ sub-formats.
/// </summary>
public DataSegment Value { get; private set; }
public bool Equals(DnsResourceDataCertificationAuthorityAuthorization other)
{
return other != null &&
Flags.Equals(other.Flags) &&
Tag.Equals(other.Tag) &&
Value.SequenceEqual(other.Value);
}
public override bool Equals(DnsResourceData other)
{
return Equals(other as DnsResourceDataCertificationAuthorityAuthorization);
}
internal DnsResourceDataCertificationAuthorityAuthorization()
: this(0, DataSegment.Empty, DataSegment.Empty)
{
}
internal override int GetLength()
{
return ConstantPartLength + Tag.Length + Value.Length;
}
internal override void WriteDataSimple(byte[] buffer, int offset)
{
buffer.Write(offset + Offset.Flags, (byte)Flags);
buffer.Write(offset + Offset.TagLength, (byte)Tag.Length);
Tag.Write(buffer, offset + Offset.Tag);
Value.Write(buffer, offset + ConstantPartLength + Tag.Length);
}
internal override DnsResourceData CreateInstance(DataSegment data)
{
if (data.Length < ConstantPartLength)
return null;
DnsCertificationAuthorityAuthorizationFlags flags = (DnsCertificationAuthorityAuthorizationFlags)data[Offset.Flags];
byte tagLength = data[Offset.TagLength];
int valueOffset = ConstantPartLength + tagLength;
if (data.Length < valueOffset)
return null;
DataSegment tag = data.SubSegment(Offset.Tag, tagLength);
DataSegment value = data.SubSegment(valueOffset, data.Length - valueOffset);
return new DnsResourceDataCertificationAuthorityAuthorization(flags, tag, value);
}
}
} }
...@@ -495,6 +495,7 @@ ...@@ -495,6 +495,7 @@
/// <summary> /// <summary>
/// Hallam-Baker. /// Hallam-Baker.
/// Certification Authority Authorization. /// Certification Authority Authorization.
/// Payload type: DnsResourceDataCertificationAuthorityAuthorization.
/// </summary> /// </summary>
Caa = 257, Caa = 257,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment