Skip to content

Instantly share code, notes, and snippets.

@pulsation
Forked from borisguery/wssetoken.php
Last active August 29, 2015 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pulsation/e02307d2f4d229cc3522 to your computer and use it in GitHub Desktop.
Save pulsation/e02307d2f4d229cc3522 to your computer and use it in GitHub Desktop.
Test WSSE token
#!/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 (4 === $argc) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $argv[3]);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(wsse_header($argv[1], $argv[2])));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$data = curl_exec($ch);
curl_close($ch);
echo "\n";
exit(0);
} else {
printf("Usage: %s [username] [password] [url]\n", ltrim($argv[0], './'));
exit(1);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment