示例#1
0
        /// <summary>
        /// Puts down a record representing an event connected with the specified Security Session Parameters.
        /// </summary>
        /// <param name="author">The author.</param>
        /// <param name="type">The type of the event(Subcategory).</param>
        /// <param name="exception">The exception associated with the event.</param>
        /// <param name="message">The message associated with the event.</param>
        /// <param name="remote">The remote host participating in the event.</param>
        /// <param name="sourceThreadId">The id of the thread where the invocation was made.</param>
        /// <param name="sourceThreadName">The name of the thread.</param>
        /// <param name="securitySessionParameters">The Security Session Parameters.</param>
        /// <param name="description">The description of the event.</param>
        /// <param name="parameters">Parameters to the description.</param>
        public void WriteSecuritySessionParametersEvent(string author, LogMessageType type, Exception exception,
                                                        Message message, HostInformation remote, int sourceThreadId, string sourceThreadName,
                                                        SecuritySessionParameters securitySessionParameters, string description, params object[] parameters)
        {
            if (message == null || securitySessionParameters == null)
            {
                this.WriteImplementationWarningEvent("BinaryLogWriter.WriteMessageCreatedEvent", LogMessageType.Error, null,
                                                     sourceThreadId, sourceThreadName, "The message or SSP is not provided. Stack trace: " + Environment.StackTrace);
                return;
            }

            lock (this._streamLock)
            {
                this.WriteRecordHeader(BinaryRecordVersion.SecuritySessionParameters, LogCategory.Security, type, author);
                this.WriteException(exception);

                this.WriteMessageSeqNo(message);
                this.WriteHostInformationId(remote);

                this.BinaryWriter.Write((int)sourceThreadId);
                this.WriteString(sourceThreadName);

                this.WriteSecuritySessionParameters(securitySessionParameters);
                this.WriteStringWithParameters(description, parameters);

                this.BinaryWriter.Flush();
            }
        }
        /// <summary>
        /// Returns an instance of the SecuritySessionParameters class brought to conformity with channels' settings.
        /// </summary>
        /// <param name="securitySessionParameters">Source parameters.</param>
        /// <returns>Fixed parameters.</returns>
        public SecuritySessionParameters FixSecuritySessionParameters(SecuritySessionParameters securitySessionParameters)
        {
            SecuritySessionAttributes fixedAttributes = (SecuritySessionAttributes)(
                ((int)securitySessionParameters.Attributes | (int)this.ForcedSecuritySessionAttributes) &
                ~((int)this.ProhibitedSecuritySessionAttributes));

            return(new SecuritySessionParameters(securitySessionParameters.Name, fixedAttributes, TimeSpan.MinValue, securitySessionParameters.GenuineConnectionType, securitySessionParameters.ConnectionName, TimeSpan.MinValue, securitySessionParameters.RemoteTransportUser));
        }
示例#3
0
 /// <summary>
 /// Puts down Security Session Parameters.
 /// </summary>
 /// <param name="parameters">The Security Session Parameters.</param>
 private void WriteSecuritySessionParameters(SecuritySessionParameters parameters)
 {
     this.BinaryWriter.Write((bool)(parameters != null));
     if (parameters != null)
     {
         this.WriteString(parameters.Name);
         this.BinaryWriter.Write((int)parameters.GenuineConnectionType);
         this.WriteString(parameters.ConnectionName);
         this.BinaryWriter.Write((long)parameters.Timeout.Ticks);
         this.BinaryWriter.Write((int)parameters.Attributes);
         this.BinaryWriter.Write((long)parameters.CloseAfterInactivity.Ticks);
     }
 }
示例#4
0
 private void CheckState()
 {
     try
     {
         SecuritySessionParameters parameters = new SecuritySessionParameters(
             SecuritySessionServices.DefaultContext.Name,
             SecuritySessionAttributes.None, TimeSpan.FromSeconds(5));
         using (new SecurityContextKeeper(parameters))
         {
             while (true)
             {
                 try
                 {
                     if (ClientEnvironment.ServerStateService.CanInteract)
                     {
                         if (ClientEnvironment.ServerStateService.ServerReady)
                         {
                             SetState(ServerState.Ready);
                         }
                         else
                         {
                             SetState(ServerState.Starting);
                         }
                     }
                     else
                     {
                         SetState(ServerState.Starting);
                     }
                 }
                 catch (ThreadAbortException)
                 {
                     return;
                 }
                 catch (Exception ex)
                 {
                     SetState(ServerState.Unavailable);
                 }
                 if (_FinishChecking.WaitOne(1000, false))
                 {
                     return;
                 }
             }
         }
     }
     catch (ThreadAbortException)
     {
     }
 }
示例#5
0
        public void RemoteInvocationWithCompressionAndPostfix()
        {
            // test compression
            var parameters = new SecuritySessionParameters(
                SecuritySessionServices.DefaultContext.Name,
                SecuritySessionAttributes.EnableCompression,
                TimeSpan.FromSeconds(5));

            var proxy = (IService)Activator.GetObject(typeof(IService), ServiceUriRem);

            using (new SecurityContextKeeper(parameters))
            {
                var greeting = proxy.Greeting("Compressed World");
                Assert.AreEqual("Hello, Compressed World!", greeting);
            }
        }
示例#6
0
        public void RemoteInvocationWithCompressionAndPostfix()
        {
            // test compression
            var parameters = new SecuritySessionParameters(
                SecuritySessionServices.DefaultContext.Name,
                SecuritySessionAttributes.EnableCompression,
                TimeSpan.FromSeconds(5));

            // note: localhost url doesn't work because it resolves to IPv6 address
            var proxy = (IService)Activator.GetObject(typeof(IService), "ghttp://127.0.0.1:8739/GxttpTestService.rem");

            using (new SecurityContextKeeper(parameters))
            {
                var greeting = proxy.Greeting("Compressed World");
                Assert.AreEqual("Goodbye, Compressed World!", greeting);
            }
        }
        public LoginResult ChangePassword(string oldPassword, string newPassword)
        {
            LoginResult res;
            SecuritySessionParameters oldParams = SecuritySessionServices.SetCurrentSecurityContext(
                new SecuritySessionParameters("/BAUMAX/SES", SecuritySessionAttributes.ForceSync, TimeSpan.MinValue,
                                              GenuineConnectionType.Persistent, null, TimeSpan.FromSeconds(10)));

            try
            {
                res = _RemoteSvc.ChangePassword(oldPassword, newPassword);
            }
            finally
            {
                SecuritySessionServices.SetCurrentSecurityContext(oldParams);
            }
            return(res);
        }
        public void RemoteInvocationWithCompression()
        {
            // test compression
            var parameters = new SecuritySessionParameters(
                SecuritySessionServices.DefaultContext.Name,
                SecuritySessionAttributes.EnableCompression,
                TimeSpan.FromSeconds(5));

            // note: localhost url should now work, although it may be resolved to IPv6 address
            var proxy = (IService)Activator.GetObject(typeof(IService), ServiceUri);

            using (new SecurityContextKeeper(parameters))
            {
                var greeting = proxy.Greeting("Compressed World");
                Assert.AreEqual("Hello, Compressed World!", greeting);
            }
        }
        public LoginResult LoginVersionCheck(string login, string password, out User resultUser, Version clientVersion)
        {
            _SvcAccess = null;
            _LogonUser = null;
            LoginResult res;

            SecuritySessionParameters oldParams = SecuritySessionServices.SetCurrentSecurityContext(
                new SecuritySessionParameters("/BAUMAX/SES", SecuritySessionAttributes.ForceSync, TimeSpan.MinValue,
                                              GenuineConnectionType.Persistent, null, TimeSpan.FromSeconds(10)));

            try
            {
                res        = _RemoteSvc.LoginVersionCheck(login, password, out resultUser, clientVersion);
                _LogonUser = resultUser;
            }
            finally
            {
                SecuritySessionServices.SetCurrentSecurityContext(oldParams);
            }

            return(res);
        }
        /// <summary>
        /// Sends a message to the remote host.
        /// </summary>
        /// <param name="message">The message to be sent.</param>
        public void Send(Message message)
        {
#if TRIAL
            _messagesBeingSent[message.MessageId] = message;
#endif

            BinaryLogWriter binaryLogWriter = this.ITransportContext.BinaryLogWriter;

            try
            {
                using (new ReaderAutoLocker(this._disposeLock))
                {
                    if (this._disposed)
                    {
                        throw OperationException.WrapException(this._disposeReason);
                    }
                }

                SecuritySession session = null;

                if (this._disposed)
                {
                    throw OperationException.WrapException(this._disposeReason);
                }

                // get the security session descriptor
                if (message.SecuritySessionParameters == null)
                {
                    SecuritySessionParameters securitySessionParameters = SecuritySessionServices.GetCurrentSecurityContext();
                    if (securitySessionParameters == null)
                    {
                        securitySessionParameters = message.Recipient.SecuritySessionParameters;
                    }
                    if (securitySessionParameters == null)
                    {
                        securitySessionParameters = this.ITransportContext.SecuritySessionParameters;
                    }
                    if (securitySessionParameters == null)
                    {
                        securitySessionParameters = SecuritySessionServices.DefaultSecuritySession;
                    }
                    message.SecuritySessionParameters = securitySessionParameters;
                }

                // LOG:
                if (binaryLogWriter != null && binaryLogWriter[LogCategory.MessageProcessing] > 0)
                {
                    binaryLogWriter.WriteSecuritySessionParametersEvent("ConnectionManager.Send",
                                                                        LogMessageType.SecuritySessionParametersAssembled, null, message, message.Recipient,
                                                                        GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name,
                                                                        message.SecuritySessionParameters,
                                                                        "Security Session Parameters have been assembled.");
                }

                // determine the type of sending
                message.IsSynchronous = (message.SecuritySessionParameters.Attributes & SecuritySessionAttributes.ForceSync) != 0 ||
                                        (message.IsSynchronous && (message.SecuritySessionParameters.Attributes & SecuritySessionAttributes.ForceAsync) == 0);

                // the time until invocation times out
                if (!message.FinishTime_Initialized)
                {
                    TimeSpan messageTimeout = message.SecuritySessionParameters.Timeout;
                    if (messageTimeout == TimeSpan.MinValue)
                    {
                        messageTimeout = (TimeSpan)this.ITransportContext.IParameterProvider[GenuineParameter.InvocationTimeout];
                    }
                    message.FinishTime = GenuineUtility.GetTimeout(messageTimeout);

                    message.FinishTime_Initialized = true;
                }

                // checks whether the message has been already processed by Security Session
                if (message.SerializedContent == null)
                {
                    session = message.Recipient.GetSecuritySession(message.SecuritySessionParameters.Name, this.ITransportContext.IKeyStore);
                    if (!session.IsEstablished)
                    {
                        if (binaryLogWriter != null && binaryLogWriter[LogCategory.Security] > 0)
                        {
                            binaryLogWriter.WriteEvent(LogCategory.Security, "ConnectionManager.Send",
                                                       LogMessageType.SecuritySessionHasNotBeenEstablishedYet, null, message, message.Recipient, null,
                                                       GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name,
                                                       session, session.Name, -1, 0, 0, 0, null, null, null, null,
                                                       "The requested Security Session is not established.");
                        }

                        session.InitiateEstablishingSecuritySession(message.SecuritySessionParameters);

                        // if it's a sync sending, then wait until security session will be established
                        if (message.IsSynchronous)
                        {
                            int timeSpanToWait = GenuineUtility.GetMillisecondsLeft(message.FinishTime);
                            if (timeSpanToWait <= 0)
                            {
                                throw GenuineExceptions.Get_Send_ServerDidNotReply();
                            }

                            // wait until Security Session will be established or a failure will be detected
                            int firedEvent = 0;
                            if (message.CancelSending != null)
                            {
                                firedEvent = WaitHandle.WaitAny(new WaitHandle[] { session.IsEstablishedEvent, session.Failed, message.CancelSending }, timeSpanToWait, false);
                            }
                            else
                            {
                                firedEvent = WaitHandle.WaitAny(new WaitHandle[] { session.IsEstablishedEvent, session.Failed }, timeSpanToWait, false);
                            }

                            if (firedEvent == WaitHandle.WaitTimeout)
                            {
                                throw GenuineExceptions.Get_Send_ServerDidNotReply();
                            }

                            // analyze the problem, if any
                            Exception exception = session.ReasonOfFailure;
                            if (firedEvent == 1)
                            {
                                if (exception != null)
                                {
                                    throw OperationException.WrapException(exception);
                                }
                                else
                                {
                                    throw GenuineExceptions.Get_Security_ContextWasNotEstablished(session.Name);
                                }
                            }

                            // if the message has been cancelled, let the sender to understand the reason
                            if (firedEvent == 2)
                            {
                                return;
                            }
                        }
                        else if (!session.IsEstablished)
                        {
                            // it's async and SS still isn't established
                            session.PutMessageToAwaitingQueue(message);
                            return;
                        }
                    }
                }

                // if serialization is necessary
                if (message.SerializedContent == null)
                {
                    // serialize the message
                    GenuineChunkedStream serializedMessageStream = new GenuineChunkedStream(false);
                    MessageCoder.Serialize(serializedMessageStream, message, (message.SecuritySessionParameters.Attributes & SecuritySessionAttributes.EnableCompression) != 0);

                    // save the name of the Security Session
                    GenuineChunkedStream resultStream = new GenuineChunkedStream(false);
                    BinaryWriter         writer       = new BinaryWriter(resultStream);
                    writer.Write(message.SecuritySessionParameters.Name);
                    session.Encrypt(serializedMessageStream, resultStream);
                    message.SerializedContent = resultStream;

                    // LOG: put down the log record
                    if (binaryLogWriter != null && binaryLogWriter[LogCategory.Security] > 0)
                    {
                        binaryLogWriter.WriteEvent(LogCategory.Security, "ConnectionManager.Send",
                                                   LogMessageType.SecuritySessionApplied, null, message, message.Recipient,
                                                   binaryLogWriter[LogCategory.Security] > 1 ? message.SerializedContent : null,
                                                   GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name, session,
                                                   session.Name, -1, 0, 0, 0, null, null, null, null,
                                                   "The message has been processed by the established Security Session.");
                    }
                }

#if TRIAL
                if (message.MessageId > 3005)
                {
                    throw GenuineExceptions.Get_Channel_TrialConditionExceeded("The maximum number of messages restriction has been exceeded. You can not send more than 3000 messages using TRIAL version.");
                }
#endif

                message.Sender = this.Local;
                this.InternalSend(message);
            }
            catch (Exception ex)
            {
                if (binaryLogWriter != null && binaryLogWriter[LogCategory.Security] > 0)
                {
                    binaryLogWriter.WriteEvent(LogCategory.MessageProcessing, "ConnectionManager.Send",
                                               LogMessageType.Error, ex, message, message.Recipient, null,
                                               GenuineUtility.CurrentThreadId, Thread.CurrentThread.Name,
                                               null, null, -1, 0, 0, 0, null, null, null, null,
                                               "An exception occurred while processing the message.");
                }

                throw;
            }
        }