/// <summary> /// Performs the authentication using the SASL Plain authentication mechanism. /// </summary> public override void Authenticate() { if (this.RequestToken()) { // Send authentication mechanism Auth auth = new Auth(); auth.Value = this.BuildMessage(); auth.Mechanism = XmppCodes.SaslXGoogleTokenMechanism; this.Connection.Send(auth); this.waitEvent.WaitOne(); if (!this.AuthenticationFailed) { // Re-Initialize XMPP Stream this.Connection.InitializeXmppStream(); // Wait until we receive the Stream features this.Connection.WaitForStreamFeatures(); } } else { this.AuthenticationFailed = true; } }
/// <summary> /// Performs the authentication using the SASL digest authentication mechanism. /// </summary> public override void Authenticate() { // Send authentication mechanism Auth auth = new Auth(); auth.Mechanism = XmppCodes.SaslDigestMD5Mechanism; this.Connection.Send(auth); this.successEvent.WaitOne(); // Verify received Digest-Challenge // Check that the nonce setting is pressent if (!this.digestChallenge.ContainsKey("nonce")) { throw new XmppException("SASL Authrization failed. Incorrect challenge received from server"); } // Check that the charset is correct if (this.digestChallenge.ContainsKey("charset") && this.digestChallenge["charset"] != "utf-8") { throw new XmppException("SASL Authrization failed. Incorrect challenge received from server"); } // Check that the mechanims is correct if (!this.digestChallenge.ContainsKey("algorithm") || this.digestChallenge["algorithm"] != "md5-sess") { throw new XmppException("SASL Authrization failed. Incorrect challenge received from server"); } // Send the Digest-Reponse Response digestResponse = new Response(); digestResponse.Value = this.BuildDigestRespose(); this.Connection.Send(digestResponse); this.successEvent.WaitOne(); if (this.digestChallenge.ContainsKey("rspauth")) { digestResponse = new Response(); this.Connection.Send(digestResponse); this.successEvent.WaitOne(); } if (!this.AuthenticationFailed) { // Re-Initialize XMPP Stream this.Connection.InitializeXmppStream(); // Wait until we receive the Stream features this.Connection.WaitForStreamFeatures(); } }