Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Finish off the X509Certificates implementation on macOS. #16707

Merged
merged 3 commits into from
Mar 6, 2017

Conversation

bartonjs
Copy link
Member

@bartonjs bartonjs commented Mar 4, 2017

  • Enable add/remove from a keychain-backed store.

  • Improve X509KeyStorageFlags usage

    • PersistKeySet will save a PFX key (and certificate) into the default keychain
    • EphemeralKeySet will throw PNSE
    • Exportable is respected for PFX
  • Add support for reading the Disallowed trust.

    • This will only read "full deny" behaviors
  • Enable or permanent-assign all remaining ActiveIssue(-1) tests.

  • Add DSA support to cert.PrivateKey from the Apple PAL

    • And add a test for it

* Enable add/remove from a keychain-backed store.

* Improve X509KeyStorageFlags usage
  * PersistKeySet will save a PFX key (and certificate) into the default keychain
  * EphemeralKeySet will throw PNSE
  * Exportable is respected for PFX

* Add support for reading the Disallowed trust.
  * This will only read "full deny" behaviors

* Enable or permanent-assign all remaining ActiveIssue(-1) tests.

* Add DSA support to cert.PrivateKey from the Apple PAL
  * And add a test for it
@@ -373,13 +414,22 @@ extern "C" int32_t AppleCryptoNative_X509ImportCertificate(uint8_t* pbData,
if (pOSStatus != nullptr)
*pOSStatus = noErr;

if (pbData == nullptr || cbData < 0 || pCertOut == nullptr || pIdentityOut == nullptr || pOSStatus == nullptr)
if (pbData == nullptr || cbData < 0 || pCertOut == nullptr || pIdentityOut == nullptr || pOSStatus == nullptr ||
exportable != !!exportable)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The !! is being used to normalize the Boolean value?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, making 2 and beyond be invalid leaves us open to recycle that spot for a flags value later if needed.

}
catch
{
tmpKeychain.Dispose();
keychain.Dispose();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume no problems will be caused by disposing of the singleton InvalidHandle?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct. The Dispose method checks to see if it's the singleton InvalidInstance and if so doesn't call down to base.Dispose(). (The existing SafeHandleCache usage/pattern)

// netstandard: DefaultKeySet
// netcoreapp-OSX: DefaultKeySet
// netcoreapp-other: EphemeralKeySet
internal static readonly X509KeyStorageFlags EphemeralIfPossible =
#if netcoreapp11
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we still need this "#if netcoreapp11"s in the code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test library builds and runs for both netcore and netstandard. EphemeralKeySet is a new feature to netcoreapp.

Assert.Throws<PlatformNotSupportedException>(
() =>
{
using (Cert.Import(TestData.EmptyPfx, null, X509KeyStorageFlags.EphemeralKeySet))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's throwing the PNSE? Assuming it's the call to Import, there's no need for the using.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. I'm pretty sure I was guarding it so that if it didn't throw it wouldn't finalize... but I guess I wouldn't care about the finalization numbers when tests were failing, and there's prior art for asserting that the X509Certificate2 ctor throws without having a using.

bartonjs added 2 commits March 6, 2017 07:46
Move the new Add/Remove certificate methods to a new Interop file, since
they're more about acting on a cert store than the keychain.
@bartonjs bartonjs merged commit 5694965 into dotnet:dev/apple_crypto Mar 6, 2017
@bartonjs bartonjs deleted the apple_x509_part3 branch March 6, 2017 16:39
@karelz karelz modified the milestone: 2.0.0 Mar 7, 2017
@bartonjs bartonjs removed their assignment Mar 14, 2017
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…fx#16707)

* Enable add/remove from a keychain-backed store.

* Improve X509KeyStorageFlags usage
  * PersistKeySet will save a PFX key (and certificate) into the default keychain
  * EphemeralKeySet will throw PNSE
  * Exportable is respected for PFX

* Add support for reading the Disallowed trust.
  * This will only read "full deny" behaviors

* Enable or permanent-assign all remaining ActiveIssue(-1) tests.

* Add DSA support to cert.PrivateKey from the Apple PAL
  * And add a test for it


Commit migrated from dotnet/corefx@5694965
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants