コード例 #1
0
        public void CanCreateExternal()
        {
            Hashtable props = new Hashtable();

            string[]    mechanisms = new string[] { "EXTERNAL", "OTHER" };
            ISaslClient client     = Sasl.CreateClient(mechanisms, "", "", "", props, this);

            Assert.IsNotNull(client);
            Assert.IsInstanceOfType(typeof(ExternalSaslClient), client);
        }
コード例 #2
0
        public void ReturnsNullIfNoFactoryFound()
        {
            Hashtable props = new Hashtable();

            props.Add(SaslProperties.PolicyNoPlainText, true);
            string[]    mechanisms = new string[] { "PLAIN", "OTHER" };
            ISaslClient client     = Sasl.CreateClient(mechanisms, "", "", "", props, this);

            Assert.IsNull(client);
        }
コード例 #3
0
        public void CanCreateDigest()
        {
            Hashtable props = new Hashtable();

            string[]    mechanisms = new string[] { "DIGEST-MD5", "OTHER" };
            ISaslClient client     = Sasl.CreateClient(mechanisms, "", "", "", props, this);

            Assert.IsNotNull(client);
            Assert.IsInstanceOfType(typeof(DigestSaslClient), client);
        }
コード例 #4
0
        public void CanCreateAnonymous()
        {
            Hashtable props = new Hashtable();

            string[]    mechanisms = new string[] { "ANONYMOUS", "OTHER" };
            ISaslClient client     = Sasl.CreateClient(mechanisms, "", "", "", props, this);

            Assert.IsNotNull(client);
            Assert.IsInstanceOfType(typeof(AnonymousSaslClient), client);
        }
コード例 #5
0
        public void CanCreatePlain()
        {
            Hashtable props = new Hashtable();

            string[]    mechanisms = new string[] { "PLAIN", "OTHER" };
            ISaslClient client     = Sasl.CreateClient(mechanisms, "", "", "", props, this);

            Assert.IsNotNull(client);
            Assert.IsInstanceOfType(typeof(PlainSaslClient), client);
        }
コード例 #6
0
        public void ChoosesStrongerMechanism()
        {
            Hashtable props = new Hashtable();

            string[]    mechanisms = new string[] { "PLAIN", "OTHER", "CRAM-MD5" };
            ISaslClient client     = Sasl.CreateClient(mechanisms, "", "", "", props, this);

            Assert.IsNotNull(client);
            Assert.IsInstanceOfType(typeof(CramMD5SaslClient), client);
        }
コード例 #7
0
        public void ParsesConfigurationSection()
        {
            // if the TEST mechanism is available, then we know
            // the configuration section worked!
            Hashtable props = new Hashtable();

            string[]    mechanisms = new string[] { "TEST" };
            ISaslClient client     = Sasl.CreateClient(mechanisms, "", "", "", props, this);

            Assert.IsNotNull(client);
            Assert.IsInstanceOfType(typeof(TestSaslClient), client);
        }
コード例 #8
0
        public static UUID Parse(string hex)
        {
            if (hex.Length != ByteLength * 2)
            {
                throw new Exception("Cannot parse UUID/GUID of invalid length");
            }

            UUID id = new UUID();

            byte *result = (byte *)&id.a;
            int   n = 0, i = 0;

            while (n < ByteLength)
            {
                result[n]    = (byte)(Sasl.FromHexChar(hex[i++]) << 4);
                result[n++] += Sasl.FromHexChar(hex[i++]);
            }

            return(id);
        }
コード例 #9
0
ファイル: LdapClient.cs プロジェクト: bestprotop/internetpack
        public void Bind(String dn, String password, DigestType digestType)
        {
            if (fCurrentConnection == null)
            {
                Open();
            }

            if (String.IsNullOrEmpty(dn) || String.IsNullOrEmpty(password))
            {
                digestType = DigestType.None;
            }

            switch (digestType)
            {
            case DigestType.MD5:
            {
                Int32 lSequenceId = SendLdapRequest(Asn1.LDAPBINDREQ,
                                                    new BerInteger(LdapVersion),
                                                    new BerString(Asn1.OCTETSTRING, ""),
                                                    new BerSequence(Asn1.LDAPBINDSASL, new BerString(Asn1.OCTETSTRING, "DIGEST-MD5")));

                Response lResponse = ReadResponse();
                if (lResponse.SequenceId != lSequenceId)
                {
                    throw new LdapException("Invalid sequence id in bind response");
                }
                if (lResponse.Code != 14 || lResponse.RestData == null || lResponse.RestData[0].Type != BerType.String)                                 // 14 = Sasl bind in progress
                {
                    throw new LdapException(lResponse.Code);
                }


                String lResult        = ((BerString)lResponse.RestData[0]).Value;
                String lEncodedResult = Sasl.MD5Login(lResult, dn, password, GetTargetHostName());

                lSequenceId = SendLdapRequest(Asn1.LDAPBINDREQ,
                                              new BerInteger(LdapVersion),
                                              new BerString(Asn1.OCTETSTRING, ""),
                                              new BerSequence(Asn1.LDAPBINDSASL, new BerString(Asn1.OCTETSTRING, lEncodedResult)));

                lResponse = ReadResponse();
                if (lResponse.SequenceId != lSequenceId)
                {
                    throw new LdapException("Invalid sequence id in bind response");
                }

                if (lResponse.Code != 14 || lResponse.RestData == null || lResponse.RestData[0].Type != BerType.String)                                 // 14 = Sasl bind in progress
                {
                    throw new LdapException(lResponse.Code);
                }

                lSequenceId = SendLdapRequest(Asn1.LDAPBINDREQ,
                                              new BerInteger(LdapVersion),
                                              new BerString(Asn1.OCTETSTRING, ""),
                                              new BerSequence(Asn1.LDAPBINDSASL, new BerString(Asn1.OCTETSTRING, "DIGEST-MD5")));

                lResponse = ReadResponse();
                if (lResponse.SequenceId != lSequenceId)
                {
                    throw new LdapException("Invalid sequence id in bind response");
                }

                if (lResponse.Code != 0)
                {
                    throw new LdapException(lResponse.Code);
                }
                break;
            }

            default:
            {
                Int32 lSequenceId = SendLdapRequest(Asn1.LDAPBINDREQ,
                                                    new BerInteger(LdapVersion),
                                                    new BerString(Asn1.OCTETSTRING, dn),
                                                    new BerString(Asn1.LDAPBINDPASSWORD, password));
                Response lResponse = ReadResponse();

                if (lResponse.SequenceId != lSequenceId)
                {
                    throw new LdapException("Invalid sequence id in bind response");
                }

                if (lResponse.Code != 0)
                {
                    throw new LdapException(lResponse.Code);
                }

                break;
            }
            }

            fLoggedIn = true;
        }