public void TestException() { Assert.Throws<ArgumentNullException>(() => new TrapV2Pdu(new Tuple<int, byte[]>(0, new byte[] { 0 }), null)); Assert.Throws<ArgumentNullException>(() => new TrapV2Pdu(0, null, 0, null)); Assert.Throws<ArgumentNullException>(() => new TrapV2Pdu(0, new ObjectIdentifier("1.3.6"), 0, null)); var pdu = new TrapV2Pdu(0, new ObjectIdentifier("1.3"), 0, new List<Variable>()); Assert.Throws<NotSupportedException>(() => { var test = pdu.ErrorIndex; }); Assert.Throws<NotSupportedException>(() => { var test = pdu.ErrorStatus; }); Assert.Throws<ArgumentNullException>(() => pdu.AppendBytesTo(null)); Assert.AreEqual("TRAP v2 PDU: request ID: 0; enterprise: .1.3; time stamp: 0 (00:00:00); variable count: 0", pdu.ToString()); }
public TrapV2Message(int requestId, VersionCode version, OctetString community, ObjectIdentifier enterprise, uint time, IList <Variable> variables) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (enterprise == null) { throw new ArgumentNullException(nameof(enterprise)); } if (community == null) { throw new ArgumentNullException(nameof(community)); } if (version != VersionCode.V2) { throw new ArgumentException("Only v2c are supported.", nameof(version)); } Version = version; Enterprise = enterprise; TimeStamp = time; Header = Header.Empty; Parameters = SecurityParameters.Create(community); TrapV2Pdu pdu = new TrapV2Pdu( requestId, enterprise, time, variables); Scope = new Scope(pdu); Privacy = DefaultPrivacyProvider.DefaultPair; _bytes = this.PackMessage(null).ToBytes(); }
public TrapV2Message(int requestId, VersionCode version, OctetString community, ObjectIdentifier enterprise, uint time, IList<Variable> variables) { if (variables == null) { throw new ArgumentNullException("variables"); } if (enterprise == null) { throw new ArgumentNullException("enterprise"); } if (community == null) { throw new ArgumentNullException("community"); } if (version != VersionCode.V2) { throw new ArgumentException("only v2c are supported", "version"); } Version = version; Enterprise = enterprise; TimeStamp = time; Header = Header.Empty; Parameters = new SecurityParameters(null, null, null, community, null, null); TrapV2Pdu pdu = new TrapV2Pdu( requestId, enterprise, time, variables); Scope = new Scope(pdu); Privacy = DefaultPrivacyProvider.DefaultPair; _bytes = SnmpMessageExtension.PackMessage(Version, Community, pdu).ToBytes(); }
public TrapV2Message(VersionCode version, int messageId, int requestId, OctetString userName, ObjectIdentifier enterprise, uint time, IList <Variable> variables, IPrivacyProvider privacy, int maxMessageSize, OctetString engineId, int engineBoots, int engineTime) { if (userName == null) { throw new ArgumentNullException("userName"); } if (variables == null) { throw new ArgumentNullException("variables"); } if (version != VersionCode.V3) { throw new ArgumentException("only v3 is supported", "version"); } if (enterprise == null) { throw new ArgumentNullException("enterprise"); } if (engineId == null) { throw new ArgumentNullException("engineId"); } if (privacy == null) { throw new ArgumentNullException("privacy"); } Version = version; Privacy = privacy; Enterprise = enterprise; TimeStamp = time; Levels recordToSecurityLevel = PrivacyProviderExtension.ToSecurityLevel(privacy); byte b = (byte)recordToSecurityLevel; // TODO: define more constants. Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), new OctetString(new[] { b }), new Integer32(3)); var authenticationProvider = Privacy.AuthenticationProvider; Parameters = new SecurityParameters( engineId, new Integer32(engineBoots), new Integer32(engineTime), userName, authenticationProvider.CleanDigest, Privacy.Salt); var pdu = new TrapV2Pdu( requestId, enterprise, time, variables); Scope = new Scope(OctetString.Empty, OctetString.Empty, pdu); Parameters.AuthenticationParameters = authenticationProvider.ComputeHash(Version, Header, Parameters, Scope, Privacy); _bytes = SnmpMessageExtension.PackMessage(Version, Header, Parameters, Scope, Privacy).ToBytes(); }
public TrapV2Message( VersionCode version, IPAddress senderIp, int messageId, int requestId, OctetString userName, ObjectIdentifier enterprise, uint time, IList <Variable> variables, IPrivacyProvider privacy, int maxMessageSize, OctetString engineId, int engineBoots, int engineTime) { if (userName == null) { throw new ArgumentNullException("userName"); } if (variables == null) { throw new ArgumentNullException("variables"); } if (version != VersionCode.V3) { throw new ArgumentException("only v3 is supported", "version"); } if (enterprise == null) { throw new ArgumentNullException("enterprise"); } if (engineId == null) { throw new ArgumentNullException("engineId"); } if (privacy == null) { throw new ArgumentNullException("privacy"); } Version = version; Privacy = privacy; Enterprise = enterprise; TimeStamp = time; Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToSecurityLevel()); var authenticationProvider = Privacy.AuthenticationProvider; Parameters = new SecurityParameters( engineId, new Integer32(engineBoots), new Integer32(engineTime), userName, authenticationProvider.CleanDigest, Privacy.Salt); var pdu = new TrapV2Pdu( SenderIP, requestId, enterprise, time, variables); Scope = new Scope(OctetString.Empty, OctetString.Empty, pdu); authenticationProvider.ComputeHash(Version, Header, Parameters, Scope, Privacy); _bytes = this.PackMessage().ToBytes(); }
public TrapV2Message(VersionCode version, int messageId, int requestId, OctetString userName, ObjectIdentifier enterprise, uint time, IList<Variable> variables, IPrivacyProvider privacy, int maxMessageSize, OctetString engineId, int engineBoots, int engineTime) { if (userName == null) { throw new ArgumentNullException("userName"); } if (variables == null) { throw new ArgumentNullException("variables"); } if (version != VersionCode.V3) { throw new ArgumentException("only v3 is supported", "version"); } if (enterprise == null) { throw new ArgumentNullException("enterprise"); } if (engineId == null) { throw new ArgumentNullException("engineId"); } if (privacy == null) { throw new ArgumentNullException("privacy"); } Version = version; Privacy = privacy; Enterprise = enterprise; TimeStamp = time; Levels recordToSecurityLevel = PrivacyProviderExtension.ToSecurityLevel(privacy); byte b = (byte)recordToSecurityLevel; // TODO: define more constants. Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), new OctetString(new[] { b }), new Integer32(3)); var authenticationProvider = Privacy.AuthenticationProvider; Parameters = new SecurityParameters( engineId, new Integer32(engineBoots), new Integer32(engineTime), userName, authenticationProvider.CleanDigest, Privacy.Salt); var pdu = new TrapV2Pdu( requestId, enterprise, time, variables); Scope = new Scope(OctetString.Empty, OctetString.Empty, pdu); Parameters.AuthenticationParameters = authenticationProvider.ComputeHash(Version, Header, Parameters, Scope, Privacy); _bytes = SnmpMessageExtension.PackMessage(Version, Header, Parameters, Scope, Privacy).ToBytes(); }
public TrapV2Message(VersionCode version, int messageId, int requestId, OctetString userName, ObjectIdentifier enterprise, uint time, IList<Variable> variables, IPrivacyProvider privacy, int maxMessageSize, OctetString engineId, int engineBoots, int engineTime) { if (userName == null) { throw new ArgumentNullException("userName"); } if (variables == null) { throw new ArgumentNullException("variables"); } if (version != VersionCode.V3) { throw new ArgumentException("only v3 is supported", "version"); } if (enterprise == null) { throw new ArgumentNullException("enterprise"); } if (engineId == null) { throw new ArgumentNullException("engineId"); } if (privacy == null) { throw new ArgumentNullException("privacy"); } Version = version; Privacy = privacy; Enterprise = enterprise; TimeStamp = time; Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToSecurityLevel()); var authenticationProvider = Privacy.AuthenticationProvider; Parameters = new SecurityParameters( engineId, new Integer32(engineBoots), new Integer32(engineTime), userName, authenticationProvider.CleanDigest, Privacy.Salt); var pdu = new TrapV2Pdu( requestId, enterprise, time, variables); // TODO: may expose engine ID in the future. Scope = new Scope(OctetString.Empty, OctetString.Empty, pdu); authenticationProvider.ComputeHash(Version, Header, Parameters, Scope, Privacy); _bytes = this.PackMessage(null).ToBytes(); }