/// <summary> /// Initiates the authentication process. /// </summary> public void Login() { Debug.Assert(Credential != null, "Credential must not be null for XEP-78 authentication"); Debug.Assert(Resource != null, "Resource must not be null for XEP-78 authentication"); this[Options.AUTO_LOGIN_THISPASS] = true; if (State == ManualSASLLoginState.Instance) { ProcessFeatures(); return; } this[Options.JID] = new JID(Credential.AuthenticationId, Server, Resource); AuthIQ aiq = new AuthIQ(Document); aiq.Type = IQType.get; Auth a = aiq.Instruction; a.Username = Credential.AuthenticationId; lock (StateLock) { State = GetAuthState.Instance; } Tracker.BeginIQ(aiq, new IqCB(OnGetAuth), null); }
public void LoginAnonymously() { //FF /* * Debug.Assert(User != null, "Username must not be null for XEP-78 authentication"); * Debug.Assert(Password != null, "Password must not be null for XEP-78 authentication"); * Debug.Assert(Resource != null, "Resource must not be null for XEP-78 authentication"); * //*/ this[Options.AUTO_LOGIN_THISPASS] = true; this[Options.ANONYMOUS] = true; if (State == ManualSASLLoginState.Instance) { ProcessFeatures(); return; } this[Options.JID] = new JID(User, Server, Resource); AuthIQ aiq = new AuthIQ(Document); aiq.Type = IQType.get; Auth a = aiq.Instruction; a.Username = User; lock (StateLock) { State = GetAuthState.Instance; } Tracker.BeginIQ(aiq, new IqCB(OnGetAuth), null); }
private void OnGetAuth(object sender, IQ i, object data) { if ((i == null) || (i.Type != IQType.result)) { FireAuthError(i); return; } Auth res = i.Query as Auth; if (res == null) { FireOnError(new InvalidOperationException("Invalid IQ result type")); return; } AuthIQ aiq = new AuthIQ(Document); aiq.Type = IQType.set; Auth a = aiq.Instruction; if ((res["sequence"] != null) && (res["token"] != null)) { a.SetZeroK(User, Password, res.Token, res.Sequence); } else if (res["digest"] != null) { a.SetDigest(User, Password, StreamID); } else if (res["password"] != null) { if (!SSLon && !this.PlaintextAuth) { FireOnError(new AuthenticationFailedException("Plaintext authentication forbidden.")); return; } a.SetAuth(User, Password); } else { FireOnError(new NotImplementedException("Authentication method not implemented for:\n" + i)); return; } if (res["resource"] != null) { a.Resource = Resource; } a.Username = User; lock (StateLock) { State = SetAuthState.Instance; } Tracker.BeginIQ(aiq, new IqCB(OnSetAuth), null); }
public void Create() { Element.ResetID(); AuthIQ iq = new AuthIQ(doc); Assert.AreEqual("<iq id=\"JN_1\" type=\"get\" />", iq.ToString()); iq = new AuthIQ(doc); Assert.AreEqual("<iq id=\"JN_2\" type=\"get\" />", iq.ToString()); iq.Query = new Auth(doc); Assert.AreEqual("<iq id=\"JN_2\" type=\"get\"><query xmlns=\"jabber:iq:auth\" /></iq>", iq.ToString()); }
/* SENT: <iq type="get" id="JCOM_14"><query xmlns="jabber:iq:auth"><username>zeroktest</username></query></iq> RECV: <iq id='JCOM_14' type='result'><query xmlns='jabber:iq:auth'><username>zeroktest</username><password/><digest/><sequence>499</sequence><token>3C7A6B0A</token><resource/></query></iq> SENT: <iq type="set" id="JCOM_15"><query xmlns="jabber:iq:auth"><username>zeroktest</username><hash>e00c83748492a3bc7e4831c9e973d117082c3abe</hash><resource>Winjab</resource></query></iq> */ [Test] public void Test_ZeroK() { IQ iq = new AuthIQ(doc); iq.Type = IQType.set; Auth a = (Auth) iq.Query; a.SetZeroK("zeroktest", "test", "3C7A6B0A", 499); a.Resource = "Winjab"; Assert.AreEqual("<iq id=\""+iq.ID+"\" type=\"set\"><query xmlns=\"jabber:iq:auth\">" + "<username>zeroktest</username>" + "<hash>e00c83748492a3bc7e4831c9e973d117082c3abe</hash>" + "<resource>Winjab</resource>" + "</query></iq>", iq.ToString()); }
[Test] public void Test_Hash() { IQ iq = new AuthIQ(doc); iq.Type = IQType.set; Auth a = (Auth) iq.Query; a.SetDigest("foo", "bar", "3B513636"); a.Resource = "Home"; Assert.AreEqual("<iq id=\""+iq.ID+"\" type=\"set\"><query xmlns=\"jabber:iq:auth\">" + "<username>foo</username>" + "<digest>37d9c887967a35d53b81f07916a309a5b8d7e8cc</digest>" + "<resource>Home</resource>" + "</query></iq>", iq.ToString()); }
public void Test_ZeroK() { AuthIQ iq = new AuthIQ(doc); iq.Type = IQType.set; Auth a = (Auth)iq.Query; a.SetZeroK("zeroktest", "test", "3C7A6B0A", 499); a.Resource = "Winjab"; Assert.AreEqual("<iq id=\"" + iq.ID + "\" type=\"set\"><query xmlns=\"jabber:iq:auth\">" + "<username>zeroktest</username>" + "<hash>e00c83748492a3bc7e4831c9e973d117082c3abe</hash>" + "<resource>Winjab</resource>" + "</query></iq>", iq.ToString()); }
public void Test_Hash() { AuthIQ iq = new AuthIQ(doc); iq.Type = IQType.set; Auth a = (Auth)iq.Query; a.SetDigest("foo", "bar", "3B513636"); a.Resource = "Home"; Assert.AreEqual("<iq id=\"" + iq.ID + "\" type=\"set\"><query xmlns=\"jabber:iq:auth\">" + "<username>foo</username>" + "<digest>37d9c887967a35d53b81f07916a309a5b8d7e8cc</digest>" + "<resource>Home</resource>" + "</query></iq>", iq.ToString()); }
private void OnGetAuth(object sender, IQ i, object data) { if ((i == null) || (i.Type != IQType.Result)) { FireAuthError(i); return; } Auth res = i.Query as Auth; if (res == null) { FireOnError(new InvalidOperationException("Invalid IQ result type")); return; } AuthIQ aiq = new AuthIQ(Document) {Type = IQType.Set}; Auth a = aiq.Instruction; if ((res["sequence"] != null) && (res["token"] != null)) { a.SetZeroK(User, Password, res.Token, res.Sequence); } else if (res["digest"] != null) { a.SetDigest(User, Password, StreamID); } else if (res["password"] != null) { if (!SSLon && !PlaintextAuth) { FireOnError(new AuthenticationFailedException("Plaintext authentication forbidden.")); return; } a.SetAuth(User, Password); } else { FireOnError(new NotImplementedException("Authentication method not implemented for:\n" + i)); return; } if (res["resource"] != null) a.Resource = Resource; a.Username = User; lock (StateLock) { State = SetAuthState.Instance; } Tracker.BeginIQ(aiq, OnSetAuth, null); }
/// <summary> /// Initiates the authentication process. /// </summary> public void Login() { Debug.Assert(User != null, "Username must not be null for XEP-78 authentication"); Debug.Assert(Password != null, "Password must not be null for XEP-78 authentication"); Debug.Assert(Resource != null, "Resource must not be null for XEP-78 authentication"); this[Options.AUTO_LOGIN_THISPASS] = true; if (State == ManualSASLLoginState.Instance) { ProcessFeatures(); return; } this[Options.JID] = new JID(User, Server, Resource); AuthIQ aiq = new AuthIQ(Document) {Type = IQType.Get}; Auth a = aiq.Instruction; a.Username = User; lock (StateLock) { State = GetAuthState.Instance; } Tracker.BeginIQ(aiq, OnGetAuth, null); }
public void Test_Create() { AuthIQ iq = new AuthIQ(doc); Assert.AreEqual("<iq id=\"" + iq.ID + "\" type=\"get\"><query xmlns=\"jabber:iq:auth\" /></iq>", iq.ToString()); }
[Test] public void Test_Create() { IQ iq = new AuthIQ(doc); Assert.AreEqual("<iq id=\""+iq.ID+"\" type=\"get\"><query xmlns=\"jabber:iq:auth\" /></iq>", iq.ToString()); }