コード例 #1
0
        public void TestPasswordToKey()
        {
            byte[] password = Encoding.ASCII.GetBytes("testpass");
            byte[] engineId = new byte[] { 0x80, 0x00, 0x1F, 0x88, 0x80, 0xE9, 0x63, 0x00, 0x00, 0xD6, 0x1F, 0xF4, 0x49 };

            byte[] key = new MD5AuthenticationProvider(new OctetString("")).PasswordToKey(password, engineId);
            Assert.AreEqual(new byte[] { 226, 221, 44, 186, 149, 93, 73, 79, 237, 69, 120, 155, 145, 7, 44, 255 }, key);
        }
コード例 #2
0
 public void TestReportFailure2()
 {
     const string data = "30780201033010020462d4a37602020578040101020103042f302d040b800000090340f4ecf2b113020124020200a4040762696c6c696e67040c62bc133ef237922dfa8ca39a04003030040b800000090340f4ecf2b1130400a81f02049d2b5c8c0201000201003011300f060a2b060106030f01010200410105";
     var bytes = ByteTool.Convert(data);
     const string userName = "******";
     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());
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: bleissem/sharpsnmplib
        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);
            }
        }
コード例 #4
0
        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 = "******";
            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);
        }
コード例 #5
0
 public void TestConstructorV2AuthMd5PrivDes()
 {
     const string bytes = "30 81 80 02  01 03 30 0F  02 02 6C 99  02 03 00 FF" +
                          "E3 04 01 07  02 01 03 04  38 30 36 04  0D 80 00 1F" +
                          "88 80 E9 63  00 00 D6 1F  F4 49 02 01  14 02 01 35" +
                          "04 07 6C 65  78 6D 61 72  6B 04 0C 80  50 D9 A1 E7" +
                          "81 B6 19 80  4F 06 C0 04  08 00 00 00  01 44 2C A3" +
                          "B5 04 30 4B  4F 10 3B 73  E1 E4 BD 91  32 1B CB 41" +
                          "1B A1 C1 D1  1D 2D B7 84  16 CA 41 BF  B3 62 83 C4" +
                          "29 C5 A4 BC  32 DA 2E C7  65 A5 3D 71  06 3C 5B 56" +
                          "FB 04 A4";
     MD5AuthenticationProvider auth = new MD5AuthenticationProvider(new OctetString("testpass"));
     IPrivacyProvider privacy = new DESPrivacyProvider(new OctetString("passtest"), auth);
     GetRequestMessage request = new GetRequestMessage(
         VersionCode.V3,
         new Header(
             new Integer32(0x6C99),
             new Integer32(0xFFE3),
             Levels.Authentication | Levels.Privacy | Levels.Reportable),
         new SecurityParameters(
             new OctetString(ByteTool.Convert("80 00 1F 88 80 E9 63 00  00 D6 1F F4  49")),
             new Integer32(0x14),
             new Integer32(0x35),
             new OctetString("lexmark"),
             new OctetString(ByteTool.Convert("80  50 D9 A1 E7 81 B6 19 80  4F 06 C0")),
             new OctetString(ByteTool.Convert("00 00 00  01 44 2C A3 B5"))),
         new Scope(
             new OctetString(ByteTool.Convert("80 00 1F 88 80 E9 63 00  00 D6 1F F4  49")),
             OctetString.Empty,
             new GetRequestPdu(
                 0x3A25,
                 new List<Variable>(1) { new Variable(new ObjectIdentifier("1.3.6.1.2.1.1.3.0")) })),
         privacy,
         null);
     Assert.AreEqual(Levels.Authentication | Levels.Privacy | Levels.Reportable, request.Header.SecurityLevel);
     Assert.AreEqual(ByteTool.Convert(bytes), request.ToBytes());
 }
コード例 #6
0
ファイル: User.cs プロジェクト: moljac/MonoMobile.SharpSNMP
        /// <summary>
        /// Initializes a new instance of the <see cref="User"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="authentication">The authentication.</param>
        /// <param name="authenticationPhrase">The authen phrase.</param>
        /// <param name="privacy">The privacy.</param>
        /// <param name="privacyPhrase">The privacy phrase.</param>
        public User(OctetString name, string authentication, OctetString authenticationPhrase, string privacy, OctetString privacyPhrase)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }

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

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

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

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

            IAuthenticationProvider authenticationProvider;
            if (string.IsNullOrEmpty(authentication))
            {
                authenticationProvider = DefaultAuthenticationProvider.Instance;
            }
            else if (authentication.ToUpperInvariant() == "MD5")
            {
                authenticationProvider = new MD5AuthenticationProvider(authenticationPhrase);
            }
            else if (authentication.ToUpperInvariant() == "SHA")
            {
                authenticationProvider = new SHA1AuthenticationProvider(authenticationPhrase);
            }
            else
            {
                throw new ArgumentException("Unknown authentication method: " + authentication, "authentication");
            }

            IPrivacyProvider privacyProvider;
            if (string.IsNullOrEmpty(privacy))
            {
                privacyProvider = new DefaultPrivacyProvider(authenticationProvider);
            }
            else if (privacy.ToUpperInvariant() == "DES")
            {
                privacyProvider = new DESPrivacyProvider(privacyPhrase, authenticationProvider);
            }
            else
            {
                throw new ArgumentException("Unknown privacy method: " + privacy, "privacy");
            }

            Name = name;
            Privacy = privacyProvider;
        }
コード例 #7
0
        public void TestGetRequestV3AuthPriv()
        {
            const string bytes = "30 81 80 02  01 03 30 0F  02 02 6C 99  02 03 00 FF" +
                                 "E3 04 01 07  02 01 03 04  38 30 36 04  0D 80 00 1F" +
                                 "88 80 E9 63  00 00 D6 1F  F4 49 02 01  14 02 01 35" +
                                 "04 07 6C 65  78 6D 61 72  6B 04 0C 80  50 D9 A1 E7" +
                                 "81 B6 19 80  4F 06 C0 04  08 00 00 00  01 44 2C A3" +
                                 "B5 04 30 4B  4F 10 3B 73  E1 E4 BD 91  32 1B CB 41" +
                                 "1B A1 C1 D1  1D 2D B7 84  16 CA 41 BF  B3 62 83 C4" +
                                 "29 C5 A4 BC  32 DA 2E C7  65 A5 3D 71  06 3C 5B 56" +
                                 "FB 04 A4";
            MD5AuthenticationProvider auth = new MD5AuthenticationProvider(new OctetString("testpass"));
            var registry = new UserRegistry();
            registry.Add(new OctetString("lexmark"), new DESPrivacyProvider(new OctetString("passtest"), auth));
            IList<ISnmpMessage> messages = MessageFactory.ParseMessages(bytes, registry);
            Assert.AreEqual(1, messages.Count);
            GetRequestMessage get = (GetRequestMessage)messages[0];
            Assert.AreEqual(27801, get.MessageId);
            //Assert.AreEqual(SecurityLevel.None | SecurityLevel.Reportable, get.Level);
            Assert.AreEqual("lexmark", get.Community.ToString());
            //OctetString digest = new MD5AuthenticationProvider(new OctetString("testpass")).ComputeHash(get);

            //Assert.AreEqual(digest, get.Parameters.AuthenticationParameters);
        }