Exemplo n.º 1
0
 public VSslCertification(VLogger log, VConsole con, VDependencyWatcher vdw)
 {
     logger  = log;
     console = con;
     self    = this;
     vdw.AddCondition(() => { return(UseCASign && !File.Exists("certs\\AHROOT.pfx")); }, new VLogger.LogObj()
     {
         ll      = VLogger.LogLevel.warning,
         message = "CA Signing is enabled, but the root CA Cert is not found at its location"
     });
 }
Exemplo n.º 2
0
        public Error InitSslStream(NetworkStream ns, string targetHost)
        {
            SslStream ssl = new SslStream(ns);

            certman = ctx.CertMod;
            if (certman == null || !certman.Started)
            {
                return(Error.CertificateManagerNotAvailable);
            }
            X509Certificate2 cert = certman.GetCert(targetHost);

            if (cert == null)
            {
                certman.BCGenerateCertificate(targetHost);
            }
            cert = certman.GetCert(targetHost);
            if (cert == null)
            {
                return(Error.CertRetrieveFailed);
            }
            SslProtocols sp = certman.GetProtocols();

            if (sp == SslProtocols.None)
            {
                return(Error.SslProtocolRetrieveFailed);
            }
            try
            {
                ssl.AuthenticateAsServer(cert, false, sp, true);
                _ssl = ssl;
                return(Error.Success);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                ctx.LogMod.Log("SSL Server Init Error:\r\n" + ex.ToString(), VLogger.LogLevel.error);
                return(Error.SslServerAuthFailed);
            }
        }