Port missing X509Certificate members#12240
Conversation
9229785 to
d16deb7
Compare
| if (cert == null) | ||
| throw new ArgumentNullException(nameof(cert)); | ||
|
|
||
| Pal = CertificatePal.FromHandle(cert.Handle); // Let FromHandle throw if certHandle is 0 |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
We'll need to add a copy constructor test for a cert which has a private key.
There was a problem hiding this comment.
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")] |
There was a problem hiding this comment.
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?)
There was a problem hiding this comment.
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")] |
There was a problem hiding this comment.
What about this test warrants the suppression?
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
I don't see anything in this change which should require adding a reference to CSP... what's this for?
There was a problem hiding this comment.
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]
9419bf9 to
078cd35
Compare
|
|
||
| [Fact] | ||
| [PlatformSpecific(PlatformID.Windows)] | ||
| [PlatformSpecific(Xunit.PlatformID.Windows)] |
There was a problem hiding this comment.
PlatformID has been renamed TestPlatforms. See #12284. Sorry for the merge conflicts.
6663c27 to
ecfae1a
Compare
0fd2fb7 to
e6114b6
Compare
|
@morganbr please review (Jeremy OOF). Main change from initial review was to support copy ctor |
e6114b6 to
5a3b905
Compare
| } | ||
|
|
||
| [Fact] | ||
| public static void TestCopyConstructor_Lifetime() |
There was a problem hiding this comment.
Can you please add a test for disposing in the reverse order as well?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Is it also possible to test that when everything is finalized after duplication that native objects do get cleaned up?
There was a problem hiding this comment.
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.
960bda6 to
db7d189
Compare
db7d189 to
63b2782
Compare
fbc27d5 to
8831b7e
Compare
Commit migrated from dotnet/corefx@91e4c88
Per issue https://github.com/dotnet/corefx/issues/9986
Also converted X509 project to ns1.7.
@bartonjs please review