This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use a custom PFX reader/writer on Unix OSes
This change moves PFX import and export primarily into managed code to work around inconsistencies across the operating systems. Current issues: * Linux * Reading * PKCS12_parse doesn't support multiple cert-with-keys. * PKCS12_parse doesn't support reading a PFX with no MAC. * OpenSSL 1.0 had a weird bug where an ECDSA cert inexplicably didn't match to its key. * Writing * PKCS12_create doesn't support multiple cert-with-keys. * PKCS12_create doesn't support writing empty collections. * macOS * Reading * Either SecItemImport does not understand the NULL (vs Empty) password, or we called it wrong... it/we cannot load a PFX which is MACd with the NULL password. * SecItemImport can only support "normalized" PFXes, where "normalized" means "how Windows XP would have written it": * PFX * SafeContents0 (no encryption) (won't load keys from an encrypted SafeContents, IIRC) * ShroudedKey0 (won't load keys from KeyBag (unencrypted), only ShroudedKeyBag (encrypted)) * ... * ShroudedKeyN * SafeContents1 (encrypted) (won't load certs from an unencrypted SafeContents, IIRC) * Cert0 * ... * CertM * MAC * AlgId: HMAC-SHA-1 (IIRC this was a requirement, but it's also the only allowed algorithm on Win7 or Win8.1...) * Writing * SecItemExport fails to create a PFX with only public keys (or, at least, with non-keychain-based certificates). * SecItemExport fails to create a PFX where some elements are in different keychains than others (including "some elements are not in a keychain"). This change moves the necessary ASN types from the Pkcs12 library into Common so they're shared between Pkcs12Info/Pkcs12Builder and X509Certificates, then uses a managed loader and managed writer. Quirks: * SecItemImport(PKCS8) doesn't support marking keys as non-exportable, so non-exportable keyloads on macOS read a PFX, write a normalized PFX in memory, then call SecItemImport(PKCS12). * Because one of the failure modes of SecItemImport(PKCS12) is that it returns certs without private keys associated, it's not possible to call SecItemImport first and fall back to the managed loader. * Windows and Linux both will happily return the wrong private key with a cert if the PFX says to do so, but on macOS the SecIdentityRef creation fails and the cert comes back with no private key. * This isn't a very realistic situation outside of our tests, so it's not something worth doing heroics for right now. The easiest answer is to make HasPrivateKey be true but the GetPrivateKey methods throw... but that's still different than the other platforms, and would be very weird with SslStream.
- Loading branch information
Showing
72 changed files
with
4,059 additions
and
877 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.