コード例 #1
0
ファイル: ZyanProxy.cs プロジェクト: yallie/zyan
        /// <summary>
        /// Initializes a new instance of the <see cref="ZyanProxy"/> class.
        /// </summary>
        /// <param name="uniqueName">Unique component name.</param>
        /// <param name="type">Component interface type.</param>
        /// <param name="connection"><see cref="ZyanConnection"/> instance.</param>
        /// <param name="implicitTransactionTransfer">Specifies whether transactions should be passed implicitly.</param>
        /// <param name="keepSynchronizationContext">Specifies whether callbacks and event handlers should use the original synchronization context.</param>
        /// <param name="sessionID">Session ID.</param>
        /// <param name="componentHostName">Name of the remote component host.</param>
        /// <param name="autoLoginOnExpiredSession">Specifies whether Zyan should login automatically with cached credentials after the session is expired.</param>
        /// <param name="activationType">Component activation type</param>
        public ZyanProxy(string uniqueName, Type type, ZyanConnection connection, bool implicitTransactionTransfer, bool keepSynchronizationContext, Guid sessionID, string componentHostName, bool autoLoginOnExpiredSession, ActivationType activationType)
            : base(type)
        {
            if (type == null)
                throw new ArgumentNullException("type");

            if (connection == null)
                throw new ArgumentNullException("connection");

            if (string.IsNullOrEmpty(uniqueName))
                _uniqueName = type.FullName;
            else
                _uniqueName = uniqueName;

            _sessionID = sessionID;
            _connection = connection;
            _componentHostName = componentHostName;
            _interfaceType = type;
            _activationType = activationType;
            _remoteDispatcher = _connection.RemoteDispatcher;
            _implicitTransactionTransfer = implicitTransactionTransfer;
            _autoLoginOnExpiredSession = autoLoginOnExpiredSession;
            _delegateCorrelationSet = new List<DelegateCorrelationInfo>();

            // capture synchronization context for callback execution
            if (keepSynchronizationContext)
            {
                _synchronizationContext = SynchronizationContext.Current;
            }
        }
コード例 #2
0
        /// <inheritdoc/>
        public override void Authenticate(Guid sessionId, IZyanDispatcher dispatcher)
        {
            // step1 request: User -> Host: I, A = g^a (identifies self, a = random number)
            var clientEphemeral = SrpClient.GenerateEphemeral();
            var request1        = new Hashtable
            {
                { SrpProtocolConstants.SRP_STEP_NUMBER, 1 },
                { SrpProtocolConstants.SRP_USERNAME, UserName },
                { SrpProtocolConstants.SRP_CLIENT_PUBLIC_EPHEMERAL, clientEphemeral.Public },
            };

            // step1 response: Host -> User: s, B = kv + g^b (sends salt, b = random number)
            var response1             = dispatcher.Logon(sessionId, request1).Parameters;
            var salt                  = (string)response1[SrpProtocolConstants.SRP_SALT];
            var serverPublicEphemeral = (string)response1[SrpProtocolConstants.SRP_SERVER_PUBLIC_EPHEMERAL];

            // step2 request: User -> Host: M = H(H(N) xor H(g), H(I), s, A, B, K)
            var privateKey    = SrpClient.DerivePrivateKey(salt, UserName, Password);
            var clientSession = SrpClient.DeriveSession(clientEphemeral.Secret, serverPublicEphemeral, salt, UserName, privateKey);
            var request2      = new Hashtable
            {
                { SrpProtocolConstants.SRP_STEP_NUMBER, 2 },
                { SrpProtocolConstants.SRP_CLIENT_SESSION_PROOF, clientSession.Proof },
            };

            // step2 response: Host -> User: H(A, M, K)
            var response2          = dispatcher.Logon(sessionId, request2).Parameters;
            var serverSessionProof = (string)response2[SrpProtocolConstants.SRP_SERVER_SESSION_PROOF];

            SrpClient.VerifySession(clientEphemeral.Public, clientSession, serverSessionProof);
        }
コード例 #3
0
 public override void Authenticate(Guid sessionId, IZyanDispatcher dispatcher)
 {
     dispatcher.Logon(sessionId, new Hashtable
     {
         { SrpProtocolConstants.SRP_STEP_NUMBER, 3 },
     });
 }
コード例 #4
0
            public override void Authenticate(Guid sessionId, IZyanDispatcher dispatcher)
            {
                var credentials = (Hashtable)CredentialsHashtable.Clone();

                if (credentials.Count == 0)
                {
                    throw new Exception("No credentials specified");
                }

                // step 0
                credentials["#"] = 0;
                var reply = dispatcher.Logon(sessionId, credentials);

                // check the reply
                var payload = reply.ErrorMessage;

                if (reply.ErrorMessage != "World")
                {
                    throw new Exception("Bad reply for step 0");
                }

                // step 1
                credentials["#"] = 1;
                credentials["@"] = "Icanhaz";
                reply            = dispatcher.Logon(sessionId, credentials);

                // check the reply
                if (reply.ErrorMessage != "Cheezburger")
                {
                    throw new Exception("Bad reply for step 1");
                }
            }
コード例 #5
0
 public override void Authenticate(Guid sessionId, IZyanDispatcher dispatcher)
 {
     dispatcher.Logon(sessionId, new Hashtable
     {
         { SrpProtocolConstants.SRP_STEP_NUMBER, 2 },
         { SrpProtocolConstants.SRP_CLIENT_SESSION_PROOF, "woof" },
     });
 }
コード例 #6
0
        /// <summary>
        /// Konstruktor.
        /// </summary>
        /// <param name="type">Schnittstelle der entfernten Komponente</param>
        /// <param name="connection">Verbindungsobjekt</param>
        /// <param name="implicitTransactionTransfer">Implizite Transaktionsübertragung</param>
        /// <param name="sessionID">Sitzungsschlüssel</param>
        /// <param name="componentHostName">Name des entfernten Komponentenhosts</param>
        /// <param name="autoLoginOnExpiredSession">Gibt an, ob sich der Proxy automatisch neu anmelden soll, wenn die Sitzung abgelaufen ist</param>
        /// <param name="autoLogoninCredentials">Optional! Anmeldeinformationen, die nur benötigt werden, wenn autoLoginOnExpiredSession auf Wahr eingestellt ist</param>
        /// <param name="activationType">Aktivierungsart</param>
        public ZyanProxy(Type type, ZyanConnection connection, bool implicitTransactionTransfer, Guid sessionID, string componentHostName, bool autoLoginOnExpiredSession, Hashtable autoLogoninCredentials, ActivationType activationType)
            : base(type)
        {
            // Wenn kein Typ angegeben wurde ...
            if (type.Equals(null))
            {
                // Ausnahme werfen
                throw new ArgumentNullException("type");
            }

            // Wenn kein Verbindungsobjekt angegeben wurde ...
            if (connection == null)
            {
                // Ausnahme werfen
                throw new ArgumentNullException("connection");
            }

            // Sitzungsschlüssel übernehmen
            _sessionID = sessionID;

            // Verbindungsobjekt übernehmen
            _connection = connection;

            // Name des Komponentenhosts übernehmen
            _componentHostName = componentHostName;

            // Schnittstellentyp übernehmen
            _interfaceType = type;

            // Aktivierungsart übernehmen
            _activationType = activationType;

            // Aufrufer von Verbindung übernehmen
            _remoteInvoker = _connection.RemoteComponentFactory;

            // Schalter für implizite Transaktionsübertragung übernehmen
            _implicitTransactionTransfer = implicitTransactionTransfer;

            // Schalter für automatische Anmeldung bei abgelaufender Sitzung übernehmen
            _autoLoginOnExpiredSession = autoLoginOnExpiredSession;

            // Wenn automatische Anmeldung aktiv ist ...
            if (_autoLoginOnExpiredSession)
            {
                // Anmeldeinformationen speichern
                _autoLoginCredentials = autoLogoninCredentials;
            }

            // Sammlung für Korrelationssatz erzeugen
            _delegateCorrelationSet = new List <DelegateCorrelationInfo>();
        }
コード例 #7
0
ファイル: ZyanProxy.cs プロジェクト: yallie/zyan
        /// <summary>
        /// Konstruktor.
        /// </summary>
        /// <param name="type">Schnittstelle der entfernten Komponente</param>
        /// <param name="connection">Verbindungsobjekt</param>
        /// <param name="implicitTransactionTransfer">Implizite Transaktionsübertragung</param>
        /// <param name="sessionID">Sitzungsschlüssel</param>
        /// <param name="componentHostName">Name des entfernten Komponentenhosts</param>
        /// <param name="autoLoginOnExpiredSession">Gibt an, ob sich der Proxy automatisch neu anmelden soll, wenn die Sitzung abgelaufen ist</param>
        /// <param name="autoLogoninCredentials">Optional! Anmeldeinformationen, die nur benötigt werden, wenn autoLoginOnExpiredSession auf Wahr eingestellt ist</param>              
        /// <param name="activationType">Aktivierungsart</param>
        public ZyanProxy(Type type, ZyanConnection connection, bool implicitTransactionTransfer, Guid sessionID, string componentHostName, bool autoLoginOnExpiredSession, Hashtable autoLogoninCredentials, ActivationType activationType)
            : base(type)
        {
            // Wenn kein Typ angegeben wurde ...
            if (type.Equals(null))
                // Ausnahme werfen
                throw new ArgumentNullException("type");

            // Wenn kein Verbindungsobjekt angegeben wurde ...
            if (connection == null)
                // Ausnahme werfen
                throw new ArgumentNullException("connection");

            // Sitzungsschlüssel übernehmen
            _sessionID = sessionID;

            // Verbindungsobjekt übernehmen
            _connection = connection;

            // Name des Komponentenhosts übernehmen
            _componentHostName = componentHostName;

            // Schnittstellentyp übernehmen
            _interfaceType = type;

            // Aktivierungsart übernehmen
            _activationType = activationType;

            // Aufrufer von Verbindung übernehmen
            _remoteInvoker = _connection.RemoteComponentFactory;

            // Schalter für implizite Transaktionsübertragung übernehmen
            _implicitTransactionTransfer = implicitTransactionTransfer;

            // Schalter für automatische Anmeldung bei abgelaufender Sitzung übernehmen
            _autoLoginOnExpiredSession = autoLoginOnExpiredSession;

            // Wenn automatische Anmeldung aktiv ist ...
            if (_autoLoginOnExpiredSession)
                // Anmeldeinformationen speichern
                _autoLoginCredentials = autoLogoninCredentials;

            // Sammlung für Korrelationssatz erzeugen
            _delegateCorrelationSet = new List<DelegateCorrelationInfo>();
        }
コード例 #8
0
ファイル: AuthCredentials.cs プロジェクト: zyanfx/Zyan
        /// <summary>
        /// Authenticates a specific user based on their credentials.
        /// </summary>
        /// <param name="sessionId">Session identity.</param>
        /// <param name="dispatcher">Remote dispatcher</param>
        public virtual void Authenticate(Guid sessionId, IZyanDispatcher dispatcher)
        {
            var credentials = CredentialsHashtable;

            if (credentials != null && credentials.Count == 0)
            {
                credentials = null;
            }

            var response = dispatcher.Logon(sessionId, credentials);

            if (!response.Completed)
            {
                throw new SecurityException(response.ErrorMessage ?? "Authentication is not completed.");
            }

            // this case is likely to be handled by ZyanDispatcher itself
            if (!response.Success)
            {
                throw new SecurityException(response.ErrorMessage ?? "Authentication is not successful.");
            }
        }
コード例 #9
0
        /// <summary>
        /// Verwaltete Ressourcen freigeben.
        /// </summary>
        public void Dispose()
        {
            // Wenn Dispose nicht bereits ausgeführt wurde ...
            if (!_isDisposed)
            {
                // Schalter setzen
                _isDisposed = true;

                // Verbindung aus der Auflistung entfernen
                _connections.Remove(this);

                // Wenn der Zeitgeber noch existiert ...
                if (_keepSessionAliveTimer != null)
                {
                    // Zeitgeber entsorgen
                    _keepSessionAliveTimer.Dispose();
                    _keepSessionAliveTimer = null;
                }
                try
                {
                    // Vom Server abmelden
                    RemoteComponentFactory.Logoff(_sessionID);
                }
                catch (RemotingException)
                { }
                catch (SocketException)
                { }
                catch (WebException)
                { }
                // Variablen freigeben
                _registeredComponents   = null;
                _remoteComponentFactory = null;
                _serverUrl = string.Empty;
                _sessionID = Guid.Empty;

                // Nicht auf Finalisierer warten (da keine unverwalteten Ressourcen freigegeben werden müssen)
                GC.SuppressFinalize(this);
            }
        }
コード例 #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ZyanProxy"/> class.
        /// </summary>
        /// <param name="uniqueName">Unique component name.</param>
        /// <param name="type">Component interface type.</param>
        /// <param name="connection"><see cref="ZyanConnection"/> instance.</param>
        /// <param name="implicitTransactionTransfer">Specifies whether transactions should be passed implicitly.</param>
        /// <param name="keepSynchronizationContext">Specifies whether callbacks and event handlers should use the original synchronization context.</param>
        /// <param name="sessionID">Session ID.</param>
        /// <param name="componentHostName">Name of the remote component host.</param>
        /// <param name="autoLoginOnExpiredSession">Specifies whether Zyan should login automatically with cached credentials after the session is expired.</param>
        /// <param name="activationType">Component activation type</param>
        public ZyanProxy(string uniqueName, Type type, ZyanConnection connection, bool implicitTransactionTransfer, bool keepSynchronizationContext, Guid sessionID, string componentHostName, bool autoLoginOnExpiredSession, ActivationType activationType)
            : base(type)
        {
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }

            if (connection == null)
            {
                throw new ArgumentNullException("connection");
            }

            if (string.IsNullOrEmpty(uniqueName))
            {
                _uniqueName = type.FullName;
            }
            else
            {
                _uniqueName = uniqueName;
            }

            _sessionID                   = sessionID;
            _connection                  = connection;
            _componentHostName           = componentHostName;
            _interfaceType               = type;
            _activationType              = activationType;
            _remoteDispatcher            = _connection.RemoteDispatcher;
            _implicitTransactionTransfer = implicitTransactionTransfer;
            _autoLoginOnExpiredSession   = autoLoginOnExpiredSession;
            _delegateCorrelationSet      = new List <DelegateCorrelationInfo>();

            // capture synchronization context for callback execution
            if (keepSynchronizationContext)
            {
                _synchronizationContext = SynchronizationContext.Current;
            }
        }
コード例 #11
0
ファイル: ZyanConnection.cs プロジェクト: xiaoxiongnpu/Zyan
        /// <summary>
        /// Releases unmanaged and — optionally — managed resources.
        /// </summary>
        /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
        protected virtual void Dispose(bool disposing)
        {
            if (!disposing)
            {
                return;
            }

            if (!_isDisposed)
            {
                _isDisposed = true;

                if (_pollingTimer != null)
                {
                    _pollingTimer.Dispose();
                    _pollingTimer = null;
                }
                _pollingEnabled = false;

                if (_keepSessionAliveTimer != null)
                {
                    _keepSessionAliveTimer.Dispose();
                    _keepSessionAliveTimer = null;
                }
                try
                {
                    foreach (var zyanProxy in AliveProxies)
                    {
                        zyanProxy.RemoveAllRemoteEventHandlers();
                    }
                    RemoteDispatcher.Logoff(_sessionID);
                }
                catch (RemotingException)
                { }
                catch (SocketException)
                { }
                catch (WebException)
                { }
                catch (MessageException)
                { }
                catch (Exception ex)
                {
                    Trace.WriteLine("Unexpected exception of type {0} caught while disposing ZyanConnection: {1}", ex.GetType(), ex.Message);
                }
                finally
                {
                    lock (_connections)
                    {
                        _connections.Remove(this);
                    }
                }
                if (_remotingChannel != null)
                {
                    // unsubscribe from connection notifications
                    var connectionNotification = _remotingChannel as IConnectionNotification;
                    if (connectionNotification != null)
                    {
                        connectionNotification.ConnectionEstablished -= Channel_ConnectionEstablished;
                    }

                    // unregister remoting channel
                    var registeredChannel = ChannelServices.GetChannel(_remotingChannel.ChannelName);
                    if (registeredChannel != null && registeredChannel == _remotingChannel)
                    {
                        ChannelServices.UnregisterChannel(_remotingChannel);
                    }

                    // dispose remoting channel, if it's disposable
                    var disposableChannel = _remotingChannel as IDisposable;
                    if (disposableChannel != null)
                    {
                        disposableChannel.Dispose();
                    }

                    _remotingChannel = null;
                }
                _remoteDispatcher      = null;
                _serverUrl             = string.Empty;
                _sessionID             = Guid.Empty;
                _protocolSetup         = null;
                _serializationHandling = null;
                _componentHostName     = string.Empty;

                if (_registeredComponents != null)
                {
                    _registeredComponents.Clear();
                    _registeredComponents = null;
                }
                if (_callInterceptors != null)
                {
                    _callInterceptors.Clear();
                    _callInterceptors = null;
                }
                if (_autoLoginCredentials != null)
                {
                    _autoLoginCredentials = null;
                }
                GC.WaitForPendingFinalizers();
            }
        }