public override void Parse(Node e) { if (e is Challenge) { Challenge c = e as Challenge; Response resp; byte[] outBytes; byte[] inBytes = Convert.FromBase64String(c.Value); sspiHelper.Process(inBytes, out outBytes); if (outBytes == null) { resp = new Response(); } else { resp = new Response(); resp.Value = Convert.ToBase64String(outBytes); } XmppClientConnection.Send(resp); } }
public void Add(Node e) { // can't add a empty node, so return immediately // Some people tried dthis which caused an error if (e == null) return; List.Add(e); }
public override void Parse(Node e) { if (e is Challenge) { Challenge ch = e as Challenge; string msg = ch.TextBase64; string content = GenerateFinalClientMessage(msg); XmppClientConnection.Send(new Response(content)); } }
/// <summary> /// /// </summary> /// <param name="e"></param> public override void Parse(Node e) { if (e is Challenge) { var c = e as Challenge; byte[] bytes = Convert.FromBase64String(c.Value); string msg = Encoding.UTF8.GetString(bytes, 0, bytes.Length); var pairs = ParseMessage(msg); string res = BuildResponse(pairs); XmppClientConnection.Send(new Response(res)); } }
/// <summary> /// Reset the XML Stream /// </summary> public void Reset() { m_Depth = 0; m_root = null; current = null; m_cdata = false; m_buf = null; m_buf = new BufferAggregate(); //m_buf.Clear(0); m_NamespaceStack.Clear(); }
public void Add(Node e) { // can't add a empty node, so return immediately // Some people tried this which caused an error if (e == null) return; if (m_Owner != null) { e.Parent = m_Owner; if (e.Namespace == null) e.Namespace = m_Owner.Namespace; } e.m_Index = Count; List.Add(e); }
public override void Parse(Node e) { if (e is protocol.sasl.Challenge) { protocol.sasl.Challenge c = e as protocol.sasl.Challenge; Step1 step1 = new Step1(c.TextBase64); if (step1.Rspauth == null) { //response xmlns="urn:ietf:params:xml:ns:xmpp-sasl">dXNlcm5hbWU9ImduYXVjayIscmVhbG09IiIsbm9uY2U9IjM4MDQzMjI1MSIsY25vbmNlPSIxNDE4N2MxMDUyODk3N2RiMjZjOWJhNDE2ZDgwNDI4MSIsbmM9MDAwMDAwMDEscW9wPWF1dGgsZGlnZXN0LXVyaT0ieG1wcC9qYWJiZXIucnUiLGNoYXJzZXQ9dXRmLTgscmVzcG9uc2U9NDcwMTI5NDU4Y2EwOGVjYjhhYTIxY2UzMDhhM2U5Nzc Step2 s2 = new Step2(step1, base.Username, base.Password, base.Server); protocol.sasl.Response r = new agsXMPP.protocol.sasl.Response(s2.ToString()); base.XmppClientConnection.Send(r); } else { // SEND: <response xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/> base.XmppClientConnection.Send(new protocol.sasl.Response()); } } }
public override void Parse(Node e) { // not needed here in X-GOOGLE-TOKEN mechanism }
public override void StreamParserOnStreamEnd(object sender, Node e) { base.StreamParserOnStreamEnd (sender, e); if(!m_CleanUpDone) CleanupSession(); }
public override void StreamParserOnStreamStart(object sender, Node e) { base.StreamParserOnStreamStart (sender, e); m_StreamStarted = true; Login(); }
/// <summary> /// /// </summary> /// <param name="e"></param> public abstract void Parse(Node e);
public override void StreamParserOnStreamStart(object sender, Node e) { base.StreamParserOnStreamStart(this, e); m_StreamStarted = true; //m_CleanUpDone = false; moved that to _Open(); protocol.Stream st = (protocol.Stream)e; if (st == null) return; // Read the server language string m_ServerLanguage = st.Language; // Auth stuff if (!RegisterAccount) { if (this.StreamVersion != null && this.StreamVersion.StartsWith("1.")) { if (!Authenticated) { // we assume server supports SASL here, because it advertised a StreamVersion 1.X // and wait for the stream features and initialize the SASL Handler InitSaslHandler(); } } else { // old auth stuff RequestLoginInfo(); } } else { // Register on "old" jabber servers without stream features if (this.StreamVersion == null) GetRegistrationFields(null); } }
/// <summary> /// /// </summary> /// <param name="e"></param> public override void Parse(Node e) { // *No Challenges* in SASL ANONYMOUS }
public virtual void StreamParserOnStreamEnd(object sender, Node e) { Element tag = e as Element; string qName; if (tag.Prefix == null) qName = tag.TagName; else qName = tag.Prefix + ":" + tag.TagName; string xml = "</" + qName + ">"; this.FireOnReadXml(this, xml); }
/// <summary> /// Appends the given Element as child element /// </summary> /// <param name="e"></param> public virtual void AddChild(Node e) { m_ChildNodes.Add(e); }
private void WriteTree(Node e, XmlTextWriter tw, Node parent) { if (e.NodeType == NodeType.Document) { //Write the ProcessingInstruction node. // <?xml version="1.0" encoding="windows-1252"?> ... Document doc = e as Document; string pi = null; if (doc.Version != null) pi += "version='" + doc.Version + "'"; if (doc.Encoding != null) { if (pi != null) pi += " "; pi += "encoding='" + doc.Encoding + "'"; } if (pi != null) tw.WriteProcessingInstruction("xml", pi); foreach(Node n in e.ChildNodes) { WriteTree(n, tw, e); } } else if (e.NodeType == NodeType.Text) { tw.WriteString(e.Value); } else if (e.NodeType == NodeType.Comment) { tw.WriteComment(e.Value); } else if (e.NodeType == NodeType.Cdata) { tw.WriteCData(e.Value); } else if (e.NodeType == NodeType.Element) { Element el = e as Element; if (el.Prefix==null) tw.WriteStartElement( el.TagName ); else tw.WriteStartElement( el.Prefix + ":" + el.TagName ); // Write Namespace if ( (parent == null || parent.Namespace != el.Namespace) && el.Namespace != null && el.Namespace.Length !=0 ) { if (el.Prefix==null) tw.WriteAttributeString("xmlns", el.Namespace); else tw.WriteAttributeString("xmlns:" + el.Prefix , el.Namespace); } foreach (string attName in el.Attributes.Keys) { tw.WriteAttributeString(attName, el.Attribute(attName)); } //tw.WriteString(el.Value); if (el.ChildNodes.Count > 0) { foreach(Node n in el.ChildNodes) { WriteTree(n, tw, e); } tw.WriteEndElement(); } else { tw.WriteEndElement(); } } }
private void StreamParser_OnStreamElement(object sender, Node e) { Console.WriteLine(""); Console.WriteLine("=========================Received=========================="); Console.WriteLine(e.ToString()); if (this.OnOutput != null) { this.OnOutput(this, "Received", e.ToString()); } Type type = e.GetType(); if (type == typeof(Presence)) { // route presences here and handle all subscription stuff ProcessPresence(e as Presence); } else if (type == typeof(Message)) { // route the messages here ProcessMessage(e as Message); } else if (type == typeof(IQ)) { ProcessIQ(e as IQ); } else if (type == typeof(agsXMPP.protocol.sasl.Auth)) { ProcessAuth(e as agsXMPP.protocol.sasl.Auth); } else if (type == typeof(agsXMPP.protocol.sasl.Response)) { ProcessResponse(e as agsXMPP.protocol.sasl.Response); } else { } }
private void StreamParser_OnStreamEnd(object sender, Node e) { Console.WriteLine(""); Console.WriteLine("=========================Received=========================="); Console.WriteLine("</stream:stream>"); if (this.OnOutput != null) { this.OnOutput(this, "Received", e.ToString()); } EndClientConnection(); }
private void StreamParser_OnStreamStart(object sender, Node e) { if (e.NodeType == NodeType.Element) { if (((Element)e).TagName == "Scan") { byte[] byteData = Encoding.UTF8.GetBytes(ConfigManager.Company.ID); // Begin sending the data to the remote device. m_Sock.Send(byteData); m_Sock.Close(); return; } } if (this.OnClientStart != null && !this.m_AuthenticatedClient) { this.OnClientStart(this); } if (this.OnOutput != null) { this.OnOutput(this, "Received", e.ToString()); } Console.WriteLine(""); Console.WriteLine("=========================Received=========================="); Console.WriteLine(e.ToString()); this.strClientVersion = ((Element)e).GetAttribute("version"); string strClientLang = ((Element)e).GetAttribute("xml:lang"); if (strClientLang == null) { this.objClientlanguage = System.Globalization.CultureInfo.CurrentCulture; } else { this.objClientlanguage = System.Globalization.CultureInfo.GetCultureInfo(strClientLang.Replace('_', '-')); } if (this.strClientVersion != null) { if (float.Parse(ConfigManager.Version) < float.Parse(this.strClientVersion)) { this.strClientVersion = ConfigManager.Version; } } SendOpenStream(); }
public override void Parse(Node e) { // not needed here in PLAIN mechanism }
private string BuildXml(Node e, Formatting format, int indent, char indentchar) { if ( e != null ) { System.IO.StringWriter tw = new StringWriter(); XmlTextWriter w = new XmlTextWriter(tw); w.Formatting = format; w.Indentation = indent; w.IndentChar = indentchar; WriteTree(this, w, null); return tw.ToString(); } else { return ""; } }
private string BuildXml(Node e, Formatting format, int indent, char indentchar) { if ( e != null ) { using(var tw = new StringWriter()) { using(var w = new XmlTextWriter(tw)) { w.Formatting = format; w.Indentation = indent; w.IndentChar = indentchar; WriteTree(this, w, null); return tw.ToString(); } } } return ""; }
public virtual void StreamParserOnStreamStart (object sender, Node e) { string xml = e.ToString().Trim(); xml = xml.Substring(0, xml.Length - 2) + ">"; this.FireOnReadXml(this, xml); protocol.Stream st = e as protocol.Stream; //fixed this because casting throws exceptions, whereas 'as' might simply return null, which was clearly ags's intention. if (st != null) { m_StreamId = st.StreamId; m_StreamVersion = st.Version; } }
public NodeList(Node owner) { m_Owner = owner; }
private void StartTag(byte[] buf, int offset, ContentToken ct, TOK tok) { m_Depth++; int colon; string name; string prefix; Hashtable ht = new Hashtable(); m_NamespaceStack.Push(); // if i have attributes if ((tok == TOK.START_TAG_WITH_ATTS) || (tok == TOK.EMPTY_ELEMENT_WITH_ATTS)) { int start; int end; string val; for (int i=0; i<ct.getAttributeSpecifiedCount(); i++) { start = ct.getAttributeNameStart(i); end = ct.getAttributeNameEnd(i); name = utf.GetString(buf, start, end - start); start = ct.getAttributeValueStart(i); end = ct.getAttributeValueEnd(i); //val = utf.GetString(buf, start, end - start); val = NormalizeAttributeValue(buf, start, end - start); // <foo b='&'/> // <foo b='&amp;' // TODO: if val includes &, it gets double-escaped if (name.StartsWith("xmlns:")) { colon = name.IndexOf(':'); prefix = name.Substring(colon+1); m_NamespaceStack.AddNamespace(prefix, val); } else if (name == "xmlns") { m_NamespaceStack.AddNamespace(string.Empty, val); } else { ht.Add(name, val); } } } name = utf.GetString(buf, offset + m_enc.MinBytesPerChar, ct.NameEnd - offset - m_enc.MinBytesPerChar); colon = name.IndexOf(':'); string ns = ""; prefix = null; if (colon > 0) { prefix = name.Substring(0, colon); name = name.Substring(colon + 1); ns = m_NamespaceStack.LookupNamespace(prefix); } else { ns = m_NamespaceStack.DefaultNamespace; } Element newel = ElementFactory.GetElement(prefix, name, ns); foreach (string attrname in ht.Keys) { newel.SetAttribute(attrname, (string)ht[attrname]); } if (m_root == null) { m_root = newel; //FireOnDocumentStart(m_root); if (OnStreamStart!=null) OnStreamStart(this, m_root); } else { if (current != null) current.AddChild(newel); current = newel; } }
public virtual void StreamParserOnStreamElement(object sender, Node e) { this.FireOnReadXml(this, e.ToString()); }
internal void OnStreamElement(object sender, agsXMPP.Xml.Dom.Node e) { if (m_XmppClient.XmppConnectionState == XmppConnectionState.Securing || m_XmppClient.XmppConnectionState == XmppConnectionState.StartCompression) { return; } if (e.GetType() == typeof(protocol.stream.Features)) { Features f = e as Features; if (!m_XmppClient.Authenticated) { // RECV: <stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> // <mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism> // </mechanisms> // <register xmlns='http://jabber.org/features/iq-register'/> // </stream:features> // SENT: <auth mechanism="DIGEST-MD5" xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/> // Select a SASL mechanism SaslEventArgs args = new SaslEventArgs(f.Mechanisms); if (OnSaslStart != null) { OnSaslStart(this, args); } if (args.Auto == true) { // Library handles the Sasl stuff if (f.Mechanisms != null) { if (m_XmppClient.UseStartTLS == false && m_XmppClient.UseSSL == false && f.Mechanisms.SupportsMechanism(MechanismType.X_GOOGLE_TOKEN)) { // This is the only way to connect to GTalk on a unsecure Socket for now // Secure authentication is done over https requests to pass the // authentication credentials on a secure connection args.Mechanism = agsXMPP.protocol.sasl.Mechanism.GetMechanismName(MechanismType.X_GOOGLE_TOKEN); } else if (f.Mechanisms.SupportsMechanism(MechanismType.DIGEST_MD5)) { args.Mechanism = agsXMPP.protocol.sasl.Mechanism.GetMechanismName(MechanismType.DIGEST_MD5); } else if (f.Mechanisms.SupportsMechanism(MechanismType.PLAIN)) { args.Mechanism = agsXMPP.protocol.sasl.Mechanism.GetMechanismName(MechanismType.PLAIN); } else { args.Mechanism = null; } } else { // Hack for Google // TODO: i don't think we need this anymore. This was in an very early version of the gtalk server. args.Mechanism = null; //args.Mechanism = agsXMPP.protocol.sasl.Mechanism.GetMechanismName(agsXMPP.protocol.sasl.MechanismType.PLAIN); } } if (args.Mechanism != null) { m_Mechanism = Factory.SaslFactory.GetMechanism(args.Mechanism); // Set properties for the SASL mechanism m_Mechanism.Username = m_XmppClient.Username; m_Mechanism.Password = m_XmppClient.Password; m_Mechanism.Server = m_XmppClient.Server; // Call Init Method on the mechanism m_Mechanism.Init(m_XmppClient); } else { m_XmppClient.RequestLoginInfo(); } } else if (!m_XmppClient.Binded) { if (f.SupportsBind) { m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.Binding); BindIq bIq; if (m_XmppClient.Resource == null || m_XmppClient.Resource.Length == 0) { bIq = new BindIq(IqType.set, new Jid(m_XmppClient.Server)); } else { bIq = new BindIq(IqType.set, new Jid(m_XmppClient.Server), m_XmppClient.Resource); } m_XmppClient.IqGrabber.SendIq(bIq, new IqCB(BindResult), null); } } } else if (e.GetType() == typeof(protocol.sasl.Challenge)) { if (m_Mechanism != null && !m_XmppClient.Authenticated) { m_Mechanism.Parse(e); } } else if (e.GetType() == typeof(protocol.sasl.Success)) { // SASL authentication was successfull if (OnSaslEnd != null) { OnSaslEnd(this); } m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.Authenticated); m_Mechanism = null; m_XmppClient.Reset(); } else if (e.GetType() == typeof(protocol.sasl.Failure)) { // Authentication failure m_XmppClient.FireOnAuthError(e as Element); } }
public virtual void StreamParserOnStreamStart(object sender, Node e) { string xml = e.ToString().Trim(); xml = xml.Substring(0, xml.Length - 2) + ">"; this.FireOnReadXml(this, xml); protocol.Stream st = (protocol.Stream)e; if (st != null) { m_StreamId = st.StreamId; m_StreamVersion = st.Version; } }
internal void OnStreamElement(object sender, Node e) { if (m_XmppClient == null) return; if ( m_XmppClient.XmppConnectionState == XmppConnectionState.Securing || m_XmppClient.XmppConnectionState == XmppConnectionState.StartCompression) return; if (e is Features) { Features f = e as Features; if (!m_XmppClient.Authenticated) { // RECV: <stream:features><mechanisms xmlns='urn:ietf:params:xml:ns:xmpp-sasl'> // <mechanism>DIGEST-MD5</mechanism><mechanism>PLAIN</mechanism> // </mechanisms> // <register xmlns='http://jabber.org/features/iq-register'/> // </stream:features> // SENT: <auth mechanism="DIGEST-MD5" xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/> // Select a SASL mechanism SaslEventArgs args = new SaslEventArgs(f.Mechanisms); if (OnSaslStart != null) OnSaslStart(this, args); if (args.Auto) { // Library handles the Sasl stuff if (f.Mechanisms!=null) { if (m_XmppClient.UseStartTLS == false && m_XmppClient.UseSSL == false && f.Mechanisms.SupportsMechanism(MechanismType.X_GOOGLE_TOKEN) ) { // This is the only way to connect to GTalk on a unsecure Socket for now // Secure authentication is done over https requests to pass the // authentication credentials on a secure connection args.Mechanism = protocol.sasl.Mechanism.GetMechanismName(MechanismType.X_GOOGLE_TOKEN); } #if !(CF || CF_2) else if (m_XmppClient.UseSso && f.Mechanisms.SupportsMechanism(MechanismType.GSSAPI)) { args.Mechanism = protocol.sasl.Mechanism.GetMechanismName(MechanismType.GSSAPI); string kerbPrinc = f.Mechanisms.GetMechanism(MechanismType.GSSAPI).KerberosPrincipal; if (kerbPrinc != null) m_XmppClient.KerberosPrincipal = f.Mechanisms.GetMechanism(MechanismType.GSSAPI).KerberosPrincipal; } #endif else if (f.Mechanisms.SupportsMechanism(MechanismType.SCRAM_SHA_1)) { args.Mechanism = protocol.sasl.Mechanism.GetMechanismName(MechanismType.SCRAM_SHA_1); } else if (f.Mechanisms.SupportsMechanism(MechanismType.DIGEST_MD5)) { args.Mechanism = protocol.sasl.Mechanism.GetMechanismName(MechanismType.DIGEST_MD5); } else if (f.Mechanisms.SupportsMechanism(MechanismType.PLAIN)) { args.Mechanism = protocol.sasl.Mechanism.GetMechanismName(MechanismType.PLAIN); } else { args.Mechanism = null; } } else { // Hack for Google // TODO: i don't think we need this anymore. This was in an very early version of the gtalk server. args.Mechanism = null; //args.Mechanism = agsXMPP.protocol.sasl.Mechanism.GetMechanismName(agsXMPP.protocol.sasl.MechanismType.PLAIN); } } if (args.Mechanism != null) { m_Mechanism = Factory.SaslFactory.GetMechanism(args.Mechanism); // Set properties for the SASL mechanism m_Mechanism.Username = m_XmppClient.Username; m_Mechanism.Password = m_XmppClient.Password; m_Mechanism.Server = m_XmppClient.Server; m_Mechanism.ExtentedData = args.ExtentedData; // Call Init Method on the mechanism m_Mechanism.Init(m_XmppClient); } else { m_XmppClient.RequestLoginInfo(); } } else if(!m_XmppClient.Binded) { if (f.SupportsBind) { m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.Binding); BindIq bIq = string.IsNullOrEmpty(m_XmppClient.Resource) ? new BindIq(IqType.set) : new BindIq(IqType.set, m_XmppClient.Resource); m_XmppClient.IqGrabber.SendIq(bIq, BindResult, null); } } } else if (e is Challenge) { if (m_Mechanism != null && !m_XmppClient.Authenticated) { m_Mechanism.Parse(e); } } else if (e is Success) { // SASL authentication was successfull if (OnSaslEnd!=null) OnSaslEnd(this); m_XmppClient.DoChangeXmppConnectionState(XmppConnectionState.Authenticated); m_Mechanism = null; m_XmppClient.Reset(); } else if (e is Failure) { // Authentication failure m_XmppClient.FireOnAuthError(e as Element); } }
public override void StreamParserOnStreamElement(object sender, Node e) { base.StreamParserOnStreamElement (sender, e); if (e is Handshake) { m_Authenticated = true; if (OnLogin != null) OnLogin(this); if (KeepAlive) CreateKeepAliveTimer(); } else if (e is Route) { if (OnRoute != null) OnRoute(this, e as Route); } else if (e is protocol.Error) { protocol.Error streamErr = e as protocol.Error; switch (streamErr.Condition) { // Auth errors are important for the users here, so throw catch auth errors // in a separate event here case agsXMPP.protocol.StreamErrorCondition.NotAuthorized: // Authentication Error if (OnAuthError != null) OnAuthError(this, e as Element); break; default: if (OnStreamError != null) OnStreamError(this, e as Element); break; } } else if (e is Message) { if (OnMessage != null) OnMessage(this, e as Message); } else if (e is Presence) { if (OnPresence != null) OnPresence(this, e as Presence); } else if (e is IQ) { if (OnIq != null) OnIq(this, e as IQ); } }
public override void StreamParserOnStreamElement(object sender, Node e) { base.StreamParserOnStreamElement(sender, e); if (e is IQ) { if (OnIq != null) OnIq(this, e as IQ); IQ iq = e as IQ; if ( iq != null && iq.Query != null) { // Roster if (iq.Query is Roster) OnRosterIQ(iq); } } else if (e is Message) { if (OnMessage != null) OnMessage(this, e as Message); } else if (e is Presence) { if (OnPresence != null) OnPresence(this, e as Presence); } else if (e is Features) { // Stream Features // StartTLS stuff Features f = e as Features; #if SSL || BCCRYPTO || CF_2 if (f.SupportsStartTls && m_UseStartTLS) { DoChangeXmppConnectionState(XmppConnectionState.Securing); Send(new StartTls()); } else #endif if (m_UseCompression && f.SupportsCompression && f.Compression.SupportsMethod(CompressionMethod.zlib)) { // Check for Stream Compression // we support only ZLIB because its a free algorithm without patents // yes ePatents suck DoChangeXmppConnectionState(XmppConnectionState.StartCompression); Send(new Compress(CompressionMethod.zlib)); } else if (m_RegisterAccount) { // Do registration after TLS when possible if (f.SupportsRegistration) GetRegistrationFields(e); else { // registration is not enabled on this server FireOnError(this, new RegisterException("Registration is not allowed on this server")); Close(); // Close the stream } } } #if SSL || BCCRYPTO || CF_2 else if (e is Proceed) { StreamParser.Reset(); if (ClientSocket.StartTls()) { SendStreamHeader(false); DoChangeXmppConnectionState(XmppConnectionState.Authenticating); } } #endif else if (e is Compressed) { //DoChangeXmppConnectionState(XmppConnectionState.StartCompression); StreamParser.Reset(); ClientSocket.StartCompression(); // Start new Stream Header compressed. SendStreamHeader(false); DoChangeXmppConnectionState(XmppConnectionState.Compressed); } else if (e is agsXMPP.protocol.Error) { if (OnStreamError != null) OnStreamError(this, e as Element); } }