public static async Task UpgradeConnectionAsync(FramingConnection connection)
        {
            connection.RawStream = new RawStream(connection);
            StreamUpgradeAcceptor upgradeAcceptor = connection.StreamUpgradeAcceptor;
            Stream stream = await upgradeAcceptor.AcceptUpgradeAsync(connection.RawStream);

            CreatePipelineFromStream(connection, stream);
        }
        public static async Task UpgradeConnectionAsync(FramingConnection connection, string contentType)
        {
            var duplexPipeStream = new DuplexPipeStream(connection.Input, connection.Output);

            connection.RawStream = duplexPipeStream;
            StreamUpgradeAcceptor upgradeAcceptor = connection.StreamUpgradeAcceptor;
            Stream stream = await upgradeAcceptor.AcceptUpgradeAsync(connection.RawStream);

            duplexPipeStream.SetContentType(contentType);
            CreatePipelineFromStream(connection, stream);
        }
예제 #3
0
 public ServerFramingDuplexSessionChannel(FramingConnection connection, ITransportFactorySettings settings,
                                          bool exposeConnectionProperty, IServiceProvider serviceProvider)
     : base(connection, settings, exposeConnectionProperty)
 {
     Connection       = connection;
     upgradeAcceptor  = connection.StreamUpgradeAcceptor;
     _serviceProvider = serviceProvider;
     //if (upgradeAcceptor != null)
     //{
     //    this.channelBindingProvider = upgrade.GetProperty<IStreamUpgradeChannelBindingProvider>();
     //    this.upgradeAcceptor = upgrade.CreateUpgradeAcceptor();
     //}
 }
예제 #4
0
            public static FramingConnectionDuplexSession CreateSession(FramingDuplexSessionChannel channel,
                                                                       StreamUpgradeAcceptor upgradeAcceptor)
            {
                StreamSecurityUpgradeAcceptor security = upgradeAcceptor as StreamSecurityUpgradeAcceptor;

                if (security == null)
                {
                    return(new FramingConnectionDuplexSession(channel));
                }
                else
                {
                    return(new SecureConnectionDuplexSession(channel));
                }
            }
예제 #5
0
		public void ClientAcceptUpgradeWithoutServiceCertificate ()
		{
			StreamSecurityUpgradeProvider p = CreateClientProvider ();
			Assert.IsNotNull (p, "#1");
			Assert.IsNull (p.Identity, "#2"); // not yet, before Open().
			p.Open ();
			StreamUpgradeAcceptor a = p.CreateUpgradeAcceptor ();
			try {
				Stream s = a.AcceptUpgrade (new MemoryStream (new byte [] {1, 2, 3, 4, 5}));
				Assert.Fail ("It should somehow raise an error."); // on Winfx it is unwise ArgumentNullException
			} catch (Exception) {
			} finally {
				p.Close ();
			}
		}
        private void SetupSecurityIfNecessary(StreamUpgradeAcceptor upgradeAcceptor)
        {
            StreamSecurityUpgradeAcceptor streamSecurityUpgradeAcceptor = upgradeAcceptor as StreamSecurityUpgradeAcceptor;

            if (streamSecurityUpgradeAcceptor != null)
            {
                this.security = streamSecurityUpgradeAcceptor.GetRemoteSecurity();
                if (this.security == null)
                {
                    string    remoteSecurityNotNegotiatedOnStreamUpgrade = Resources.RemoteSecurityNotNegotiatedOnStreamUpgrade;
                    object[]  via = new object[] { this.Via };
                    Exception protocolException = new ProtocolException(Microsoft.ServiceBus.SR.GetString(remoteSecurityNotNegotiatedOnStreamUpgrade, via));
                    throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(protocolException);
                }
                this.WriteAuditEvent(streamSecurityUpgradeAcceptor, AuditLevel.Success, null);
            }
        }
            public UpgradeConnectionAsyncResult(Microsoft.ServiceBus.Channels.IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts, AsyncCallback callback, object state) : base(callback, state)
            {
                this.upgradeAcceptor  = upgradeAcceptor;
                this.connectionStream = new Microsoft.ServiceBus.Channels.ConnectionStream(connection, defaultTimeouts);
                bool         flag        = false;
                IAsyncResult asyncResult = upgradeAcceptor.BeginAcceptUpgrade(this.connectionStream, Microsoft.ServiceBus.Channels.InitialServerConnectionReader.UpgradeConnectionAsyncResult.onAcceptUpgrade, this);

                if (asyncResult.CompletedSynchronously)
                {
                    this.CompleteAcceptUpgrade(asyncResult);
                    flag = true;
                }
                if (flag)
                {
                    base.Complete(true);
                }
            }
            public ServerFramingDuplexSessionChannel(Microsoft.ServiceBus.Channels.ConnectionOrientedTransportChannelListener channelListener, Microsoft.ServiceBus.Channels.ServerSessionPreambleConnectionReader preambleReader, EndpointAddress localAddress, bool exposeConnectionProperty, Microsoft.ServiceBus.Channels.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.upgradeAcceptor = upgrade.CreateUpgradeAcceptor();
                }
                MessagingClientEtwProvider.Provider.RelayChannelConnectionTransfer(base.Activity, base.Connection.Activity);
            }
        private static void ProcessUpgradeRequest(FramingConnection connection, ServerSessionDecoder decoder)
        {
            StreamUpgradeAcceptor upgradeAcceptor = connection.StreamUpgradeAcceptor;

            if (upgradeAcceptor == null)
            {
                // TODO: SendFault
                //SendFault(FramingEncodingString.UpgradeInvalidFault, ref timeoutHelper);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new ProtocolException(SR.Format(SR.UpgradeRequestToNonupgradableService, decoder.Upgrade)));
            }

            if (!upgradeAcceptor.CanUpgrade(decoder.Upgrade))
            {
                // TODO: SendFault
                //SendFault(FramingEncodingString.UpgradeInvalidFault, ref timeoutHelper);
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(
                          new ProtocolException(SR.Format(SR.UpgradeProtocolNotSupported, decoder.Upgrade)));
            }
        }
        public Microsoft.ServiceBus.Channels.IConnection CompletePreamble(TimeSpan timeout)
        {
            Microsoft.ServiceBus.Common.TimeoutHelper timeoutHelper = new Microsoft.ServiceBus.Common.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);
                ExceptionUtility exceptionUtility    = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                string           contentTypeMismatch = Resources.ContentTypeMismatch;
                object[]         contentType         = new object[] { this.decoder.ContentType, this.transportSettings.MessageEncoderFactory.Encoder.ContentType };
                throw exceptionUtility.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(contentTypeMismatch, contentType)));
            }
            StreamUpgradeAcceptor streamUpgradeAcceptor = null;
            StreamUpgradeProvider upgrade = this.transportSettings.Upgrade;

            if (upgrade != null)
            {
                streamUpgradeAcceptor = upgrade.CreateUpgradeAcceptor();
            }
            Microsoft.ServiceBus.Channels.IConnection connection = base.Connection;
            while (true)
            {
                if (this.size == 0)
                {
                    this.offset = 0;
                    this.size   = connection.Read(this.connectionBuffer, 0, (int)this.connectionBuffer.Length, timeoutHelper.RemainingTime());
                    if (this.size == 0)
                    {
                        break;
                    }
                }
                do
                {
                    int num = this.decoder.Decode(this.connectionBuffer, this.offset, this.size);
                    if (num > 0)
                    {
                        Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleConnectionReader = this;
                        serverSingletonPreambleConnectionReader.offset = serverSingletonPreambleConnectionReader.offset + num;
                        Microsoft.ServiceBus.Channels.ServerSingletonPreambleConnectionReader serverSingletonPreambleConnectionReader1 = this;
                        serverSingletonPreambleConnectionReader1.size = serverSingletonPreambleConnectionReader1.size - num;
                    }
                    switch (this.decoder.CurrentState)
                    {
                    case Microsoft.ServiceBus.Channels.ServerSingletonDecoder.State.UpgradeRequest:
                    {
                        if (streamUpgradeAcceptor == null)
                        {
                            this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UpgradeInvalid", ref timeoutHelper);
                            ExceptionUtility exceptionUtility1 = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                            string           upgradeRequestToNonupgradableService = Resources.UpgradeRequestToNonupgradableService;
                            object[]         objArray = new object[] { this.decoder.Upgrade };
                            throw exceptionUtility1.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(upgradeRequestToNonupgradableService, objArray)));
                        }
                        if (!streamUpgradeAcceptor.CanUpgrade(this.decoder.Upgrade))
                        {
                            this.SendFault("http://schemas.microsoft.com/ws/2006/05/framing/faults/UpgradeInvalid", ref timeoutHelper);
                            ExceptionUtility exceptionUtility2           = Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility;
                            string           upgradeProtocolNotSupported = Resources.UpgradeProtocolNotSupported;
                            object[]         upgrade1 = new object[] { this.decoder.Upgrade };
                            throw exceptionUtility2.ThrowHelperError(new ProtocolException(Microsoft.ServiceBus.SR.GetString(upgradeProtocolNotSupported, upgrade1)));
                        }
                        connection.Write(Microsoft.ServiceBus.Channels.ServerSingletonEncoder.UpgradeResponseBytes, 0, (int)Microsoft.ServiceBus.Channels.ServerSingletonEncoder.UpgradeResponseBytes.Length, true, timeoutHelper.RemainingTime());
                        Microsoft.ServiceBus.Channels.IConnection preReadConnection = connection;
                        if (this.size > 0)
                        {
                            preReadConnection = new Microsoft.ServiceBus.Channels.PreReadConnection(preReadConnection, this.connectionBuffer, this.offset, this.size);
                        }
                        try
                        {
                            connection            = Microsoft.ServiceBus.Channels.InitialServerConnectionReader.UpgradeConnection(preReadConnection, streamUpgradeAcceptor, this.transportSettings);
                            this.connectionBuffer = connection.AsyncReadBuffer;
                            continue;
                        }
                        catch (Exception exception1)
                        {
                            Exception exception = exception1;
                            if (Fx.IsFatal(exception))
                            {
                                throw;
                            }
                            this.WriteAuditFailure(streamUpgradeAcceptor as StreamSecurityUpgradeAcceptor, exception);
                            throw;
                        }
                        break;
                    }

                    case Microsoft.ServiceBus.Channels.ServerSingletonDecoder.State.Start:
                    {
                        this.SetupSecurityIfNecessary(streamUpgradeAcceptor);
                        connection.Write(Microsoft.ServiceBus.Channels.ServerSessionEncoder.AckResponseBytes, 0, (int)Microsoft.ServiceBus.Channels.ServerSessionEncoder.AckResponseBytes.Length, true, timeoutHelper.RemainingTime());
                        return(connection);
                    }

                    default:
                    {
                        continue;
                    }
                    }
                }while (this.size != 0);
            }
            throw Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.decoder.CreatePrematureEOFException());
        }
        public static Microsoft.ServiceBus.Channels.IConnection UpgradeConnection(Microsoft.ServiceBus.Channels.IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts)
        {
            Microsoft.ServiceBus.Channels.ConnectionStream connectionStream = new Microsoft.ServiceBus.Channels.ConnectionStream(connection, defaultTimeouts);
            Stream stream = upgradeAcceptor.AcceptUpgrade(connectionStream);

            if (upgradeAcceptor is StreamSecurityUpgradeAcceptor && Microsoft.ServiceBus.Diagnostics.DiagnosticUtility.ShouldTraceInformation)
            {
                TraceUtility.TraceEvent(TraceEventType.Information, TraceCode.StreamSecurityUpgradeAccepted, new StringTraceRecord("Type", upgradeAcceptor.GetType().ToString()), connection, null);
            }
            return(new Microsoft.ServiceBus.Channels.StreamConnection(stream, connectionStream));
        }
 public static IAsyncResult BeginUpgradeConnection(Microsoft.ServiceBus.Channels.IConnection connection, StreamUpgradeAcceptor upgradeAcceptor, IDefaultCommunicationTimeouts defaultTimeouts, AsyncCallback callback, object state)
 {
     return(new Microsoft.ServiceBus.Channels.InitialServerConnectionReader.UpgradeConnectionAsyncResult(connection, upgradeAcceptor, defaultTimeouts, callback, state));
 }