/// <summary> /// Initializes a new instance of the <see cref="SetRequestMessage"/> class. /// </summary> /// <param name="version">The version.</param> /// <param name="messageId">The message id.</param> /// <param name="requestId">The request id.</param> /// <param name="contextName">The context name.</param> /// <param name="variables">The variables.</param> /// <param name="privacy">The privacy provider.</param> /// <param name="maxMessageSize">Size of the max message.</param> public SetRequestMessage(VersionCode version, int messageId, int requestId, OctetString contextName, IList <Variable> variables, IPrivacyProvider privacy, int maxMessageSize) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (contextName == null) { throw new ArgumentNullException(nameof(contextName)); } if (version != VersionCode.V3) { throw new ArgumentException("Only v3 is supported.", nameof(version)); } Version = version; Privacy = privacy ?? throw new ArgumentNullException(nameof(privacy)); Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToSecurityLevel() | Levels.Reportable, new Integer32((int)SecurityModel.Tsm)); Parameters = SecurityParameters.Empty; var pdu = new SetRequestPdu( requestId, variables); var contextEngineId = OctetString.Empty; Scope = new Scope(contextEngineId, contextName, pdu); Privacy.ComputeHash(Version, Header, Parameters, Scope); _bytes = this.PackMessage(null).ToBytes(); }
/// <summary> /// Initializes a new instance of the <see cref="ResponseMessage"/> class. /// </summary> /// <param name="version">The version.</param> /// <param name="header">The header.</param> /// <param name="parameters">The parameters.</param> /// <param name="scope">The scope.</param> /// <param name="privacy">The privacy provider.</param> /// <param name="needAuthentication">if set to <c>true</c>, authentication is needed.</param> /// <param name="length">The length bytes.</param> public ResponseMessage(VersionCode version, Header header, SecurityParameters parameters, Scope scope, IPrivacyProvider privacy, bool needAuthentication, byte[]?length) { Version = version; Header = header ?? throw new ArgumentNullException(nameof(header)); Parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); Scope = scope ?? throw new ArgumentNullException(nameof(scope)); Privacy = privacy ?? throw new ArgumentNullException(nameof(privacy)); if (needAuthentication) { Privacy.ComputeHash(Version, Header, Parameters, Scope); } _bytes = this.PackMessage(length).ToBytes(); }
/// <summary> /// Initializes a new instance of the <see cref="ReportMessage"/> class. /// </summary> /// <param name="version">The version code.</param> /// <param name="header">The header.</param> /// <param name="parameters">The security parameters.</param> /// <param name="scope">The scope.</param> /// <param name="privacy">The privacy provider.</param> /// <param name="length">The length bytes.</param> public ReportMessage(VersionCode version, Header header, SecurityParameters parameters, Scope scope, IPrivacyProvider privacy, byte[]?length) { if (version != VersionCode.V3) { throw new ArgumentException("Only v3 is supported.", nameof(version)); } Version = version; Header = header ?? throw new ArgumentNullException(nameof(header)); Parameters = parameters ?? throw new ArgumentNullException(nameof(parameters)); Scope = scope ?? throw new ArgumentNullException(nameof(scope)); Privacy = privacy ?? throw new ArgumentNullException(nameof(privacy)); Privacy.ComputeHash(Version, Header, Parameters, Scope); _bytes = this.PackMessage(length).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(nameof(userName)); } if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (version != VersionCode.V3) { throw new ArgumentException("Only v3 is supported.", nameof(version)); } if (engineId == null) { throw new ArgumentNullException(nameof(engineId)); } Version = version; Privacy = privacy ?? throw new ArgumentNullException(nameof(privacy)); Enterprise = enterprise ?? throw new ArgumentNullException(nameof(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); Privacy.ComputeHash(Version, Header, Parameters, Scope); _bytes = this.PackMessage(null).ToBytes(); }
/// <summary> /// Initializes a new instance of the <see cref="SetRequestMessage"/> class. /// </summary> /// <param name="version">The version.</param> /// <param name="messageId">The message id.</param> /// <param name="requestId">The request id.</param> /// <param name="userName">Name of the user.</param> /// <param name="contextName">The context name.</param> /// <param name="variables">The variables.</param> /// <param name="privacy">The privacy provider.</param> /// <param name="maxMessageSize">Size of the max message.</param> /// <param name="report">The report.</param> /// <param name="securityModel">The type of security model</param> public SetRequestMessage(VersionCode version, int messageId, int requestId, OctetString userName, OctetString contextName, IList <Variable> variables, IPrivacyProvider privacy, int maxMessageSize, ISnmpMessage report, SecurityModel securityModel) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (userName == null) { throw new ArgumentNullException(nameof(userName)); } if (contextName == null) { throw new ArgumentNullException(nameof(contextName)); } if (version != VersionCode.V3) { throw new ArgumentException("Only v3 is supported.", nameof(version)); } if (report == null) { throw new ArgumentNullException(nameof(report)); } Version = version; Privacy = privacy ?? throw new ArgumentNullException(nameof(privacy)); Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToSecurityLevel() | Levels.Reportable, new Integer32((int)securityModel)); var parameters = report.Parameters; var authenticationProvider = Privacy.AuthenticationProvider; if (securityModel == SecurityModel.Tsm) { Parameters = SecurityParameters.Empty; } else { Parameters = new SecurityParameters( parameters.EngineId, parameters.EngineBoots, parameters.EngineTime, userName, authenticationProvider.CleanDigest, Privacy.Salt); } var pdu = new SetRequestPdu( requestId, variables); var scope = report.Scope; var contextEngineId = scope.ContextEngineId == OctetString.Empty ? parameters.EngineId : scope.ContextEngineId; if (contextEngineId == null) { throw new SnmpException("invalid REPORT message"); } Scope = new Scope(contextEngineId, contextName, pdu); Privacy.ComputeHash(Version, Header, Parameters, Scope); _bytes = this.PackMessage(null).ToBytes(); }