From b6ed814f4c3ef54da3887a872eb85ede70eba982 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Mon, 31 May 2010 07:06:56 +0000 Subject: [PATCH] 2010-05-31 Atsushi Enomoto * ClientCredentialsElement.cs, HttpDigestClientElement.cs, ConfigUtil.cs : implement ClientCredentialsElement.CreateBehavior(). svn path=/trunk/mcs/; revision=158188 --- .../ChangeLog | 5 ++ .../ClientCredentialsElement.cs | 70 ++++++++++++++++++- .../ConfigUtil.cs | 65 +++++++++++++++++ .../HttpDigestClientElement.cs | 8 +-- 4 files changed, 139 insertions(+), 9 deletions(-) diff --git a/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ChangeLog b/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ChangeLog index 39440be8b65..5f3be1f1eb0 100755 --- a/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ChangeLog +++ b/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ChangeLog @@ -1,3 +1,8 @@ +2010-05-31 Atsushi Enomoto + + * ClientCredentialsElement.cs, HttpDigestClientElement.cs, + ConfigUtil.cs : implement ClientCredentialsElement.CreateBehavior(). + 2010-04-05 Atsushi Enomoto * BaseAddressPrefixFilterElementCollection.cs diff --git a/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ClientCredentialsElement.cs b/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ClientCredentialsElement.cs index 5ea382213f7..03f451f0c7c 100644 --- a/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ClientCredentialsElement.cs +++ b/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ClientCredentialsElement.cs @@ -40,6 +40,8 @@ using System.Security.Principal; using System.IdentityModel.Claims; using System.IdentityModel.Policy; using System.IdentityModel.Tokens; +using System.IdentityModel.Selectors; +using System.Security.Cryptography.X509Certificates; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Description; @@ -72,6 +74,7 @@ namespace System.ServiceModel.Configuration get { return (X509InitiatorCertificateClientElement) base ["clientCertificate"]; } } + [MonoTODO] [ConfigurationProperty ("httpDigest", Options = ConfigurationPropertyOptions.None)] public HttpDigestClientElement HttpDigest { @@ -138,11 +141,72 @@ namespace System.ServiceModel.Configuration get { return (WindowsClientElement) base ["windows"]; } } - [MonoTODO] - protected internal override object CreateBehavior () { - throw new NotImplementedException (); + protected internal override object CreateBehavior () + { + var cb = new ClientCredentials (); + cb.SupportInteractive = SupportInteractive; + // how is "Type" used? + + // ClientCertificate + if (!String.IsNullOrEmpty (ClientCertificate.FindValue)) + cb.ClientCertificate.SetCertificate (ClientCertificate.StoreLocation, ClientCertificate.StoreName, ClientCertificate.X509FindType, ClientCertificate.FindValue); + + // HttpDigest + if (HttpDigest.ImpersonationLevel != TokenImpersonationLevel.None) + throw new NotImplementedException (); + + // IssuedToken + var bi = cb.IssuedToken; + var ci = IssuedToken; + bi.CacheIssuedTokens = ci.CacheIssuedTokens; + bi.DefaultKeyEntropyMode = ci.DefaultKeyEntropyMode; + bi.IssuedTokenRenewalThresholdPercentage = ci.IssuedTokenRenewalThresholdPercentage; + foreach (IssuedTokenClientBehaviorsElement ccb in ci.IssuerChannelBehaviors) + bi.IssuerChannelBehaviors.Add (new Uri (ccb.IssuerAddress, UriKind.RelativeOrAbsolute), ConfigUtil.CreateEndpointBehaviors (ccb.BehaviorConfiguration)); + bi.LocalIssuerAddress = ci.LocalIssuer.CreateInstance (); + bi.LocalIssuerBinding = ConfigUtil.CreateBinding (ci.LocalIssuer.Binding, ci.LocalIssuer.BindingConfiguration); + bi.MaxIssuedTokenCachingTime = ci.MaxIssuedTokenCachingTime; + + // Peer + if (!String.IsNullOrEmpty (Peer.Certificate.FindValue)) + cb.Peer.SetCertificate (Peer.Certificate.StoreLocation, Peer.Certificate.StoreName, Peer.Certificate.X509FindType, Peer.Certificate.FindValue); + // cb.Peer.MeshPassword = /* cannot fill it here */ + cb.Peer.MessageSenderAuthentication.CustomCertificateValidator = (X509CertificateValidator) CreateInstance (Peer.MessageSenderAuthentication.CustomCertificateValidatorType); + cb.Peer.MessageSenderAuthentication.CertificateValidationMode = Peer.MessageSenderAuthentication.CertificateValidationMode; + cb.Peer.MessageSenderAuthentication.RevocationMode = Peer.MessageSenderAuthentication.RevocationMode; + cb.Peer.MessageSenderAuthentication.TrustedStoreLocation = Peer.MessageSenderAuthentication.TrustedStoreLocation; + cb.Peer.PeerAuthentication.CustomCertificateValidator = (X509CertificateValidator) CreateInstance (Peer.PeerAuthentication.CustomCertificateValidatorType); + cb.Peer.PeerAuthentication.CertificateValidationMode = Peer.PeerAuthentication.CertificateValidationMode; + cb.Peer.PeerAuthentication.RevocationMode = Peer.PeerAuthentication.RevocationMode; + cb.Peer.PeerAuthentication.TrustedStoreLocation = Peer.PeerAuthentication.TrustedStoreLocation; + + // ServiceCertificate + var bsc = cb.ServiceCertificate; + var csc = ServiceCertificate; + var bsca = bsc.Authentication; + var csca = csc.Authentication; + bsc.DefaultCertificate = csc.DefaultCertificate.CreateInstance (); + bsca.CertificateValidationMode = csca.CertificateValidationMode; + if (csca.CustomCertificateValidatorType != null) + bsca.CustomCertificateValidator = (X509CertificateValidator) CreateInstance (csca.CustomCertificateValidatorType); + bsca.RevocationMode = csca.RevocationMode; + bsca.TrustedStoreLocation = csca.TrustedStoreLocation; + foreach (X509ScopedServiceCertificateElement sce in ServiceCertificate.ScopedCertificates) + bsc.ScopedCertificates.Add (sce.TargetUri, sce.CreateInstance ()); + + // cb.UserNamePassword : not configurable ... + + // Windows + cb.Windows.AllowedImpersonationLevel = Windows.AllowedImpersonationLevel; + cb.Windows.AllowNtlm = Windows.AllowNtlm; + + return cb; } + object CreateInstance (string typeName) + { + return String.IsNullOrEmpty (typeName) ? null : Activator.CreateInstance (System.Type.GetType (typeName, true)); + } } } diff --git a/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ConfigUtil.cs b/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ConfigUtil.cs index ba23d85f08e..69af67d968c 100644 --- a/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ConfigUtil.cs +++ b/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/ConfigUtil.cs @@ -28,6 +28,7 @@ using System; using System.Configuration; using System.Collections.Generic; +using System.Security.Cryptography.X509Certificates; using System.ServiceModel.Channels; using System.ServiceModel.Configuration; using System.ServiceModel.Description; @@ -82,5 +83,69 @@ namespace System.ServiceModel.Configuration return b; } + + public static KeyedByTypeCollection CreateEndpointBehaviors (string bindingConfiguration) + { + var ec = BehaviorsSection.EndpointBehaviors [bindingConfiguration]; + if (ec == null) + return null; + var c = new KeyedByTypeCollection (); + foreach (var bxe in ec) + c.Add ((IEndpointBehavior) bxe.CreateBehavior ()); + return c; + } + + public static EndpointAddress CreateInstance (this EndpointAddressElementBase el) + { + return new EndpointAddress (el.Address, el.Identity.CreateInstance (), el.Headers.Headers); + } + + public static EndpointIdentity CreateInstance (this IdentityElement el) + { + if (el.Certificate != null) + return new X509CertificateEndpointIdentity (el.Certificate.CreateInstance ()); + else if (el.CertificateReference != null) + return new X509CertificateEndpointIdentity (el.CertificateReference.CreateInstance ()); + else if (el.Dns != null) + return new DnsEndpointIdentity (el.Dns.Value); + else if (el.Rsa != null) + return new RsaEndpointIdentity (el.Rsa.Value); + else if (el.ServicePrincipalName != null) + return new SpnEndpointIdentity (el.ServicePrincipalName.Value); + else if (el.UserPrincipalName != null) + return new UpnEndpointIdentity (el.UserPrincipalName.Value); + else + return null; + } + + public static X509Certificate2 CreateInstance (this CertificateElement el) + { + return new X509Certificate2 (Convert.FromBase64String (el.EncodedValue)); + } + + public static X509Certificate2 CreateCertificateFrom (StoreLocation storeLocation, StoreName storeName, X509FindType findType, Object findValue) + { + throw new NotImplementedException (); + } + + public static X509Certificate2 CreateInstance (this CertificateReferenceElement el) + { + return CreateCertificateFrom (el.StoreLocation, el.StoreName, el.X509FindType, el.FindValue); + } + + public static X509Certificate2 CreateInstance (this X509ClientCertificateCredentialsElement el) + { + return CreateCertificateFrom (el.StoreLocation, el.StoreName, el.X509FindType, el.FindValue); + } + + public static X509Certificate2 CreateInstance (this X509ScopedServiceCertificateElement el) + { + return CreateCertificateFrom (el.StoreLocation, el.StoreName, el.X509FindType, el.FindValue); + } + + public static X509Certificate2 CreateInstance (this X509DefaultServiceCertificateElement el) + { + return CreateCertificateFrom (el.StoreLocation, el.StoreName, el.X509FindType, el.FindValue); + } } } diff --git a/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/HttpDigestClientElement.cs b/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/HttpDigestClientElement.cs index 5d6dce63e19..2f04f5acfd4 100644 --- a/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/HttpDigestClientElement.cs +++ b/mcs/class/System.ServiceModel/System.ServiceModel.Configuration/HttpDigestClientElement.cs @@ -54,7 +54,6 @@ using System.Xml; namespace System.ServiceModel.Configuration { - [MonoTODO] public sealed partial class HttpDigestClientElement : ConfigurationElement { @@ -66,7 +65,7 @@ namespace System.ServiceModel.Configuration { properties = new ConfigurationPropertyCollection (); impersonation_level = new ConfigurationProperty ("impersonationLevel", - typeof (TokenImpersonationLevel), "Identification", null/* FIXME: get converter for TokenImpersonationLevel*/, null, + typeof (TokenImpersonationLevel), "Identification", null, null, ConfigurationPropertyOptions.None); properties.Add (impersonation_level); @@ -76,12 +75,11 @@ namespace System.ServiceModel.Configuration { } - // Properties [ConfigurationProperty ("impersonationLevel", Options = ConfigurationPropertyOptions.None, - DefaultValue = "Identification")] + DefaultValue = TokenImpersonationLevel.Identification)] public TokenImpersonationLevel ImpersonationLevel { get { return (TokenImpersonationLevel) base [impersonation_level]; } set { base [impersonation_level] = value; } @@ -90,8 +88,6 @@ namespace System.ServiceModel.Configuration protected override ConfigurationPropertyCollection Properties { get { return properties; } } - - } } -- 2.25.1