/// <summary>
        /// Saves the settings so the channel can be opened later.
        /// </summary>
        /// <param name="url">The URL.</param>
        /// <param name="settings">The settings.</param>
        private void SaveSettings(Uri url, TransportChannelSettings settings)
        {
            // save the settings.
            m_url              = url;
            m_settings         = settings;
            m_operationTimeout = settings.Configuration.OperationTimeout;

            // initialize the quotas.
            m_quotas = new ChannelQuotas();

            m_quotas.MaxBufferSize         = m_settings.Configuration.MaxBufferSize;
            m_quotas.MaxMessageSize        = m_settings.Configuration.MaxMessageSize;
            m_quotas.ChannelLifetime       = m_settings.Configuration.ChannelLifetime;
            m_quotas.SecurityTokenLifetime = m_settings.Configuration.SecurityTokenLifetime;

            m_quotas.MessageContext = new ServiceMessageContext();

            m_quotas.MessageContext.MaxArrayLength      = m_settings.Configuration.MaxArrayLength;
            m_quotas.MessageContext.MaxByteStringLength = m_settings.Configuration.MaxByteStringLength;
            m_quotas.MessageContext.MaxMessageSize      = m_settings.Configuration.MaxMessageSize;
            m_quotas.MessageContext.MaxStringLength     = m_settings.Configuration.MaxStringLength;
            m_quotas.MessageContext.NamespaceUris       = m_settings.NamespaceUris;
            m_quotas.MessageContext.ServerUris          = new StringTable();
            m_quotas.MessageContext.Factory             = m_settings.Factory;

            m_quotas.CertificateValidator = settings.CertificateValidator;

            // create the buffer manager.
            m_bufferManager = new BufferManager("Client", (int)Int32.MaxValue, settings.Configuration.MaxBufferSize);
        }
Beispiel #2
0
        private void SaveSettings(Uri url, TransportChannelSettings settings)
        {
            m_url = new Uri(url.ToString());

            m_settings         = settings;
            m_operationTimeout = settings.Configuration.OperationTimeout;

            // initialize the quotas.
            m_quotas = new ChannelQuotas();

            m_quotas.MaxBufferSize         = m_settings.Configuration.MaxBufferSize;
            m_quotas.MaxMessageSize        = m_settings.Configuration.MaxMessageSize;
            m_quotas.ChannelLifetime       = m_settings.Configuration.ChannelLifetime;
            m_quotas.SecurityTokenLifetime = m_settings.Configuration.SecurityTokenLifetime;

            m_quotas.MessageContext = new ServiceMessageContext();

            m_quotas.MessageContext.MaxArrayLength      = m_settings.Configuration.MaxArrayLength;
            m_quotas.MessageContext.MaxByteStringLength = m_settings.Configuration.MaxByteStringLength;
            m_quotas.MessageContext.MaxMessageSize      = m_settings.Configuration.MaxMessageSize;
            m_quotas.MessageContext.MaxStringLength     = m_settings.Configuration.MaxStringLength;
            m_quotas.MessageContext.NamespaceUris       = m_settings.NamespaceUris;
            m_quotas.MessageContext.ServerUris          = new StringTable();
            m_quotas.MessageContext.Factory             = m_settings.Factory;

            m_quotas.CertificateValidator = settings.CertificateValidator;
        }
Beispiel #3
0
 /// <summary>
 /// Attaches the object to an existing socket.
 /// </summary>
 public TcpReverseConnectChannel(
     string contextId,
     ITcpChannelListener listener,
     BufferManager bufferManager,
     ChannelQuotas quotas,
     EndpointDescriptionCollection endpoints)
     :
     base(contextId, listener, bufferManager, quotas, null, null, endpoints)
 {
 }
Beispiel #4
0
 /// <summary>
 /// Create channel
 /// </summary>
 /// <param name="contextId"></param>
 /// <param name="listener"></param>
 /// <param name="bufferManager"></param>
 /// <param name="quotas"></param>
 /// <param name="serverCertificate"></param>
 /// <param name="serverCertificateChain"></param>
 /// <param name="endpoints"></param>
 public SecureChannel(string contextId, ITcpChannelListener listener,
                      BufferManager bufferManager, ChannelQuotas quotas,
                      X509Certificate2 serverCertificate,
                      X509Certificate2Collection serverCertificateChain,
                      EndpointDescriptionCollection endpoints) :
     base(contextId, listener, bufferManager, quotas, serverCertificate,
          serverCertificateChain, endpoints)
 {
     _endpoints = endpoints;
 }
Beispiel #5
0
 /// <summary>
 /// Attaches the object to an existing socket.
 /// </summary>
 public TcpListenerChannel(
     string contextId,
     ITcpChannelListener listener,
     BufferManager bufferManager,
     ChannelQuotas quotas,
     X509Certificate2 serverCertificate,
     EndpointDescriptionCollection endpoints)
     :
     this(contextId, listener, bufferManager, quotas, serverCertificate, null, endpoints)
 {
 }
 /// <summary>
 /// Attaches the object to an existing socket.
 /// </summary>
 public UaSCUaBinaryChannel(
     string contextId,
     BufferManager bufferManager,
     ChannelQuotas quotas,
     X509Certificate2 serverCertificate,
     EndpointDescriptionCollection endpoints,
     MessageSecurityMode securityMode,
     string securityPolicyUri)
     :
     this(contextId, bufferManager, quotas, serverCertificate, null, endpoints, securityMode, securityPolicyUri)
 {
 }
 /// <summary>
 /// Attaches the object to an existing socket.
 /// </summary>
 public TcpServerChannel(
     string contextId,
     UaTcpChannelListener listener,
     BufferManager bufferManager,
     ChannelQuotas quotas,
     X509Certificate2 serverCertificate,
     EndpointDescriptionCollection endpoints)
     :
     base(contextId, bufferManager, quotas, serverCertificate, endpoints, MessageSecurityMode.None, SecurityPolicies.None)
 {
     m_listener        = listener;
     m_queuedResponses = new SortedDictionary <uint, IServiceResponse>();
 }
        /// <summary>
        /// Opens the listener and starts accepting connection.
        /// </summary>
        /// <param name="baseAddress">The base address.</param>
        /// <param name="settings">The settings to use when creating the listener.</param>
        /// <param name="callback">The callback to use when requests arrive via the channel.</param>
        /// <exception cref="ArgumentNullException">Thrown if any parameter is null.</exception>
        /// <exception cref="ServiceResultException">Thrown if any communication error occurs.</exception>
        public void Open(
            Uri baseAddress,
            TransportListenerSettings settings,
            ITransportListenerCallback callback)
        {
            // assign a unique guid to the listener.
            m_listenerId = Guid.NewGuid().ToString();

            m_uri          = baseAddress;
            m_descriptions = settings.Descriptions;
            EndpointConfiguration configuration = settings.Configuration;

            // initialize the quotas.
            m_quotas = new ChannelQuotas();
            var messageContext = new ServiceMessageContext()
            {
                NamespaceUris = settings.NamespaceUris,
                ServerUris    = new StringTable(),
                Factory       = settings.Factory
            };

            if (configuration != null)
            {
                m_quotas.MaxBufferSize             = configuration.MaxBufferSize;
                m_quotas.MaxMessageSize            = configuration.MaxMessageSize;
                m_quotas.ChannelLifetime           = configuration.ChannelLifetime;
                m_quotas.SecurityTokenLifetime     = configuration.SecurityTokenLifetime;
                messageContext.MaxArrayLength      = configuration.MaxArrayLength;
                messageContext.MaxByteStringLength = configuration.MaxByteStringLength;
                messageContext.MaxMessageSize      = configuration.MaxMessageSize;
                messageContext.MaxStringLength     = configuration.MaxStringLength;
            }
            m_quotas.MessageContext = messageContext;

            m_quotas.CertificateValidator = settings.CertificateValidator;

            // save the server certificate.
            m_serverCertificate      = settings.ServerCertificate;
            m_serverCertificateChain = settings.ServerCertificateChain;

            m_bufferManager          = new BufferManager("Server", (int)Int32.MaxValue, m_quotas.MaxBufferSize);
            m_channels               = new Dictionary <uint, TcpListenerChannel>();
            m_reverseConnectListener = settings.ReverseConnectListener;

            // save the callback to the server.
            m_callback = callback;

            // start the listener.
            Start();
        }
Beispiel #9
0
        /// <summary>
        /// Opens the listener and starts accepting connection.
        /// </summary>
        /// <param name="baseAddress">The base address.</param>
        /// <param name="settings">The settings to use when creating the listener.</param>
        /// <param name="callback">The callback to use when requests arrive via the channel.</param>
        /// <exception cref="ArgumentNullException">Thrown if any parameter is null.</exception>
        /// <exception cref="ServiceResultException">Thrown if any communication error occurs.</exception>
        public void Open(
            Uri baseAddress,
            TransportListenerSettings settings,
            ITransportListenerCallback callback)
        {
            // assign a unique guid to the listener.
            m_listenerId = Guid.NewGuid().ToString();

            m_uri          = baseAddress;
            m_descriptions = settings.Descriptions;
            var configuration = settings.Configuration;

            // initialize the quotas.
            m_quotas = new ChannelQuotas {
                MaxBufferSize         = configuration.MaxBufferSize,
                MaxMessageSize        = configuration.MaxMessageSize,
                ChannelLifetime       = configuration.ChannelLifetime,
                SecurityTokenLifetime = configuration.SecurityTokenLifetime,

                MessageContext = new ServiceMessageContext {
                    MaxArrayLength      = configuration.MaxArrayLength,
                    MaxByteStringLength = configuration.MaxByteStringLength,
                    MaxMessageSize      = configuration.MaxMessageSize,
                    MaxStringLength     = configuration.MaxStringLength,
                    NamespaceUris       = settings.NamespaceUris,
                    ServerUris          = new StringTable(),
                    Factory             = settings.Factory
                },

                CertificateValidator = settings.CertificateValidator
            };

            // save the callback to the server.
            m_callback = callback;

            m_serverCert = settings.ServerCertificate;

            // start the listener
            Start();
        }
        /// <summary>
        /// Attaches the object to an existing socket.
        /// </summary>
        public UaSCUaBinaryChannel(
            string contextId,
            BufferManager bufferManager,
            ChannelQuotas quotas,
            X509Certificate2 serverCertificate,
            X509Certificate2Collection serverCertificateChain,
            EndpointDescriptionCollection endpoints,
            MessageSecurityMode securityMode,
            string securityPolicyUri)
        {
            if (bufferManager == null)
            {
                throw new ArgumentNullException(nameof(bufferManager));
            }

            if (quotas == null)
            {
                throw new ArgumentNullException(nameof(quotas));
            }

            // create a unique contex if none provided.
            m_contextId = contextId;

            if (String.IsNullOrEmpty(m_contextId))
            {
                m_contextId = Guid.NewGuid().ToString();
            }

            // secuirty turned off if message security mode is set to none.
            if (securityMode == MessageSecurityMode.None)
            {
                securityPolicyUri = SecurityPolicies.None;
            }

            if (securityMode != MessageSecurityMode.None)
            {
                if (serverCertificate == null)
                {
                    throw new ArgumentNullException(nameof(serverCertificate));
                }

                if (serverCertificate.RawData.Length > TcpMessageLimits.MaxCertificateSize)
                {
                    throw new ArgumentException(
                              Utils.Format("The DER encoded certificate may not be more than {0} bytes.", TcpMessageLimits.MaxCertificateSize),
                              nameof(serverCertificate));
                }
            }

            if (new UTF8Encoding().GetByteCount(securityPolicyUri) > TcpMessageLimits.MaxSecurityPolicyUriSize)
            {
                throw new ArgumentException(
                          Utils.Format("UTF-8 form of the security policy URI may not be more than {0} bytes.", TcpMessageLimits.MaxSecurityPolicyUriSize),
                          nameof(securityPolicyUri));
            }

            m_bufferManager          = bufferManager;
            m_quotas                 = quotas;
            m_serverCertificate      = serverCertificate;
            m_serverCertificateChain = serverCertificateChain;
            m_endpoints              = endpoints;
            m_securityMode           = securityMode;
            m_securityPolicyUri      = securityPolicyUri;
            m_discoveryOnly          = false;
            m_uninitialized          = true;

            m_state             = TcpChannelState.Closed;
            m_receiveBufferSize = quotas.MaxBufferSize;
            m_sendBufferSize    = quotas.MaxBufferSize;

            if (m_receiveBufferSize < TcpMessageLimits.MinBufferSize)
            {
                m_receiveBufferSize = TcpMessageLimits.MinBufferSize;
            }

            if (m_receiveBufferSize > TcpMessageLimits.MaxBufferSize)
            {
                m_receiveBufferSize = TcpMessageLimits.MaxBufferSize;
            }

            if (m_sendBufferSize < TcpMessageLimits.MinBufferSize)
            {
                m_sendBufferSize = TcpMessageLimits.MinBufferSize;
            }

            if (m_sendBufferSize > TcpMessageLimits.MaxBufferSize)
            {
                m_sendBufferSize = TcpMessageLimits.MaxBufferSize;
            }

            m_maxRequestMessageSize  = quotas.MaxMessageSize;
            m_maxResponseMessageSize = quotas.MaxMessageSize;

            CalculateSymmetricKeySizes();
        }