gpt4 book ai didi

powershell - wap cmdlet - 添加证书错误

转载 作者:行者123 更新时间:2023-12-03 03:20:57 26 4
gpt4 key购买 nike

尝试使用 WAPPA 将证书上传到 Azure 时,我做错了什么命令,添加证书

这是我在 powershell 中运行的内容:

add-certificate -ServiceName myService -CertificateToDeploy ".\mycert.cer" -SubscriptionId 1234c88c-xxxx-xxxx-ad88-888c6ec5fc4a -Certificate (get-item cert:\CurrentUser\My\0E5A777B38724D85F415E011192D2EF888888884)

这是不断出现的错误。

Add-Certificate : The index value is not valid. At line:1 char:16 + add-certificate <<...(removed repeat of command)... + CategoryInfo : CloseError: (:) [Add-Certificate], CryptographicException + FullyQualifiedErrorId : Microsoft.Samples.AzureManagementTools.PowerShell.Certificates.AddCertificateCommand

我们确信 serviceName 和 subscriptionId 是正确的,并且查看所有示例,我们可以发现其他参数似乎也正确......但显然其中一个(或两个)不是。我们只是不明白为什么。

非常感谢任何建议:-)

最佳答案

Add-Certificate 命令旨在将证书(通常带有私钥)上传到托管服务。 IIRC,它将尝试使用 .pfx 包装器包装 .cer 文件,并使用简单的密码上传该文件。这样做是因为门户网站过去需要带有证书的密码(它假设人们只上传带有私钥的证书)。由于加密异常,该代码路径中的某些内容可能是错误的。我希望有更多的堆栈跟踪可供查看。

如果您上传 pfx(带有可导出 key ),这有效吗?这只是因为 .cer 文件和缺少密码而导致的问题吗?

另一个想法:-ServiceName 参数可能区分大小写,因为它解析为 DNS 名称 (servicename.cloudapp.net)。您能确保全部使用小写吗?

编辑:另一个想法 - 尝试将 .cer 导入您的系统并使用 get-item cert: 格式再次引用它。查看代码,我不完全确定它是否可以在指定的文件路径不是 pfx 时正常工作。我猜测导入带有空白密码的 .cer 文件可能会失败。这只能通过运行我通过内部(思维)调试器看到的代码来实现:

    private byte[] GetCertificateData()
{
var cert = new X509Certificate2();
byte[] certData = null;

if (((this.CertificateToDeploy is PSObject) && ((PSObject)this.CertificateToDeploy).ImmediateBaseObject is X509Certificate) ||
(this.CertificateToDeploy is X509Certificate))
{
cert = ((PSObject)this.CertificateToDeploy).ImmediateBaseObject as X509Certificate2;

try
{
certData = cert.HasPrivateKey ? cert.Export(X509ContentType.Pfx) : cert.Export(X509ContentType.Pkcs12);
}
catch (CryptographicException)
{
certData = cert.HasPrivateKey ? cert.RawData : cert.Export(X509ContentType.Pkcs12);
}
}
else
{
cert.Import(this.ResolvePath(this.CertificateToDeploy.ToString()), this.Password, X509KeyStorageFlags.Exportable);
certData = cert.HasPrivateKey ? cert.Export(X509ContentType.Pfx, this.Password) : cert.Export(X509ContentType.Pkcs12);
}

return certData;
}

关于powershell - wap cmdlet - 添加证书错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6908093/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com