The introduction of SOAP (Simple Object Access Protocol) was an important step toward simpler transfer of information and data. The protocol structure is based on the markup language XML (Extensible Markup Language) and therefore allows much more flexible message handling than would be possible with pure HTTP solutions and RPCs as standalone applications. Only the right combination of these protocols enables efficient and reliable communication on the internet that meets the technical requirements of today’s web services and apps.

Today’s data exchange over the internet carries large volumes of security-relevant data and information. Examples include online shops and account management through smartphone or PC apps. These applications request and transfer sensitive personal data as well as critical information such as account details and passwords. Appropriate security measures are needed at this point to protect the data transfer as well as possible. SOAP supports digital signatures and strong encryption.

Digital Signatures for Messages

On an unsecured LAN or WLAN connection, a message that has been sent can be read by third parties with little effort. The risk is not limited to the content itself. The XML schemas can also be read and interpreted, which may reveal the internal workings of the web services. Both offer additional points of attack beyond the unprotected data being transported. SOAP provides several approaches to securing a data transfer. A digital signature can confirm the original sender, and additional encryption can protect the actual information and data.

Put simply, the digital signature identifies the sender. In practice, a digital signature is created for the SOAP body element of a SOAP message with a private key, and the corresponding certificate is inserted into the header of the request together with the signature. Recipients can then easily verify that the message comes from the original sender and has remained unchanged since it was signed. The following code excerpt shows an example of creating a new signature and setting up a new SOAP context.

xml
X509Certificate cert = (X509Certificate)store.Certificates[listBox1.SelectedIndex];
X509SecurityToken certToken = new X509SecurityToken(cert);
proxy.RequestSoapContext.Security.Tokens.Add(certToken);
proxy.RequestSoapContext.Security.Elements.Add(new Signature(certToken));

When signing SOAP messages, keep in mind that the default method usually covers the SOAP body as well as various SOAP header parts. In practice, however, there is often a requirement to sign only specific SOAP parts. If an intermediary changes certain SOAP parts, a default signature over them becomes invalid. If only specific elements that do not change are signed, the signature remains valid when other parts are modified. In the Signature class, the SignatureOptions option offers the following flags for the individual parts.

  • IncludePath
  • IncludePathAction
  • IncludePathFrom
  • IncludePathId
  • IncludePathTo
  • IncludeSoapBody
  • IncludeTimestamp
  • IncludeTimestampCreated
  • IncludeTimestampExpires
  • IncludeNone

You can use any combination of the flags for the option. The only exception is IncludeNone. This flag means that no other flags may be included in the option.

Encryption with Tokens and Certificates

To encrypt SOAP messages effectively, a suitable token should be available. The WSS standard (Web Services Security) provides several options for supplying one. The X.509 certificate is the preferred option, and various tokens can be used as an alternative. A basic distinction is made between the following tokens.

  • Username token
  • Binary token

Before we can sign a SOAP message, however, we first have to establish who performed the signing. WSS defines an element named <UsernameToken> for this purpose. It is available in the three different forms shown below.

xml
<!-- No password -->
<UsernameToken>
<Username>Volkmar</Username>
</UsernameToken>
xml
<!-- Plain-text password -->
<UsernameToken>
<Username>Volkmar</Username>
<Password Type="wsse:PasswordText">#d7T1*?u14f70Ab22</Password>
</UsernameToken>
xml
<!-- Base64-encoded password -->
<UsernameToken>
<Username>Volkmar</Username>
<Password Type="wsse:PasswordDigest">I2Q3VDEqP3UxNGY3MEFiMjI=</Password>
</UsernameToken>

The first element contains only the username and no password. This form is used whenever a secure user check is provided elsewhere and only the username is needed. In the second variant, the password is transferred in plain text along with the username. This requires a database on the receiving side that stores users and passwords so that the values can be compared. The third method uses a password version extended by the digest variant of Base64 encoding and thus allows the password to be transferred in protected form.

Plain Base64 encoding initially offers only basic protection. A password that is captured and sent again could, for example, be used to authenticate as the sender. The digest variant makes this kind of misuse much harder. The digest function in WSS adds an element that cannot be altered. A hash value is formed from a combination of the password, a nonce (a functionally unique string), and the creation time of the token. This makes forgery considerably more difficult.

The WSS X.509 Security Token

In addition to the username token described above, WSS also includes the BinarySecurityToken element. The specification defines corresponding types for the X.509 v3 certificate and the Kerberos v5 ticket system. When you use the X.509 token, you will quickly notice similarities to the username token. In software development on the Microsoft platform, the user’s private certificate store is simply used for this purpose.

The original version of the Microsoft .NET Framework did not provide dedicated classes for accessing the certificate store. With WSE (Web Services Enhancements), however, Microsoft defined dedicated access classes that make working with the certificate store considerably easier. The following code shows how the Microsoft.Web.Services.Security.X509 classes are used to fill a ListBox with the common names of all certificates in a user’s personal certificate store.

xml
using Microsoft.Web.Services;
using Microsoft.Web.Services.Security;
using Microsoft.Web.Services.Security.X509;
...
private X509CertificateStore store;
...
private void Form1_Load(object sender, System.EventArgs e)
{
store = X509CertificateStore.CurrentUserStore(
X509CertificateStore.MyStore);
store.OpenRead();
foreach(X509Certificate cert in store.Certificates)
{
listBox1.Items.Add(cert.GetName());
}
}

Now that we have access to the certificate store of the Windows system, we can assign the certificate that the user selects in the filled ListBox directly to the corresponding SOAP context, as follows.

xml
X509Certificate cert =
(X509Certificate)store.Certificates[listBox1.SelectedIndex];
proxy.RequestSoapContext.Security.Tokens.Add(
new X509SecurityToken(cert));

On the server side, access to the user certificate resembles access to the username token. With a suitably adapted check in the web method, the request can now be tested for the X.509 certificate and processed accordingly. A short source code excerpt illustrates this integration.

xml
// Only accept SOAP requests
SoapContext requestContext = HttpSoapContext.RequestContext;
if (requestContext == null)
{
throw new ApplicationException("Non-SOAP request.");
}
// We only allow requests with one security token
if (requestContext.Security.Tokens.Count == 1)
{
foreach (SecurityToken tok in requestContext.Security.Tokens)
{
// Only accept X.509 Certificates
if (tok is X509SecurityToken)
{
X509SecurityToken certToken = (X509SecurityToken)tok;
return "Hello " + certToken.Certificate.GetName();
}
else
{
throw new SoapException(
"X.509 security token required.",
SoapException.ClientFaultCode);
}
}
} ...

Conclusion

Transferring messages and data over SOAP offers several significant advantages in network traffic. The WSS specification is an important step toward securing data transfer over HTTP, XML, and SOAP. A solid security infrastructure is the basis for the data protection that is urgently needed. Interoperable web services can draw on various options such as digital signatures and security tokens. If, for example, you work with Windows systems and offer web services on them, Microsoft WSE can give you a solid starting point that is easy to integrate for securing your server and web services.

Share LinkedIn X Email