Library tutorials & articles
Authentication for Web Services
The Choices We Made
So now the question becomes how do we build such a mechanism. To do so, we are faced with many decisions. Since it's almost always a good idea to be aware of the boundaries for our decision, let's review our criteria
- Passwords must not be transmitted in cleartext
- Having a valid set of credentials (in our case, a company code, user id and password) is sufficient to gain access. It is unlikely, given the requirements that we place on the password (minimum of six characters, including at least one number), that the credentials could be guessed so long as they are maintained securely by the client.
- The shipment rating request can be made using either SSL or standard HTTP, depending on the requirement of the client
- It should be easy for a client to connect our service to their security environment
- It should be easy for a developer to use the security mechanism implemented by our web service
Given these boundaries, what thought process do we go through? First, let's address the requirement that password not be sent in cleartext means that encryption will be part of the solution. And given our encryption choices, it seems that SSL is be best solution to make it easy on both the client and developer. And do we really need to have SSL used on every message? Certainly not if we're willing to have other messages sent in the clear. Although I'm not usually in favor of designing features for a user to turn on and off (I believe that it is actually a form of laziness on the developer's part), in this case we will leave it up to the client as to whether they feel comfortable having their shipping information sent across the Internet without the benefit of SSL.
Next up. How do we get the credentials from the client to our server. Our options? We could put them into the SOAP header. We could put them into the SOAP body. The reality is that it doesn't make a difference. We actually have them in the body because it seems more natural. But this is one case where the choice is more a matter of style then technique.
So where does that leave us. What we will be implementing is as follows. First, we will add a Login method to our web service. The parameters are the company code, the user id and the password. The result will be a security token (specifically a sort-of GUID that gets generated upon successful validation). This token will be used in subsequent calls to the web service. That way we can use SSL for the first call only while leaving the remainder in HTTP.
How are we going to generate our token. The obvious choice is to use a GUID as generated by Windows. But that does expose us to a subtle risk. If we use just a plain GUID, then every time we get a request that contains a 32-character string in the Token parameter, we need to validate it against the list of tokens that we maintain in the database. If someone wanted to launch a denial of service attack against us, they would just need to send multiple requests all having a 32-character token. Our database servers would go mad trying to identify all of them.
Our solution is to add a check digit to the token. In our example, it is placed at the end of the token, but the location is not important. The reason for including the check digit is that it allows us to validate the token before hitting the database, thus reducing the threat.
Related articles
Related discussion
-
Stock Exchange Rate
by devart_jamesyang (3 replies)
-
what's new?
by fengtui (3 replies)
-
Messenger Infostructure
by jonorossi (17 replies)
-
Sorting
by Stevesoft (5 replies)
-
Simple database question
by Rajeev Sharma (3 replies)
Events coming up
-
Oct
14
What’s New in Visual Studio 2008 Service Pack 1?
Birmingham, United Kingdom
“Service Pack? We’re calling it a Service Pack? Are you kidding??!?!” Visual Studio 2008 Service Pack 1 will release later in 2008 alongside .NET Framework V3.5 Service Pack 1 and, together, they represent a significant upgrade to Visual Studio 2008. There are enhancements across many areas of the .NET Framework such as data access, windows application development and web development and there are also corresponding changes in the development environment to support the new framework features.
Hi,
I have enjoyed reading the article so far and I have a quick question. Isn't the interception of the security token almost as useful to a hacker as the interception of the original credentials? If so (even marginally) then why is it neccessary to go to such lengths to hide the login name and password, but not the token? Couldn't a hacker keep the token alive by using it regularly, therefore avoiding any expiration? Would it be possible to explore these issues, in the scope of the article?
Thanks,
Seamus