public static IConnection UpgradeConnection(IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts)
        {
            ConnectionStream stream  = new ConnectionStream(connection, defaultTimeouts);
            Stream           stream2 = upgradeAcceptor.AcceptUpgrade(stream);

            if ((upgradeAcceptor is StreamSecurityUpgradeAcceptor) && DiagnosticUtility.ShouldTraceInformation)
            {
                TraceUtility.TraceEvent(TraceEventType.Information, 0x4002e, System.ServiceModel.SR.GetString("TraceCodeStreamSecurityUpgradeAccepted"), new StringTraceRecord("Type", upgradeAcceptor.GetType().ToString()), connection, null);
            }
            return(new StreamConnection(stream2, stream));
        }
        private void SetupSecurityIfNecessary(StreamUpgradeAcceptor upgradeAcceptor)
        {
            StreamSecurityUpgradeAcceptor securityUpgradeAcceptor = upgradeAcceptor as StreamSecurityUpgradeAcceptor;

            if (securityUpgradeAcceptor != null)
            {
                this.security = securityUpgradeAcceptor.GetRemoteSecurity();
                if (this.security == null)
                {
                    Exception exception = new ProtocolException(System.ServiceModel.SR.GetString("RemoteSecurityNotNegotiatedOnStreamUpgrade", new object[] { this.Via }));
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception);
                }
                this.WriteAuditEvent(securityUpgradeAcceptor, AuditLevel.Success, null);
            }
        }
        public static IConnection UpgradeConnection(IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts)
        {
            ConnectionStream connectionStream = new ConnectionStream(connection, defaultTimeouts);
            Stream           stream           = upgradeAcceptor.AcceptUpgrade(connectionStream);

            if (upgradeAcceptor is StreamSecurityUpgradeAcceptor)
            {
                if (DiagnosticUtility.ShouldTraceInformation)
                {
                    TraceUtility.TraceEvent(TraceEventType.Information,
                                            TraceCode.StreamSecurityUpgradeAccepted, SR.GetString(SR.TraceCodeStreamSecurityUpgradeAccepted),
                                            new StringTraceRecord("Type", upgradeAcceptor.GetType().ToString()), connection, null);
                }
            }

            return(new StreamConnection(stream, connectionStream));
        }
            public UpgradeConnectionAsyncResult(IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts, AsyncCallback callback, object state) : base(callback, state)
            {
                this.upgradeAcceptor  = upgradeAcceptor;
                this.connectionStream = new ConnectionStream(connection, defaultTimeouts);
                bool         flag   = false;
                IAsyncResult result = upgradeAcceptor.BeginAcceptUpgrade(this.connectionStream, onAcceptUpgrade, this);

                if (result.CompletedSynchronously)
                {
                    this.CompleteAcceptUpgrade(result);
                    flag = true;
                }
                if (flag)
                {
                    base.Complete(true);
                }
            }
 public ServerFramingDuplexSessionChannel(ConnectionOrientedTransportChannelListener channelListener, ServerSessionPreambleConnectionReader preambleReader, EndpointAddress localAddress, bool exposeConnectionProperty, ConnectionDemuxer connectionDemuxer) : base(channelListener, localAddress, preambleReader.Via, exposeConnectionProperty)
 {
     this.channelListener = channelListener;
     this.connectionDemuxer = connectionDemuxer;
     base.Connection = preambleReader.Connection;
     this.decoder = preambleReader.Decoder;
     this.connectionBuffer = preambleReader.connectionBuffer;
     this.offset = preambleReader.BufferOffset;
     this.size = preambleReader.BufferSize;
     this.rawConnection = preambleReader.RawConnection;
     StreamUpgradeProvider upgrade = channelListener.Upgrade;
     if (upgrade != null)
     {
         this.channelBindingProvider = upgrade.GetProperty<IStreamUpgradeChannelBindingProvider>();
         this.upgradeAcceptor = upgrade.CreateUpgradeAcceptor();
     }
 }
Ejemplo n.º 6
0
        ChannelBinding IStreamUpgradeChannelBindingProvider.GetChannelBinding(StreamUpgradeAcceptor upgradeAcceptor, ChannelBindingKind kind)
        {
            if (upgradeAcceptor == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("upgradeAcceptor");
            }
            SslStreamSecurityUpgradeAcceptor acceptor = upgradeAcceptor as SslStreamSecurityUpgradeAcceptor;

            if (acceptor == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("upgradeAcceptor", System.ServiceModel.SR.GetString("UnsupportedUpgradeAcceptor", new object[] { upgradeAcceptor.GetType() }));
            }
            if (kind != ChannelBindingKind.Endpoint)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("kind", System.ServiceModel.SR.GetString("StreamUpgradeUnsupportedChannelBindingKind", new object[] { base.GetType(), kind }));
            }
            return(acceptor.ChannelBinding);
        }
        ChannelBinding IStreamUpgradeChannelBindingProvider.GetChannelBinding(StreamUpgradeAcceptor upgradeAcceptor, ChannelBindingKind kind)
        {
            if (upgradeAcceptor == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("upgradeAcceptor");
            }

            SslStreamSecurityUpgradeAcceptor sslupgradeAcceptor = upgradeAcceptor as SslStreamSecurityUpgradeAcceptor;

            if (sslupgradeAcceptor == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("upgradeAcceptor", string.Format(SRServiceModel.UnsupportedUpgradeAcceptor, upgradeAcceptor.GetType()));
            }

            if (kind != ChannelBindingKind.Endpoint)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("kind", string.Format(SRServiceModel.StreamUpgradeUnsupportedChannelBindingKind, this.GetType(), kind));
            }

            return(sslupgradeAcceptor.ChannelBinding);
        }
            public UpgradeConnectionAsyncResult(IConnection connection,
                StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts,
                AsyncCallback callback, object state)
                : base(callback, state)
            {
                this.upgradeAcceptor = upgradeAcceptor;
                this.connectionStream = new ConnectionStream(connection, defaultTimeouts);
                bool completeSelf = false;

                IAsyncResult result = upgradeAcceptor.BeginAcceptUpgrade(connectionStream, onAcceptUpgrade, this);

                if (result.CompletedSynchronously)
                {
                    CompleteAcceptUpgrade(result);
                    completeSelf = true;
                }

                if (completeSelf)
                {
                    base.Complete(true);
                }
            }
        public static IConnection UpgradeConnection(IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts)
        {
            ConnectionStream connectionStream = new ConnectionStream(connection, defaultTimeouts);
            Stream stream = upgradeAcceptor.AcceptUpgrade(connectionStream);
            if (upgradeAcceptor is StreamSecurityUpgradeAcceptor)
            {
                if (DiagnosticUtility.ShouldTraceInformation)
                {
                    TraceUtility.TraceEvent(TraceEventType.Information,
                        TraceCode.StreamSecurityUpgradeAccepted, SR.GetString(SR.TraceCodeStreamSecurityUpgradeAccepted),
                        new StringTraceRecord("Type", upgradeAcceptor.GetType().ToString()), connection, null);
                }
            }

            return new StreamConnection(stream, connectionStream);
        }
 public static IAsyncResult BeginUpgradeConnection(IConnection connection, StreamUpgradeAcceptor upgradeAcceptor,
     IDefaultCommunicationTimeouts defaultTimeouts, AsyncCallback callback, object state)
 {
     return new UpgradeConnectionAsyncResult(connection, upgradeAcceptor, defaultTimeouts, callback, state);
 }
 public static IAsyncResult BeginUpgradeConnection(IConnection connection, StreamUpgradeAcceptor upgradeAcceptor,
                                                   IDefaultCommunicationTimeouts defaultTimeouts, AsyncCallback callback, object state)
 {
     return(new UpgradeConnectionAsyncResult(connection, upgradeAcceptor, defaultTimeouts, callback, state));
 }
        public IConnection CompletePreamble(TimeSpan timeout)
        {
            int           num;
            TimeoutHelper timeoutHelper = new TimeoutHelper(timeout);

            if (!this.transportSettings.MessageEncoderFactory.Encoder.IsContentTypeSupported(this.decoder.ContentType))
            {
                this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/ContentTypeInvalid", ref timeoutHelper);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("ContentTypeMismatch", new object[] { this.decoder.ContentType, this.transportSettings.MessageEncoderFactory.Encoder.ContentType })));
            }
            StreamUpgradeAcceptor upgradeAcceptor         = null;
            StreamUpgradeProvider upgrade                 = this.transportSettings.Upgrade;
            IStreamUpgradeChannelBindingProvider property = null;

            if (upgrade != null)
            {
                property        = upgrade.GetProperty <IStreamUpgradeChannelBindingProvider>();
                upgradeAcceptor = upgrade.CreateUpgradeAcceptor();
            }
            IConnection connection = base.Connection;

Label_00B1:
            if (this.size == 0)
            {
                this.offset = 0;
                this.size   = connection.Read(this.connectionBuffer, 0, this.connectionBuffer.Length, timeoutHelper.RemainingTime());
                if (this.size == 0)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.decoder.CreatePrematureEOFException());
                }
            }
Label_0101:
            num = this.decoder.Decode(this.connectionBuffer, this.offset, this.size);
            if (num > 0)
            {
                this.offset += num;
                this.size   -= num;
            }
            switch (this.decoder.CurrentState)
            {
            case ServerSingletonDecoder.State.UpgradeRequest:
            {
                if (upgradeAcceptor == null)
                {
                    this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UpgradeInvalid", ref timeoutHelper);
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("UpgradeRequestToNonupgradableService", new object[] { this.decoder.Upgrade })));
                }
                if (!upgradeAcceptor.CanUpgrade(this.decoder.Upgrade))
                {
                    this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UpgradeInvalid", ref timeoutHelper);
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ProtocolException(System.ServiceModel.SR.GetString("UpgradeProtocolNotSupported", new object[] { this.decoder.Upgrade })));
                }
                connection.Write(ServerSingletonEncoder.UpgradeResponseBytes, 0, ServerSingletonEncoder.UpgradeResponseBytes.Length, true, timeoutHelper.RemainingTime());
                IConnection innerConnection = connection;
                if (this.size > 0)
                {
                    innerConnection = new PreReadConnection(innerConnection, this.connectionBuffer, this.offset, this.size);
                }
                try
                {
                    connection            = InitialServerConnectionReader.UpgradeConnection(innerConnection, upgradeAcceptor, this.transportSettings);
                    this.connectionBuffer = connection.AsyncReadBuffer;
                    if ((property != null) && property.IsChannelBindingSupportEnabled)
                    {
                        this.channelBindingToken = property.GetChannelBinding(upgradeAcceptor, ChannelBindingKind.Endpoint);
                    }
                    goto Label_02C0;
                }
                catch (Exception exception)
                {
                    if (Fx.IsFatal(exception))
                    {
                        throw;
                    }
                    this.WriteAuditFailure(upgradeAcceptor as StreamSecurityUpgradeAcceptor, exception);
                    throw;
                }
                break;
            }

            case ServerSingletonDecoder.State.Start:
                break;

            default:
                goto Label_02C0;
            }
            this.SetupSecurityIfNecessary(upgradeAcceptor);
            connection.Write(ServerSessionEncoder.AckResponseBytes, 0, ServerSessionEncoder.AckResponseBytes.Length, true, timeoutHelper.RemainingTime());
            return(connection);

Label_02C0:
            if (this.size != 0)
            {
                goto Label_0101;
            }
            goto Label_00B1;
        }
 private void SetupSecurityIfNecessary(StreamUpgradeAcceptor upgradeAcceptor)
 {
     StreamSecurityUpgradeAcceptor securityUpgradeAcceptor = upgradeAcceptor as StreamSecurityUpgradeAcceptor;
     if (securityUpgradeAcceptor != null)
     {
         this.security = securityUpgradeAcceptor.GetRemoteSecurity();
         if (this.security == null)
         {
             Exception exception = new ProtocolException(System.ServiceModel.SR.GetString("RemoteSecurityNotNegotiatedOnStreamUpgrade", new object[] { this.Via }));
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(exception);
         }
         this.WriteAuditEvent(securityUpgradeAcceptor, AuditLevel.Success, null);
     }
 }