Home | Documentation |
The HTTP-DA plugin
updated Mon Apr 22 2024 by Robert van Engelen
|
The upgraded HTTP digest authentication plugin for gSOAP adds support for the RFC7616 draft that is backwards compatible with RFC2617. The new plugin adds SHA-256 (and SHA-512/256 when OpenSSL supports it) algorithms, including the -sess variants. To maintain backwards compatibility with RFC2617 the MD5 algorithm is still supported but not recommended.
HTTP digest authentication does not transmit the user id and password for authentication. Instead, a server negotiates credentials (username and/or password) with a client using cryptographic hashing algorithms with nonce values to prevent replay attacks.
By contrast, HTTP basic authentication is not safe over unencrypted channels because the password is transmitted to the server unencrypted. Therefore, this mechanism provides no confidentiality protection for the transmitted credentials. HTTPS is typically preferred over or used in conjunction with HTTP basic authentication.
To support HTTP digest authentication in favor of HTTP basic authentication, you will need to install OpenSSL and follow these steps to build your projects:
-DWITH_OPENSSL
.stdsoap2.c[pp]
source.plugin/httpda.c
, plugin/smdevp.c
, and plugin/threads.c
The plugin is MT-safe by means of internal mutex locks. Mutex ensures exclusive access and updates of the shared session store with nonces to prevent replay attacks.
HTTP basic authentication is the default authentication mechanism supported by gSOAP. You can set the basic authentication credentials at the client-side with:
or if you use a proxy object generated with saopcpp2 option -j:
HTTP basic authentication should never be used over plain HTTP, because the credentials (the ID and password) are transmitted in the clear in base64 encoded form which is easily reversible. This mechanism is safer to use over HTTPS, because the HTTP headers and body are encrypted.
This upgraded HTTP digest authentication plugin supports RFC7616 and RFC2617. RFC7616 adds SHA2 and is backwards compatible to clients that use MD5. The MD5 algorithm is not allowed in FIPS making SHA-256 or SHA-512-256 digest algorithms mandatory. The client-side of the plugin handles both RFCs automatically.
To use HTTP digest authentication with gSOAP, register the http_da plugin as follows:
or if you use a proxy object generated with saopcpp2 option -j:
To make a client-side service call you will need to create a digest store http_da_info
. The store holds the digest information locally on your machine to manage repeated authentication challenges from all servers you connect to. Use http_da_save()
to add credentials to the store and release the store with http_da_release()
when you no longer need the credentials.
The http_da_info
store is intended for one thread to issue a sequence of calls that are all authenticated without requiring (re)negotiation. You should not share the http_da_info
store with multiple threads, unless you use mutex locks.
Here is an example:
Again, if you use a proxy object then replace the soap_call_ns__method
with the proxy method invocation, as was shown earlier.
The <authrealm>
string is the protected realm of the server that requires authorization. This string can be obtained with the soap.authrealm
string after an unsuccessful non-authenticated call so you can use it to save credentials to the digest store:
Before a second call is made to the same endpoint that requires authentication, you must restore the authentication state with http_da_restore()
, then use it, and finally release it with http_da_release()
:
For HTTP proxies requiring HTTP digest authenticaiton, use the 'proxy' functions of the plugin:
A client authenticating against a server:
A client authenticating against a proxy:
As explained in the gSOAP user guid, server-side HTTP basic authentication is enforced by simply checking the soap.userid
and soap.passwd
values in a service method that requires client authentication:
HTTP digest authentication is verified differently, because digests are compared, not passwords:
The http_da_verify_post()
function checks the HTTP POST credentials by computing and comparing a digest of the password. The HTTP POST method is used for two-way SOAP/XML communications with request and response messages. One-way SOAP/XML messaging may use HTTP POST or HTTP GET. To verify an HTTP GET operation, use http_da_verify_get()
instead, for example in the HTTP GET handler implemented with the HTTP GET plugin. Likewise, use http_da_verify_put()
for HTTP PUT, http_da_verify_patch()
for HTTP PATCH, and http_da_verify_del()
for HTTP DELETE. To verify other HTTP methods, use the http_da_verify_method()
function with the method as a string argument, for example:
Server-side operations that handle other methods than HTTP POST and GET, such as PATCH, PUT, and DELETE should be implemented with the HTTP POST plugin. This plugin uses a dispatch table with a handler corresponding to the HTTP method to serve.
RFC7616 recommends SHA2 over MD5. MD5 is not secure. The MD5 algorithm is not allowed in FIPS and SHA-256 or SHA-512-256 are mandatory. This upgraded HTTP digest plugin uses SHA-256 as the default algorithm and reverts to MD5 only if required by a client that does not support RFC7616.
The default SHA-256 digest algorithm is enabled automatically. However, at the server side you can also use a plugin registry option to set a different algorithm as the default:
where <option>
is one of:
http_da_md5()
MD5 (not recommended).http_da_md5_sess()
MD5-sess (not recommended).http_da_sha256()
SHA-256 (recommended).http_da_sha256_sess()
SHA-256-sess (recommended).http_da_sha512_256()
SHA-512-256 (not yet supported).http_da_sha512_256_sess()
SHA-512-256-sess (not yet supported).When non-MD5 option is selected, the server will present that digest algorithm together with the MD5 authentication algorithm as challenge to the client. If the client is upgraded to RFC7616 it selects the newer protocol. If the client is not upgraded it will select the older MD5-based protocol.
To revert to RFC2617 use http_da_md5()
(not recommended).
HTTP digest authentication cannot be used with streaming MTOM/MIME/DIME attachments. Non-streaming MTOM/MIME/DIME attachments are handled just fine. MTOM/MIM/DIME attachment streaming is automatically turned off by the plugin and attachment data is buffered rather than streamed.