Skip to content

Commit 662bbec

Browse files
authored
Fix issue when importing no-password certificate (Azure#16758)
* fix issue if importing no password certificate * add change log
1 parent 40501f6 commit 662bbec

File tree

2 files changed

+4
-20
lines changed

2 files changed

+4
-20
lines changed

src/KeyVault/KeyVault/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* Fixed the issue when importing no-password certificate [#16742]
2122

2223
## Version 4.2.0
2324
* Added cmdlets: `Invoke-AzKeyVaultKeyRotation`, `Get-AzKeyVaultKeyRotationPolicy` and `Set-AzKeyVaultKeyRotationPolicy`

src/KeyVault/KeyVault/Commands/ImportAzureKeyVaultCertificate.cs

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,7 @@ public override void ExecuteCmdlet()
140140

141141
if (doImport)
142142
{
143-
byte[] base64Bytes;
144-
145-
if (Password == null)
146-
{
147-
base64Bytes = userProvidedCertColl.Export(X509ContentType.Pfx);
148-
}
149-
else
150-
{
151-
base64Bytes = userProvidedCertColl.Export(X509ContentType.Pfx, Password.ConvertToString());
152-
}
153-
143+
byte[] base64Bytes = userProvidedCertColl.Export(X509ContentType.Pfx, Password?.ConvertToString());
154144
string base64CertCollection = Convert.ToBase64String(base64Bytes);
155145
certBundle = this.DataServiceClient.ImportCertificate(VaultName, Name, base64CertCollection, Password, Tag == null ? null : Tag.ConvertToDictionary());
156146
}
@@ -188,15 +178,8 @@ internal X509Certificate2Collection InitializeCertificateCollection()
188178
}
189179

190180
X509Certificate2Collection certificateCollection = new X509Certificate2Collection();
191-
192-
if (null == this.Password)
193-
{
194-
certificateCollection.Import(certFile.FullName);
195-
}
196-
else
197-
{
198-
certificateCollection.Import(certFile.FullName, this.Password.ConvertToString(), X509KeyStorageFlags.Exportable);
199-
}
181+
182+
certificateCollection.Import(certFile.FullName, this.Password?.ConvertToString(), X509KeyStorageFlags.Exportable);
200183

201184
return certificateCollection;
202185
}

0 commit comments

Comments
 (0)