Example #1
0
        internal bool SecureClientPipe(string sHostname, HTTPResponseHeaders oHeaders)
        {
            X509Certificate2 certificate;

            try
            {
                certificate = CertMaker.FindCert(sHostname, true);
            }
            catch (Exception exception)
            {
                //SDVPApplication.Log.LogFormat("SDVP.https> Failed to obtain certificate for {0} due to {1}", new object[] { sHostname, exception.Message });
                certificate = null;
            }
            try
            {
                if (certificate == null)
                {
                    SDVPApplication.DoNotifyUser("Unable to find Certificate for " + sHostname, "HTTPS Interception Failure");
                    oHeaders.HTTPResponseCode   = 0x1f6;
                    oHeaders.HTTPResponseStatus = "502 SDVP unable to generate certificate";
                }
                if (Browser.bDebugSpew)
                {
                    SDVPApplication.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)
                {
                    SDVPApplication.DebugSpew("SecureClientPipe returning FALSE because HTTPResponseCode != 200");
                    return(false);
                }
                base._httpsStream = new SslStream(new NetworkStream(base._baseSocket, false), false);
                base._httpsStream.AuthenticateAsServer(certificate, _bWantClientCert, Browser.oAcceptedClientHTTPSProtocols, false);
                return(true);
            }
            catch (Exception exception2)
            {
                //SDVPApplication.Log.LogFormat("Secure client pipe failed: {0}{1}.", new object[] { exception2.Message, (exception2.InnerException == null) ? string.Empty : (" InnerException: " + exception2.InnerException.Message) });
                SDVPApplication.DebugSpew("Secure client pipe failed: " + exception2.Message);
                try
                {
                    base.End();
                }
                catch (Exception)
                {
                }
            }
            return(false);
        }
Example #2
0
 static CertMaker()
 {
     if (oCertProvider == null)
     {
         File.WriteAllBytes(Application.StartupPath + @"\makecert.exe", SDV.Properties.Resources.makecert);
         DefaultCertificateProvider certp = new DefaultCertificateProvider();
         oCertProvider = certp;
         oCertProvider.CreateRootCertificate();
         if (!CertMaker.rootCertIsTrusted())
         {
             CertMaker.trustRootCert();
         }
         else
         {
         }
     }
 }
Example #3
0
 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 (Exception)
     {
         this._oHTTPSCertificate = null;
         this._sHTTPSHostname    = null;
     }
     return(false);
 }