问题描述
我们正在Windows Docker容器中构建一个ASP.NET应用程序,以作为Azure IoTEdge模块运行。该模块会定期从云中获取直接方法回调,并使用更新的服务器证书作为PKCS#12 .pfx文件。 PFX文件受密码保护,包含证书链和私钥。该证书每年由新的中间CA证书签名。我们需要在连接时显示的ASP.NET证书包括这些更新的中间证书。使用openssl s_client -host <ip> -port 443 -prexit -showcerts
,我们只会看到设备证书。
经过大量令人困惑的研究后,我们认为我们已将其范围缩小至需要在容器的Intermediate CA X509商店中使用IntermediateCA。看起来“当前用户”存储已足够,但“本地计算机”似乎也可以正常工作。这是我们当前正在使用的代码。
StoreName storeName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? StoreName.CertificateAuthority : StoreName.Root;
using (var store = new X509Store(storeName,StoreLocation.CurrentUser))
{
store.Open(OpenFlags.OpenExistingOnly | OpenFlags.ReadWrite);
X509Certificate2Collection collection = new X509Certificate2Collection();
collection.Import(currentWebServerCertificateFilename,currentWebServerCertificatePassword,X509KeyStorageFlags.X509KeyStorageFlags.DefaultKeySet);
foreach (var cert in collection)
{
if (cert.Thumbprint == myCert.Thumbprint) { continue; }
if (store.Certificates.Contains(cert)) { continue; }
store.Add(cert);
}
}
当我们推出此容器图像时。我们在日志中看到以下内容
Unhandled exception. Internal.Cryptography.CryptoThrowHelper+WindowsCryptographicException: Access is denied.
at Internal.Cryptography.Pal.StorePal.Add(ICertificatePal certificate)
at System.Security.Cryptography.X509Certificates.X509Store.Add(X509Certificate2 certificate)
at Daikin.SystemManager.WebService.Program.addIntermediateCertificateToStore(X509Certificate2 myCert) in C:\src\DaikinSystemManagerWebService\Program.cs:line 134
at Daikin.SystemManager.WebService.Program.getWebServerCertificate() in C:\src\DaikinSystemManagerWebService\Program.cs:line 100
at Daikin.SystemManager.WebService.Program.CreateHostBuilder(String[] args) in C:\src\DaikinSystemManagerWebService\Program.cs:line 38
at Daikin.SystemManager.WebService.Program.Main(String[] args) in C:\src\DaikinSystemManagerWebService\Program.cs:line 26```
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)