authNoPriv() публичный Метод

Set class security to enabled authentication and no privacy. To perform authentication, authentication password needs to be supplied and authentication protocol to be used to perform authentication. This method does not initialize the packet user name. Use SNMPV3Packet.SecurityName method to set the security name (also called user name) for this request.
public authNoPriv ( byte userName, byte authenticationPassword, AuthenticationDigests authenticationProtocol ) : void
userName byte User name
authenticationPassword byte Authentication password to use in authenticating the message. This /// value has to match the password configured on the agent.
authenticationProtocol AuthenticationDigests Authentication protocol to use. Available authentication protocols are: /// for HMAC-MD5 authentication, and /// for HMAC-SHA1 message authentication.
Результат void
        /// <summary>
        /// Construct and send SNMP v3 authNoPriv 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 cref="AuthenticationDigests"/> enumeration for
        /// available digests</param>
        /// <param name="authSecret">Authentication secret</param>
        public void SendV3Trap(IpAddress receiver, int receiverPort, byte[] engineId, Int32 senderEngineBoots,
                               Int32 senderEngineTime, string senderUserName, UInt32 senderUpTime, Oid trapObjectID, VbCollection varList,
                               AuthenticationDigests authDigest, byte[] authSecret)
        {
            SnmpV3Packet packet = new SnmpV3Packet();

            packet.Pdu.Type = PduType.V2Trap;
            packet.authNoPriv(ASCIIEncoding.UTF8.GetBytes(senderUserName), authSecret, authDigest);
            packet.SetEngineId(engineId);
            packet.SetEngineTime(senderEngineBoots, senderEngineTime);
            packet.ScopedPdu.TrapObjectID.Set(trapObjectID);
            packet.ScopedPdu.TrapSysUpTime.Value = senderUpTime;
            packet.ScopedPdu.VbList.Add(varList);
            packet.MsgFlags.Reportable = false;
            SendV3Trap(packet, receiver, receiverPort);
        }
Пример #2
0
 /// <summary>
 /// InitializePacket SNMP packet with values from this class. Works only on SNMP version 3 packets.
 /// </summary>
 /// <param name="packet">Instance of <see cref="SnmpV3Packet"/></param>
 /// <exception cref="SnmpInvalidVersionException">Thrown when parameter packet is not SnmpV3Packet</exception>
 public void InitializePacket(SnmpPacket packet)
 {
     if (packet is SnmpV3Packet)
     {
         SnmpV3Packet pkt    = (SnmpV3Packet)packet;
         bool         isAuth = (_authenticationProtocol == AuthenticationDigests.None) ? false : true;
         bool         isPriv = (_privacyProtocol == PrivacyProtocols.None) ? false : true;
         if (isAuth && isPriv)
         {
             pkt.authPriv(_securityName, _authenticationSecret, _authenticationProtocol, _privacySecret, _privacyProtocol);
         }
         else if (isAuth && !isPriv)
         {
             pkt.authNoPriv(_securityName, _authenticationSecret, _authenticationProtocol);
         }
         else
         {
             pkt.NoAuthNoPriv(_securityName);
         }
         pkt.USM.EngineId.Set(_engineId);
         pkt.USM.EngineBoots     = _engineBoots.Value;
         pkt.USM.EngineTime      = GetCurrentEngineTime();
         pkt.MaxMessageSize      = _maxMessageSize.Value;
         pkt.MsgFlags.Reportable = _reportable;
         if (_contextEngineId.Length > 0)
         {
             pkt.ScopedPdu.ContextEngineId.Set(_contextEngineId);
         }
         else
         {
             pkt.ScopedPdu.ContextEngineId.Set(_engineId);
         }
         if (_contextName.Length > 0)
         {
             pkt.ScopedPdu.ContextName.Set(_contextName);
         }
         else
         {
             pkt.ScopedPdu.ContextName.Reset();
         }
     }
     else
     {
         throw new SnmpInvalidVersionException("Invalid SNMP version.");
     }
 }
Пример #3
0
 /// <summary>
 /// Prepare packet for transmission by filling target specific information in the packet.
 /// </summary>
 /// <param name="packet">SNMP packet class for the required version</param>
 /// <returns>True if packet values are correctly set, otherwise false.</returns>
 public bool PreparePacketForTransmission(SnmpPacket packet)
 {
     if (packet is SnmpV3Packet)
     {
         SnmpV3Packet pkt    = (SnmpV3Packet)packet;
         bool         isAuth = (_authenticationProtocol == AuthenticationDigests.None) ? false : true;
         bool         isPriv = (_privacyProtocol == PrivacyProtocols.None) ? false : true;
         if (isAuth && isPriv)
         {
             pkt.authPriv(_securityName, _authenticationSecret, _authenticationProtocol, _privacySecret, _privacyProtocol);
         }
         else if (isAuth && !isPriv)
         {
             pkt.authNoPriv(_securityName, _authenticationSecret, _authenticationProtocol);
         }
         else
         {
             pkt.NoAuthNoPriv(_securityName);
         }
         pkt.USM.EngineId.Set(_engineId);
         pkt.USM.EngineBoots     = _engineBoots.Value;
         pkt.USM.EngineTime      = GetCurrentEngineTime();
         pkt.MaxMessageSize      = _maxMessageSize.Value;
         pkt.MsgFlags.Reportable = _reportable;
         if (_contextEngineId.Length > 0)
         {
             pkt.ScopedPdu.ContextEngineId.Set(_contextEngineId);
         }
         else
         {
             pkt.ScopedPdu.ContextEngineId.Set(_engineId);
         }
         if (_contextName.Length > 0)
         {
             pkt.ScopedPdu.ContextName.Set(_contextName);
         }
         else
         {
             pkt.ScopedPdu.ContextName.Reset();
         }
     }
     return(false);
 }
Пример #4
0
        /// <summary>
        /// Construct and send SNMP v3 authNoPriv 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 cref="AuthenticationDigests"/> enumeration for
        /// available digests</param>
        /// <param name="authSecret">Authentication secret</param>
        public void SendV3Trap(IpAddress receiver, int receiverPort, byte[] engineId, Int32 senderEngineBoots,
			Int32 senderEngineTime, string senderUserName, UInt32 senderUpTime, Oid trapObjectID, VbCollection varList,
			AuthenticationDigests authDigest, byte[] authSecret)
        {
            SnmpV3Packet packet = new SnmpV3Packet();
            packet.Pdu.Type = PduType.V2Trap;
            packet.authNoPriv(ASCIIEncoding.UTF8.GetBytes(senderUserName), authSecret, authDigest);
            packet.SetEngineId(engineId);
            packet.SetEngineTime(senderEngineBoots, senderEngineTime);
            packet.ScopedPdu.TrapObjectID.Set(trapObjectID);
            packet.ScopedPdu.TrapSysUpTime.Value = senderUpTime;
            packet.ScopedPdu.VbList.Add(varList);
            packet.MsgFlags.Reportable = false;
            SendV3Trap(packet, receiver, receiverPort);
        }