Skip to content

Commit

Permalink
Fix System.ServiceModel.Description.ClientCredentials..ctor
Browse files Browse the repository at this point in the history
The protected constructor and MakeReadOnly() method does not properly clone the
_clientCertificate, _serverCertificate fields

Fixes dotnet#458
  • Loading branch information
iamjasonp committed Oct 27, 2015
1 parent 87b0d51 commit 21354e3
Showing 1 changed file with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,29 @@ protected ClientCredentials(ClientCredentials other)
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("other");
if (other._userName != null)
_userName = new UserNamePasswordClientCredential(other._userName);
if (other._clientCertificate != null)
_clientCertificate = new X509CertificateInitiatorClientCredential(other._clientCertificate);
if (other._serviceCertificate != null)
_serviceCertificate = new X509CertificateRecipientClientCredential(other._serviceCertificate);
if (other._httpDigest != null)
_httpDigest = new HttpDigestClientCredential(other._httpDigest);
_isReadOnly = other._isReadOnly;
}

public UserNamePasswordClientCredential UserName
{
get
{
if (_userName == null)
{
_userName = new UserNamePasswordClientCredential();
if (_isReadOnly)
_userName.MakeReadOnly();
}
return _userName;
}
}

public X509CertificateInitiatorClientCredential ClientCertificate
{
get
Expand Down Expand Up @@ -60,21 +78,6 @@ public X509CertificateRecipientClientCredential ServiceCertificate
}
}

public UserNamePasswordClientCredential UserName
{
get
{
if (_userName == null)
{
_userName = new UserNamePasswordClientCredential();
if (_isReadOnly)
_userName.MakeReadOnly();
}
return _userName;
}
}


public WindowsClientCredential Windows
{
get
Expand Down Expand Up @@ -177,8 +180,18 @@ public virtual void ApplyClientBehavior(ServiceEndpoint serviceEndpoint, ClientR
// RC0 workaround to freeze credentials when the channel factory is opened
internal void MakeReadOnly()
{
_isReadOnly = true;

if (_clientCertificate != null)
_clientCertificate.MakeReadOnly();
if (_serviceCertificate != null)
_serviceCertificate.MakeReadOnly();
if (_userName != null)
_userName.MakeReadOnly();
if (_windows != null)
_windows.MakeReadOnly();
if (_httpDigest != null)
_httpDigest.MakeReadOnly();
}
}
}

0 comments on commit 21354e3

Please sign in to comment.