Middleware
Application Server
Date: Feb 6, 2006
Author: Sirish V Vepa
SSL could be used to secure the communications. However, the security is bound to the transport channel. The message is not secure once it is received from the peer. To overcome the dependence on transport security, and also meet emerging business requirements, a new standard was developed.
The OASIS standard WS-Security offers a mechanism to authenticate requests in addition to providing integrity and confidentiality of the messages.
This example demonstrates interoperability between a Microsoft .NET Web Service Client and a Web Service hosted in Oracle OC4J, one of the very important facets of the WS-Security.
Software requirements
Notations used throughout the document
Consider you need to provide your employment history as part of a job application to the requesting party (prospective employee). An Employment Verification Service (EVS) provides a secure and an automatic mechanism of sharing this information with the requestor. Given that the employment history may contain personal information such as your Social security number, date of birth, etc, this information should be treated carefully, and as such you perhaps would want to share this information with someone you could trust (a future employee).
In this service, you provide the requestor with a key, which will give access to your employment history to the requestor. The key is a constructed from information known to you, the EVS and the requestor. Thus, it is necessary to protect the key when it is sent over the Internet.
This example is a highly simplified EVS, which checks if there is any employment history at all for the applicant. To sufficiently protect the communication, the request is signed and encrypted. The response is sent in clear.
Signing the request provides message integrity and message authentication (who sent the message?). Requests for employment verification are received only from known employees. Encryption obfuscates the request, and thus is kept a secret from an eavesdropper.
Since the response is a 'yes/no', confirming whether the applicant has an employment history or not, and is not meaningful to an eavesdropper (we don't know for whom the request was sent!!!), the response is sent in the clear.
The EVS is represented as a Web Service hosted in OC4J. The client is a .NET client. The web service method exists represents the request/response between the .NET client and OC4J. The figure below illustrates this scenario.

The request needs to be signed and encrypted. The signing operation is performed using a private key. Hence, the .NET client requires a private key accessible to it. Encryption utilizes the recipient's public key. Thus, the .NET client also requires the recipient's public key.
Conversely, to verify the request, the client's public key must be accessible to OC4J, and to decrypt the message, the Web Service must use the decryption private key. As part of building the application, we need to distribute the public keys to the respective counterparts (OC4J and .NET client).
WSE ships with a few sample test certificates. For this example, .NET Client for XML signing will use the WSE2QuickStartClient Certificate.
This Web Service also ships with a test certificate oc4j_webservice_decrkey that is used for decrypting the request. The figure below shows the desired setup.

List the contents of the ZIP file, for example
The WSE client will use the Windows store to access the X.509 Certificates and the corresponding private keys. The certificates are located under
NOTE If you are using WSE v3.0, the certificates can be installed by running a setup batch file. Refer to the instructions in
The public key corresponding to the decryption key used by the web service must be installed in the Microsoft client. This is accomplished by first exporting the public key from the Java Key Store used by the web service. Issue the following command.
keytool -export -file c:\temp\service.cer -alias oc4j_service_decrkey -keystore %HOWTO_HOME%\etc\service.jks -storepass oracle
The certificate is exported to the file c:\temp\service.cer.
From a Windows Explorer, double-click on this file, and click on Install Certificate.

Import the certificate into the Personal store.


Close the dialog and return to the MMC console.

c:\temp\wse_client.cer.
c:\temp\mstest_rootca.cer
keytool -import -file C:\temp\wse_client. cer -alias wse_client -keystore service.jks -storepass oracle
When prompted to trust the certificate, enter yes
keytool -import -file C:\temp\mstest_ca.cer -alias wse_rootca -keystore service.jks -storepass oracle
When prompted to trust the certificate, enter yes
Stand Alone Installation: %ORACLE_HOME%/bin/oc4j start
Note that the oc4j command expects the JAVA_HOME environment variable to point to a full JDK installation.
OracleAS Managed Installation: %ORACLE_HOME%/opmn/bin/opmnctl startall
The web service is created using a bottom up approach. Using a Java Class, a WSDL is constructed, and from the WSDL, the Web Service is created. The web service is packaged as part of a J2EE application archive and deployed to OC4J. Creating a Web Service using this approach is discussed in an OTN sample 'How-to: Construct and Use Simple Web Services' (click on this link to locate this sample).
Security policies such as encryption and signing requirements for inbound and outbound messages are expressed in an XML file configured along with the Web Service. The file %HOWTO_HOME%\etc\serverConfig.xml contains all the policy requirements for this web service.
Since the Web Service requires that the request is signed and encrypted, the inbound policy declaration is expressed as
<runtime enabled="security"> <security> <key-store path="META-INF/service.jks" store-pass="oracle"/> <encryption-key alias="oc4j_service_decrkey" key-pass="service_secret123"/>
<inbound> ...
The inbound messages must be signed. The following XML fragment expresses this
<verify-signature>
<signature-methods>
<signature-method>RSA-SHA1</signature-method>
</signature-methods>
...
RSA-SHA1 is the default signature method in OC4J, if the algorithm is not specified.
The request body is also decrypted. The following XML fragment expresses this
<decrypt>
<encryption-methods>
<encryption-method>AES-128</encryption-method>
</encryption-methods>
<keytransport-methods>
<keytransport-method>RSA-1_5</keytransport-method>
</keytransport-methods>
...
</decrypt>
ASE-128 is the default encryption algorithm for OC4J and WSE. The encryption method need not mentioned in the serverConfig.xml file, but is listed in this example for demonstration purpose only. Finally, the key transport algorithm is set to RSA15. Thus, messages exchanged between the .NET client and the Web Service hosted in OC4J should be interoperable.
To build and deploy the web service, type the following command from the %HOWTO_HOME% directory:
You should now have the newly created EmployeeVerification.ear in your %HOWTO_HOME%/lib directory.
This command would also attempt to deploy the web service if the build is successful. It will first test whether OC4J is running.
Note that you can also deploy the application separately . Ensure the %ORACLE_HOME% environment variable is defined, and from the %HOWTO_HOME% directory, type the command:
ant deploy
%HOWTO_HOME%\src\dotn\EmployeeVerificationServiceClient.cs

The value is hard coded in the Client code ( Client.cs )
// base64 encoding of the Windows Key Identifier.
String signKey = "gBfo0147lM6cKnTbbMSuMVvmFY4=";
Client.cs
// base64 encoding of the Windows Key Identifier.
String encryptKey = "4UJqUr7kho+JSeFdfETLtrPkWLE=";
Client.cs
The .NET client code includes a Visual Studio Project file. The code could be compiled using Visual Studio, or, using the supplied batch file
The .NET Web Service Client program is executed by running the Client.exe executable. The output should look similar to this screen shot

ant cli-build To run the client, execute ant cli-run

The warning messages issued by the client runtime can be ignored, since the Java Keystore used by the client ( client.jks), contains certificates that do not have the subjectKeyIdentifier (version 1 X.509 certificate). This should not be an issue in a production environment using X.509 v3 certificates.