Some background: in order to provide authentication I'm using certificates on client and server side (WCF) and use one certificate for all clients (manually loading it from application directory - not the safest way, but it doesn't require to manage certificate storage and making installation more difficult):
AddressHeader hostHdr = AddressHeader.CreateAddressHeader(ServiceFactory.CLIENT_HOST_HEADER, ServiceFactory.NAMESPACE, hostName);
builder.Headers.Add(hostHdr);
builder.Identity = new X509CertificateEndpointIdentity(GetServiceCertificate(name));
_factory = new ChannelFactory<T>(name, builder.ToEndpointAddress());
_factory.Credentials.ClientCertificate.Certificate = GetClientCertificate(name);
X509ServiceCertificateAuthentication auth = _factory.Credentials.ServiceCertificate.Authentication;
auth.CertificateValidationMode =X509CertificateValidationMode.Custom;
auth.CustomCertificateValidator = new CustomCertificateValidator(new[] {GetServiceCertificate(name)});
This is client side, and serverside host setting up looks like this:
private void CertificateSetup(ServiceHost host)
{
if (ServiceCertificate != null)
host.Credentials.ServiceCertificate.Certificate = ServiceCertificate;
X509ClientCertificateAuthentication authentication =
host.Credentials.ClientCertificate.Authentication;
authentication.CertificateValidationMode =
X509CertificateValidationMode.Custom;
authentication.CustomCertificateValidator =
new CustomCertificateValidator(new [] {ClientCertificate});
}
That works fine and allows to sign messages, but as far as security mode set in following way:
<security mode="Message">
<message clientCredentialType="Certificate" />
</security>
But i need
string name = OperationContext.Current.ServiceSecurityContext.WindowsIdentity.Name;
somehow to obtain WindowsIdentity in ServiceSecurityContext. Mixed (Transport and Message) security mode is not helpful, because I don't know why but even if i set Windows clientCredentials in config for Transport part mode infrastructure tries to establish SSL connection.
Any ideas ????