示例#1
0
        /// <summary>
        /// Based on the supplied privacyProtocol, return instance of the privacy protocol implementation class.
        /// </summary>
        /// <param name="privProtocol">Privacy protocol code. Available protocols are <see cref="EPrivacyProtocols.DES"/>,
        /// <see cref="EPrivacyProtocols.AES128"/>, <see cref="EPrivacyProtocols.AES192"/>, <see cref="EPrivacyProtocols.AES256"/> and
        /// <see cref="EPrivacyProtocols.TripleDES"/>.</param>
        /// <returns>Privacy protocol implementation class on success. If privacy protocol is <see cref="EPrivacyProtocols.None"/>
        /// then null is returned.</returns>
        public static IPrivacyProtocol GetInstance(EPrivacyProtocols privProtocol)
        {
            switch (privProtocol)
            {
            case EPrivacyProtocols.None:
                return(null);

            case EPrivacyProtocols.DES:
                return(new PrivacyDES());

            case EPrivacyProtocols.AES128:
                return(new PrivacyAES128());

            case EPrivacyProtocols.AES192:
                return(new PrivacyAES192());

            case EPrivacyProtocols.AES256:
                return(new PrivacyAES256());

            case EPrivacyProtocols.TripleDES:
                return(new Privacy3DES());

            default:
                return(null);
            }
        }
示例#2
0
        /// <summary>Reset the class. Initialize all member values to class defaults.</summary>
        public void Reset()
        {
            engineId    = new OctetString();
            engineBoots = new Integer32();
            engineTime  = new Integer32();

            engineTimeStamp = DateTime.MinValue;

            privacyProtocol        = EPrivacyProtocols.None;
            authenticationProtocol = AuthenticationDigests.None;

            privacySecret        = new MutableByte();
            authenticationSecret = new MutableByte();

            contextEngineId = new OctetString();
            contextName     = new OctetString();
            securityName    = new OctetString();

            // max message size is initialized to 64KB by default. It will be
            // to the smaller of the two values after discovery process
            maxMessageSize = new Integer32(64 * 1024);

            reportable = true;

            privacyKey        = null;
            authenticationKey = null;
        }
示例#3
0
        /// <summary>Copy constructor. Initialize the class with the values of the parameter class values.</summary>
        /// <param name="second">Parameter class.</param>
        public SecureAgentParameters(SecureAgentParameters second)
            : this()
        {
            contextEngineId.Set(second.ContextEngineId);
            contextName.Set(second.ContextName);
            engineBoots.Value = second.EngineBoots.Value;
            engineId.Set(second.EngineId);
            engineTime.Value     = second.EngineTime.Value;
            engineTimeStamp      = second.EngineTimeStamp();
            maxMessageSize.Value = second.MaxMessageSize.Value;
            privacyProtocol      = second.Privacy;
            privacySecret.Set(second.PrivacySecret);
            authenticationProtocol = second.Authentication;
            authenticationSecret.Set(second.AuthenticationSecret);
            reportable = second.Reportable;
            securityName.Set(second.SecurityName);

            if (second.AuthenticationKey != null)
            {
                authenticationKey = (byte[])second.AuthenticationKey.Clone();
            }

            if (second.PrivacyKey != null)
            {
                privacyKey = (byte[])second.PrivacyKey.Clone();
            }
        }
示例#4
0
        /// <summary>Reset the class. Initialize all member values to class defaults.</summary>
        public void Reset()
        {
            targetAddress = new IpAddress(System.Net.IPAddress.Loopback);
            targetPort    = 161;
            targetVersion = ESnmpVersion.Ver3;
            timeOut       = 2000;
            retry         = 1;

            engineId    = new OctetString();
            engineBoots = new Integer32();
            engineTime  = new Integer32();

            engineTimeStamp = DateTime.MinValue;

            privacyProtocol        = EPrivacyProtocols.None;
            authenticationProtocol = AuthenticationDigests.None;

            privacySecret        = new MutableByte();
            authenticationSecret = new MutableByte();

            contextEngineId = new OctetString();
            contextName     = new OctetString();
            securityName    = new OctetString();

            // max message size is initialized to 64KB by default. It will be
            // to the smaller of the two values after discovery process
            maximumMessageSize = new Integer32(64 * 1024);

            reportable = true;
        }
示例#5
0
        /// <summary>Construct and send SNMP v3 authPriv Trap</summary>
        /// <param name="receiver">Trap receiver IP address</param>
        /// <param name="receiverPort">Trap receiver UDP port number</param>
        /// <param name="engineId">Sender SNMP engineId</param>
        /// <param name="senderEngineBoots">Sender SNMP engine boots</param>
        /// <param name="senderEngineTime">Sender SNMP engine time</param>
        /// <param name="senderUserName">Security (user) name</param>
        /// <param name="senderUpTime">Sender upTime</param>
        /// <param name="trapObjectID">Trap object ID</param>
        /// <param name="varList">Variable binding list</param>
        /// <param name="authDigest">
        /// Authentication digest. See <see cref="AuthenticationDigests"/> enumeration for
        /// available digests
        /// </param>
        /// <param name="authSecret">Authentication secret</param>
        /// <param name="privProtocol">
        /// Privacy protocol. See <see cref="EPrivacyProtocols"/> enumeration for
        /// available privacy protocols.
        /// </param>
        /// <param name="privSecret">Privacy secret</param>
        public void SendV3Trap(
            IpAddress receiver,
            int receiverPort,
            byte[] engineId,
            int senderEngineBoots,
            int senderEngineTime,
            string senderUserName,
            uint senderUpTime,
            Oid trapObjectID,
            VbCollection varList,
            AuthenticationDigests authDigest,
            byte[] authSecret,
            EPrivacyProtocols privProtocol,
            byte[] privSecret
            )
        {
            SnmpV3Packet packet = new SnmpV3Packet();

            packet.Pdu.Type = EPduType.V2Trap;
            packet.AuthPriv(Encoding.UTF8.GetBytes(senderUserName), authSecret, authDigest, privSecret, privProtocol);
            packet.SetEngineId(engineId);
            packet.SetEngineTime(senderEngineBoots, senderEngineTime);
            packet.ScopedPdu.TrapObjectID.Set(trapObjectID);
            packet.ScopedPdu.TrapSysUpTime.Value = senderUpTime;
            packet.ScopedPdu.VbList.Add(varList);
            packet.MessageFlags.Reportable = false;
            SendV3Trap(packet, receiver, receiverPort);
        }
示例#6
0
 /// <summary>Prepare class for authPriv operations.</summary>
 /// <param name="securityName">User security name</param>
 /// <param name="authDigest">Authentication protocol</param>
 /// <param name="authSecret">Authentication secret (password)</param>
 /// <param name="privProtocol">Privacy protocol</param>
 /// <param name="privSecret">Privacy secret (encryption password)</param>
 public void AuthPriv(string securityName, AuthenticationDigests authDigest, string authSecret, EPrivacyProtocols privProtocol, string privSecret)
 {
     this.securityName.Set(securityName);
     authenticationProtocol = authDigest;
     authenticationSecret.Set(authSecret);
     privacyProtocol = privProtocol;
     privacySecret.Set(privSecret);
 }
示例#7
0
 /// <summary>Prepare class for authNoPriv operations. Set privacy protocol to none</summary>
 /// <param name="securityName">User security name</param>
 /// <param name="authDigest">Authentication protocol</param>
 /// <param name="authSecret">Authentication secret (password)</param>
 public void AuthNoPriv(string securityName, AuthenticationDigests authDigest, string authSecret)
 {
     this.securityName.Set(securityName);
     authenticationProtocol = authDigest;
     authenticationSecret.Set(authSecret);
     privacyProtocol = EPrivacyProtocols.None;
     privacySecret.Clear();
 }
示例#8
0
 /// <summary>Prepare class for noAuthNoPriv operations. Set authentication and privacy protocols to none.</summary>
 /// <param name="securityName">User security name</param>
 public void NoAuthNoPriv(string securityName)
 {
     this.securityName.Set(securityName);
     authenticationProtocol = AuthenticationDigests.None;
     authenticationSecret.Clear();
     privacyProtocol = EPrivacyProtocols.None;
     privacySecret.Clear();
 }
示例#9
0
 /// <summary>Copy constructor.</summary>
 /// <param name="value">Class to copy values from</param>
 public UserSecurityModel(UserSecurityModel value)
     : this()
 {
     engineId.Set(value.EngineId);
     engineBoots.Value = value.EngineBoots;
     engineTime.Value  = value.EngineTime;
     securityName.Set(value.SecurityName);
     authenticationParameters = new OctetString();
     privacySecret            = new MutableByte();
     privacy           = EPrivacyProtocols.None;
     privacyParameters = new OctetString();
 }
示例#10
0
        /// <summary>
        /// Reset USM object to default values. All OctetString and MutableByte members are reset to 0 length and
        /// privacy and authentication protocols are set to none.
        /// </summary>
        public void Reset()
        {
            Type           = 3;
            engineId       = new OctetString();
            engineBoots    = new Integer32();
            engineTime     = new Integer32();
            authentication = AuthenticationDigests.None;

            securityName             = new OctetString();
            authenticationSecret     = new MutableByte();
            authenticationParameters = new OctetString();
            privacySecret            = new MutableByte();
            privacy           = EPrivacyProtocols.None;
            privacyParameters = new OctetString();
        }
示例#11
0
        /// <summary>
        /// Copy all relevant values from the SnmpV3Packet class. Do not use this class for
        /// updating the SNMP version 3 discovery process results because secret name, authentication
        /// and privacy values are updated as well which discovery process doesn't use.
        /// </summary>
        /// <param name="packet"><see cref="SnmpV3Packet"/> cast as <see cref="SnmpPacket"/></param>
        /// <exception cref="SnmpInvalidVersionException">Thrown when SNMP packet class other then version 3 is passed as parameter</exception>
        public void UpdateValues(SnmpPacket packet)
        {
            if (packet is SnmpV3Packet pkt)
            {
                authenticationProtocol = pkt.USM.Authentication;
                privacyProtocol        = pkt.USM.Privacy;
                authenticationSecret.Set(pkt.USM.AuthenticationSecret);
                privacySecret.Set(pkt.USM.PrivacySecret);
                securityName.Set(pkt.USM.SecurityName);

                if (pkt.MaxMessageSize < maxMessageSize.Value)
                {
                    maxMessageSize.Value = pkt.MaxMessageSize;
                }

                UpdateDiscoveryValues(pkt);
            }
            else
            {
                throw new SnmpInvalidVersionException("Invalid SNMP version.");
            }
        }
示例#12
0
 /// <summary>Set packet security to authentication enabled and privacy protection enabled (SNMP v3 mode authPriv)</summary>
 /// <param name="userName">User name</param>
 /// <param name="authenticationPassword">Authentication password</param>
 /// <param name="authenticationProtocol">Authentication protocol. See definitions in <see cref="AuthenticationDigests"/> enumeration.</param>
 /// <param name="privacyPassword">Privacy protection password.</param>
 /// <param name="privacyProtocol">Privacy protocol. See definitions in <see cref="EPrivacyProtocols"/> enumeration.</param>
 public void AuthPriv(byte[] userName, byte[] authenticationPassword, AuthenticationDigests authenticationProtocol, byte[] privacyPassword, EPrivacyProtocols privacyProtocol)
 {
     NoAuthNoPriv(userName); // reset authentication and privacy values and set user name
     messageFlags.Authentication = true;
     userSecurityModel.AuthenticationSecret.Set(authenticationPassword);
     userSecurityModel.Authentication = authenticationProtocol;
     messageFlags.Privacy             = true;
     userSecurityModel.PrivacySecret.Set(privacyPassword);
     userSecurityModel.Privacy = privacyProtocol;
 }