'BasicSecurityProfile' sample throws exception 'NonValidatingX509Token' does not support 'X

NB: see 'Update' below.
I've been trying to work with X509 certificate-based authentication, but couldnt get it working. So, I thought I'd try one of the samples that uses x509 certificates. But when I try and run theBasicSecurityProfilesample app (C:\Program Files\Microsoft SDKs\WinFX\ samples\WCF\TechnologySamples\ Basic\Binding\BasicProfile\BasicSecurityProfile\CS\), I get the exception listed below. The exception is thrown when the client attempts to contact the service.
(I'm running the server from the command-line and the client in VS.
The 'setup.bat' file ran successfully to create and install the appropriate keys.)

System.ServiceModel.MessageIOException was unhandled
Message="There was an error writing the message."
Source="mscorlib"
StackTrace:

Server stack trace:
at System.ServiceModel.Message.WriteMessage(XmlDictionaryWriter writer)
at System.ServiceModel.Channels.BufferedMessageWriter.WriteMessage(Message message, BufferManager bufferManager, Int32 initialOffset, Int32 maxSize)
at System.ServiceModel.Channels.TextMessageEncoderFactory.TextMessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager, Int32 messageOffset)
at System.ServiceModel.Channels.MessageEncoder.WriteMessage(Message message, Int32 maxMessageSize, BufferManager bufferManager)
at System.ServiceModel.Channels.HttpOutput.SerializeBufferedMessage(Message message)
at System.ServiceModel.Channels.HttpOutput.Send()
at System.ServiceModel.Channels.HttpChannelFactory.HttpRequestChannel.HttpChannelRequest.SendRequest(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.RequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.SecurityChannelFactory.SecurityRequestChannel.Request(Message message, TimeSpan timeout)
at System.ServiceModel.RequestChannelBinder.Request(Message message, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)

Exception rethrown at [0]:
at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
at ICalculator.Add(Double n1, Double n2)
at CalculatorProxy.Add(Double n1, Double n2) in C:\Program Files\Microsoft SDKs\WinFX\samples\WCF\TechnologySamples\Basic\Binding\BasicProfile\BasicSecurityProfile\CS\client\generatedProxy.cs:line 61
at Microsoft.ServiceModel.Samples.Client.Main(String[] args) in C:\Program Files\Microsoft SDKs\WinFX\samples\WCF\TechnologySamples\Basic\Binding\BasicProfile\BasicSecurityProfile\CS\client\client.cs:line 18

The inner exception is:
'NonValidatingX509Token' does not support 'X509SubjectKeyIdentifierClause' creation.

at System.ServiceModel.Security.Tokens.SecurityToken.CreateKeyIdentifierClause[T]()
at System.ServiceModel.Security.Tokens.X509SecurityToken.CreateKeyIdentifierClause[T]()
at System.ServiceModel.Security.Tokens.SecurityTokenParameters.CreateKeyIdentifierClause[TExternalClause,TInternalClause](SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
at System.ServiceModel.Security.Tokens.X509SecurityTokenParameters.CreateKeyIdentifierClause(SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
at System.ServiceModel.Security.SendSecurityHeader.Encrypt()
at System.ServiceModel.Security.SendSecurityHeader.Execute()
at System.ServiceModel.Security.SecurityAppliedMessage.ApplyDelayedSecurityIfNecessary()
at System.ServiceModel.Security.SecurityAppliedMessage.OnWriteStartEnvelope(XmlDictionaryWriter writer)
at System.ServiceModel.Message.OnWriteMessage(XmlDictionaryWriter writer)
at System.ServiceModel.Message.WriteMessage(XmlDictionaryWriter writer)
Update: the problem appears to be (if Im reading the code right) that (in the ServiceModel source code) theX509SubjectKeyIdentifierClauseclass fails to get theX509SubjectKeyIdentifierExtensionfrom the certificate in itsprivate static byte[] GetSkiRawData(X509Certificate2 certificate) method.
I have no idea what's going on in this code, or what a subjectkeyidentifier is, but I can see that the certificates created by the sample's batch file dont have this extension.
So, can anyone shed light on what the problem is with this sample - are the certificates not suitable, or is there some other problem?


[5593 byte] By [innes] at [2008-2-4]
# 1
Hello again - has anyone else managed to get this sample (which comes with the WinFX beta) to work?
innes at 2007-9-9 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 2
Hi innes,

I believe that the sample doesnt work because WCF is looking for a X509v3 type with a Subject Key Identifier (SKI). The certs that come with makecert (which is the way how the samples of WCF is set up) doesnt have an SKI and so that is why there is this error.

A x509 with an SKI is the best approach for interoperability purposes.

I have blogged about this here:
http://www.softwaremaker.net/blog/BugInTheBasicHttpBindingWSSecurityOfTheWCFSeptCTPDrop.aspx

I hope this helps.

Softwaremaker at 2007-9-9 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...
# 3
Thanks, softwaremaker - good to know it's not just me. I wonder if there is something especially magical about certs with an SKI - I couldnt find any easily available tool for generating them. I will have to locate a windows server installation to mess about with...
innes at 2007-9-9 > top of Msdn Tech,Visual Studio Orcas,Windows Communication Foundation (Indigo)...

Visual Studio Orcas

Site Classified