Need a Security Scenario for asp.net webservice

637 Views Asked by At

I have developed a .Net 3.5 windows forms application. I also want to design a website that has a webservice with multiple Webmethods to query the database on the host machine. I want the webservice to be called ONLY through my winapp and my website! And I don't want any other people to be able to call and use my webservice but only some people who have access to the windows application that I have developed.

I need a good security scenario for this! I truly appreciate anyone who can help me because this is my first experience of developing a webservice and I really need it to be as secure as I mentioned!

1

There are 1 best solutions below

5
On BEST ANSWER

What you're talking about is going to be difficult to do for several reasons, but primarily this:

If you put anything in code on your WinForms app, it can be decompiled very easily. You can obfuscate the code all you like, but it can be de-compiled.

Because of that, any code that you have in your app can be read by anyone with access to the code. You should always treat any WinForms app as if it's completely compromised, and ensure that the security at the server end compensates.

Because of this, you can't simply store usernames and passwords in configuration files or in code. You have to come up with something else. You CAN use authentication and prompt the user to enter a username/password on program launch, and use that. However, people tend to share these things, so you may want to go for extra protection.

You can put the connection info, or secrets into the app.config and encrypt it, but anyone who can de-compile the code, can recompile it, and add code to decrypt it at will.

You can provide signed keys with your app, and use that in an authentication mechanism, but that can be bypassed.

You can restrict your IP address to specific IP addresses, but those can be spoofed.

However...

By layering all of the above techniques, you can make it difficult for an attacker to bypass your precautions. We did the following in one of our apps where we had a similar requirement:

  • We set up a database that holds a GUID record for each authorized customer, and IP addresses allowed for that customer.
  • Every web method expects a CustomerKey parameter. (the guid mentioned above) Each call to a web service checks the key against the IP address.
    • If it matches, valid data is returned.
    • If it fails, valid looking data is returned. We actually return what looks like good data, but it's really not. This makes it harder for an attacker to know if they've actually broken through the defenses.
  • In the WinForms app, the key is stored in the app.config, which is encrypted in the main() event (the entry point for WinForms apps). This is to prevent the casual reader from accessing it.
  • The program is launched automatically on install, so that the encryption happens at startup, to minimize the chance someone can read the file before it's encrypted.
  • Also, the code is obfuscated.

Layering the defenses, hopefully, will discourage the average attacker.

Microsoft has some guidelines as well: http://msdn.microsoft.com/en-us/library/ff648643.aspx