-
-
Save h4cc/7215924 to your computer and use it in GitHub Desktop.
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) { | |
// 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 [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