Example #1
0
		public override Tag Step(Tag tag)
		{
            if (tag.Name.LocalName == "success")
			{
				var succ = tag;
				PopulateDirectives(succ);
#if DEBUG
				Manager.Events.LogMessage(this, LogType.Debug, "rspauth = {0}", this["rspauth"]);
#endif


				return succ;
			}

            if (tag.Name.LocalName == "failure")
				return tag;

			var chall = tag;
#if DEBUG
			Manager.Events.LogMessage(this, LogType.Debug, _enc.GetString(tag.Bytes, 0, tag.Bytes.Length));
#endif
			PopulateDirectives(chall);
            Tag res = new tags.xmpp_sasl.response() as Tag;
			if (this["rspauth"] == null)
			{
				GenerateResponseHash();
				res.Bytes = GenerateResponse();
			}

			return res as Tag;
		}
Example #2
0
        public override Tag Step(Tag tag)
		{
            switch (tag.Name.LocalName)
			{
				case "challenge":
					{
						_serverFirst = tag.Bytes;
						var response = _utf.GetString(tag.Bytes, 0, tag.Bytes.Length );

#if DEBUG
						Manager.Events.LogMessage(this, LogType.Debug, "Challenge: {0}", response);
#endif

						// Split challenge into pieces
						var tokens = response.Split(',');

						_snonce = tokens[0].Substring(2);
						// Ensure that the first length of nonce is the same nonce we sent.
						var r = _snonce.Substring(0, _nonce.Length);
						if (0 != String.Compare(r, _nonce))
						{
#if DEBUG
							Manager.Events.LogMessage(this, LogType.Debug, "{0} does not match {1}", r, _nonce);
#endif
						}

#if DEBUG
						Manager.Events.LogMessage(this, LogType.Debug, "Getting Salt");
#endif
						var a = tokens[1].Substring(2);
						_salt = Convert.FromBase64String(a);
#if DEBUG
						Manager.Events.LogMessage(this, LogType.Debug, "Getting Iterations");
#endif
						var i = tokens[2].Substring(2);
						_i = int.Parse(i);
#if DEBUG
						Manager.Events.LogMessage(this, LogType.Debug, "Iterations: {0}", _i);
#endif

						var final = new StringBuilder();
						final.Append("c=biws,r=");
						final.Append(_snonce);

						_clientFinal = final.ToString();

						CalculateProofs();

						final.Append(",p=");
						final.Append(_clientProof);

#if DEBUG
						Manager.Events.LogMessage(this, LogType.Debug, "Final Message: {0}", final.ToString());
#endif

                        Tag resp = new tags.xmpp_sasl.response() as Tag;
						resp.Bytes = _utf.GetBytes(final.ToString());

						return resp;
					}

				case "success":
					{
						var response = _utf.GetString(tag.Bytes, 0, tag.Bytes.Length );
						var signature = Convert.FromBase64String(response.Substring(2));
						return _utf.GetString(signature, 0, signature.Length ) == _utf.GetString(_serverSignature, 0, _serverSignature.Length ) ? tag : null;
					}
				case "failure":
				    return tag;
			}

			return null;
		}
Example #3
0
        public override Tag Step(Tag tag)
        {
            switch (tag.Name.LocalName)
            {
            case "challenge":
            {
                _serverFirst = tag.Bytes;
                var response = _utf.GetString(tag.Bytes, 0, tag.Bytes.Length);

#if DEBUG
                Manager.Events.LogMessage(this, LogType.Debug, "Challenge: {0}", response);
#endif

                // Split challenge into pieces
                var tokens = response.Split(',');

                _snonce = tokens[0].Substring(2);
                // Ensure that the first length of nonce is the same nonce we sent.
                var r = _snonce.Substring(0, _nonce.Length);
                if (0 != String.Compare(r, _nonce))
                {
#if DEBUG
                    Manager.Events.LogMessage(this, LogType.Debug, "{0} does not match {1}", r, _nonce);
#endif
                }

#if DEBUG
                Manager.Events.LogMessage(this, LogType.Debug, "Getting Salt");
#endif
                var a = tokens[1].Substring(2);
                _salt = Convert.FromBase64String(a);
#if DEBUG
                Manager.Events.LogMessage(this, LogType.Debug, "Getting Iterations");
#endif
                var i = tokens[2].Substring(2);
                _i = int.Parse(i);
#if DEBUG
                Manager.Events.LogMessage(this, LogType.Debug, "Iterations: {0}", _i);
#endif

                var final = new StringBuilder();
                final.Append("c=biws,r=");
                final.Append(_snonce);

                _clientFinal = final.ToString();

                CalculateProofs();

                final.Append(",p=");
                final.Append(_clientProof);

#if DEBUG
                Manager.Events.LogMessage(this, LogType.Debug, "Final Message: {0}", final.ToString());
#endif

                Tag resp = new tags.xmpp_sasl.response() as Tag;
                resp.Bytes = _utf.GetBytes(final.ToString());

                return(resp);
            }

            case "success":
            {
                var response  = _utf.GetString(tag.Bytes, 0, tag.Bytes.Length);
                var signature = Convert.FromBase64String(response.Substring(2));
                return(_utf.GetString(signature, 0, signature.Length) == _utf.GetString(_serverSignature, 0, _serverSignature.Length) ? tag : null);
            }

            case "failure":
                return(tag);
            }

            return(null);
        }