Skip to content

Instantly share code, notes, and snippets.

@borisguery
Created September 27, 2012 08:19
Show Gist options
  • Save borisguery/3792855 to your computer and use it in GitHub Desktop.
Save borisguery/3792855 to your computer and use it in GitHub Desktop.
WsseToken generator for curl
#!/usr/bin/env php
<?php
function wsse_header($username, $password) {
$nonce = hash_hmac('sha512', uniqid(null, true), uniqid(), true);
$created = new DateTime('now', new DateTimezone('UTC'));
$created = $created->format(DateTime::ISO8601);
$digest = sha1($nonce.$created.$password, true);
return sprintf(
'X-WSSE: UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"',
$username,
base64_encode($digest),
base64_encode($nonce),
$created
);
}
if (3 === $argc) {
printf("%s", wsse_header($argv[1], $argv[2]));
exit(0);
} else {
printf("Usage: %s [username] [password]\n", ltrim($argv[0], './'));
exit(1);
}
/**
* Set up:
* -------
* chmod +x wssetoken.php
*
* Usage:
* ------
* ./wssetoken.php guery.b@gmail.com S3cЯ3tS3cЯɘT
*
* Results in:
* -----------
* X-WSSE: UsernameToken Username="guery.b@gmail.com", PasswordDigest="qjr06a/T+oVJHxIhQvfgmF/kipM=", Nonce="vK6a/Y5tk0yQtNSOtkFTfsITPiBZUIyHIMBztkyeVdsAbSsLsAkbbBDa9WFzj1+d5aIV6YjkUVKWmJDR+GHs9A==", Created="2012-09-27T08:15:53+0000"
*
* Usage within curl:
* ------------------
* curl -v -H"$(./wssetoken.php guery.b@gmail.com S3cЯ3tS3cЯɘT)" http://example.com/api/secured/resource
*/
@h4cc
Copy link

h4cc commented Oct 29, 2013

I wrote a fork and removed the hash_hmac, because of that binary hash, the nonces and digest generated would contain slashes '/'. The system i work with can not handle slashes...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment