-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Support PEM for CertificatesClient.DownloadCertificate #19018
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@pakrym @schaabs if you're good with the It's not as robust as net50's |
|
Well, this is surprising:
The regex must get compiled as used. I also took out the file reading from |
|
A subsequent run against net461 (though, in the end this did not produce results), netcoreapp3.1, and netcoreapp5.0 resulted in more plausible numbers:
|
|
[@heaths] it's a binary file of 4133 bytes. |
sdk/keyvault/Azure.Security.KeyVault.Certificates/src/PemReader.cs
Outdated
Show resolved
Hide resolved
sdk/keyvault/Azure.Security.KeyVault.Certificates/src/PemReader.cs
Outdated
Show resolved
Hide resolved
Resolves Azure#16897 Resolves Azure#18945
sdk/keyvault/Azure.Security.KeyVault.Certificates/src/PemReader.cs
Outdated
Show resolved
Hide resolved
Fixed the namespace of a type that was previously migrated, which was used by another project.
Also resolves a few PR feedback discussions.
|
Sorry for the force push, but the build break was caused by a change in master after I branched that the PR build was picking up. Mainly just moved |
| } | ||
| else if (secret.ContentType == CertificateContentType.Pem) | ||
| { | ||
| X509Certificate2 x509 = PemReader.LoadCertificate(value.AsSpan(), certificate.Cer, allowCertificateOnly: true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems PemReader only supports RSA certificates at the moment. This wasn't a concern with ClientCertificateCredentials because ATM AAD only supports RSA certificates for authentication, but the certificate here could also be an EC certificate no? Perhaps we should guard against this and file an issue to support EC certificates as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This - and the old implementation - only support labels like "BEGIN PRIVATE KEY", not "BEGIN RSA PRIVATE KEY" or "BEGIN EC PRIVATE KEY", so I don't think there's anything to guard as it just won't parse into a valid private key, which will throw an InvalidDataException as the old impl did before.
Still, I can open a bug to add support for "RSA PRIVATE KEY" since it could work alternatively.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also opened #19047 to track support EC private keys for Key Vault.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that since you're calling get certificate you might have information on what the key type of the current certificate is (although it might just be on the policy which could be different from the actual cert). If this is a case you could get use it to give a better error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's only in the key_props of the policy, so it wouldn't help.
That said, investigations show that Key Vault and openssl pkcs12 both produce PEM files with only CERTIFICATE and PRIVATE KEY (see #19047 (comment)). We should probably add some tests, but I'm not sure there's really any support to add right now - not for Key Vault, at least. Might if you want to support loading full chains (up to and/or including the root) for ClientCertificateCredential.
Resolves #16897
Resolves #18945