/// <summary> /// Create the network layer /// </summary> /// <param name="logger">The logger to use when creating</param> /// <returns>The created layer</returns> public override INetworkLayer CreateLayer(Logger logger) { SslNetworkLayer layer = new SslNetworkLayer(Config); layer.Binding = Binding; return(layer); }
/// <summary> /// /// </summary> /// <param name="adapter"></param> /// <param name="meta"></param> /// <param name="globalMeta"></param> /// <param name="service"></param> /// <returns></returns> public override ProxyToken Accept(IDataAdapter adapter, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service) { ProxyToken token = null; if (_config.SslConfig.Enabled) { IDataAdapter client = null; INetworkLayer ssl = new SslNetworkLayer(_config.SslConfig); ssl.Negotiate(ref adapter, ref client, null, _logger, null, null, new PropertyBag("Root"), NetworkLayerBinding.Server); } if (adapter is HttpProxyDataAdapter) { HttpProxyDataAdapter proxyAdapter = (HttpProxyDataAdapter)adapter; token = new FullHttpProxyToken(proxyAdapter.Url.Host, proxyAdapter.Url.Port); token.State.Add("adapter", adapter); } else { DataAdapterToStream stm = new DataAdapterToStream(adapter); DataReader reader = new DataReader(stm); try { HttpRequestHeader header = HttpParser.ReadRequestHeader(reader, false, _logger); if (HandleProxyAuthentication(reader, stm, ref header)) { // We just have a connect if (header.IsConnect) { token = HandleConnect(header, stm); } else { token = HandleOtherRequest(header, stm, service); } } } catch (HttpStreamParserException ex) { _logger.LogError(CANAPE.Net.Properties.Resources.HttpProxyServer_InvalidRequest, ex.Message); // TODO: Put in some decent error codes ReturnResponse(null, 400, "Bad Request", "GET", HttpVersion.Version11, stm); } catch (EndOfStreamException) { token = null; } } return(token); }
/// <summary> /// /// </summary> /// <param name="adapter"></param> /// <param name="meta"></param> /// <param name="globalMeta"></param> /// <param name="service"></param> /// <returns></returns> public override ProxyToken Accept(IDataAdapter adapter, MetaDictionary meta, MetaDictionary globalMeta, ProxyNetworkService service) { ProxyToken token = null; TcpClientDataAdapter tcpAdapter = adapter as TcpClientDataAdapter; if (_config.SslConfig.Enabled) { IDataAdapter client = null; INetworkLayer ssl = new SslNetworkLayer(_config.SslConfig); ssl.Negotiate(ref adapter, ref client, null, _logger, null, null, new PropertyBag("Root"), NetworkLayerBinding.Server); } DataAdapterToStream stm = new DataAdapterToStream(adapter); DataReader reader = new DataReader(stm); try { HttpRequestHeader header = HttpParser.ReadRequestHeader(reader, false, _logger); token = HandleOtherRequest(header, stm, tcpAdapter); } catch (HttpStreamParserException ex) { _logger.LogError(CANAPE.Net.Properties.Resources.HttpProxyServer_InvalidRequest, ex.Message); // TODO: Put in some decent error codes ReturnResponse(null, 400, "Bad Request", "GET", HttpVersion.Version11, stm); } catch (EndOfStreamException) { token = null; } return(token); }
/// <summary> /// /// </summary> /// <param name="logger"></param> /// <param name="ssl"></param> public LegacyHttpProxyServer(Logger logger, SslNetworkLayer ssl) : base(logger) { _ssl = ssl; }