internal bool SecureClientPipe(string sHostname, HTTPResponseHeaders oHeaders) { X509Certificate2 certificate; try { certificate = CertMaker.FindCert(sHostname, true); } catch (Exception exception) { //KProxyApplication.Log.LogFormat("KProxy.https> Failed to obtain certificate for {0} due to {1}", new object[] { sHostname, exception.Message }); certificate = null; } try { if (certificate == null) { KProxyApplication.DoNotifyUser("Unable to find Certificate for " + sHostname, "HTTPS Interception Failure"); oHeaders.HTTPResponseCode = 0x1f6; oHeaders.HTTPResponseStatus = "502 KProxy unable to generate certificate"; } if (KPCONFIG.bDebugSpew) { KProxyApplication.DebugSpew("SecureClientPipe for: " + this.ToString() + " sending data to client:\n" + Utilities.ByteArrayToHexView(oHeaders.ToByteArray(true, true), 0x20)); } base.Send(oHeaders.ToByteArray(true, true)); if (oHeaders.HTTPResponseCode != 200) { KProxyApplication.DebugSpew("SecureClientPipe returning FALSE because HTTPResponseCode != 200"); return(false); } base._httpsStream = new SslStream(new NetworkStream(base._baseSocket, false), false); base._httpsStream.AuthenticateAsServer(certificate, _bWantClientCert, KPCONFIG.oAcceptedClientHTTPSProtocols, false); return(true); } catch (Exception exception2) { //KProxyApplication.Log.LogFormat("Secure client pipe failed: {0}{1}.", new object[] { exception2.Message, (exception2.InnerException == null) ? string.Empty : (" InnerException: " + exception2.InnerException.Message) }); KProxyApplication.DebugSpew("Secure client pipe failed: " + exception2.Message); try { base.End(); } catch { } } return(false); }
internal bool ActAsHTTPSEndpointForHostname(string sHTTPSHostname) { try { if (string.IsNullOrEmpty(sHTTPSHostname)) { throw new ArgumentException(); } this._oHTTPSCertificate = CertMaker.FindCert(sHTTPSHostname, true); this._sHTTPSHostname = this._oHTTPSCertificate.Subject; return(true); } catch { this._oHTTPSCertificate = null; this._sHTTPSHostname = null; } return(false); }