views:

243

answers:

3

I have a webservice that that uses message layer security with X.509 certificates in WSE 3.0. The service uses a X509v3 policy to sign various elements in the soapheader.

I need to do some custom checks on the certificates so I've tried to implement a custom X509SecurityTokenManager and added a section in web.config.

When I call the service with my Wseproxy I would expect a error (NotImplementedException) but the call goes trough and, in the example below, "foo" is printed at the console.

The question is: What have missed? The binarySecurityTokenManager type in web.config matches the full classname of RDI.Server.X509TokenManager. X509TokenManager inherits from X509SecurityTokenManager (altough methods are just stubs).

using System;
using System.Xml;
using System.Security.Permissions;
using System.Security.Cryptography;
using Microsoft.Web.Services3;
using Microsoft.Web.Services3.Security.Tokens;

namespace RDI.Server
{

[SecurityPermissionAttribute(SecurityAction.Demand,Flags = SecurityPermissionFlag.UnmanagedCode)]
public class X509TokenManager : Microsoft.Web.Services3.Security.Tokens.X509SecurityTokenManager
{
 public X509TokenManager() : base()
 {
  throw new NotImplementedException("Stub");
 }

 public X509TokenManager(XmlNodeList configData) : base(configData)
 {
  throw new NotImplementedException("Stub");
 }

 protected override void AuthenticateToken(X509SecurityToken token)
 {
  base.AuthenticateToken(token);
  throw new NotImplementedException("Stub");
 }
}
}

The first few lines of my web.config, edited for brevity <?xml version="1.0"?> <configuration><configSections><section name="microsoft.web.services3" type="..." /> </configSections><microsoft.web.services3><policy fileName="wse3policyCache.config" /> <security><binarySecurityTokenManager><add type="RDI.Server.X509TokenManager" valueType="http://docs.oasis-open.org/..." /></binarySecurityTokenManager></security></microsoft.web.services3>

(Btw, how do one format xml nicely here at stackoverflow?)

Administration.AdministrationWse test = new TestConnector.Administration.AdministrationWse();

X509Certificate2 cert = GetCert("RDIDemoUser2");
X509SecurityToken x509Token = new X509SecurityToken(cert);
test.SetPolicy("X509");
test.SetClientCredential(x509Token);

string message = test.Ping("foo");

Console.WriteLine(message);

I'm stuck at .NET 2.0 (VS2005) for the time being so I presume WCF is out of the question, otherwise interoperability isn't a problem, as I will have control of both clients and services in the system.

A: 

Not particular constructive advice I know, but if I was you I'd get off WSE3.0 as soon as possible. We did some work with trying to get it to interoperate with WCF and a Java client earlier this year and it was an obsolute KNIGHTMARE.

WCF on the other hand is practically sane and the documentation on areas like this is pretty good. Is that an option for you?

Kieran Benton
A: 

@Kieran Benton I'm stuck at .NET 2.0 (VS2005) for the time being so I presume WCF is out of the question, otherwise interoperability isn't a problem, as I will have control of both clients and services in the system.

Carl-Johan
+1  A: 

The problem was located elsewhere. My serverproject was an web-app and some options wasn't available for web-apps just for web-sites. So I made a small web-site project and compared web.configs and noticed that some lines diffed.

These lines was in the website web.config but not in my other projekt

  <soapServerProtocolFactory type="Microsoft.Web.Services3.WseProtocolFactory, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  <soapExtensionImporterTypes>
    <add type="Microsoft.Web.Services3.Description.WseExtensionImporter, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
  </soapExtensionImporterTypes>

After I added those lines i got the expected error.

Carl-Johan