Esempio n. 1
0
        public void Open(bool insist)
        {
            BlockingCell connectionStartCell = new BlockingCell();

            m_model0.m_connectionStartCell = connectionStartCell;
            m_frameHandler.Timeout         = HandshakeTimeout;
            m_frameHandler.SendHeader();

            ConnectionStartDetails connectionStart = (ConnectionStartDetails)
                                                     connectionStartCell.Value;

            AmqpVersion serverVersion = new AmqpVersion(connectionStart.m_versionMajor,
                                                        connectionStart.m_versionMinor);

            if (!serverVersion.Equals(Protocol.Version))
            {
                TerminateMainloop();
                FinishClose();
                throw new ProtocolVersionMismatchException(Protocol.MajorVersion,
                                                           Protocol.MinorVersion,
                                                           serverVersion.Major,
                                                           serverVersion.Minor);
            }

            // FIXME: check that PLAIN is supported.
            // FIXME: parse out locales properly!
            ConnectionTuneDetails connectionTune =
                m_model0.ConnectionStartOk(BuildClientPropertiesTable(),
                                           "PLAIN",
                                           Encoding.UTF8.GetBytes("\0" + m_parameters.UserName +
                                                                  "\0" + m_parameters.Password),
                                           "en_US");

            ushort channelMax = (ushort)NegotiatedMaxValue(m_parameters.RequestedChannelMax,
                                                           connectionTune.m_channelMax);

            ChannelMax = channelMax;

            uint frameMax = NegotiatedMaxValue(m_parameters.RequestedFrameMax,
                                               connectionTune.m_frameMax);

            FrameMax = frameMax;

            ushort heartbeat = (ushort)NegotiatedMaxValue(m_parameters.RequestedHeartbeat,
                                                          connectionTune.m_heartbeat);

            Heartbeat = heartbeat;

            m_model0.ConnectionTuneOk(channelMax,
                                      frameMax,
                                      heartbeat);

            string knownHosts = m_model0.ConnectionOpen(m_parameters.VirtualHost,
                                                        "", // FIXME: make configurable?
                                                        insist);

            KnownHosts = AmqpTcpEndpoint.ParseMultiple(Protocol, knownHosts);
        }
Esempio n. 2
0
 public void Decode(ByteBuffer buffer)
 {
     if (buffer.Length < this.EncodeSize)
     {
         throw AmqpEncoding.GetEncodingException(SRAmqp.AmqpInsufficientBufferSize(this.EncodeSize, buffer.Length));
     }
     if (AmqpBitConverter.ReadUInt(buffer) != 1095586128)
     {
         throw AmqpEncoding.GetEncodingException("ProtocolName");
     }
     this.protocolId = (Microsoft.ServiceBus.Messaging.Amqp.ProtocolId)AmqpBitConverter.ReadUByte(buffer);
     this.version    = new AmqpVersion(AmqpBitConverter.ReadUByte(buffer), AmqpBitConverter.ReadUByte(buffer), AmqpBitConverter.ReadUByte(buffer));
 }
Esempio n. 3
0
        public bool TryGetVersion(AmqpVersion requestedVersion, out AmqpVersion supportedVersion)
        {
            supportedVersion = this.DefaultVersion;
            foreach (AmqpVersion version in this.Versions)
            {
                if (version.Equals(requestedVersion))
                {
                    supportedVersion = requestedVersion;
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 4
0
        public bool TryGetVersion(AmqpVersion requestedVersion, out AmqpVersion supportedVersion)
        {
            supportedVersion = this.DefaultVersion;
            foreach (AmqpVersion version in this.Versions)
            {
                if (version.Equals(requestedVersion))
                {
                    supportedVersion = requestedVersion;
                    return true;
                }
            }

            return false;
        }
Esempio n. 5
0
        public void Decode(ByteBuffer buffer)
        {
            if (buffer.Length < this.EncodeSize)
            {
                throw new AmqpException(AmqpErrorCode.DecodeError, AmqpResources.GetString(AmqpResources.AmqpInsufficientBufferSize, this.EncodeSize, buffer.Length));
            }

            uint prefix = AmqpBitConverter.ReadUInt(buffer);
            if (prefix != ProtocolHeader.AmqpPrefix)
            {
                throw new AmqpException(AmqpErrorCode.DecodeError, "ProtocolName" + prefix.ToString("X8"));
            }

            this.protocolId = (ProtocolId)AmqpBitConverter.ReadUByte(buffer);

            this.version = new AmqpVersion(
                AmqpBitConverter.ReadUByte(buffer),
                AmqpBitConverter.ReadUByte(buffer),
                AmqpBitConverter.ReadUByte(buffer));
        }
Esempio n. 6
0
        public void Decode(ByteBuffer buffer)
        {
            if (buffer.Length < this.EncodeSize)
            {
                throw new AmqpException(AmqpErrorCode.DecodeError, AmqpResources.GetString(AmqpResources.AmqpInsufficientBufferSize, this.EncodeSize, buffer.Length));
            }

            uint prefix = AmqpBitConverter.ReadUInt(buffer);

            if (prefix != ProtocolHeader.AmqpPrefix)
            {
                throw new AmqpException(AmqpErrorCode.DecodeError, "ProtocolName" + prefix.ToString("X8"));
            }

            this.protocolId = (ProtocolId)AmqpBitConverter.ReadUByte(buffer);

            this.version = new AmqpVersion(
                AmqpBitConverter.ReadUByte(buffer),
                AmqpBitConverter.ReadUByte(buffer),
                AmqpBitConverter.ReadUByte(buffer));
        }
Esempio n. 7
0
        public bool TryGetVersion(AmqpVersion requestedVersion, out AmqpVersion supportedVersion)
        {
            bool flag;

            supportedVersion = this.DefaultVersion;
            using (IEnumerator <AmqpVersion> enumerator = this.Versions.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    if (!enumerator.Current.Equals(requestedVersion))
                    {
                        continue;
                    }
                    supportedVersion = requestedVersion;
                    flag             = true;
                    return(flag);
                }
                return(false);
            }
            return(flag);
        }
        protected void StartAndTune()
        {
            var connectionStartCell = new BlockingCell();
            m_model0.m_connectionStartCell = connectionStartCell;
            m_model0.HandshakeContinuationTimeout = m_factory.HandshakeContinuationTimeout;
            m_frameHandler.ReadTimeout = m_factory.HandshakeContinuationTimeout.Milliseconds;
            m_frameHandler.SendHeader();

            var connectionStart = (ConnectionStartDetails)
                connectionStartCell.Value;

            if (connectionStart == null)
            {
                throw new IOException("connection.start was never received, likely due to a network timeout");
            }

            ServerProperties = connectionStart.m_serverProperties;

            var serverVersion = new AmqpVersion(connectionStart.m_versionMajor,
                connectionStart.m_versionMinor);
            if (!serverVersion.Equals(Protocol.Version))
            {
                TerminateMainloop();
                FinishClose();
                throw new ProtocolVersionMismatchException(Protocol.MajorVersion,
                    Protocol.MinorVersion,
                    serverVersion.Major,
                    serverVersion.Minor);
            }

            m_clientProperties = new Dictionary<string, object>(m_factory.ClientProperties);
            m_clientProperties["capabilities"] = Protocol.Capabilities;
            m_clientProperties["connection_name"] = this.ClientProvidedName;

            // FIXME: parse out locales properly!
            ConnectionTuneDetails connectionTune = default(ConnectionTuneDetails);
            bool tuned = false;
            try
            {
                string mechanismsString = Encoding.UTF8.GetString(connectionStart.m_mechanisms, 0, connectionStart.m_mechanisms.Length);
                string[] mechanisms = mechanismsString.Split(' ');
                AuthMechanismFactory mechanismFactory = m_factory.AuthMechanismFactory(mechanisms);
                if (mechanismFactory == null)
                {
                    throw new IOException("No compatible authentication mechanism found - " +
                                          "server offered [" + mechanismsString + "]");
                }
                AuthMechanism mechanism = mechanismFactory.GetInstance();
                byte[] challenge = null;
                do
                {
                    byte[] response = mechanism.handleChallenge(challenge, m_factory);
                    ConnectionSecureOrTune res;
                    if (challenge == null)
                    {
                        res = m_model0.ConnectionStartOk(m_clientProperties,
                            mechanismFactory.Name,
                            response,
                            "en_US");
                    }
                    else
                    {
                        res = m_model0.ConnectionSecureOk(response);
                    }

                    if (res.m_challenge == null)
                    {
                        connectionTune = res.m_tuneDetails;
                        tuned = true;
                    }
                    else
                    {
                        challenge = res.m_challenge;
                    }
                }
                while (!tuned);
            }
            catch (OperationInterruptedException e)
            {
                if (e.ShutdownReason != null && e.ShutdownReason.ReplyCode == Constants.AccessRefused)
                {
                    throw new AuthenticationFailureException(e.ShutdownReason.ReplyText);
                }
                throw new PossibleAuthenticationFailureException(
                    "Possibly caused by authentication failure", e);
            }

            var channelMax = (ushort)NegotiatedMaxValue(m_factory.RequestedChannelMax,
                connectionTune.m_channelMax);
            m_sessionManager = new SessionManager(this, channelMax);

            uint frameMax = NegotiatedMaxValue(m_factory.RequestedFrameMax,
                connectionTune.m_frameMax);
            FrameMax = frameMax;

            var heartbeat = (ushort)NegotiatedMaxValue(m_factory.RequestedHeartbeat,
                connectionTune.m_heartbeat);
            Heartbeat = heartbeat;

            m_model0.ConnectionTuneOk(channelMax,
                frameMax,
                heartbeat);

            // now we can start heartbeat timers
            MaybeStartHeartbeatTimers();
        }
Esempio n. 9
0
 public ProtocolHeader(ProtocolId id, AmqpVersion version)
 {
     this.protocolId = id;
     this.version    = version;
 }
 /// <summary>
 /// Initializes the object.
 /// </summary>
 /// <param name="version">The supported version.</param>
 public AmqpTransportProvider(AmqpVersion version)
     : this()
 {
     this.Versions.Add(version);
 }
Esempio n. 11
0
 public ProtocolHeader(Microsoft.ServiceBus.Messaging.Amqp.ProtocolId id, AmqpVersion version)
 {
     this.protocolId = id;
     this.version    = version;
 }
Esempio n. 12
0
 public ProtocolHeader(ProtocolId id, AmqpVersion version)
 {
     this.protocolId = id;
     this.version = version;
     this.InitializePacket();
 }
Esempio n. 13
0
        public void Open(bool insist)
        {
            BlockingCell connectionStartCell = new BlockingCell();

            m_model0.m_connectionStartCell = connectionStartCell;
            m_frameHandler.Timeout         = HandshakeTimeout;
            m_frameHandler.SendHeader();

            ConnectionStartDetails connectionStart = (ConnectionStartDetails)
                                                     connectionStartCell.Value;

            ServerProperties = connectionStart.m_serverProperties;

            AmqpVersion serverVersion = new AmqpVersion(connectionStart.m_versionMajor,
                                                        connectionStart.m_versionMinor);

            if (!serverVersion.Equals(Protocol.Version))
            {
                TerminateMainloop();
                FinishClose();
                throw new ProtocolVersionMismatchException(Protocol.MajorVersion,
                                                           Protocol.MinorVersion,
                                                           serverVersion.Major,
                                                           serverVersion.Minor);
            }

            m_clientProperties = new Hashtable(m_factory.ClientProperties);

            // FIXME: check that PLAIN is supported.
            // FIXME: parse out locales properly!
            ConnectionTuneDetails connectionTune = default(ConnectionTuneDetails);

            try
            {
                connectionTune =
                    m_model0.ConnectionStartOk(m_clientProperties,
                                               "PLAIN",
                                               Encoding.UTF8.GetBytes(
                                                   "\0" + m_factory.UserName +
                                                   "\0" + m_factory.Password),
                                               "en_US");
            }
            catch (OperationInterruptedException e)
            {
                throw new PossibleAuthenticationFailureException(
                          "Possibly caused by authentication failure", e);
            }

            ushort channelMax = (ushort)NegotiatedMaxValue(m_factory.RequestedChannelMax,
                                                           connectionTune.m_channelMax);

            m_sessionManager = new SessionManager(this, channelMax);

            uint frameMax = NegotiatedMaxValue(m_factory.RequestedFrameMax,
                                               connectionTune.m_frameMax);

            FrameMax = frameMax;

            ushort heartbeat = (ushort)NegotiatedMaxValue(m_factory.RequestedHeartbeat,
                                                          connectionTune.m_heartbeat);

            Heartbeat = heartbeat;

            m_model0.ConnectionTuneOk(channelMax,
                                      frameMax,
                                      heartbeat);

            string knownHosts = m_model0.ConnectionOpen(m_factory.VirtualHost,
                                                        "", // FIXME: make configurable?
                                                        insist);

            KnownHosts = AmqpTcpEndpoint.ParseMultiple(Protocol, knownHosts);
        }
Esempio n. 14
0
 public ProtocolHeader(ProtocolId id, AmqpVersion version)
 {
     this.protocolId = id;
     this.version = version;
 }
Esempio n. 15
0
 /// <summary>
 /// Initializes the object.
 /// </summary>
 /// <param name="tlsSettings">The TLS transport settings.</param>
 /// <param name="version">The supported version.</param>
 public TlsTransportProvider(TlsTransportSettings tlsSettings, AmqpVersion version)
     : this(tlsSettings)
 {
     this.Versions.Add(version);
 }
Esempio n. 16
0
 public ProtocolHeader(ProtocolId id, AmqpVersion version)
 {
     this.protocolId = id;
     this.version    = version;
     this.InitializePacket();
 }