如何以及在何处存储加载p12证书文件的密码

时间:2017-09-05 07:32:47

标签: asp.net-mvc powershell teamcity octopus-deploy

我尝试使用密码加载p12证书文件,我想知道在生产环境中存储和使用密码的最佳做法是什么。

使用的代码是:

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

var handler = new WebRequestHandler();
var certificate = new X509Certificate2Collection();
certificate.Import(@"D:\certificate.p12", "password", X509KeyStorageFlags.DefaultKeySet);
handler.ClientCertificates.AddRange(certificate);
handler.ServerCertificateValidationCallback = ValidateServerCertificate;

var client = new HttpClient(handler)
{
    BaseAddress = new Uri(chargeCodeServer)
};

使用的密码位于以下行:

certificate.Import(@"D:\certificate.p12", "password", X509KeyStorageFlags.DefaultKeySet);

我们使用TeamCity,Octopus和使用Powershell脚本进行部署。如果还有其他需要,请告诉我。

1 个答案:

答案 0 :(得分:0)

Octopus Deploy允许您存储"敏感"变量。当您使用敏感标记时,它不会在八达通UI或八达通日志文件中显示该值。

所有八达通变量都可在任何Powershell部署任务中使用。

变量受八爪鱼主密钥保护,所以我认为这是保存此类信息的合理位置 - 特别是因为八达通非常善于允许您使用(例如)不同的证书环境,具有不同的凭证。

相关问题