int
soap_wsse_add_UsernameTokenDigest(struct soap *soap, const char *id, const char *username, const char *password)
{ _wsse__Security *security = soap_wsse_add_Security(soap);
time_t now = time(NULL);
const char *created = soap_dateTime2s(soap, now);
char HA[SOAP_SMD_SHA1_SIZE], HABase64[29];
char nonce[SOAP_WSSE_NONCELEN], *nonceBase64;
DBGFUN2("soap_wsse_add_UsernameTokenDigest", "id=%s", id?id:"", "username=%s", username?username:"");
/* generate a nonce */
calc_nonce(soap, nonce);
nonceBase64 = soap_s2base64(soap, (unsigned char*)nonce, NULL, SOAP_WSSE_NONCELEN);
/* The specs are not clear: compute digest over binary nonce or base64 nonce? */
/* compute SHA1(created, nonce, password) */
calc_digest(soap, created, nonce, SOAP_WSSE_NONCELEN, password, HA);
/* Hm...?
calc_digest(soap, created, nonceBase64, strlen(nonceBase64), password, HA);
*/
soap_s2base64(soap, (unsigned char*)HA, HABase64, SOAP_SMD_SHA1_SIZE);
/* populate the UsernameToken with digest */
soap_wsse_add_UsernameTokenText(soap, id, username, HABase64);
/* populate the remainder of the password, nonce, and created */
security->UsernameToken->Password->Type = (char*)wsse_PasswordDigestURI;
security->UsernameToken->Nonce = nonceBase64;
security->UsernameToken->wsu__Created = soap_strdup(soap, created);
return SOAP_OK;
}