/// <summary>
        /// Create the security option from the different security field values.
        /// </summary>
        /// <param name="classificationLevel">
        /// This field specifies the (U.S.) classification level at which the datagram must be protected.
        /// The information in the datagram must be protected at this level.
        /// </param>
        /// <param name="protectionAuthorities">
        /// This field identifies the National Access Programs or Special Access Programs
        /// which specify protection rules for transmission and processing of the information contained in the datagram.
        /// </param>
        /// <param name="length">
        /// The number of bytes this option will take.
        /// </param>
        public IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel classificationLevel, IpV4OptionSecurityProtectionAuthorities protectionAuthorities, byte length)
            : base(IpV4OptionType.BasicSecurity)
        {
            if (length < OptionMinimumLength)
            {
                throw new ArgumentOutOfRangeException("length", length, "Minimum option length is " + OptionMinimumLength);
            }

            if (length == OptionMinimumLength && protectionAuthorities != IpV4OptionSecurityProtectionAuthorities.None)
            {
                throw new ArgumentException("Can't have a protection authority without minimum of " + (OptionValueMinimumLength + 1) + " length",
                                            "protectionAuthorities");
            }

            if (classificationLevel != IpV4OptionSecurityClassificationLevel.Confidential &&
                classificationLevel != IpV4OptionSecurityClassificationLevel.Secret &&
                classificationLevel != IpV4OptionSecurityClassificationLevel.TopSecret &&
                classificationLevel != IpV4OptionSecurityClassificationLevel.Unclassified)
            {
                throw new ArgumentException("Invalid classification level " + classificationLevel);
            }

            _classificationLevel   = classificationLevel;
            _protectionAuthorities = protectionAuthorities;
            _length = length;
        }
Esempio n. 2
0
        /// <summary>
        /// Tries to read the option from a buffer starting from the option value (after the type and length).
        /// </summary>
        /// <param name="buffer">The buffer to read the option from.</param>
        /// <param name="offset">The offset to the first byte to read the buffer. Will be incremented by the number of bytes read.</param>
        /// <param name="valueLength">The number of bytes the option value should take according to the length field that was already read.</param>
        /// <returns>On success - the complex option read. On failure - null.</returns>
        Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength)
        {
//            if (buffer == null)
//                throw new ArgumentNullException("buffer");

            if (valueLength < OptionValueMinimumLength)
            {
                return(null);
            }

            // Classification level
            IpV4OptionSecurityClassificationLevel classificationLevel = (IpV4OptionSecurityClassificationLevel)buffer[offset++];

            if (classificationLevel != IpV4OptionSecurityClassificationLevel.Confidential &&
                classificationLevel != IpV4OptionSecurityClassificationLevel.Secret &&
                classificationLevel != IpV4OptionSecurityClassificationLevel.TopSecret &&
                classificationLevel != IpV4OptionSecurityClassificationLevel.Unclassified)
            {
                return(null);
            }

            // Protection authorities
            int protectionAuthoritiesLength = valueLength - OptionValueMinimumLength;
            IpV4OptionSecurityProtectionAuthorities protectionAuthorities = IpV4OptionSecurityProtectionAuthorities.None;

            if (protectionAuthoritiesLength > 0)
            {
                for (int i = 0; i < protectionAuthoritiesLength - 1; ++i)
                {
                    if ((buffer[offset + i] & 0x01) == 0)
                    {
                        return(null);
                    }
                }
                if ((buffer[offset + protectionAuthoritiesLength - 1] & 0x01) != 0)
                {
                    return(null);
                }

                protectionAuthorities = (IpV4OptionSecurityProtectionAuthorities)(buffer[offset] & 0xFE);
            }
            offset += protectionAuthoritiesLength;

            return(new IpV4OptionBasicSecurity(classificationLevel, protectionAuthorities, (byte)(OptionMinimumLength + protectionAuthoritiesLength)));
        }
Esempio n. 3
0
 public IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel classificationLevel, IpV4OptionSecurityProtectionAuthorities protectionAuthorities, byte length)
     : base(IpV4OptionType.BasicSecurity)
 {
     if ((int)length < 3)
     {
         throw new ArgumentOutOfRangeException("length", (object)length, "Minimum option length is " + (object)3);
     }
     if ((int)length == 3 && protectionAuthorities != IpV4OptionSecurityProtectionAuthorities.None)
     {
         throw new ArgumentException("Can't have a protection authority without minimum of " + (object)2 + " length", "protectionAuthorities");
     }
     if (classificationLevel != IpV4OptionSecurityClassificationLevel.Confidential && classificationLevel != IpV4OptionSecurityClassificationLevel.Secret && (classificationLevel != IpV4OptionSecurityClassificationLevel.TopSecret && classificationLevel != IpV4OptionSecurityClassificationLevel.Unclassified))
     {
         throw new ArgumentException("Invalid classification level " + (object)classificationLevel);
     }
     this._classificationLevel   = classificationLevel;
     this._protectionAuthorities = protectionAuthorities;
     this._length = length;
 }
Esempio n. 4
0
        Option IOptionComplexFactory.CreateInstance(byte[] buffer, ref int offset, byte valueLength)
        {
            if ((int)valueLength < 1)
            {
                return((Option)null);
            }
            IpV4OptionSecurityClassificationLevel classificationLevel = (IpV4OptionSecurityClassificationLevel)buffer[offset++];

            switch (classificationLevel)
            {
            case IpV4OptionSecurityClassificationLevel.Confidential:
            case IpV4OptionSecurityClassificationLevel.Secret:
            case IpV4OptionSecurityClassificationLevel.TopSecret:
            case IpV4OptionSecurityClassificationLevel.Unclassified:
                int num = (int)valueLength - 1;
                IpV4OptionSecurityProtectionAuthorities protectionAuthorities = IpV4OptionSecurityProtectionAuthorities.None;
                if (num > 0)
                {
                    for (int index = 0; index < num - 1; ++index)
                    {
                        if (((int)buffer[offset + index] & 1) == 0)
                        {
                            return((Option)null);
                        }
                    }
                    if (((int)buffer[offset + num - 1] & 1) != 0)
                    {
                        return((Option)null);
                    }
                    protectionAuthorities = (IpV4OptionSecurityProtectionAuthorities)((uint)buffer[offset] & 254U);
                }
                offset += num;
                return((Option) new IpV4OptionBasicSecurity(classificationLevel, protectionAuthorities, (byte)(3 + num)));

            default:
                return((Option)null);
            }
        }
 /// <summary>
 /// Create the security option with only classification level.
 /// </summary>
 /// <param name="classificationLevel">
 /// This field specifies the (U.S.) classification level at which the datagram must be protected.
 /// The information in the datagram must be protected at this level.
 /// </param>
 public IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel classificationLevel)
     : this(classificationLevel, IpV4OptionSecurityProtectionAuthorities.None, OptionMinimumLength)
 {
 }
Esempio n. 6
0
 public IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel classificationLevel)
     : this(classificationLevel, IpV4OptionSecurityProtectionAuthorities.None, (byte)3)
 {
 }