Created
September 27, 2012 08:19
-
-
Save borisguery/3792855 to your computer and use it in GitHub Desktop.
WsseToken generator for curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 [email protected] S3cЯ3tS3cЯɘT | |
* | |
* Results in: | |
* ----------- | |
* X-WSSE: UsernameToken Username="[email protected]", 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 [email protected] 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
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...