Пример #1
0
 internal HttpConnectingClient(SecureTcpListener server, SecurityOptions options,
                               AppFunc next, bool useHandshake, bool usePriorities,
                               bool useFlowControl, List <string> listOfRootFiles)
 {
     _listOfRootFiles = listOfRootFiles;
     _usePriorities   = usePriorities;
     _useHandshake    = useHandshake;
     _useFlowControl  = useFlowControl;
     _server          = server;
     _next            = next;
     _options         = options;
     _fileHelper      = new FileHelper(ConnectionEnd.Server);
 }
Пример #2
0
        /// <summary>
        /// Initializes new instance of Http2 server.
        /// </summary>
        /// <param name="port">Port to listen.</param>
        public Http2Server(int port)
        {
            this.Port = port;

            ExtensionType[] extensions = new ExtensionType[] { ExtensionType.Renegotiation, ExtensionType.ALPN };
            SecurityOptions options    = new SecurityOptions(SecureProtocol.Tls1, extensions, ConnectionEnd.Server);

            options.VerificationType  = CredentialVerification.None;
            options.Certificate       = Org.Mentalis.Security.Certificates.Certificate.CreateFromCerFile(@"certificate.pfx");
            options.Flags             = SecurityFlags.Default;
            options.AllowedAlgorithms = SslAlgorithms.RSA_AES_128_SHA | SslAlgorithms.NULL_COMPRESSION;
            _server = new SecureTcpListener(Port, options);
        }
Пример #3
0
        public HttpSocketServer(Func <IDictionary <string, object>, Task> next, IDictionary <string, object> properties)
        {
            _next = next;

            var addresses = (IList <IDictionary <string, object> >)properties[OwinConstants.CommonKeys.Addresses];

            var address = addresses.First();

            _port   = Int32.Parse(address.Get <string>("port"));
            _scheme = address.Get <string>("scheme");

            _useHandshake   = (bool)properties["use-handshake"];
            _usePriorities  = (bool)properties["use-priorities"];
            _useFlowControl = (bool)properties["use-flowControl"];

            int securePort;

            try
            {
                securePort = int.Parse(ConfigurationManager.AppSettings["securePort"]);
            }
            catch (Exception)
            {
                Http2Logger.LogError("Incorrect port in the config file!" + ConfigurationManager.AppSettings["securePort"]);
                return;
            }

            if (_port == securePort && _scheme == Uri.UriSchemeHttp ||
                _port != securePort && _scheme == Uri.UriSchemeHttps)
            {
                Http2Logger.LogError("Invalid scheme or port! Use https for secure port.");
                return;
            }

            var extensions = new[] { ExtensionType.Renegotiation, ExtensionType.ALPN };

            // protocols should be in order of their priority
            _options = _port == securePort ? new SecurityOptions(SecureProtocol.Tls1, extensions, new[] { Protocols.Http2, Protocols.Http1 }, ConnectionEnd.Server)
                                : new SecurityOptions(SecureProtocol.None, extensions, new[] { Protocols.Http2, Protocols.Http1 }, ConnectionEnd.Server);

            _options.VerificationType  = CredentialVerification.None;
            _options.Certificate       = Certificate.CreateFromCerFile(AssemblyName + CertificateFilename);
            _options.Flags             = SecurityFlags.Default;
            _options.AllowedAlgorithms = SslAlgorithms.RSA_AES_256_SHA | SslAlgorithms.NULL_COMPRESSION;

            _server = new SecureTcpListener(_port, _options);

            ThreadPool.SetMaxThreads(30, 10);

            Listen();
        }
Пример #4
0
        /// <summary><see cref="Ch.Elca.Iiop.IServerConnectionListener.StartListening"</summary>
        public int StartListening(IPAddress bindTo, int listeningPortSuggestion, out TaggedComponent[] taggedComponents)
        {
            if (!m_isInitalized)
            {
                throw CreateNotInitalizedException();
            }
            if (m_listenerActive)
            {
                throw CreateAlreadyListeningException();
            }
            int resultPort = listeningPortSuggestion;

            m_listener = new SecureTcpListener(bindTo, listeningPortSuggestion, m_sslOpts);
            // start TCP-Listening
            m_listener.Start();
            if (listeningPortSuggestion == 0)
            {
                // auto-assign port selected
                resultPort = ((IPEndPoint)m_listener.LocalEndpoint).Port;
            }

            if (m_isSecured)
            {
                // create ssl tagged component
                SSLComponentData sslData = new SSLComponentData(Convert.ToInt16(m_supportedOptions),
                                                                Convert.ToInt16(m_requiredOptions),
                                                                (short)resultPort);
                taggedComponents = new TaggedComponent[] {
                    new TaggedComponent(TAG_SSL_SEC_TRANS.ConstVal,
                                        m_codec.encode_value(sslData))
                };
                resultPort = 0; // don't allow unsecured connections -> port is in ssl components
            }
            else
            {
                taggedComponents = new TaggedComponent[0];
            }

            m_listenerActive = true;
            // start the handler thread
            m_listenerThread.Start();
            return(resultPort);
        }