authPriv() public method

Set packet security to authentication enabled and privacy protection enabled (SNMP v3 mode authPriv)
public authPriv ( byte userName, byte authenticationPassword, AuthenticationDigests authenticationProtocol, byte privacyPassword, PrivacyProtocols privacyProtocol ) : void
userName byte User name
authenticationPassword byte Authentication password
authenticationProtocol AuthenticationDigests Authentication protocol. See definitions in enumeration.
privacyPassword byte Privacy protection password.
privacyProtocol PrivacyProtocols Privacy protocol. See definitions in enumeration.
return void
        /// <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="PrivacyProtocols"/> enumeration for
        /// available privacy protocols.</param>
        /// <param name="privSecret">Privacy 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, PrivacyProtocols privProtocol, byte[] privSecret)
        {
            SnmpV3Packet packet = new SnmpV3Packet();

            packet.Pdu.Type = PduType.V2Trap;
            packet.authPriv(ASCIIEncoding.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.MsgFlags.Reportable = false;
            SendV3Trap(packet, receiver, receiverPort);
        }
Exemplo n.º 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.");
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 4
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="PrivacyProtocols"/> enumeration for
        /// available privacy protocols.</param>
        /// <param name="privSecret">Privacy 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, PrivacyProtocols privProtocol, byte[] privSecret)
        {
            SnmpV3Packet packet = new SnmpV3Packet();
            packet.Pdu.Type = PduType.V2Trap;
            packet.authPriv(ASCIIEncoding.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.MsgFlags.Reportable = false;
            SendV3Trap(packet, receiver, receiverPort);
        }