Пример #1
0
        /// <summary>
        /// Perform the next step
        /// </summary>
        /// <param name="s">Null if it's the initial response</param>
        /// <param name="doc">Document to create Steps in</param>
        /// <returns></returns>
        public override Step step(Step s, XmlDocument doc)
        {
            Debug.Assert(s == null);
            Auth a = new Auth(doc);
            a.Mechanism = MechanismType.PLAIN;
            MemoryStream ms = new MemoryStream();

            // message = [authorize-id] NUL authenticate-id NUL password

            // Skip authzid.
            ms.WriteByte(0);
            string u = this[USERNAME];
            if ((u == null) || (u == ""))
                throw new SASLException("Username required");
            byte[] bu = System.Text.Encoding.UTF8.GetBytes(u);
            ms.Write(bu, 0, bu.Length);
            ms.WriteByte(0);
            string p = this[PASSWORD];
            if ((p == null) || (p == ""))
                throw new SASLException("Password required");
            byte[] pu = System.Text.Encoding.UTF8.GetBytes(p);
            ms.Write(pu, 0, pu.Length);

            a.Bytes = ms.ToArray();
            return a;
        }
Пример #2
0
 /// <summary>
 /// Perform the next step
 /// </summary>
 /// <param name="s">Null if it's the initial response</param>
 /// <param name="doc">Document to create Steps in</param>
 /// <returns></returns>
 public override Step step(Step s, XmlDocument doc)
 {
     Debug.Assert(s == null);
     Auth a = new Auth(doc);
     a.Mechanism = MechanismType.EXTERNAL;
     return a;
 }
Пример #3
0
        /// <summary>
        /// Process the next DIGEST-MD5 step.
        /// </summary>
        /// <param name="s">The previous step.  Null for the first step</param>
        /// <param name="doc">Document to create next step in.</param>
        /// <returns></returns>
        /// <exception cref="AuthenticationFailedException">Thrown if authentication fails</exception>
        public override Step step(Step s, XmlDocument doc)
        {
            Step resp = null;

            if (s == null)
            { // first step
                Auth a = new Auth(doc);
                a.Mechanism = MechanismType.DIGEST_MD5;
                return a;
            }

            Debug.Assert(s is Challenge);
            populateDirectives(ENC.GetString(s.Bytes));
            validateStartDirectives();


            resp = new Response(doc);
            if (this["rspauth"] == null)  // we haven't authenticated yet
            {
                generateResponseString();
                resp.Bytes = generateResponse();
            }
            else // we have authenticated
            {
                // make sure what is in rspauth is correct
                if (!validateResponseAuth())
                {
                    throw new AuthenticationFailedException();
                }
            }
            return resp;
        }