Home | Documentation |
The gSOAP WS-Trust Extensible Framework
updated Thu Apr 15 2021 by Robert van Engelen
|
The material in this section relates to the WS-Trust specification.
The WS-Trust framework is extensible. New client-side and server-side WS-Trust operations can be added. Several predefined operations are included to get you started. The list of predefined operations will be expanded over time. Please inquire Genivia tech support services.
To use the WS-Trust framework, make sure that the wst.h
specification is imported in the .h file for soapcpp2, e.g. after running wsdl2h check the generated .h file:
If the import is not there, add it manually. Then run soapcpp2 as usual with option -Iimport
to import wst.h from the import directory.
The wst.h and the WS-Trust-dependent wstx.h and other gSOAP-specific .h header files are located in the import directory of the gSOAP package. These files define the WS-Trust and other WS-* protocol header elements and types. The wstx.h header file defines the WS-Trust RequestSecurityTokenRequest and RequestSecurityTokenRequestCollection operations.
Compile your code with -DWITH_DOM
and -DWITH_OPENSSL
to enable WS-Security plugin API features.
Compile and link your code with wsseapi.c and wstapi.c, and include wsseapi.h and wstapi.h in your code.
Internally, the wstapi.c code enables SOAP 1.2 messaging. This will not affect your SOAP 1.1 messaging.
The WS-Trust bindings in wst.h in the import directory were generated from the WS-Trust schema for you with the wsdl2h tool and WS/WS-typemap.dat as follows:
wsdl2h -cgyex -o wst.h -t WS/WS-typemap.dat WS/WS-Trust.xsd
The following modifications to wst.h are required to be made after generating wst.h with wsdl2h:
//gsoapopt
http://docs.oasis-open.org/ws-sx/ws-trust/200512
to remove the trailing /
(slash)//gsoap wst schema namespace
directive to //gsoap wst schema import
directive#import "wsp_appliesto.h"
#import "wstx.h"
at the end of the definitions in wst.hTo expand or customize the WS-Trust bindings by adding (or removing) content model elements to the RequestSecurityToken and RequestSecurityTokenResponse, edit WS/WS-typemap.dat for the following two definition blocks:
wst__RequestSecurityTokenType = $\ _wsp__AppliesTo_* wsp__AppliesTo; wst__RequestSecurityTokenType = $\ char* KeyType; wst__RequestSecurityTokenType = $\ char* RequestType; wst__RequestSecurityTokenType = $\ char* TokenType; wst__RequestSecurityTokenType = $\ wst__EntropyType* Entropy; wst__RequestSecurityTokenType = $\ char* ComputedKeyAlgorithm; wst__RequestSecurityTokenType = $\ unsigned int* KeySize; wst__RequestSecurityTokenType = $\ struct wst__BinaryExchangeType* BinaryExchange; wst__RequestSecurityTokenType = $\ struct wst__AuthenticatorType* Authenticator; wst__RequestSecurityTokenResponseType = $\ struct wst__RequestedSecurityTokenType* RequestedSecurityToken; wst__RequestSecurityTokenResponseType = $\ struct wst__RequestedReferenceType* RequestedAttachedReference; wst__RequestSecurityTokenResponseType = $\ struct wst__RequestedReferenceType* RequestedUnattachedReference; wst__RequestSecurityTokenResponseType = $\ struct wst__RequestedProofTokenType* RequestedProofToken; wst__RequestSecurityTokenResponseType = $\ struct wst__RequestedTokenCancelledType* RequestedTokenCancelled; wst__RequestSecurityTokenResponseType = $\ char* KeyType; wst__RequestSecurityTokenResponseType = $\ char* RequestType; wst__RequestSecurityTokenResponseType = $\ char* TokenType; wst__RequestSecurityTokenResponseType = $\ wst__EntropyType* Entropy; wst__RequestSecurityTokenResponseType = $\ struct wst__BinaryExchangeType* BinaryExchange; wst__RequestSecurityTokenResponseType = $\ struct wst__AuthenticatorType* Authenticator;
For example, to add the wst:Lifetime
element to the RequestSecurityTokenResponse add the following two lines:
wst__RequestSecurityTokenResponseType = $\ wst__LifetimeType* Lifetime;
where wst__LifetimeType
is declared in wst.h. The pointer makes it optional.
Then follow the instructions in the previous section to regenerate wst.h.
Given the new Lifetime
element, the wstapi.c framework can be extended to use this element information as follows:
This section lists the predefined WS-Trust operations implemented in wstapi.c.
Request SAML 1.0 or SAML 2.0 token, with endpoint
service endpoint URL (send to), soapver
SOAP version with 1 = SOAP 1.1, 2 = SOAP 1.2 (SOAP 1.2 is recommended), applyto
is your service domain, username
to authenticate or NULL, password
to authenticate or NULL, saml1
if non-NULL, requests SAML 1.0 and upon return points to a pointer that is set to the SAML 1.0 assertion received, saml2
if non-NULL, requests SAML 2.0 and upon return points to a pointer that is set to the SAML 2.0 assertion received.
Returns SOAP_OK
on success when the assertion could be verified, with saml1
or saml2
set.
For example:
This prints several of the assertion's properties, including the conditions under which the assertion is valid. The NotBefore
and NotOnOrAfter
conditions can be checked against the current time as follows:
Request P_SHA1 token with endpoint
service endpoint URL (send to), soapver
SOAP version with 1 = SOAP 1.1, 2 = SOAP 1.2 (SOAP 1.2 is recommended), applyto
your service domain, username
to authenticate or NULL, password
to authenticate or NULL, psha1
is filled with the P_SHA1 result token of psa1len
bytes.
Returns SOAP_OK
on success.
Similar to the previous section, request a P_SHA256 token with:
To implement a WS-Trust server in C, run soapcpp2 as follows:
soapcpp2 -c -L file.h
where file.h has an #import "wst.h"
. This generates the soapServer.c and soapC.c code you need to compile with wstapi.c, wsaapi.c, wsseapi.c, smdevp.c, and mecevp.c. Link with libgsoapssl.a (or stdsoap2.c and dom.c). Use -DWITH_OPENSSL
and -DWITH_DOM
to compile the source code.
For C++, use:
soapcpp2 -L file.h
This generates the soapServer.cpp and soapC.cpp code you need to compile with wstapi.c, wsaapi.c, wsseapi.c, smdevp.c, and mecevp.c. Link with libgsoapssl++.a (or stdsoap2.cpp and dom.cpp). Use -DWITH_OPENSSL
and -DWITH_DOM
to compile the source code.
If you prefer to use soapcpp2 option -j
(or -i
) to generate C++ server objects, please run soacpp2 again as follows:
soapcpp2 -j -L file.h soapcpp2 -CL -pwst import/wst.h
This generates wstClient.cpp, which should be compiled together with the rest of your project code.
You should define the following service operations:
If you are combinding WS-Trust with other service operations, then you must also chain the service operations at the server side as follows:
where the service
object is an instance of the application services generated by soapcpp2 -j
.