/// <summary>
 /// Creates an instance from vendor id, subtype and data.
 /// </summary>
 /// <param name="vendorId">
 /// The SMI Network Management Private Enterprise Code of the IANA- maintained Private Enterprise Numbers registry.
 /// See http://www.iana.org/assignments/enterprise-numbers/enterprise-numbers
 /// </param>
 /// <param name="subtype">
 /// Indicating the type of vendor-specific information carried in the option.
 /// The administration of the Sub-type is done by the Vendor.
 /// </param>
 /// <param name="data">Vendor-specific data that is carried in this message.</param>
 public IpV6MobilityOptionVendorSpecific(uint vendorId, byte subtype, DataSegment data)
     : base(IpV6MobilityOptionType.VendorSpecific)
 {
     VendorId = vendorId;
     Subtype = subtype;
     Data = data;
 }
 public IpV6OptionSmfDpdSequenceHashAssistValue(DataSegment data)
 {
     byte[] hashAssistValueBuffer = new byte[data.Length - Offset.HashAssistValue];
     data.Buffer.BlockCopy(data.StartOffset + Offset.HashAssistValue, hashAssistValueBuffer, 0, hashAssistValueBuffer.Length);
     hashAssistValueBuffer[0] &= 0x7F;
     HashAssistValue = new DataSegment(hashAssistValueBuffer);
 }
 internal override IpV6Option CreateInstance(DataSegment data)
 {
     if (data.Length != OptionDataLength)
         return null;
     IpV6Address homeAddress = data.ReadIpV6Address(0, Endianity.Big);
     return new IpV6OptionHomeAddress(homeAddress);
 }
        internal override IpV6Option CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
                return null;

            return new IpV6OptionTunnelEncapsulationLimit(data[0]);
        }
 /// <summary>
 /// Creates an instance from status, remove and mobile node identity.
 /// </summary>
 /// <param name="status">
 /// Indicating the result of the dynamic DNS update procedure.
 /// This field must be set to 0 and ignored by the receiver when the DNS Update mobility option is included in a Binding Update message.
 /// When the DNS Update mobility option is included in the Binding Acknowledgement message, 
 /// values of the Status field less than 128 indicate that the dynamic DNS update was performed successfully by the Home Agent.
 /// Values greater than or equal to 128 indicate that the dynamic DNS update was not completed by the HA.
 /// </param>
 /// <param name="remove">
 /// Whether the Mobile Node is requesting the HA to remove the DNS entry identified by the FQDN specified in this option and the HoA of the Mobile Node.
 /// If false, the Mobile Node is requesting the HA to create or update a DNS entry with its HoA and the FQDN specified in the option.
 /// </param>
 /// <param name="mobileNodeIdentity">
 /// The identity of the Mobile Node in FQDN format to be used by the Home Agent to send a Dynamic DNS update.
 /// </param>
 public IpV6MobilityOptionDnsUpdate(IpV6DnsUpdateStatus status, bool remove, DataSegment mobileNodeIdentity)
     : base(IpV6MobilityOptionType.DnsUpdate)
 {
     Status = status;
     Remove = remove;
     MobileNodeIdentity = mobileNodeIdentity;
 }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length < MinIdentifierLength || data.Length > MaxIdentifierLength)
                return null;

            return new IpV6MobilityOptionServiceSelection(data);
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length < OptionDataMinimumLength)
                return null;

            IpV6LocalMobilityAnchorAddressCode code = (IpV6LocalMobilityAnchorAddressCode)data[Offset.Code];
            switch (code)
            {
                case IpV6LocalMobilityAnchorAddressCode.IpV6:
                {
                    if (data.Length != Offset.LocalMobilityAnchorAddress + IpV6Address.SizeOf)
                        return null;
                    IpV6Address localMobilityAnchorAddress = data.ReadIpV6Address(Offset.LocalMobilityAnchorAddress, Endianity.Big);
                    return new IpV6MobilityOptionLocalMobilityAnchorAddress(localMobilityAnchorAddress);
                }

                case IpV6LocalMobilityAnchorAddressCode.IpV4:
                {
                    if (data.Length != Offset.LocalMobilityAnchorAddress + IpV4Address.SizeOf)
                        return null;
                    IpV4Address localMobilityAnchorAddress = data.ReadIpV4Address(Offset.LocalMobilityAnchorAddress, Endianity.Big);
                    return new IpV6MobilityOptionLocalMobilityAnchorAddress(localMobilityAnchorAddress);
                }

                default:
                    return null;
            }
        }
 public IpV6ExtensionHeaderEncapsulatingSecurityPayload(uint securityParametersIndex, uint sequenceNumber, DataSegment encryptedDataAndAuthenticationData)
     : base(null)
 {
     SecurityParametersIndex = securityParametersIndex;
     SequenceNumber = sequenceNumber;
     EncryptedDataAndAuthenticationData = encryptedDataAndAuthenticationData;
 }
 public IpV6ExtensionHeaderAuthentication(IpV4Protocol nextHeader, uint securityParametersIndex, uint sequenceNumber, DataSegment authenticationData)
     : base(nextHeader)
 {
     SecurityParametersIndex = securityParametersIndex;
     SequenceNumber = sequenceNumber;
     AuthenticationData = authenticationData;
 }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
                return null;

            return new IpV6MobilityOptionRedirectCapability();
        }
        internal override IpV6Option CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
                return null;

            return new IpV6OptionRouterAlert((IpV6RouterAlertType)data.ReadUShort(0, Endianity.Big));
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
                return null;

            return new IpV6MobilityOptionCryptographicallyGeneratedAddressParametersRequest();
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length < OptionDataMinimumLength)
                return null;

            bool isIpV4 = data.ReadBool(Offset.IsIpV4, Mask.IsIpV4);
            bool isIpV6 = data.ReadBool(Offset.IsIpV6, Mask.IsIpV6);

            if (isIpV4 && !isIpV6)
            {
                if (data.Length != OptionDataMinimumLength + IpV4Address.SizeOf)
                    return null;
                IpV4Address localMobilityAddress = data.ReadIpV4Address(Offset.LocalMobilityAddress, Endianity.Big);
                return new IpV6MobilityOptionRedirect(localMobilityAddress);
            }
            if (isIpV6 && !isIpV4)
            {
                if (data.Length != OptionDataMinimumLength + IpV6Address.SizeOf)
                    return null;
                IpV6Address localMobilityAddress = data.ReadIpV6Address(Offset.LocalMobilityAddress, Endianity.Big);
                return new IpV6MobilityOptionRedirect(localMobilityAddress);
            }

            return null;
        }
Esempio n. 14
0
        private static IpV6ExtensionHeader CreateStandardInstance(IpV4Protocol nextHeader, DataSegment extensionHeaderData, out int numBytesRead)
        {
            numBytesRead = 0;
            if (extensionHeaderData.Length < MinimumLength)
                return null;
            IpV4Protocol nextNextHeader = (IpV4Protocol)extensionHeaderData[Offset.NextHeader];
            int length = (extensionHeaderData[Offset.HeaderExtensionLength] + 1) * 8;
            if (extensionHeaderData.Length < length)
                return null;

            DataSegment data = extensionHeaderData.Subsegment(Offset.Data, length - Offset.Data);
            numBytesRead = data.Length;

            switch (nextHeader)
            {
                case IpV4Protocol.IpV6HopByHopOption: // 0
                    return IpV6ExtensionHeaderHopByHopOptions.ParseData(nextNextHeader, data);

                case IpV4Protocol.IpV6Route: // 43
                    return IpV6ExtensionHeaderRouting.ParseData(nextNextHeader, data);

                case IpV4Protocol.FragmentHeaderForIpV6: // 44
                    return IpV6ExtensionHeaderFragmentData.ParseData(nextNextHeader, data);
                
                case IpV4Protocol.IpV6Opts:                     // 60
                    return IpV6ExtensionHeaderDestinationOptions.ParseData(nextNextHeader, data);

                case IpV4Protocol.MobilityHeader:        // 135
                    return IpV6ExtensionHeaderMobility.ParseData(nextNextHeader, data);

                default:
                    throw new InvalidOperationException("Invalid nextHeader value" + nextHeader);
            }
        }
 /// <summary>
 /// Creates an instance from subtype, mobility security parameter index and authentication data.
 /// </summary>
 /// <param name="subtype">A number assigned to identify the entity and/or mechanism to be used to authenticate the message.</param>
 /// <param name="mobilitySecurityParameterIndex">
 /// A number in the range [0-4294967296] used to index into the shared-key-based mobility security associations.
 /// </param>
 /// <param name="authenticationData">
 /// Has the information to authenticate the relevant mobility entity.
 /// This protects the message beginning at the Mobility Header up to and including the mobility SPI field.
 /// </param>
 public IpV6MobilityOptionAuthentication(IpV6AuthenticationSubtype subtype, uint mobilitySecurityParameterIndex, DataSegment authenticationData)
     : base(IpV6MobilityOptionType.Authentication)
 {
     Subtype = subtype;
     MobilitySecurityParameterIndex = mobilitySecurityParameterIndex;
     AuthenticationData = authenticationData;
 }
        internal override IpV6Option CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
                return null;

            return new IpV6OptionJumboPayload(data.ReadUInt(0, Endianity.Big));
        }
 public static void ReadData(DataSegment data, out IpV4OptionQuickStartFunction function, out byte rate, out byte ttl, out uint nonce)
 {
     function = (IpV4OptionQuickStartFunction)(data[Offset.Function] & Mask.Function);
     rate = (byte)(data[Offset.Rate] & Mask.Rate);
     ttl = data[Offset.Ttl];
     nonce = data.ReadUInt(Offset.Nonce, Endianity.Big);
 }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
                return null;

            return new IpV6MobilityOptionBindingRefreshAdvice(data.ReadUShort(0, Endianity.Big));
        }
        internal static IpV6ExtensionHeaderRouting ParseData(IpV4Protocol nextHeader, DataSegment data)
        {
            if (data.Length < DataMinimumLength)
                return null;
            IpV6RoutingType routingType = (IpV6RoutingType)data[DataOffset.RoutingType];
            byte segmentsLeft = data[DataOffset.SegmentsLeft];
            DataSegment routingData = data.Subsegment(DataOffset.TypeSpecificData, data.Length - DataOffset.TypeSpecificData);
            switch (routingType)
            {
                case IpV6RoutingType.SourceRoute:
                    return IpV6ExtensionHeaderRoutingSourceRoute.ParseRoutingData(nextHeader, segmentsLeft, routingData);

                case IpV6RoutingType.Nimrod:
                    // Unused.
                    return null;

                case IpV6RoutingType.Type2RoutingHeader:
                    return IpV6ExtensionHeaderRoutingHomeAddress.ParseRoutingData(nextHeader, segmentsLeft, routingData);

                case IpV6RoutingType.RoutingProtocolLowPowerAndLossyNetworksSourceRouteHeader:
                    return IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks.ParseRoutingData(nextHeader, segmentsLeft, routingData);

                default:
                    return null;
            }
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
                return null;

            return new IpV6MobilityOptionAlternateIpV4CareOfAddress(data.ReadIpV4Address(0, Endianity.Big));
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
                return null;

            return new IpV6MobilityOptionCareOfTestInit();
        }
        internal override DnsResourceData CreateInstance(DataSegment data)
        {
            List<DataSegment> strings = ReadStrings(data, NumStrings);
            if (strings == null || strings.Count != NumStrings)
                return null;

            return new DnsResourceDataHostInformation(strings[0], strings[1]);
        }
        internal static IpV6ExtensionHeaderMobilityFastNeighborAdvertisement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            if (messageData.Length < MinimumMessageDataLength)
                return null;

            IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options));
            return new IpV6ExtensionHeaderMobilityFastNeighborAdvertisement(nextHeader, checksum, options);
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            byte value;
            if (!Read(data, out value))
                return null;

            return new IpV6MobilityOptionHandoffIndicator((IpV6HandoffIndicator)value);
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            IpV6Address linkLocalAddress;
            if (!Read(data, out linkLocalAddress))
                return null;

            return new IpV6MobilityOptionLinkLocalAddress(linkLocalAddress);
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            IpV4Address careOfAddress;
            if (!Read(data, out careOfAddress))
                return null;

            return new IpV6MobilityOptionIpV4CareOfAddress(careOfAddress);
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            if (data.Length != OptionDataLength)
                return null;

            uint greKeyIdentifier = data.ReadUInt(Offset.GreKeyIdentifier, Endianity.Big);
            return new IpV6MobilityOptionGreKey(greKeyIdentifier);
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            byte value;
            if (!Read(data, out value))
                return null;

            return new IpV6MobilityOptionAccessTechnologyType((IpV6AccessTechnologyType)value);
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            IpV6Address alternateCareOfAddress;
            if (!Read(data, out alternateCareOfAddress))
                return null;

            return new IpV6MobilityOptionAlternateCareOfAddress(alternateCareOfAddress);
        }
        internal override IpV6MobilityOption CreateInstance(DataSegment data)
        {
            ulong careOfKeygenToken;
            if (!Read(data, out careOfKeygenToken))
                return null;

            return new IpV6MobilityOptionCareOfTest(careOfKeygenToken);
        }
        internal static IpV6ExtensionHeaderRoutingHomeAddress ParseRoutingData(IpV4Protocol nextHeader, byte segmentsLeft, DataSegment routingData)
        {
            if (routingData.Length != ConstRoutingDataLength)
            {
                return(null);
            }

            IpV6Address homeAddress = routingData.ReadIpV6Address(RoutingDataOffset.HomeAddress, Endianity.Big);

            return(new IpV6ExtensionHeaderRoutingHomeAddress(nextHeader, segmentsLeft, homeAddress));
        }
        public DnsResourceDataCertificationAuthorityAuthorization(DnsCertificationAuthorityAuthorizationFlags flags, DataSegment tag, DataSegment value)
        {
            if (tag == null)
            {
                throw new ArgumentNullException("tag");
            }

            if (tag.Length > byte.MaxValue)
            {
                throw new ArgumentOutOfRangeException("tag", tag.Length, string.Format(CultureInfo.InvariantCulture, "Cannot be longer than {0}", byte.MaxValue));
            }

            Flags = flags;
            Tag   = tag;
            Value = value;
        }
Esempio n. 33
0
 public DnsResourceDataCertificationAuthorityAuthorization(DnsCertificationAuthorityAuthorizationFlags flags, DataSegment tag, DataSegment value)
 {
     if (tag == null)
     {
         throw new ArgumentNullException("tag");
     }
     if (tag.Length > (int)byte.MaxValue)
     {
         throw new ArgumentOutOfRangeException("tag", (object)tag.Length, string.Format((IFormatProvider)CultureInfo.InvariantCulture, "Cannot be longer than {0}", new object[1]
         {
             (object)byte.MaxValue
         }));
     }
     this.Flags = flags;
     this.Tag   = tag;
     this.Value = value;
 }
Esempio n. 34
0
 public IpV6OptionIlnpNonce(DataSegment nonce)
     : base(IpV6OptionType.IlnpNonce)
 {
     Nonce = nonce;
 }
Esempio n. 35
0
 public IpV6OptionSmfDpdIpV4(IpV4Address taggerId, DataSegment identifier)
     : base(identifier)
 {
     TaggerId = taggerId;
 }
Esempio n. 36
0
        internal static IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks ParseRoutingData(IpV4Protocol nextHeader, byte segmentsLeft, DataSegment routingData)
        {
            if (routingData.Length < RoutingDataMinimumLength)
            {
                return(null);
            }

            byte commonPrefixLengthForNonLastAddresses =
                (byte)((routingData[RoutingDataOffset.CommonPrefixLengthForNonLastAddresses] & RoutingDataMask.CommonPrefixLengthForNonLastAddresses) >>
                       RoutingDataShift.CommonPrefixLengthForNonLastAddresses);

            if (commonPrefixLengthForNonLastAddresses > MaxCommonPrefixLength)
            {
                return(null);
            }

            byte commonPrefixLengthForLastAddress =
                (byte)(routingData[RoutingDataOffset.CommonPrefixLengthForLastAddress] & RoutingDataMask.CommonPrefixLengthForLastAddress);

            if (commonPrefixLengthForLastAddress > MaxCommonPrefixLength)
            {
                return(null);
            }

            byte padSize = (byte)((routingData[RoutingDataOffset.PadSize] & RoutingDataMask.PadSize) >> RoutingDataShift.PadSize);

            if (padSize > MaxPadSize)
            {
                return(null);
            }

            int addressesLength = routingData.Length - RoutingDataOffset.Addresses - padSize;
            int numAddresses    = addressesLength == 0
                                   ? 0
                                   : (addressesLength - (IpV6Address.SizeOf - commonPrefixLengthForLastAddress)) /
                                  (IpV6Address.SizeOf - commonPrefixLengthForNonLastAddresses) + 1;

            if (numAddresses < 0)
            {
                return(null);
            }

            IpV6Address[] addresses = new IpV6Address[numAddresses];
            if (numAddresses > 0)
            {
                byte[] addressBytes = new byte[IpV6Address.SizeOf];
                for (int i = 0; i < numAddresses - 1; ++i)
                {
                    DataSegment addressSegment =
                        routingData.Subsegment(RoutingDataOffset.Addresses + i * (IpV6Address.SizeOf - commonPrefixLengthForNonLastAddresses),
                                               IpV6Address.SizeOf - commonPrefixLengthForNonLastAddresses);
                    addressSegment.Write(addressBytes, commonPrefixLengthForNonLastAddresses);
                    addresses[i] = addressBytes.ReadIpV6Address(0, Endianity.Big);
                }

                addressBytes = new byte[IpV6Address.SizeOf];
                DataSegment lastAddressSegment =
                    routingData.Subsegment(RoutingDataOffset.Addresses + (numAddresses - 1) * (IpV6Address.SizeOf - commonPrefixLengthForNonLastAddresses),
                                           IpV6Address.SizeOf - commonPrefixLengthForLastAddress);
                lastAddressSegment.Write(addressBytes, commonPrefixLengthForLastAddress);
                addresses[numAddresses - 1] = addressBytes.ReadIpV6Address(0, Endianity.Big);
            }
            return(new IpV6ExtensionHeaderRoutingProtocolLowPowerAndLossyNetworks(nextHeader, segmentsLeft, commonPrefixLengthForNonLastAddresses,
                                                                                  commonPrefixLengthForLastAddress, addresses));
        }
 public DnsResourceDataNextDomainSecure3Parameters(DnsSecNSec3HashAlgorithm hashAlgorithm, DnsSecNSec3Flags flags, ushort iterations, DataSegment salt)
     : base(hashAlgorithm, flags, iterations, salt)
 {
 }
Esempio n. 38
0
        internal static IpV6ExtensionHeaderMobilityFastBindingAcknowledgement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            IpV6BindingAcknowledgementStatus status;
            bool   keyManagementMobilityCapability;
            ushort sequenceNumber;
            ushort lifetime;
            IpV6MobilityOptions options;

            if (!ParseMessageDataFields(messageData, out status, out keyManagementMobilityCapability, out sequenceNumber, out lifetime, out options))
            {
                return(null);
            }

            return(new IpV6ExtensionHeaderMobilityFastBindingAcknowledgement(nextHeader, checksum, status, keyManagementMobilityCapability, sequenceNumber,
                                                                             lifetime, options));
        }
Esempio n. 39
0
        /// <summary>
        /// Constructs an instance out of the address family, prefix length, negation and address family dependent part fields.
        /// </summary>
        /// <param name="addressFamily">The address family value.</param>
        /// <param name="prefixLength">
        /// Prefix length.
        /// Upper and lower bounds and interpretation of this value are address family specific.
        ///
        /// For IPv4, specifies the number of bits of the IPv4 address starting at the most significant bit.
        /// Legal values range from 0 to 32.
        ///
        /// For IPv6, specifies the number of bits of the IPv6 address starting at the most significant bit.
        /// Legal values range from 0 to 128.
        /// </param>
        /// <param name="negation">Negation flag, indicates the presence of the "!" character in the textual format.</param>
        /// <param name="addressFamilyDependentPart">
        /// For IPv4, the encoding follows the encoding specified for the A RR by RFC 1035.
        /// Trailing zero octets do not bear any information (e.g., there is no semantic difference between 10.0.0.0/16 and 10/16) in an address prefix,
        /// so the shortest possible AddressFamilyDependentPart can be used to encode it.
        /// However, for DNSSEC (RFC 2535) a single wire encoding must be used by all.
        /// Therefore the sender must not include trailing zero octets in the AddressFamilyDependentPart regardless of the value of PrefixLength.
        /// This includes cases in which AddressFamilyDependentPart length times 8 results in a value less than PrefixLength.
        /// The AddressFamilyDependentPart is padded with zero bits to match a full octet boundary.
        /// An IPv4 AddressFamilyDependentPart has a variable length of 0 to 4 octets.
        ///
        /// For IPv6, the 128 bit IPv6 address is encoded in network byte order (high-order byte first).
        /// The sender must not include trailing zero octets in the AddressFamilyDependentPart regardless of the value of PrefixLength.
        /// This includes cases in which AddressFamilyDependentPart length times 8 results in a value less than PrefixLength.
        /// The AddressFamilyDependentPart is padded with zero bits to match a full octet boundary.
        /// An IPv6 AddressFamilyDependentPart has a variable length of 0 to 16 octets.
        /// </param>
        public DnsAddressPrefix(AddressFamily addressFamily, byte prefixLength, bool negation, DataSegment addressFamilyDependentPart)
        {
            if (addressFamilyDependentPart == null)
            {
                throw new ArgumentNullException("addressFamilyDependentPart");
            }

            if (addressFamilyDependentPart.Length > AddressFamilyDependentPartMaxLength)
            {
                throw new ArgumentOutOfRangeException("addressFamilyDependentPart", addressFamilyDependentPart, "Cannot be longer than " + AddressFamilyDependentPartMaxLength);
            }

            AddressFamily = addressFamily;
            PrefixLength  = prefixLength;
            Negation      = negation;
            AddressFamilyDependentPart = addressFamilyDependentPart;
        }
Esempio n. 40
0
 internal override DnsResourceData CreateInstance(DataSegment data)
 {
     return((DnsResourceData) new DnsResourceDataAnything(data));
 }
Esempio n. 41
0
 public DnsResourceDataAnything(DataSegment data)
 {
     this.Data = data;
 }
Esempio n. 42
0
 public DnsResourceDataAnything()
 {
     this.Data = DataSegment.Empty;
 }
Esempio n. 43
0
 /// <summary>
 /// Constructs an ISDN resource data from the ISDN address and subaddress.
 /// </summary>
 /// <param name="isdnAddress">
 /// Identifies the ISDN number of the owner and DDI (Direct Dial In) if any, as defined by E.164 and E.163,
 /// the ISDN and PSTN (Public Switched Telephone Network) numbering plan.
 /// E.163 defines the country codes, and E.164 the form of the addresses.
 /// </param>
 /// <param name="subaddress">Specifies the subaddress (SA).</param>
 public DnsResourceDataIsdn(DataSegment isdnAddress, DataSegment subaddress)
     : base(isdnAddress, subaddress)
 {
 }
Esempio n. 44
0
 /// <summary>
 /// Constructs an instance out of the precedence, gateway, algorithm and public key fields.
 /// </summary>
 /// <param name="precedence">
 /// Precedence for this record.
 /// Gateways listed in IPSECKEY records with lower precedence are to be attempted first.
 /// Where there is a tie in precedence, the order should be non-deterministic.
 /// </param>
 /// <param name="gateway">
 /// Indicates a gateway to which an IPsec tunnel may be created in order to reach the entity named by this
 /// resource record.
 /// </param>
 /// <param name="algorithm">Identifies the public key's cryptographic algorithm and determines the format of the public key field.</param>
 /// <param name="publicKey">Contains the algorithm-specific portion of the KEY RR RDATA.</param>
 public DnsResourceDataIpSecKey(byte precedence, DnsGateway gateway, DnsPublicKeyAlgorithm algorithm, DataSegment publicKey)
 {
     Precedence = precedence;
     Gateway    = gateway;
     Algorithm  = algorithm;
     PublicKey  = publicKey;
 }
Esempio n. 45
0
 public DnsOptionClientSubnet(AddressFamily family, byte sourceMask, byte scopeNetmask, DataSegment address)
     : base(DnsOptionCode.ClientSubnet)
 {
     Family        = family;
     SourceNetmask = sourceMask;
     ScopeNetmask  = scopeNetmask;
     Address       = address;
 }
 public DnsResourceDataHostInformation(DataSegment cpu, DataSegment os)
     : base(cpu, os)
 {
 }
Esempio n. 47
0
        internal static IpV6ExtensionHeaderHopByHopOptions ParseData(IpV4Protocol nextHeader, DataSegment data)
        {
            IpV6Options options = new IpV6Options(data);

            return(new IpV6ExtensionHeaderHopByHopOptions(nextHeader, options));
        }
Esempio n. 48
0
        public static IpV6Option NextIpV6Option(this Random random)
        {
            IpV6OptionType optionType = random.NextEnum <IpV6OptionType>();

            switch (optionType)
            {
            case IpV6OptionType.Pad1:
                return(new IpV6OptionPad1());

            case IpV6OptionType.PadN:
                return(new IpV6OptionPadN(random.Next(10)));

            case IpV6OptionType.JumboPayload:
                return(new IpV6OptionJumboPayload(random.NextUInt()));

            case IpV6OptionType.TunnelEncapsulationLimit:
                return(new IpV6OptionTunnelEncapsulationLimit(random.NextByte()));

            case IpV6OptionType.RouterAlert:
                return(new IpV6OptionRouterAlert(random.NextEnum <IpV6RouterAlertType>()));

            case IpV6OptionType.QuickStart:
                return(new IpV6OptionQuickStart(random.NextEnum <IpV4OptionQuickStartFunction>(),
                                                random.NextByte(IpOptionQuickStartCommon.RateMaximumValue + 1), random.NextByte(),
                                                random.NextUInt() & 0x3FFFFFFF));

            case IpV6OptionType.Calipso:
                return(new IpV6OptionCalipso(random.NextEnum <IpV6CalipsoDomainOfInterpretation>(), random.NextByte(), random.NextUShort(),
                                             random.NextDataSegment(random.NextInt(0, IpV6OptionCalipso.CompartmentBitmapMaxLength + 1) / 4 * sizeof(int))));

            case IpV6OptionType.SimplifiedMulticastForwardingDuplicatePacketDetection:
                if (random.NextBool())
                {
                    return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionSequenceHashAssistValue(random.NextDataSegment(random.NextInt(1, 100))));
                }
                IpV6TaggerIdType taggerIdType = random.NextEnum <IpV6TaggerIdType>();
                DataSegment      identifier   = random.NextDataSegment(random.NextInt(0, 100));
                switch (taggerIdType)
                {
                case IpV6TaggerIdType.Null:
                    return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionNull(identifier));

                case IpV6TaggerIdType.Default:
                    return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionDefault(random.NextDataSegment(random.NextInt(1, 17)), identifier));

                case IpV6TaggerIdType.IpV4:
                    return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionIpV4(random.NextIpV4Address(), identifier));

                case IpV6TaggerIdType.IpV6:
                    return(new IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionIpV6(random.NextIpV6Address(), identifier));

                default:
                    throw new InvalidOperationException(string.Format("Invalid taggerIdType value {0}", taggerIdType));
                }

            case IpV6OptionType.HomeAddress:
                return(new IpV6OptionHomeAddress(random.NextIpV6Address()));

            case IpV6OptionType.EndpointIdentification:
                return(new IpV6OptionEndpointIdentification(random.NextDataSegment(random.Next(10)), random.NextDataSegment(random.Next(10))));

            case IpV6OptionType.RoutingProtocolLowPowerAndLossyNetworksOption:
                return(new IpV6OptionRoutingProtocolLowPowerAndLossyNetworks(random.NextBool(), random.NextBool(), random.NextBool(), random.NextByte(),
                                                                             random.NextUShort(), random.NextDataSegment(random.Next(10))));

            case IpV6OptionType.IdentifierLocatorNetworkProtocolNonce:
                return(new IpV6OptionIdentifierLocatorNetworkProtocolNonce(random.NextDataSegment(random.Next(10))));

            case IpV6OptionType.LineIdentification:
                return(new IpV6OptionLineIdentificationDestination(random.NextDataSegment(random.Next(10))));

            default:
                throw new InvalidOperationException(string.Format("Invalid optionType value {0}", optionType));
            }
        }
Esempio n. 49
0
 public IpV6Option CreateInstance(DataSegment data)
 {
     return(IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetection.CreateInstance(data));
 }
 /// <summary>
 /// Creates an instance from tagger id and identifier.
 /// </summary>
 /// <param name="taggerId">
 /// Used to differentiate multiple ingressing border gateways that may commonly apply the SMF_DPD option header to packets from a particular source.
 /// </param>
 /// <param name="identifier">
 /// DPD packet Identifier.
 /// When the TaggerId field is present, the Identifier can be considered a unique packet identifier
 /// in the context of the TaggerId:srcAddr:dstAddr tuple.
 /// When the TaggerId field is not present, then it is assumed that the source applied the SMF_DPD option
 /// and the Identifier can be considered unique in the context of the IPv6 packet header srcAddr:dstAddr tuple.
 /// </param>
 public IpV6OptionSimplifiedMulticastForwardingDuplicatePacketDetectionIpV4(IpV4Address taggerId, DataSegment identifier)
     : base(identifier)
 {
     TaggerId = taggerId;
 }
Esempio n. 51
0
 internal override IpV6Option CreateInstance(DataSegment data)
 {
     return(new IpV6OptionIlnpNonce(data));
 }
Esempio n. 52
0
 /// <summary>
 /// Constructs an instance out of the type covered, algorithm, labels, original TTL, signature expiration, signature inception, key tag,
 /// signer's name and signature fields.
 /// </summary>
 /// <param name="typeCovered">The type of the other RRs covered by this SIG.</param>
 /// <param name="algorithm">The key algorithm.</param>
 /// <param name="labels">
 /// An unsigned count of how many labels there are in the original SIG RR owner name not counting the null label for root and not counting any initial "*" for a wildcard.
 /// If a secured retrieval is the result of wild card substitution, it is necessary for the resolver to use the original form of the name in verifying the digital signature.
 /// This field makes it easy to determine the original form.
 ///
 /// If, on retrieval, the RR appears to have a longer name than indicated by "labels", the resolver can tell it is the result of wildcard substitution.
 /// If the RR owner name appears to be shorter than the labels count, the SIG RR must be considered corrupt and ignored.
 /// The maximum number of labels allowed in the current DNS is 127 but the entire octet is reserved and would be required should DNS names ever be expanded to 255 labels.
 /// </param>
 /// <param name="originalTtl">
 /// The "original TTL" field is included in the RDATA portion to avoid
 /// (1) authentication problems that caching servers would otherwise cause by decrementing the real TTL field and
 /// (2) security problems that unscrupulous servers could otherwise cause by manipulating the real TTL field.
 /// This original TTL is protected by the signature while the current TTL field is not.
 ///
 /// NOTE:  The "original TTL" must be restored into the covered RRs when the signature is verified.
 /// This generaly implies that all RRs for a particular type, name, and class, that is, all the RRs in any particular RRset, must have the same TTL to start with.
 /// </param>
 /// <param name="signatureExpiration">
 /// The last time the signature is valid.
 /// Numbers of seconds since the start of 1 January 1970, GMT, ignoring leap seconds.
 /// Ring arithmetic is used.
 /// This time can never be more than about 68 years after the inception.
 /// </param>
 /// <param name="signatureInception">
 /// The first time the signature is valid.
 /// Numbers of seconds since the start of 1 January 1970, GMT, ignoring leap seconds.
 /// Ring arithmetic is used.
 /// This time can never be more than about 68 years before the expiration.
 /// </param>
 /// <param name="keyTag">
 /// Used to efficiently select between multiple keys which may be applicable and thus check that a public key about to be used
 /// for the computationally expensive effort to check the signature is possibly valid.
 /// For algorithm 1 (MD5/RSA) as defined in RFC 2537,
 /// it is the next to the bottom two octets of the public key modulus needed to decode the signature field.
 /// That is to say, the most significant 16 of the least significant 24 bits of the modulus in network (big endian) order.
 /// For all other algorithms, including private algorithms, it is calculated as a simple checksum of the KEY RR.
 /// </param>
 /// <param name="signersName">
 /// The domain name of the signer generating the SIG RR.
 /// This is the owner name of the public KEY RR that can be used to verify the signature.
 /// It is frequently the zone which contained the RRset being authenticated.
 /// Which signers should be authorized to sign what is a significant resolver policy question.
 /// The signer's name may be compressed with standard DNS name compression when being transmitted over the network.
 /// </param>
 /// <param name="signature">
 /// The actual signature portion of the SIG RR binds the other RDATA fields to the RRset of the "type covered" RRs with that owner name and class.
 /// This covered RRset is thereby authenticated.
 /// To accomplish this, a data sequence is constructed as follows:
 ///
 /// data = RDATA | RR(s)...
 ///
 /// where "|" is concatenation,
 ///
 /// RDATA is the wire format of all the RDATA fields in the SIG RR itself (including the canonical form of the signer's name) before but not including the signature,
 /// and RR(s) is the RRset of the RR(s) of the type covered with the same owner name and class as the SIG RR in canonical form and order.
 ///
 /// How this data sequence is processed into the signature is algorithm dependent.
 /// </param>
 public DnsResourceDataSignature(DnsType typeCovered, DnsAlgorithm algorithm, byte labels, uint originalTtl, SerialNumber32 signatureExpiration,
                                 SerialNumber32 signatureInception, ushort keyTag, DnsDomainName signersName, DataSegment signature)
 {
     TypeCovered         = typeCovered;
     Algorithm           = algorithm;
     Labels              = labels;
     OriginalTtl         = originalTtl;
     SignatureExpiration = signatureExpiration;
     SignatureInception  = signatureInception;
     KeyTag              = keyTag;
     SignersName         = signersName;
     Signature           = signature;
 }
 public DnsResourceDataDnsKey(bool zoneKey, bool revoke, bool secureEntryPoint, byte protocol, DnsAlgorithm algorithm, DataSegment publicKey)
 {
     this.ZoneKey          = zoneKey;
     this.Revoke           = revoke;
     this.SecureEntryPoint = secureEntryPoint;
     this.Protocol         = protocol;
     this.Algorithm        = algorithm;
     this.PublicKey        = publicKey;
 }
Esempio n. 54
0
 internal override IpV6MobilityOption CreateInstance(DataSegment data)
 {
     throw new InvalidOperationException("Pad1 options shouldn't be registered.");
 }
Esempio n. 55
0
 private static ushort CalculateChecksum(byte[] buffer, int offset, int length)
 {
     return(DataSegment.Sum16BitsToChecksum(DataSegment.Sum16Bits(buffer, offset, Math.Min(2, length)) + DataSegment.Sum16Bits(buffer, offset + 2 + 2, length - 2 - 2)));
 }
        internal static IpV6ExtensionHeaderMobilityFastNeighborAdvertisement ParseMessageData(IpV4Protocol nextHeader, ushort checksum, DataSegment messageData)
        {
            if (messageData.Length < MinimumMessageDataLength)
            {
                return(null);
            }

            IpV6MobilityOptions options = new IpV6MobilityOptions(messageData.Subsegment(MessageDataOffset.Options, messageData.Length - MessageDataOffset.Options));

            return(new IpV6ExtensionHeaderMobilityFastNeighborAdvertisement(nextHeader, checksum, options));
        }
Esempio n. 57
0
        internal static IpV6ExtensionHeaderRoutingSourceRoute ParseRoutingData(IpV4Protocol nextHeader, byte segmentsLeft, DataSegment routingData)
        {
            if (routingData.Length < RoutingDataMinimumLength)
            {
                return(null);
            }

            if ((routingData.Length - RoutingDataMinimumLength) % IpV6Address.SizeOf != 0)
            {
                return(null);
            }

            int numAddresses = (routingData.Length - RoutingDataMinimumLength) / IpV6Address.SizeOf;

            IpV6Address[] addresses = new IpV6Address[numAddresses];
            for (int i = 0; i != numAddresses; ++i)
            {
                addresses[i] = routingData.ReadIpV6Address(RoutingDataOffset.Addresses + i * IpV6Address.SizeOf, Endianity.Big);
            }
            return(new IpV6ExtensionHeaderRoutingSourceRoute(nextHeader, segmentsLeft, addresses));
        }
Esempio n. 58
0
 /// <summary>
 /// Constructs an instance from the zone key, revoke, secure entry point, protocol, algorithm and public key fields.
 /// </summary>
 /// <param name="zoneKey">
 /// If true, the DNSKEY record holds a DNS zone key, and the DNSKEY RR's owner name must be the name of a zone.
 /// If false, then the DNSKEY record holds some other type of DNS public key and must not be used to verify RRSIGs that cover RRsets.
 /// </param>
 /// <param name="revoke">
 /// If true, and the resolver sees an RRSIG(DNSKEY) signed by the associated key,
 /// then the resolver must consider this key permanently invalid for all purposes except for validating the revocation.
 /// </param>
 /// <param name="secureEntryPoint">
 /// RFC 3757.
 /// If true, then the DNSKEY record holds a key intended for use as a secure entry point.
 /// This flag is only intended to be a hint to zone signing or debugging software as to the intended use of this DNSKEY record;
 /// validators must not alter their behavior during the signature validation process in any way based on the setting of this bit.
 /// This also means that a DNSKEY RR with the SEP bit set would also need the Zone Key flag set in order to be able to generate signatures legally.
 /// A DNSKEY RR with the SEP set and the Zone Key flag not set MUST NOT be used to verify RRSIGs that cover RRsets.
 /// </param>
 /// <param name="protocol">
 /// Must have value 3, and the DNSKEY RR MUST be treated as invalid during signature verification if it is found to be some value other than 3.
 /// </param>
 /// <param name="algorithm">Identifies the public key's cryptographic algorithm and determines the format of the Public Key field.</param>
 /// <param name="publicKey">The public key material. The format depends on the algorithm of the key being stored.</param>
 public DnsResourceDataDnsKey(bool zoneKey, bool revoke, bool secureEntryPoint, byte protocol, DnsAlgorithm algorithm, DataSegment publicKey)
 {
     ZoneKey          = zoneKey;
     Revoke           = revoke;
     SecureEntryPoint = secureEntryPoint;
     Protocol         = protocol;
     Algorithm        = algorithm;
     PublicKey        = publicKey;
 }
Esempio n. 59
0
 private static byte CalculateCompartmentLength(DataSegment compartmentBitmap)
 {
     return((byte)(compartmentBitmap.Length / sizeof(int)));
 }
        /// <summary>
        /// Creates an instance from next header, security parameter index, sequence number and authenticator.
        /// </summary>
        /// <param name="nextHeader">
        /// Identifies the type of header immediately following this extension header.
        /// </param>
        /// <param name="securityParametersIndex">
        /// The SPI is an arbitrary 32-bit value that, in combination with the destination IP address and security protocol (AH),
        /// uniquely identifies the Security Association for this datagram.
        /// The set of SPI values in the range 1 through 255 are reserved by the Internet Assigned Numbers Authority (IANA) for future use;
        /// a reserved SPI value will not normally be assigned by IANA unless the use of the assigned SPI value is specified in an RFC.
        /// It is ordinarily selected by the destination system upon establishment of an SA.
        /// </param>
        /// <param name="sequenceNumber">
        /// Contains a monotonically increasing counter value (sequence number).
        /// It is mandatory and is always present even if the receiver does not elect to enable the anti-replay service for a specific SA.
        /// Processing of the Sequence Number field is at the discretion of the receiver, i.e., the sender must always transmit this field,
        /// but the receiver need not act upon it.
        /// </param>
        /// <param name="authenticationData">
        /// This is a variable-length field that contains the Integrity Check Value (ICV) for this packet.
        /// The field must be an integral multiple of 32 bits in length.
        /// This field may include explicit padding.
        /// This padding is included to ensure that the length of the AH header is an integral multiple of 32 bits (IPv4) or 64 bits (IPv6).
        /// All implementations must support such padding.
        /// The authentication algorithm specification must specify the length of the ICV and the comparison rules and processing steps for validation.
        /// </param>
        public IpV6ExtensionHeaderAuthentication(IpV4Protocol?nextHeader, uint securityParametersIndex, uint sequenceNumber, DataSegment authenticationData)
            : base(nextHeader)
        {
            if (authenticationData == null)
            {
                throw new ArgumentNullException("authenticationData");
            }

            if (authenticationData.Length % 4 != 0)
            {
                throw new ArgumentException(
                          string.Format(CultureInfo.InvariantCulture, "Authentication Data must be an integral multiple of 4 byte in length, and not {0}.",
                                        authenticationData.Length),
                          "authenticationData");
            }
            SecurityParametersIndex = securityParametersIndex;
            SequenceNumber          = sequenceNumber;
            AuthenticationData      = authenticationData;
        }