Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Port missing X509Certificate members#12240

Merged
steveharter merged 3 commits into
dotnet:masterfrom
steveharter:PortDsaCertEx
Oct 6, 2016
Merged

Port missing X509Certificate members#12240
steveharter merged 3 commits into
dotnet:masterfrom
steveharter:PortDsaCertEx

Conversation

@steveharter
Copy link
Copy Markdown
Contributor

@steveharter steveharter commented Sep 30, 2016

Per issue https://github.com/dotnet/corefx/issues/9986

Also converted X509 project to ns1.7.

@bartonjs please review

if (cert == null)
throw new ArgumentNullException(nameof(cert));

Pal = CertificatePal.FromHandle(cert.Handle); // Let FromHandle throw if certHandle is 0
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This doesn't work for Linux (it loses private keys). You'll need to do a PAL clone.

Assert.Equal(expectedThumbPrint, actualThumbprint);
};

using (X509Certificate2 c = new X509Certificate2(TestData.MsCertificate))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We'll need to add a copy constructor test for a cert which has a private key.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should also add a test that proves they have independent lifetimes.

  • Create cert A from PFX
  • Create cert B from PFX
  • Get private key from B
  • Dispose A
  • Dispose key
  • Get another private key from B (and make sure it works)

}

[Theory, MemberData(nameof(BrainpoolCurvesPfx))]
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp1_0, "dotnet/corefx#12235")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the actual problem here? release/1.0.0 had this code in it. Did we register netcoreapp10 against netstandard1.5 instead of netstandard1.6? If so, is that being tracked as a problem? If it's by design, should we be testing as netstandard1.6 instead of netcoreapp10? (But don't we currently test as netcoreapp10? So why is this passing today?)

Copy link
Copy Markdown
Contributor Author

@steveharter steveharter Sep 30, 2016

Choose a reason for hiding this comment

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

It is passing today because we x-compile the X509Certificates project against ns1.6 but don't do that anymore with this set of changes (so the assembly is coming from public nuget). My understanding is that the tests require code\fixes added in the 4.1.1 version of that assembly (corefx 1.1.0 branch). Once ns1.6 gets updates the tests should work again.

}

[Fact]
[SkipOnTargetFramework(TargetFrameworkMonikers.Netcoreapp1_0, "dotnet/corefx#12235")]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What about this test warrants the suppression?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note that I removed these attributes as 1.0 tests are not currently running any longer. I need to follow up on this however they were not broken because of anything done in this PR

"System.Runtime.InteropServices.RuntimeInformation": "4.3.0-beta-24522-03",
"System.Security.Cryptography.Algorithms": "4.3.0-beta-24522-03",
"System.Security.Cryptography.Cng": "4.3.0-beta-24522-03",
"System.Security.Cryptography.Csp": "4.3.0-beta-24522-03",
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see anything in this change which should require adding a reference to CSP... what's this for?

Copy link
Copy Markdown
Contributor Author

@steveharter steveharter Oct 5, 2016

Choose a reason for hiding this comment

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

Note Csp is included in the implementation assembly (and was before)

Without it:

Internal\Cryptography\Pal.Windows\CertificatePal.PrivateKey.cs(61,41): error CS0246: The type or namespace name 'CspParameters' could not be found (are you missing a using directive or an assembly reference?) [C:\git\api22\src\System.Security.Cryptography.X509Certificates\src\System.Security.Cryptography.X509Certificates.csproj]
Internal\Cryptography\Pal.Windows\CertificatePal.PrivateKey.cs(154,17): error CS0246: The type or namespace name 'CspParameters' could not be found (are you missing a using directive or an assembly reference?) [C:\git\api22\src\System.Security.Cryptography.X509Certificates\src\System.Security.Cryptography.X509Certificates.csproj]

@steveharter steveharter force-pushed the PortDsaCertEx branch 4 times, most recently from 9419bf9 to 078cd35 Compare September 30, 2016 19:32

[Fact]
[PlatformSpecific(PlatformID.Windows)]
[PlatformSpecific(Xunit.PlatformID.Windows)]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

PlatformID has been renamed TestPlatforms. See #12284. Sorry for the merge conflicts.

@steveharter
Copy link
Copy Markdown
Contributor Author

@morganbr please review (Jeremy OOF). Main change from initial review was to support copy ctor

}

[Fact]
public static void TestCopyConstructor_Lifetime()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can you please add a test for disposing in the reverse order as well?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

It also doesn't look like you added the test Jeremy suggested (creating two separate objects from the same PFX and confirming their lifetimes are independent)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is it also possible to test that when everything is finalized after duplication that native objects do get cleaned up?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Can you please add a test for disposing in the reverse order as well?

Done

It also doesn't look like you added the test Jeremy suggested (creating two separate objects from the same PFX and confirming their lifetimes are independent)

I read Jeremy's comment as being what I added as TestCopyConstructor_Lifetime() meaning the second cert was created with the first cert otherwise I don't see how I could have broken that. Note that some of the commit history was lost due to rebasing (I added TestCopyConstructor_Lifetime() after Jeremy's comment). However, I did add a new test verbatim that will test completely independent objects.

Is it also possible to test that when everything is finalized after duplication that native objects do get cleaned up?

Good suggestion however I don't think I have a good way to test that without reflection and\or using a gc.collect pattern.

@steveharter steveharter force-pushed the PortDsaCertEx branch 2 times, most recently from 960bda6 to db7d189 Compare October 6, 2016 00:17
@steveharter steveharter merged commit 91e4c88 into dotnet:master Oct 6, 2016
@karelz karelz modified the milestone: 1.2.0 Dec 3, 2016
@steveharter steveharter deleted the PortDsaCertEx branch April 15, 2019 18:20
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants