internal override void Handle() { if (_serverFeatures.TLSSupport == ServerFeatures.TLSSupportType.Required || (_serverFeatures.TLSSupport == ServerFeatures.TLSSupportType.SupportedNotRequired && (Context.Settings.UseTLS == UseTLS.Always || Context.Settings.UseTLS == UseTLS.IfSupported))) { Context.OnConnectionStateChanged(ConnectionStateType.Securing); Context.Connection.Send(new StartTlsRequest()); StartTlsResponse startTlsResponse = StartTlsResponse.CreateFromXml(Context.Connection.Receive()); if (!startTlsResponse.Proceed) { //throw new InvalidOperationException("Attempt to start TLS negotiation failed"); } Context.Connection.Secure(Context.Settings.TlsCertificateCallback); Context.Connection.InitializeStream(); _serverFeatures = ServerFeatures.CreateFromXml(Context.Connection.Receive()); } NextState = new CompressState(Context, _serverFeatures); }
internal override void Handle() { if (!_serverFeatures.Mechanisms.Contains("DIGEST-MD5")) { //throw new NotSupportedException("No supported auth mechanisms"); } Context.OnConnectionStateChanged(ConnectionStateType.Authenticating); Context.Connection.Send(new DigestMD5SaslAuth()); SaslChallenge saslChallenge = SaslChallenge.CreateFromXml(Context.Connection.Receive()); var digestMD5Authentication = new DigestMD5Authentication(saslChallenge.ChallangeString); string response = digestMD5Authentication.GetDigestResponse(Context.Settings.UserJId.User, Context.Settings.Password, digestMD5Authentication.Realms[0], Context.Settings.UserJId.Domain); Context.Connection.Send(new SaslResponse(response)); SaslAuthResult saslAuthResult = SaslAuthResult.CreateFromXml(Context.Connection.Receive()); if (!saslAuthResult.Success) { StreamException.ThrowStreamException(saslAuthResult.FailReason); } Context.Connection.InitializeStream(); _serverFeatures = ServerFeatures.CreateFromXml(Context.Connection.Receive()); NextState = new BindResourceState(Context, _serverFeatures); }
internal CompressState(IXmppContext context, ServerFeatures serverFeatures) : base(context) { _serverFeatures = serverFeatures; }
internal SaslAuthState(IXmppContext context, ServerFeatures serverFeatures) : base(context) { _serverFeatures = serverFeatures; }
internal static ServerFeatures CreateFromXml(XElement element) { var serverFeatures = new ServerFeatures(); XElement chile = element.Descendants(XName.Get("starttls", NamespaceStrings.XmppTls)).FirstOrDefault(); if (chile != null) { serverFeatures.TLSSupport = chile.Element(XName.Get("required", NamespaceStrings.XmppTls)) != null ? TLSSupportType.Required : TLSSupportType.SupportedNotRequired; } serverFeatures.Mechanisms = (from mechanism in element.Descendants(XName.Get("mechanism", NamespaceStrings.XmppSasl)) select mechanism.Value).ToList(); chile = element.Descendants(XName.Get("bind", NamespaceStrings.XmppBind)).FirstOrDefault(); if (chile != null) { serverFeatures.Bind = true; } chile = element.Descendants(XName.Get("session", NamespaceStrings.XmppSession)).FirstOrDefault(); if (chile != null) { serverFeatures.Session = true; } return serverFeatures; }
internal BindResourceState(IXmppContext context, ServerFeatures serverFeatures) : base(context) { _serverFeatures = serverFeatures; }