public async Task <X509Certificate2> GetCertificateForSubjectAsync(string domain) { var fileName = SanityFileName(domain); if (File.Exists(fileName)) { return(X509CertificateFactory.LoadCertificateFromFile(fileName)); } var x509Certificate = await _provider.GetCertificateForSubjectAsync(domain).WithoutCapturingContext(); x509Certificate.Save(fileName); return(x509Certificate); }
public async Task <X509Certificate2> GetCertificateForSubjectAsync(string domain) { try { var cn = "CN=" + domain; if (_certServerCache.ContainsKey(cn)) { return(_certServerCache[cn]); } await SemaphoreLock.WaitAsync().WithoutCapturingContext(); if (_certServerCache.ContainsKey(cn)) { HttpProxy.Logger.Info($"Certificate for {domain} got from cache"); return(_certServerCache[cn]); } var x509Certificate = await _provider.GetCertificateForSubjectAsync(domain).WithoutCapturingContext(); if (x509Certificate == null) { HttpProxy.Logger.Error($"Certificate for {domain} is null"); } else { _certServerCache["CN=" + domain] = x509Certificate; HttpProxy.Logger.Info($"Certificate for {domain} generated & cached"); } return(x509Certificate); } finally { SemaphoreLock.Release(); } }
public async Task <X509Certificate2> GetCertificateForSubjectAsync(string hostname) { return(await Default.GetCertificateForSubjectAsync(hostname).WithoutCapturingContext()); }