当前位置: 首页>>代码示例>>C#>>正文


C# Security.UserRegistry类代码示例

本文整理汇总了C#中Lextm.SharpSnmpLib.Security.UserRegistry的典型用法代码示例。如果您正苦于以下问题:C# UserRegistry类的具体用法?C# UserRegistry怎么用?C# UserRegistry使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


UserRegistry类属于Lextm.SharpSnmpLib.Security命名空间,在下文中一共展示了UserRegistry类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestConstructor

 public void TestConstructor()
 {
     var response = new ResponseMessage(
         VersionCode.V3,
         new Header(
             new Integer32(500),
             new Integer32(4000),
             Levels.Reportable),
         new SecurityParameters(
             OctetString.Empty,
             Integer32.Zero,
             Integer32.Zero,
             new OctetString("lextm"),
             OctetString.Empty,
             OctetString.Empty),
         new Scope(
             OctetString.Empty,
             OctetString.Empty,
             new ResponsePdu(0x2C6B, ErrorCode.NoError, 0, new List<Variable>{ new Variable(new ObjectIdentifier("1.3.6.1.1.2.5.0"), new Integer32(400))})),
         DefaultPrivacyProvider.DefaultPair,
         true,
         null);
     var registry = new UserRegistry();
     registry.Add(new OctetString("lextm"), DefaultPrivacyProvider.DefaultPair);
     var messages = MessageFactory.ParseMessages(response.ToBytes(), registry);
     Assert.AreEqual(1, messages.Count);
 }
开发者ID:bleissem,项目名称:sharpsnmplib,代码行数:27,代码来源:ResponseMessageTestFixture.cs

示例2: SnmpContextBase

 /// <summary>
 /// Initializes a new instance of the <see cref="SnmpContextBase"/> class.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="users">The users.</param>
 /// <param name="group">The engine core group.</param>
 /// <param name="binding">The binding.</param>
 protected SnmpContextBase(ISnmpMessage request, IPEndPoint sender, UserRegistry users, EngineGroup group, IListenerBinding binding)
 {
     Request = request;
     Binding = binding;
     Users = users;
     Sender = sender;
     CreatedTime = DateTime.Now;
     Group = group;
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:17,代码来源:SnmpContextBase.cs

示例3: Create

        /// <summary>
        /// Creates the specified request.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="sender">The sender.</param>
        /// <param name="users">The users.</param>
        /// <param name="group">The engine group.</param>
        /// <param name="binding">The binding.</param>
        /// <returns></returns>
        public static SnmpContext Create(ISnmpMessage request, IPEndPoint sender, UserRegistry users, EngineGroup group, IListenerBinding binding)
        {
            if (request.Version == VersionCode.V3)
            {
                return new SecureSnmpContext(request, sender, users, group, binding);
            }

            return new NormalSnmpContext(request, sender, users, binding);
        }
开发者ID:moljac,项目名称:MonoMobile.SharpSNMP,代码行数:18,代码来源:SnmpContextFactory.cs

示例4: ParseMessages

 /// <summary>
 /// Creates <see cref="ISnmpMessage"/> instances from a string.
 /// </summary>
 /// <param name="bytes">Byte string.</param>
 /// <param name="registry">The registry.</param>
 /// <returns></returns>
 public static IList<ISnmpMessage> ParseMessages(IEnumerable<char> bytes, UserRegistry registry)
 {
     if (bytes == null)
     {
         throw new ArgumentNullException("bytes");
     }
     
     if (registry == null)
     {
         throw new ArgumentNullException("registry");
     }
     
     return ParseMessages(ByteTool.Convert(bytes), registry);
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:20,代码来源:MessageFactory.cs

示例5: TestReportFailure2

 public void TestReportFailure2()
 {
     const string data = "30780201033010020462d4a37602020578040101020103042f302d040b800000090340f4ecf2b113020124020200a4040762696c6c696e67040c62bc133ef237922dfa8ca39a04003030040b800000090340f4ecf2b1130400a81f02049d2b5c8c0201000201003011300f060a2b060106030f01010200410105";
     var bytes = ByteTool.Convert(data);
     const string userName = "billing";
     IAuthenticationProvider auth = new MD5AuthenticationProvider(new OctetString("testing345"));
     IPrivacyProvider priv = new DefaultPrivacyProvider(auth);
     var users = new UserRegistry();
     users.Add(new User(new OctetString(userName), priv));
     var messages = MessageFactory.ParseMessages(bytes, users);
     Assert.AreEqual(1, messages.Count);
     var message = messages[0];
     Assert.AreEqual(1, message.Variables().Count);
     Assert.AreEqual("not in time window", message.Variables()[0].Id.GetErrorMessage());
 }
开发者ID:yutaodou,项目名称:sharpsnmplib,代码行数:15,代码来源:MessageFactoryTestFixture.cs

示例6: txtBytes_TextChanged

        private void txtBytes_TextChanged(object sender, EventArgs e)
        {
            tvMessage.Nodes.Clear();
            var users = new UserRegistry();
            IAuthenticationProvider authen;
            if (tscbAuthentication.SelectedIndex == 0)
            {
                authen = DefaultAuthenticationProvider.Instance;
            }
            else if (tscbAuthentication.SelectedIndex == 1)
            {
                authen = new MD5AuthenticationProvider(new OctetString(tstxtAuthentication.Text));
            }
            else
            {
                authen = new SHA1AuthenticationProvider(new OctetString(tstxtAuthentication.Text));
            }

            IPrivacyProvider privacy;
            if (tscbPrivacy.SelectedIndex == 0)
            {
                privacy = new DefaultPrivacyProvider(authen);
            }
            else if (tscbPrivacy.SelectedIndex == 1)
            {
                privacy = new DESPrivacyProvider(new OctetString(tstxtPrivacy.Text), authen);
            }
            else
            {
                privacy = new AESPrivacyProvider(new OctetString(tstxtPrivacy.Text), authen);
            }

            users.Add(new User(new OctetString(tstxtUser.Text), privacy));

            try
            {
                var messages = MessageFactory.ParseMessages(ByteTool.Convert(txtBytes.Text.Replace("\"", null).Replace("+", null)), users);
                messages.Fill(tvMessage);
            }
            catch (Exception ex)
            {
                tvMessage.Nodes.Add(ex.Message);
            }
        }
开发者ID:bleissem,项目名称:sharpsnmplib,代码行数:44,代码来源:Form1.cs

示例7: Main

        public static void Main(string[] args)
        {
            if (args.Length != 0)
            {
                return;
            }

            var users = new UserRegistry();
            users.Add(new OctetString("neither"), DefaultPrivacyProvider.DefaultPair);
            users.Add(new OctetString("authen"), new DefaultPrivacyProvider(new MD5AuthenticationProvider(new OctetString("authentication"))));
            users.Add(new OctetString("privacy"), new DESPrivacyProvider(new OctetString("privacyphrase"),
                                                                         new MD5AuthenticationProvider(new OctetString("authentication")))); 

            var trapv1 = new TrapV1MessageHandler();
            trapv1.MessageReceived += WatcherTrapV1Received;
            var trapv1Mapping = new HandlerMapping("v1", "TRAPV1", trapv1);

            var trapv2 = new TrapV2MessageHandler();
            trapv2.MessageReceived += WatcherTrapV2Received;
            var trapv2Mapping = new HandlerMapping("v2,v3", "TRAPV2", trapv2);

            var inform = new InformRequestMessageHandler();
            inform.MessageReceived += WatcherInformRequestReceived;
            var informMapping = new HandlerMapping("v2,v3", "INFORM", inform);

            var store = new ObjectStore();
            var v1 = new Version1MembershipProvider(new OctetString("public"), new OctetString("public"));
            var v2 = new Version2MembershipProvider(new OctetString("public"), new OctetString("public"));
            var v3 = new Version3MembershipProvider();
            var membership = new ComposedMembershipProvider(new IMembershipProvider[] {v1, v2, v3});
            var handlerFactory = new MessageHandlerFactory(new[] {trapv1Mapping, trapv2Mapping, informMapping});

            var pipelineFactory = new SnmpApplicationFactory(store, membership, handlerFactory);
            using (var engine = new SnmpEngine(pipelineFactory, new Listener { Users = users }, new EngineGroup()))
            {
                engine.Listener.AddBinding(new IPEndPoint(IPAddress.Any, 162));
                engine.Start();
                Console.WriteLine("#SNMP is available at http://sharpsnmplib.codeplex.com");
                Console.WriteLine("Press any key to stop . . . ");
                Console.Read();
                engine.Stop();
            }
        }
开发者ID:bleissem,项目名称:sharpsnmplib,代码行数:43,代码来源:Program.cs

示例8: TestToBytes3

 public void TestToBytes3()
 {
     var privacy = new DESPrivacyProvider(new OctetString("privacyphrase"), new MD5AuthenticationProvider(new OctetString("authentication")));
     var trap = new TrapV2Message(
         VersionCode.V3,
         new Header(
             new Integer32(1004947569),
             new Integer32(0x10000),
             privacy.ToSecurityLevel()),
         new SecurityParameters(
             new OctetString(ByteTool.Convert("80001F8880E9630000D61FF449")),
             Integer32.Zero,
             Integer32.Zero,
             new OctetString("lextm"),
             new OctetString(ByteTool.Convert("61A9A486AF4A861BD5C0BB1F")), 
             new OctetString(ByteTool.Convert("0000000069D39B2A"))),
         new Scope(OctetString.Empty, OctetString.Empty,
                   new TrapV2Pdu(
                       234419641,
                       new ObjectIdentifier("1.3.6"),
                       0,
                       new List<Variable>())),
         privacy, 
         null);         
     byte[] bytes = trap.ToBytes();
     UserRegistry registry = new UserRegistry();
     registry.Add(new OctetString("lextm"), privacy);
     IList<ISnmpMessage> messages = MessageFactory.ParseMessages(bytes, registry);
     Assert.AreEqual(1, messages.Count);
     ISnmpMessage message = messages[0];
     Assert.AreEqual("80001F8880E9630000D61FF449", message.Parameters.EngineId.ToHexString());
     Assert.AreEqual(0, message.Parameters.EngineBoots.ToInt32());
     Assert.AreEqual(0, message.Parameters.EngineTime.ToInt32());
     Assert.AreEqual("lextm", message.Parameters.UserName.ToString());
     Assert.AreEqual("61A9A486AF4A861BD5C0BB1F", message.Parameters.AuthenticationParameters.ToHexString());
     Assert.AreEqual("0000000069D39B2A", message.Parameters.PrivacyParameters.ToHexString());
     Assert.AreEqual("", message.Scope.ContextEngineId.ToHexString()); // SNMP#NET returns string.Empty here.
     Assert.AreEqual("", message.Scope.ContextName.ToHexString());
     Assert.AreEqual(0, message.Scope.Pdu.Variables.Count);
     Assert.AreEqual(1004947569, message.MessageId());
     Assert.AreEqual(234419641, message.RequestId());
 }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:42,代码来源:TrapV2MessageTestFixture.cs

示例9: TestReportFailure

        public void TestReportFailure()
        {
            const string data = "30 70 02 01 03 30"+
                                "11 02 04 76 EB 6A 22 02 03 00 FF F0 04 01 01 02 01 03 04 33 30 31 04 09"+

                                "80 00 05 23 01 C1 4D BB 83 02 01 5B 02 03 1C 93 9D 04 0C 4D 44 35 5F 44"+
                                "45 53 5F 55 73 65 72 04 0C E5 C7 C5 2E 17 7E 87 62 AB 56 D6 C7 04 00 30"+
                                "23 04 00 04 00 A8 1D 02 01 00 02 01 00 02 01 00 30 12 30 10 06 0A 2B 06"+

                                "01 06 03 0F 01 01 02 00 41 02 05 EE";
            var bytes = ByteTool.Convert(data);
            const string userName = "MD5_DES_User";
            const string phrase = "AuthPassword";
            const string privatePhrase = "PrivPassword";
            IAuthenticationProvider auth = new MD5AuthenticationProvider(new OctetString(phrase));
            IPrivacyProvider priv = new DESPrivacyProvider(new OctetString(privatePhrase), auth);
            var users = new UserRegistry();
            users.Add(new User(new OctetString(userName), priv));
            var messages = MessageFactory.ParseMessages(bytes, users);
            Assert.AreEqual(1, messages.Count);
            var message = messages[0];
            Assert.AreEqual(1, message.Variables().Count);
        }
开发者ID:yutaodou,项目名称:sharpsnmplib,代码行数:23,代码来源:MessageFactoryTestFixture.cs

示例10: SecureAgentProfile

        public SecureAgentProfile(Guid id, VersionCode version, IPEndPoint agent, string agentName, string authenticationPassphrase, string privacyPassphrase, int authenticationMethod, int privacyMethod, string userName, int timeout)
            : base(id, version, agent, agentName, userName, timeout)
        {
            AuthenticationPassphrase = authenticationPassphrase;
            PrivacyPassphrase = privacyPassphrase;
            AuthenticationMethod = authenticationMethod;
            PrivacyMethod = privacyMethod;

            switch (AuthenticationMethod)
            {
                case 0:
                    _auth = DefaultAuthenticationProvider.Instance;
                    break;
                case 1:
                    _auth = new MD5AuthenticationProvider(new OctetString(AuthenticationPassphrase));
                    break;
                case 2:
                    _auth = new SHA1AuthenticationProvider(new OctetString(AuthenticationPassphrase));
                    break;
            }

            switch (PrivacyMethod)
            {
                case 0:
                    _privacy = new DefaultPrivacyProvider(_auth);
                    break;
                case 1:
                    _privacy = new DESPrivacyProvider(new OctetString(PrivacyPassphrase), _auth);
                    break;
                case 2:
                    _privacy = new AESPrivacyProvider(new OctetString(PrivacyPassphrase), _auth);
                    break;
            }
            
            _registry = new UserRegistry().Add(new OctetString(userName), _privacy);
        }
开发者ID:xxjeng,项目名称:nuxleus,代码行数:36,代码来源:SecureAgentProfile.cs

示例11: SnmpMessageAsyncResult

 public SnmpMessageAsyncResult(IAsyncResult inner, Socket socket, UserRegistry users, IPEndPoint receiver, byte[] buffer)
 {
     _buffer = buffer;
     WorkSocket = socket;
     Users = users;
     Receiver = receiver;
     Inner = inner;
 }
开发者ID:nickolaykon,项目名称:sharpsnmplib,代码行数:8,代码来源:SnmpMessageExtension.cs

示例12: SecureSnmpContext

 /// <summary>
 /// Initializes a new instance of the <see cref="SecureSnmpContext"/> class.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <param name="sender">The sender.</param>
 /// <param name="users">The users.</param>
 /// <param name="group">The engine core group.</param>
 /// <param name="binding">The binding.</param>
 public SecureSnmpContext(ISnmpMessage request, IPEndPoint sender, UserRegistry users, EngineGroup group, IListenerBinding binding)
     : base(request, sender, users, group, binding)
 {
 }
开发者ID:bleissem,项目名称:sharpsnmplib,代码行数:12,代码来源:SecureSnmpContext.cs

示例13: GetResponse

        /// <summary>
        /// Sends an  <see cref="ISnmpMessage"/> and handles the response from agent.
        /// </summary>
        /// <param name="request">The <see cref="ISnmpMessage"/>.</param>
        /// <param name="timeout">The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.</param>
        /// <param name="receiver">Agent.</param>
        /// <param name="udpSocket">The UDP <see cref="Socket"/> to use to send/receive.</param>
        /// <param name="registry">The user registry.</param>
        /// <returns></returns>
        public static ISnmpMessage GetResponse(this ISnmpMessage request, int timeout, IPEndPoint receiver, UserRegistry registry, Socket udpSocket)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (udpSocket == null)
            {
                throw new ArgumentNullException("udpSocket");
            }

            if (receiver == null)
            {
                throw new ArgumentNullException("receiver");
            }
            
            if (registry == null)
            {
                throw new ArgumentNullException("registry");
            }

            var requestCode = request.TypeCode();
            if (requestCode == SnmpType.TrapV1Pdu || requestCode == SnmpType.TrapV2Pdu || requestCode == SnmpType.ReportPdu)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "not a request message: {0}", requestCode));
            }

            var bytes = request.ToBytes();
            #if CF
            int bufSize = 8192;
            #else
            var bufSize = udpSocket.ReceiveBufferSize;
            #endif
            var reply = new byte[bufSize];

            // Whatever you change, try to keep the Send and the Receive close to each other.
            udpSocket.SendTo(bytes, receiver);
            #if !CF
            udpSocket.ReceiveTimeout = timeout;
            #endif
            int count;
            try
            {
                count = udpSocket.Receive(reply, 0, bufSize, SocketFlags.None);
            }
            catch (SocketException ex)
            {
                // FIXME: If you use a Mono build without the fix for this issue (https://bugzilla.novell.com/show_bug.cgi?id=599488), please uncomment this code.
                /*
                if (SnmpMessageExtension.IsRunningOnMono && ex.ErrorCode == 10035)
                {
                    throw TimeoutException.Create(receiver.Address, timeout);
                }
                // */

                if (ex.ErrorCode == WSAETIMEDOUT)
                {
                    throw TimeoutException.Create(receiver.Address, timeout);
                }

                throw;
            }

            // Passing 'count' is not necessary because ParseMessages should ignore it, but it offer extra safety (and would avoid an issue if parsing >1 response).
            var response = MessageFactory.ParseMessages(reply, 0, count, registry)[0];
            var responseCode = response.TypeCode();
            if (responseCode == SnmpType.ResponsePdu || responseCode == SnmpType.ReportPdu)
            {
                var requestId = request.MessageId();
                var responseId = response.MessageId();
                if (responseId != requestId)
                {
                    throw OperationException.Create(string.Format(CultureInfo.InvariantCulture, "wrong response sequence: expected {0}, received {1}", requestId, responseId), receiver.Address);
                }

                return response;
            }

            throw OperationException.Create(string.Format(CultureInfo.InvariantCulture, "wrong response type: {0}", responseCode), receiver.Address);
        }
开发者ID:nickolaykon,项目名称:sharpsnmplib,代码行数:90,代码来源:SnmpMessageExtension.cs

示例14: BeginGetResponse

        /// <summary>
        /// Begins to asynchronously send an <see cref="ISnmpMessage"/> to an <see cref="IPEndPoint"/>.
        /// </summary>
        /// <param name="request">The <see cref="ISnmpMessage"/>.</param>
        /// <param name="receiver">Agent.</param>
        /// <param name="registry">The user registry.</param>
        /// <param name="udpSocket">The UDP <see cref="Socket"/> to use to send/receive.</param>
        /// <param name="callback">The callback.</param>
        /// <param name="state">The state object.</param>
        /// <returns></returns>
        public static IAsyncResult BeginGetResponse(this ISnmpMessage request, IPEndPoint receiver, UserRegistry registry, Socket udpSocket, AsyncCallback callback, object state)
        {
            if (request == null)
            {
                throw new ArgumentNullException("request");
            }

            if (udpSocket == null)
            {
                throw new ArgumentNullException("udpSocket");
            }

            if (receiver == null)
            {
                throw new ArgumentNullException("receiver");
            }

            if (registry == null)
            {
                throw new ArgumentNullException("registry");
            }

            var requestCode = request.TypeCode();
            if (requestCode == SnmpType.TrapV1Pdu || requestCode == SnmpType.TrapV2Pdu || requestCode == SnmpType.ReportPdu)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "not a request message: {0}", requestCode));
            }

            // Whatever you change, try to keep the Send and the Receive close to each other.
            udpSocket.SendTo(request.ToBytes(), receiver);
            #if CF
            var bufferSize = 8192;
            #else
            var bufferSize = udpSocket.ReceiveBufferSize;
            #endif
            var buffer = new byte[bufferSize];

            // http://sharpsnmplib.codeplex.com/workitem/7234
            if (callback != null)
            {
                AsyncCallback wrapped = callback;
                callback = asyncResult =>
                {
                    var result = new SnmpMessageAsyncResult(asyncResult, udpSocket, registry, receiver, buffer);
                    wrapped(result);
                };
            }

            var ar = udpSocket.BeginReceive(buffer, 0, bufferSize, SocketFlags.None, callback, state);
            return new SnmpMessageAsyncResult(ar, udpSocket, registry, receiver, buffer);
        }
开发者ID:nickolaykon,项目名称:sharpsnmplib,代码行数:61,代码来源:SnmpMessageExtension.cs

示例15: GetResponse

        /// <summary>
        /// Sends this <see cref="SetRequestMessage"/> and handles the response from agent.
        /// </summary>
        /// <param name="timeout">The time-out value, in milliseconds. The default value is 0, which indicates an infinite time-out period. Specifying -1 also indicates an infinite time-out period.</param>
        /// <param name="receiver">Agent.</param>
        /// <param name="socket">The UDP <see cref="Socket"/> to use to send/receive.</param>
        /// <returns></returns>
        private ISnmpMessage GetResponse(int timeout, IPEndPoint receiver, Socket socket)
        {
            if (socket == null)
            {
                throw new ArgumentNullException("socket");
            }
            
            if (receiver == null)
            {
                throw new ArgumentNullException("receiver");
            }

            UserRegistry registry = new UserRegistry();
            if (Version == VersionCode.V3)
            {
                registry.Add(Parameters.UserName, Privacy);
            }

            return MessageFactory.GetResponse(receiver, ToBytes(), MessageId, timeout, registry, socket);
        }
开发者ID:moljac,项目名称:MonoMobile.SharpSNMP,代码行数:27,代码来源:SetRequestMessage.cs


注:本文中的Lextm.SharpSnmpLib.Security.UserRegistry类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。