コード例 #1
0
ファイル: CertesWrapper.cs プロジェクト: wushian/WinCertes
        /// <summary>
        /// CertesWrapper class constructor
        /// </summary>
        /// <param name="serviceUri">The ACME service URI (endin in /directory). If null, defaults to Let's encrypt</param>
        /// <param name="accountEmail">The email address to be registered within the ACME account. If null, no email will be used</param>
        public CertesWrapper(string serviceUri = null, string accountEmail = null)
        {
            _settings = new CertesSettings();
            _config   = new RegistryConfig();

            // Let's initialize the password
            PfxPassword = Guid.NewGuid().ToString("N").Substring(0, 16);
            logger.Debug($"PFX password will be: {PfxPassword}");

            // Dealing with Server URI
            if (serviceUri != null)
            {
                _settings.ServiceURI = new Uri(serviceUri);
            }
            else
            {
                _settings.ServiceURI = WellKnownServers.LetsEncryptV2;
            }
            // Dealing with account email
            _settings.AccountEmail = accountEmail;
            // Dealing with key
            if (_config.ReadStringParameter("accountKey") != null)
            {
                _settings.AccountKey = KeyFactory.FromPem(_config.ReadStringParameter("accountKey"));
            }
            else
            {
                _settings.AccountKey = KeyFactory.NewKey(KeyAlgorithm.RS256);
                _config.WriteStringParameter("accountKey", _settings.AccountKey.ToPem());
            }
        }
コード例 #2
0
ファイル: CertesWrapper.cs プロジェクト: yantailee/WinCertes
        /// <summary>
        /// CertesWrapper class constructor
        /// </summary>
        /// <param name="serviceUri">The ACME service URI (endin in /directory). If null, defaults to Let's encrypt</param>
        /// <param name="accountEmail">The email address to be registered within the ACME account. If null, no email will be used</param>
        public CertesWrapper(int extra = -1, string serviceUri = null, string accountEmail = null)
        {
            _settings = new CertesSettings();
            _config   = new RegistryConfig(extra);

            // Let's initialize the password
            PfxPassword = Guid.NewGuid().ToString("N").Substring(0, 16);
            logger.Debug($"PFX password will be: {PfxPassword}");

            // Dealing with Server URI
            if (serviceUri != null)
            {
                _settings.ServiceURI = new Uri(serviceUri);
            }
            else
            {
                _settings.ServiceURI = WellKnownServers.LetsEncryptV2;
            }
            // Dealing with account email
            _settings.AccountEmail = accountEmail;
            if (_config.ReadIntParameter("keySize") > 0)
            {
                _keySize = _config.ReadIntParameter("keySize");
            }
            // Dealing with key
            if (_config.ReadStringParameter("accountKey") != null)
            {
                _settings.AccountKey = KeyFactory.FromPem(_config.ReadStringParameter("accountKey"));
            }
            else
            {
                _settings.AccountKey = KeyFactory.FromPem(Utils.GenerateRSAKeyAsPEM(_keySize));
                _config.WriteStringParameter("accountKey", _settings.AccountKey.ToPem());
            }
            // Instantiating HTTP Client
            AssemblyName certesAssembly    = typeof(AcmeContext).Assembly.GetName();
            AssemblyName winCertesAssembly = typeof(Program).Assembly.GetName();

            _httpClient = new HttpClient();
            _httpClient.DefaultRequestHeaders.Add("User-Agent", $"WinCertes/{winCertesAssembly.Version.ToString()} (Certes/{certesAssembly.Version.ToString()}; {Environment.OSVersion.VersionString})");
        }