GetCertificate() private method

private GetCertificate ( string name ) : X509Certificate2
name string
return System.Security.Cryptography.X509Certificates.X509Certificate2
Esempio n. 1
0
        public void Start()
        {
            //HttpServer.Logging.LogFactory.Assign(new HttpServer.Logging.ConsoleLogFactory(null));

            // TODO: more than one Interception can be configured with the same port and IP

            foreach (var interception in state_.Config.Interceptions)
            {
                IPAddress ip = GetIp(interception.IPv4);
                if (ip == null)
                {
                    state_.Logger.Error("Invalid IPv4 address: {0}", interception.IPv4);
                    continue;
                }

                state_.Logger.Information("Intercept {0} {2} {3}:{1}", interception.Protocol, interception.Port, interception.Name, ip);

                try
                {
                    HttpListener listener = interception.Protocol == Protocol.Https ?
                                            HttpListener.Create(ip, interception.Port, certificatesMgr_.GetCertificate(interception.Name)) :
                                            HttpListener.Create(ip, interception.Port);
                    listener.RequestReceived += OnRequest;
                    listener.Start(state_.Config.Web.WebBacklog);
                    listeners_.Add(listener);
                }
                catch (System.Net.Sockets.SocketException e)
                {
                    state_.Logger.Exception(e, "Error setting up listener on port {0}", interception.Port);
                }
            }
        }