Skip to content

Commit 8d9bfd8

Browse files
committed
Fix 1574 and enable tests
* Use X509Certificate2 copy constructor as it becomes available in 2.0. * Enable those TCP tests require service certificate. They pass by using the X509Certificate2 copy constructor.
1 parent 751134a commit 8d9bfd8

File tree

14 files changed

+9
-83
lines changed

14 files changed

+9
-83
lines changed

src/System.Private.ServiceModel/src/Extensions/X509Certificate2Extensions.cs

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/System.Private.ServiceModel/src/System/IdentityModel/Claims/X509CertificateClaimSet.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,7 @@ internal X509CertificateClaimSet(X509Certificate2 certificate, bool clone)
3333
if (certificate == null)
3434
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("certificate");
3535

36-
// dotnet/wcf#1574
37-
// ORIGINAL CODE:
38-
// _certificate = clone ? new X509Certificate2(certificate.Handle) : certificate;
39-
40-
_certificate = clone ? certificate.CloneCertificateInternal() : certificate;
36+
_certificate = clone ? new X509Certificate2(certificate) : certificate;
4137
}
4238

4339
private X509CertificateClaimSet(X509CertificateClaimSet from)
@@ -515,11 +511,7 @@ public X509Identity(X500DistinguishedName x500DistinguishedName)
515511
internal X509Identity(X509Certificate2 certificate, bool clone, bool disposable)
516512
: base(X509, X509)
517513
{
518-
// dotnet/wcf#1574
519-
// ORIGINAL CODE:
520-
// _certificate = clone ? new X509Certificate2(certificate.Handle) : certificate;
521-
522-
_certificate = clone ? certificate.CloneCertificateInternal() : certificate;
514+
_certificate = clone ? new X509Certificate2(certificate) : certificate;
523515

524516
_disposable = clone || disposable;
525517
}

src/System.Private.ServiceModel/src/System/IdentityModel/Selectors/X509SecurityTokenProvider.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,7 @@ internal X509SecurityTokenProvider(X509Certificate2 certificate, bool clone)
2828
_clone = clone;
2929
if (_clone)
3030
{
31-
// dotnet/wcf#1574
32-
// ORIGINAL CODE:
33-
// _certificate = new X509Certificate2(certificate.Handle);
34-
35-
_certificate = certificate.CloneCertificateInternal();
31+
_certificate = new X509Certificate2(certificate);
3632
}
3733
else
3834
{

src/System.Private.ServiceModel/src/System/IdentityModel/Tokens/X509SecurityToken.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ internal X509SecurityToken(X509Certificate2 certificate, string id, bool clone,
5454

5555
_id = id;
5656

57-
// dotnet/wcf#1574
58-
// ORIGINAL CODE:
59-
// _certificate = clone ? new X509Certificate2(certificate.Handle) : certificate;
60-
_certificate = clone ? certificate.CloneCertificateInternal() : certificate;
57+
_certificate = clone ? new X509Certificate2(certificate) : certificate;
6158

6259
// if the cert needs to be cloned then the token owns the clone and should dispose it
6360
_disposable = clone || disposable;

src/System.Private.ServiceModel/src/System/ServiceModel/Channels/SslStreamSecurityUpgradeProvider.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,7 @@ private void SetupServerCertificate(SecurityToken token)
252252
SR.InvalidTokenProvided, _serverTokenProvider.GetType(), typeof(X509SecurityToken))));
253253
}
254254

255-
// dotnet/wcf#1574
256-
// ORIGINAL CODE:
257-
// _serverCertificate = new X509Certificate2(x509Token.Certificate.Handle);
258-
_serverCertificate = x509Token.Certificate.CloneCertificateInternal();
255+
_serverCertificate = new X509Certificate2(x509Token.Certificate);
259256
}
260257

261258
private void CleanupServerCertificate()
@@ -713,10 +710,7 @@ private bool ValidateRemoteCertificate(object sender, X509Certificate certificat
713710
{
714711
// Note: add ref to handle since the caller will reset the cert after the callback return.
715712

716-
// dotnet/wcf#1574
717-
// ORIGINAL CODE:
718-
// X509Certificate2 certificate2 = new X509Certificate2(certificate.Handle);
719-
X509Certificate2 certificate2 = certificate.CloneCertificateInternal();
713+
X509Certificate2 certificate2 = new X509Certificate2(certificate);
720714

721715
SecurityToken token = new X509SecurityToken(certificate2, false);
722716
ReadOnlyCollection<IAuthorizationPolicy> authorizationPolicies = _serverCertificateAuthenticator.ValidateToken(token);

src/System.Private.ServiceModel/src/System/ServiceModel/Security/SecurityUtils.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -882,10 +882,7 @@ private static X509Certificate2 GetCertificateFromStoreCore(StoreName storeName,
882882
certs = store.Certificates.Find(findType, findValue, false);
883883
if (certs.Count == 1)
884884
{
885-
// dotnet/wcf#1574
886-
// ORIGINAL CODE:
887-
// return new X509Certificate2(certs[0].Handle);
888-
return certs[0].CloneCertificateInternal();
885+
return new X509Certificate2(certs[0]);
889886
}
890887
if (throwIfMultipleOrNoMatch)
891888
{

src/System.Private.ServiceModel/tests/Scenarios/Binding/Custom/CustomBindingTests.4.1.0.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public partial class CustomBindingTests : ConditionalWcfTest
1313
{
1414
// Tcp: Client and Server bindings setup exactly the same using default settings.
1515
[WcfFact]
16-
[Issue(1886, OS = OSID.AnyOSX)]
1716
[Condition(nameof(Root_Certificate_Installed), nameof(Client_Certificate_Installed))]
1817
[OuterLoop]
1918
public static void DefaultSettings_Tcp_Binary_Echo_RoundTrips_String()

src/System.Private.ServiceModel/tests/Scenarios/Client/ExpectedExceptions/ExpectedExceptionTests.4.1.0.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ public static void DuplexCallback_Throws_FaultException_ReturnsFaultedTask()
329329
}
330330

331331
[WcfFact]
332-
[Issue(1886, OS = OSID.AnyOSX)]
333332
[OuterLoop]
334333
// Verify product throws MessageSecurityException when the Dns identity from the server does not match the expectation
335334
public static void TCP_ServiceCertExpired_Throw_MessageSecurityException()

src/System.Private.ServiceModel/tests/Scenarios/Client/ExpectedExceptions/ExpectedExceptionTests.4.1.1.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
public partial class ExpectedExceptionTests : ConditionalWcfTest
1313
{
1414
[WcfFact]
15-
[Issue(1886, OS = OSID.AnyOSX)]
1615
[Condition(nameof(Root_Certificate_Installed), nameof(Client_Certificate_Installed))]
1716
[OuterLoop]
1817
// Confirm that the Validate method of the custom X509CertificateValidator is called and that an exception thrown there is handled correctly.

src/System.Private.ServiceModel/tests/Scenarios/Security/TransportSecurity/Tcp/ClientCredentialTypeCertificateCanonicalNameTests.4.1.0.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public class Tcp_ClientCredentialTypeCertificateCanonicalNameTests : Conditional
2525
// to pass a variation or fail a variation.
2626

2727
[WcfFact]
28-
[Issue(1886, OS = OSID.AnyOSX)]
2928
[Condition(nameof(Root_Certificate_Installed))]
3029
[OuterLoop]
3130
public static void Certificate_With_CanonicalName_Localhost_Address_EchoString()
@@ -97,7 +96,6 @@ public static void Certificate_With_CanonicalName_Localhost_Address_EchoString()
9796
}
9897

9998
[WcfFact]
100-
[Issue(1886, OS = OSID.AnyOSX)]
10199
[Condition(nameof(Root_Certificate_Installed))]
102100
[OuterLoop]
103101
public static void Certificate_With_CanonicalName_DomainName_Address_EchoString()
@@ -174,7 +172,6 @@ public static void Certificate_With_CanonicalName_DomainName_Address_EchoString(
174172
}
175173

176174
[WcfFact]
177-
[Issue(1886, OS = OSID.AnyOSX)]
178175
[Condition(nameof(Root_Certificate_Installed))]
179176
[OuterLoop]
180177
public static void Certificate_With_CanonicalName_Fqdn_Address_EchoString()

0 commit comments

Comments
 (0)