Visual Basic.NET
  Home arrow Visual Basic.NET arrow Page 6 - Web Services Enhancements 2.0: Security an...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
VISUAL BASIC.NET

Web Services Enhancements 2.0: Security and Policy (VB.NET)
By: MSDN Virtual Labs
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2006-07-13

    Table of Contents:
  • Web Services Enhancements 2.0: Security and Policy (VB.NET)
  • Creating User Accounts and Groups
  • Sending a UsernameToken
  • Requiring a UsernameToken
  • Implementing a UsernameTokenManager
  • Signing with a UsernameToken
  • Encrypting with a UsernameToken

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Web Services Enhancements 2.0: Security and Policy (VB.NET) - Signing with a UsernameToken


    (Page 6 of 7 )

    In addition to security token authentication, it may also be desirable to sign the message in order to achieve integrity (prevent tampering). In this step, you'll add code to sign the SOAP messages with a DerivedKeyToken, based on the UsernameToken you're already using.

    1. Return to InvoiceManagerForm.vb in the SecureInvoiceClient project.
       
    2. Return to the ConfigureProxy method you wrote earlier and instantiate a DerivedKeyToken supplying the UsernameToken to the constructor. 

    3. Add the DerivedKeyToken to the Tokens collection of the proxy's RequestSoapContext

    4. Instantiate a MessageSignature object, based on the new DerivedKeyToken and add this to the Elements collection of the proxy's RequestSoapContext.

    5. Your ConfigureProxy method should look something like this now:

      ...
      Private Sub ConfigureProxy(ByVal proxy As _  
        WebServicesClientProtocol) proxy.RequestSoapContext.
      Security.Tokens.Add(login.
      Token)
        
      Dim dk As New DerivedKeyToken(login.Token)   
         proxy.RequestSoapContext.
      Security.Tokens.Add(dk)  
         proxy.RequestSoapContext.
      Security.Elements.Add(
      _
            New MessageSignature(dk))
      End Sub 'ConfigureProxy
      ...


    6. Build and run SecureInvoiceClient. Verify that everything still works as before.

    7. Return to Windows Explorer and open the output trace file C:Microsoft Hands-on-LabDEV-HOL34VBExercisesAbeforeSecure
      InvoiceClientbinOutputTrace.
      webinfo
      and notice that the last SOAP request was signed using the provided UsernameToken.

    8. Close OutputTrace.webinfo.

    9. Since the message is signed with a UsernameToken, the signature itself can be used as proof of possession, thereby removing the need to send a password altogether. Return to login.vb and, in the button1_Click method, change the password option from PasswordOption.SendHashed to PasswordOption.SendNone.

    10. Build, run, test, and verify that everything still works.

    Requiring a Signature

    The only problem with this situation is that the WebMethod's don't current require a signature. And if the user doesn't provide a signature or a password, the infrastructure will let the request through. Try commenting out the line of code that adds the signature and rerun the client application. Provide bad password and verify that the request still works. You'll have to add code to each WebMethod to require a signature like you did before for UsernameTokens.

    1. Open WseSecurityHelpers.vb in the SecureInvoiceServiceA project.

    2. Add a new method to the WseSecurityHelpers class named CheckForSignature. It should take a SoapContext as input and return void as illustrated here:

      ...
      Public Shared Sub CheckForSignature(ByVal context
      As SoapContext)
      End Sub
      ...
       

    3. Within the method, write code to check the SoapContext for a MessageSignature object. It will be found in the SoapContext.Security.Elements collection if present. If a signature is not present, throw a SoapException indicating "missing signature".

      ...
      Public Shared Sub CheckForSignature(ByVal context
      As SoapContext)
         If context Is Nothing Then
            Throw New Exception("Only SOAP requests are permitted.")
         End If
         If context.Security.Elements.Count = 0 Then
      Throw New SoapException("Missing signature",
      _   
      soapException.ClientFaultCode) 
         End If
         Dim foundSignature As Boolean = False
         Dim se As ISecurityElement
         For Each se In context.Security.Elements
            If TypeOf se Is MessageSignature Then 
               foundSignature = True
            End If
         Next se
         If Not foundSignature Then
            Throw New SoapException("Missing signature",  
       SoapException.ClientFaultCode) 
         End If

      End Sub 'CheckForSignature
      ... 

    4. At the beginning of the GetUsernameToken method in the same class, add a call to this new method. Since all of the WebMethod's currently call GetUsernameToken, we know this method will also be called.

           Public Shared Function GetUsernameToken(ByVal context _
              As SoapContext) As UsernameToken 
        
      CheckForSignature(context)
       

    5. Build the project and test invoking the client without a signature. Verify that you get the "missing signature" exception. Test invoking the client with a signature, and without providing a password (PasswordOption.SendNone), and verify that it works.

    More Visual Basic.NET Articles
    More By MSDN Virtual Labs


       · This lab is excerpted from a larger document titled "Web Services Enhancement 2.0:...
       · I wonder that where I can find SecureInvoiceA.sln you mentioned in Web Services...
       · Please check our link to the Microsoft Virtual Labs website, ...
       · i havent got the SecureInvoiceA.sln...i checked in the link u provided...can u...
       · Microsoft must have moved a few things around -- try this:...
       · Web Services Enhancements 2.0: Security and Policy (VB.NET), The reason for going...
       · Can you specify the location of SecureInvoiceClient project.Urgent reply soon
     

    VISUAL BASIC.NET ARTICLES

    - Working with Classes and Properties for Game...
    - Working with Loops, Arrays, and Collections ...
    - Learning Loops in VB.NET for Game Development
    - Learning VB.NET: Working with Variables, Con...
    - The Basics of VB.NET Through Text Game Devel...
    - Learning VB.NET Through Text Game Development
    - Types of Operators in Visual Basic
    - Operators
    - Understanding Custom Events using Visual Bas...
    - Polymorphism using Abstract Classes in Visua...
    - Shadowing using Shadows in Visual Basic.NET ...
    - Overloading and Overriding in Visual Basic.N...
    - More on Controlling Windows Fax Services Usi...
    - Programmatically Controlling Windows Fax Ser...
    - Focusing on Forms and Menus in Visual Basic





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway