Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Securing WCF service using basicHttpBinding which supports streaming

My question is in regards to the best (aka "least painful") way to secure access to a WCF service that is only exposed to our company's internal users. The goal is to ensure that the service is only accessed via a single Windows forms application that each of our users has installed. When the service is called, I want the service to be able to validate that it was called from the permitted application.

The service to be secured uses basicHttpBinding, which supports streaming, so I believe I am limited to Transport level security.

Below are simplified versions of the <bindings> and <services> sections from my service's config file.

<bindings>
  <basicHttpBinding>
    <binding name="Service1Binding" transferMode="Streamed"/>    
  </basicHttpBinding>
</bindings>

<services>
    <service name="WCFServiceSecurity.Service1" 
        behaviorConfiguration="WCFServiceSecurity.Service1Behavior">
        <endpoint address=""
            binding="basicHttpBinding"
            contract="WCFServiceSecurity.IService1"
            bindingConfiguration="Service1Binding"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
    </service>
</services>

Can anyone offer some details as to what actions I would need to take in order to implement security on this service?

Note: I'm new to WCF and am not familiar with security at all, so let me know if I haven't provided enough detail.


UPDATE:

As suggested by marc_s, I'd like to secure the WCF service using some sort of username/password mechanism. This gives a little more direction towards an answer, but I'm still somewhat blurry on how to actually do this.

Because my service requires streaming to be enabled, I have to use basicHttpBinding and Transport level security (right?); further to that, the method contained in my service can only accept a Stream object.

Taking those constraints into consideration along with my preference to use username/password validation...

  • How should I modify my service's config file to force username/password credentials to be supplied?
  • How will my service validate the supplied credentials?
  • How will my client application pass credentials the service when making a call?
  • Will this require using SSL and, if so, will all client machines require a certificate as well?

UPDATE:

After explaining the trouble I've been having with securing this service to my boss, I was given the go-ahead to try the Windows Authentication route. Sadly, I've had no luck in implementing this type of authentication with my Streamed service (argh). After making the appropriate changes (as outlined here - the only exception being that my transferMode="Streamed") and accessing my service, I was presented with the following error:

HTTP request streaming cannot be used in conjunction with HTTP authentication. Either disable request streaming or specify anonymous HTTP authentication.

I then stumbled upon the following quote here which offers some clarification:

You can't do transport auth. with streaming. If you have to use HTTP request streaming, you'll have to run without security.

The way security works is:

WCF Client makes an http request to the Server.

The Server responds with something saying, "You aren't authorized, send me a basic/digest/etc credential."

The Client gets that response and resends its message with the credentials tacked on.

Now the Server gets the message, verifies the credentials, and continues. Request Streaming isn't designed to work with that security pattern. If it did, it would be really slow, since the Client would send the entire stream, get the message from the Server that it wasn't authorized, then it would have to resend the entire stream with credentials.

So now I'm looking for opinions, how would you secure your streaming-enabled WCF service? As mentioned previously, some sort of username/password mechanism would be preferred. Feel free to think outside the box on this one...

Any help is greatly appreciated!

like image 504
Steve Dignan Avatar asked May 10 '09 14:05

Steve Dignan


2 Answers

Well, I found a lot of issues surrounding security/streaming while working on this problem. The hack (er...um...workaround) I finally ended up going with was to create a new DataContract that inherits MemoryStream and decorated it with a BaseStream property (for holding the data I want streamed) along with appropriate properties used for simple authentication.

Here is the resulting DataContract:

[DataContract]
[KnownType( typeof( MemoryStream ) )] 
public class StreamWithCredentials : MemoryStream
{
    [DataMember]
    public Stream BaseStream { get; set; }

    [DataMember]
    public string Username { get; set; }

    [DataMember]
    public string Password { get; set; }
}

The above DataContract ends up being the input parameter of my service's method. The first action my service takes is to authenticate the supplied credentials against known valid values and to continue as appropriate.

Now I do know that this is not the most secure option but my directive was to avoid using SSL (which I'm not even sure is possible anyway - as stated here) for this internal process.

That being said, this was the best solution to the above stated problem I could come up with, hope this helps anyone else stricken with this issue.

Thanks to all who responded.

like image 51
Steve Dignan Avatar answered Oct 22 '22 18:10

Steve Dignan


There's a number of things you could do:

  • add a certificate to each and every machine that's allowed to use your service, and check for that certificate. That only allows you to exclude "unauthorized" machines - you cannot limit it to a specific application
  • same as above, but include the certificate embedded in your winforms app and send it from there (do not store it in the machine's certificate store)
  • require a username / password that only that particular app of yours knows about and can transmit to your service; e.g. someone else would not be able to present the appropriate credentials

EDIT 2: OK, so the username/password approach seems to get out of hand.... what if you just have basic transport security (SSL) for basic protection, and then use the MessageContract to define header and body of your SOAP message, include a specific value in the header, and then just check for that presence of the element in the header in your service?

Something like that:

[DataContract]
class YourRequestData
{
 ...
}

[MessageContract]
public class YourRequest
{
  [MessageBodyMember]
  public YourRequestData bodyData { get; set; }

  [MessageHeader]
  public string AppThumbprint { get; set; }
}

And then on your server in your code just check for the presence and the validity of that AppThumbprint code:

public Stream RequestStream(YourRequest request)
{
  if(AppThumbprintIsValid(request.AppThumbprint))
  {
     .... begin your streaming
  }
}

That might end up being a lot easier than the username/password security scenario.

Marc

like image 32
marc_s Avatar answered Oct 22 '22 18:10

marc_s