Azure / Azure/azure-powershell

Az >12.1.0 - Az.KeyVault - Import-AzKeyVaultCertificate - Import of .p7b files has been broken

Open
#25,843 7 comments 0 reactions 0 assignees View on GitHub
bug customer-reported Tracking
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### Description

Hi @BethanyZhou,

There appears to be a regression in relation to this PR: https://github.com/Azure/azure-powershell/pull/25333, and this issue: https://github.com/Azure/azure-powershell/issues/24323

Specifically, the Az.KeyVault module previously supported certificate import, via `Import-AzKeyVaultCertificate`, of a PKCS7 `.p7b` file.

However, the new code in `ImportAzureKeyVaultCertificate.GetEnumerableBytes` seems to assume `PEM` format, as it is expecting the `-----BEGIN CERTIFICATE-----` and `-----END CERTIFICATE-----`, which are not present in PKCS7. Instead, `-----BEGIN PKCS7-----` and `-----END PKCS7-----` are expected.

### Issue script & Debug output

```PowerShell
Import-AzKeyVaultCertificate -VaultName somevault -Name somecert -FilePath somefile.p7b
```

### Environment data

```PowerShell
Name Value
---- -----
PSVersion 7.4.4
PSEdition Core
GitCommitId 7.4.4
OS Ubuntu 22.04.4 LTS
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```

### Module versions

```PowerShell
Using the Github Azure/powershell@v1 action:

{
"Success": "true",
"AzVersion": "12.1.0"
}
```

### Error output

```PowerShell
Import-AzKeyVaultCertificate: /path/to.ps1:136
Line |
136 | Import-AzKeyVaultCertificate -VaultName $Vault -Name $($PSKeyVaul …
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| X5C must have at least one valid item Status: 400 (Bad Request)
| ErrorCode: BadParameter Content:
| {"error":{"code":"BadParameter","message":"X5C must have at least one
| valid item\r\n"}} Headers: Cache-Control: no-cache Pragma: no-cache
| x-ms-keyvault-region: australiaeast x-ms-client-request-id:
| 19237a88-00ac-485a-b9ed-0c1a483c487f x-ms-request-id:
| 42fa87c0-9848-4d06-8209-60a0fa130f38 x-ms-keyvault-service-version:
| 1.9.1652.1 x-ms-keyvault-network-info:
| conn_type=Ipv4;addr=172.177.75.81;act_addr_fam=InterNetwork;
| X-Content-Type-Options: REDACTED Strict-Transport-Security: REDACTED
| Date: Mon, 19 Aug 2024 01:28:45 GMT Content-Length: 87 Content-Type:
| application/json; charset=utf-8 Expires: -1
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.