internal void ApplyConfiguration(X509CertificateRecipientClientCredential creds)
        {
            if (creds == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("creds");
            }
            PropertyInformationCollection propertyInfo = this.ElementInformation.Properties;

            if (propertyInfo[ConfigurationStrings.StoreLocation].ValueOrigin != PropertyValueOrigin.Default ||
                propertyInfo[ConfigurationStrings.StoreName].ValueOrigin != PropertyValueOrigin.Default ||
                propertyInfo[ConfigurationStrings.X509FindType].ValueOrigin != PropertyValueOrigin.Default ||
                propertyInfo[ConfigurationStrings.FindValue].ValueOrigin != PropertyValueOrigin.Default)
            {
                creds.SetDefaultCertificate(this.StoreLocation, this.StoreName, this.X509FindType, this.FindValue);
            }
        }
Exemple #2
0
        internal void ApplyConfiguration(X509CertificateRecipientClientCredential cert)
        {
            if (cert == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("cert");
            }
            if (base.ElementInformation.Properties["authentication"].ValueOrigin != PropertyValueOrigin.Default)
            {
                this.Authentication.ApplyConfiguration(cert.Authentication);
            }
            this.DefaultCertificate.ApplyConfiguration(cert);
            X509ScopedServiceCertificateElementCollection scopedCertificates = this.ScopedCertificates;

            for (int i = 0; i < scopedCertificates.Count; i++)
            {
                scopedCertificates[i].ApplyConfiguration(cert);
            }
        }
Exemple #3
0
        protected ClientCredentials(ClientCredentials other)
        {
            if (other == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("other");
            }
            if (other.userName != null)
            {
                this.userName = new UserNamePasswordClientCredential(other.userName);
            }
            if (other.clientCertificate != null)
            {
                this.clientCertificate = new X509CertificateInitiatorClientCredential(other.clientCertificate);
            }
            if (other.serviceCertificate != null)
            {
                this.serviceCertificate = new X509CertificateRecipientClientCredential(other.serviceCertificate);
            }
            if (other.windows != null)
            {
                this.windows = new WindowsClientCredential(other.windows);
            }
            if (other.httpDigest != null)
            {
                this.httpDigest = new HttpDigestClientCredential(other.httpDigest);
            }
            if (other.issuedToken != null)
            {
                this.issuedToken = new IssuedTokenClientCredential(other.issuedToken);
            }
            if (other.peer != null)
            {
                this.peer = new PeerCredential(other.peer);
            }

            this.getInfoCardTokenCallback = other.getInfoCardTokenCallback;
            this.supportInteractive       = other.supportInteractive;
            this.securityTokenHandlerCollectionManager = other.securityTokenHandlerCollectionManager;
            this.useIdentityConfiguration = other.useIdentityConfiguration;
            this.isReadOnly = other.isReadOnly;
        }
Exemple #4
0
        protected virtual void ConfigureServiceAuthentication(X509CertificateRecipientClientCredential service)
        {
            var authentication = service.Authentication;

            if (RevocationMode.HasValue)
            {
                authentication.RevocationMode = RevocationMode.Value;
            }

            if (CertificateValidationMode.HasValue)
            {
                authentication.CertificateValidationMode = CertificateValidationMode.Value;
            }

            if (RemoteCertificateValidator != null)
            {
                authentication.CustomCertificateValidator = RemoteCertificateValidator;
            }

            if (TrustedStoreLocation.HasValue)
            {
                authentication.TrustedStoreLocation = TrustedStoreLocation.Value;
            }

            if (DefaultRemoteCertificate != null)
            {
                service.DefaultCertificate = DefaultRemoteCertificate;
            }

            if (ScopedRemoteCertificates != null)
            {
                foreach (var certificateScope in ScopedRemoteCertificates)
                {
                    service.ScopedCertificates.Add(certificateScope.Key, certificateScope.Value);
                }
            }
        }
 protected ClientCredentials(ClientCredentials other)
 {
     if (other == null)
     {
         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;
 }
Exemple #6
0
        //</snippet23>

        //<snippet24>
        public void snippet24(CalculatorClient cc)
        {
            X509CertificateRecipientClientCredential rcc = cc.ClientCredentials.ServiceCertificate;
            X509Certificate2 cert = rcc.DefaultCertificate;
        }
Exemple #7
0
        //</snippet20>


        //<snippet21>
        public void snippet21(CalculatorClient cc)
        {
            X509CertificateRecipientClientCredential rcc   = cc.ClientCredentials.ServiceCertificate;
            X509ServiceCertificateAuthentication     xauth = rcc.Authentication;
        }
Exemple #8
0
        private void Run()
        {
            //<snippet31>
            //<snippet30>
            WSHttpBinding    b      = new WSHttpBinding();
            EndpointAddress  ea     = new EndpointAddress("http://localhost/Calculator");
            CalculatorClient client = new CalculatorClient(b, ea);
            //<snippet9>
            IssuedTokenClientCredential itcc = client.ClientCredentials.IssuedToken;

            //</snippet9>
            //</snippet30>

            //<snippet10>
            itcc.LocalIssuerAddress = new EndpointAddress("http://fabrikam.com/sts");
            //</snippet10>
            //</snippet31>

            AddressHeader a1 = AddressHeader.CreateAddressHeader("Hello", "World", "hello");

            AddressHeader[] addressHeaders = new AddressHeader[] { a1 };

            //<snippet11>
            itcc.LocalIssuerAddress = new EndpointAddress(new Uri("http://fabrikam.com/sts"),
                                                          addressHeaders);
            //</snippet11>

            //<snippet12>
            itcc.LocalIssuerAddress = new EndpointAddress(
                new Uri("http://fabrikam.com/sts"),
                EndpointIdentity.CreateDnsIdentity("fabrikam.com"),
                addressHeaders);
            //</snippet12>

            //<snippet13>
            itcc.LocalIssuerBinding = new WSHttpBinding("LocalIssuerBinding");
            //</snippet13>

            //<snippet32>
            SynchronousReceiveBehavior myEndpointBehavior = new SynchronousReceiveBehavior();

            //<snippet14>
            itcc.LocalIssuerChannelBehaviors.Add(myEndpointBehavior);
            //</snippet14>
            //</snippet32>

            //<snippet15>
            itcc.MaxIssuedTokenCachingTime = new TimeSpan(0, 10, 0);
            //</snippet15>

            //<snippet16>
            itcc.IssuedTokenRenewalThresholdPercentage = 80;
            //</snippet16>

            //<snippet17>
            itcc.DefaultKeyEntropyMode = SecurityKeyEntropyMode.ServerEntropy;
            //</snippet17>

            //<snippet33>
            //<snippet18>
            X509CertificateRecipientClientCredential rcc =
                client.ClientCredentials.ServiceCertificate;
            //</snippet18>

            X509Certificate2 cert = new X509Certificate2();

            //<snippet19>
            rcc.ScopedCertificates.Add(new Uri("http://fabrikam.com/sts"), cert);
            //</snippet19>
            //</snippet33>
        }
Exemple #9
0
 /// <summary>
 /// This function sets the Credentials that you can see in the app.config file under endPointBehavior/ServiceCertificate. It's always
 /// set the same way, and since we're not using the App.config file to set the behavior when we generate proxies (so that users can dynamically set the clientcertificate),
 /// we have to set these values programatically. The behavior is still in the app.config file, and is used to set a default certificate when the client starts.
 /// </summary>
 /// <param name="incredents"></param>
 protected void GetCredentialsForServiceCertificate(X509CertificateRecipientClientCredential incredents)
 {
     incredents.Authentication.CertificateValidationMode = X509CertificateValidationMode.ChainTrust;
     incredents.Authentication.RevocationMode            = X509RevocationMode.NoCheck;
     incredents.Authentication.TrustedStoreLocation      = StoreLocation.LocalMachine;
 }