Skip to content

Instantly share code, notes, and snippets.

@h4cc
Forked from borisguery/wssetoken.php
Last active May 28, 2016 08:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save h4cc/7215924 to your computer and use it in GitHub Desktop.
Save h4cc/7215924 to your computer and use it in GitHub Desktop.
#!/usr/bin/env php
<?php
function wsse_header($username, $password) {
// Needed to change hashing, so not nounces with '/' inside will not be generated.
$nonce = sha1(uniqid(null, true) . uniqid());
$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
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment