/// <summary> /// Creates a <see cref="GetRequestMessage"/> with all contents. /// </summary> /// <param name="requestId">The request id.</param> /// <param name="version">Protocol version</param> /// <param name="community">Community name</param> /// <param name="variables">Variables</param> public GetRequestMessage(int requestId, VersionCode version, OctetString community, IList <Variable> variables) { if (variables == null) { throw new ArgumentNullException("variables"); } if (community == null) { throw new ArgumentNullException("community"); } if (version == VersionCode.V3) { throw new ArgumentException("only v1 and v2c are supported", "version"); } Version = version; Header = Header.Empty; Parameters = new SecurityParameters(null, null, null, community, null, null); GetRequestPdu pdu = new GetRequestPdu( requestId, ErrorCode.NoError, 0, variables); Scope = new Scope(pdu); Privacy = DefaultPrivacyProvider.DefaultPair; _bytes = SnmpMessageExtension.PackMessage(Version, Header, Parameters, Scope, Privacy).ToBytes(); }
/// <summary> /// Creates a <see cref="GetRequestMessage"/> with all contents. /// </summary> /// <param name="requestId">The request id.</param> /// <param name="version">Protocol version</param> /// <param name="community">Community name</param> /// <param name="variables">Variables</param> public GetRequestMessage(int requestId, VersionCode version, OctetString community, IList <Variable> variables) { if (variables == null) { throw new ArgumentNullException(nameof(variables)); } if (community == null) { throw new ArgumentNullException(nameof(community)); } if (version == VersionCode.V3) { throw new ArgumentException("Only v1 and v2c are supported.", nameof(version)); } Version = version; Header = Header.Empty; Parameters = SecurityParameters.Create(community); var pdu = new GetRequestPdu( requestId, variables); Scope = new Scope(pdu); Privacy = DefaultPrivacyProvider.DefaultPair; _bytes = this.PackMessage(null).ToBytes(); }
/// <summary> /// Creates a <see cref="GetRequestMessage"/> with all contents. /// </summary> /// <param name="requestId">The request id.</param> /// <param name="version">Protocol version</param> /// <param name="community">Community name</param> /// <param name="variables">Variables</param> public GetRequestMessage(int requestId, VersionCode version, OctetString community, IList<Variable> variables) { if (variables == null) { throw new ArgumentNullException("variables"); } if (community == null) { throw new ArgumentNullException("community"); } if (version == VersionCode.V3) { throw new ArgumentException("only v1 and v2c are supported", "version"); } Version = version; Header = Header.Empty; Parameters = SecurityParameters.Create(community); var pdu = new GetRequestPdu( requestId, variables); Scope = new Scope(pdu); Privacy = DefaultPrivacyProvider.DefaultPair; _bytes = this.PackMessage(null).ToBytes(); }
/// <summary> /// Creates a <see cref="GetRequestMessage"/> with all contents. /// </summary> /// <param name="requestId">The request id.</param> /// <param name="version">Protocol version</param> /// <param name="community">Community name</param> /// <param name="variables">Variables</param> public GetRequestMessage(int requestId, VersionCode version, OctetString community, IList<Variable> variables) { if (variables == null) { throw new ArgumentNullException("variables"); } if (community == null) { throw new ArgumentNullException("community"); } if (version == VersionCode.V3) { throw new ArgumentException("only v1 and v2c are supported", "version"); } Version = version; Header = Header.Empty; Parameters = new SecurityParameters(null, null, null, community, null, null); GetRequestPdu pdu = new GetRequestPdu( requestId, ErrorCode.NoError, 0, variables); Scope = new Scope(pdu); Privacy = DefaultPrivacyProvider.DefaultPair; _bytes = SnmpMessageExtension.PackMessage(Version, Header, Parameters, Scope, Privacy).ToBytes(); }
/// <summary> /// Initializes a new instance of the <see cref="GetRequestMessage"/> 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="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> public GetRequestMessage(VersionCode version, int messageId, int requestId, OctetString userName, IList <Variable> variables, IPrivacyProvider privacy, int maxMessageSize, ISnmpMessage report) { 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 (report == null) { throw new ArgumentNullException("report"); } if (privacy == null) { throw new ArgumentNullException("privacy"); } Version = version; Privacy = privacy; Levels recordToSecurityLevel = PrivacyProviderExtension.ToSecurityLevel(privacy); recordToSecurityLevel |= Levels.Reportable; 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 parameters = report.Parameters; var authenticationProvider = Privacy.AuthenticationProvider; Parameters = new SecurityParameters( parameters.EngineId, parameters.EngineBoots, parameters.EngineTime, userName, authenticationProvider.CleanDigest, Privacy.Salt); GetRequestPdu pdu = new GetRequestPdu( requestId, ErrorCode.NoError, 0, variables); var scope = report.Scope; Scope = new Scope(scope.ContextEngineId, scope.ContextName, pdu); Parameters.AuthenticationParameters = authenticationProvider.ComputeHash(Version, Header, Parameters, Scope, Privacy); _bytes = SnmpMessageExtension.PackMessage(Version, Header, Parameters, Scope, Privacy).ToBytes(); }
/// <summary> /// Initializes a new instance of the <see cref="GetRequestMessage"/> 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">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> public GetRequestMessage(VersionCode version, int messageId, int requestId, OctetString userName, OctetString contextName, IList <Variable> variables, IPrivacyProvider privacy, int maxMessageSize, ISnmpMessage report) { if (userName == null) { throw new ArgumentNullException(nameof(userName)); } 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)); } if (report == null) { throw new ArgumentNullException(nameof(report)); } if (privacy == null) { throw new ArgumentNullException(nameof(privacy)); } Version = version; Privacy = privacy; Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToSecurityLevel() | Levels.Reportable); var parameters = report.Parameters; var authenticationProvider = Privacy.AuthenticationProvider; Parameters = new SecurityParameters( parameters.EngineId, parameters.EngineBoots, parameters.EngineTime, userName, authenticationProvider.CleanDigest, Privacy.Salt); var pdu = new GetRequestPdu( requestId, variables); var scope = report.Scope; var contextEngineId = scope.ContextEngineId == OctetString.Empty ? parameters.EngineId : scope.ContextEngineId; 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="GetRequestMessage"/> 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="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> public GetRequestMessage(VersionCode version, int messageId, int requestId, OctetString userName, IList <Variable> variables, IPrivacyProvider privacy, int maxMessageSize, ISnmpMessage report) { 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 (report == null) { throw new ArgumentNullException("report"); } if (privacy == null) { throw new ArgumentNullException("privacy"); } Version = version; Privacy = privacy; Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToOctetString(true)); var parameters = report.Parameters; var authenticationProvider = Privacy.AuthenticationProvider; Parameters = new SecurityParameters( parameters.EngineId, parameters.EngineBoots, parameters.EngineTime, userName, authenticationProvider.CleanDigest, Privacy.Salt); GetRequestPdu pdu = new GetRequestPdu( requestId, variables); var scope = report.Scope; Scope = new Scope(scope.ContextEngineId, scope.ContextName, pdu); authenticationProvider.ComputeHash(Version, Header, Parameters, Scope, Privacy); _bytes = this.PackMessage().ToBytes(); }
public void Test() { byte[] expected = Properties.Resources.get; ISnmpMessage message = MessageFactory.ParseMessages(expected, new UserRegistry())[0]; Assert.Equal(SnmpType.GetRequestPdu, message.TypeCode()); GetRequestPdu pdu = (GetRequestPdu)message.Pdu(); Assert.Equal(1, pdu.Variables.Count); Variable v = pdu.Variables[0]; Assert.Equal(new uint[] { 1, 3, 6, 1, 2, 1, 1, 6, 0 }, v.Id.ToNumerical()); Assert.Equal(typeof(Null), v.Data.GetType()); Assert.True(expected.Length >= message.ToBytes().Length); }
/// <summary> /// Initializes a new instance of the <see cref="GetRequestMessage"/> 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">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 GetRequestMessage(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)); } if (privacy == null) { throw new ArgumentNullException(nameof(privacy)); } Version = version; Privacy = 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 GetRequestPdu( requestId, variables); var contextEngineId = OctetString.Empty; Scope = new Scope(contextEngineId, contextName, pdu); Privacy.ComputeHash(Version, Header, Parameters, Scope); _bytes = this.PackMessage(null).ToBytes(); }
public void TestConstructor() { var pdu = new GetRequestPdu(0, ErrorCode.NoError, 0, new List <Variable>()); Assert.AreEqual("GET request PDU: seq: 0; status: 0; index: 0; variable count: 0", pdu.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="GetRequestMessage"/> 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="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> public GetRequestMessage(VersionCode version, int messageId, int requestId, OctetString userName, IList<Variable> variables, IPrivacyProvider privacy, int maxMessageSize, ISnmpMessage report) { 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 (report == null) { throw new ArgumentNullException("report"); } if (privacy == null) { throw new ArgumentNullException("privacy"); } Version = version; Privacy = privacy; Header = new Header(new Integer32(messageId), new Integer32(maxMessageSize), privacy.ToSecurityLevel() | Levels.Reportable); var parameters = report.Parameters; var authenticationProvider = Privacy.AuthenticationProvider; Parameters = new SecurityParameters( parameters.EngineId, parameters.EngineBoots, parameters.EngineTime, userName, authenticationProvider.CleanDigest, Privacy.Salt); var pdu = new GetRequestPdu( requestId, variables); var scope = report.Scope; var contextEngineId = scope.ContextEngineId == OctetString.Empty ? parameters.EngineId : scope.ContextEngineId; Scope = new Scope(contextEngineId, scope.ContextName, pdu); authenticationProvider.ComputeHash(Version, Header, Parameters, Scope, Privacy); _bytes = this.PackMessage(null).ToBytes(); }
public void TestConstructor() { var pdu = new GetRequestPdu(0, ErrorCode.NoError, 0, new List<Variable>()); Assert.AreEqual("GET request PDU: seq: 0; status: 0; index: 0; variable count: 0", pdu.ToString()); }
/// <summary> /// Initializes a new instance of the <see cref="GetRequestMessage"/> 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="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> public GetRequestMessage(VersionCode version, int messageId, int requestId, OctetString userName, IList<Variable> variables, IPrivacyProvider privacy, int maxMessageSize, ISnmpMessage report) { 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 (report == null) { throw new ArgumentNullException("report"); } if (privacy == null) { throw new ArgumentNullException("privacy"); } Version = version; Privacy = privacy; Levels recordToSecurityLevel = PrivacyProviderExtension.ToSecurityLevel(privacy); recordToSecurityLevel |= Levels.Reportable; 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 parameters = report.Parameters; var authenticationProvider = Privacy.AuthenticationProvider; Parameters = new SecurityParameters( parameters.EngineId, parameters.EngineBoots, parameters.EngineTime, userName, authenticationProvider.CleanDigest, Privacy.Salt); GetRequestPdu pdu = new GetRequestPdu( requestId, ErrorCode.NoError, 0, variables); var scope = report.Scope; Scope = new Scope(scope.ContextEngineId, scope.ContextName, pdu); Parameters.AuthenticationParameters = authenticationProvider.ComputeHash(Version, Header, Parameters, Scope, Privacy); _bytes = SnmpMessageExtension.PackMessage(Version, Header, Parameters, Scope, Privacy).ToBytes(); }