diff options
author | Elmer Thomas <elmer@thinkingserious.com> | 2016-06-14 16:31:06 -0700 |
---|---|---|
committer | Elmer Thomas <elmer@thinkingserious.com> | 2016-06-14 16:31:06 -0700 |
commit | 1dd4de646cef60c0eca70c8fe8047909052fbf98 (patch) | |
tree | 42ec2e6a68f5d80f0a18281657ce3dd6a6eae31b | |
parent | 69c39f0d976d6568a9f3156798def9630a9f1789 (diff) | |
download | sendgrid-php-1dd4de646cef60c0eca70c8fe8047909052fbf98.zip sendgrid-php-1dd4de646cef60c0eca70c8fe8047909052fbf98.tar.gz sendgrid-php-1dd4de646cef60c0eca70c8fe8047909052fbf98.tar.bz2 |
Debugging upload script
-rwxr-xr-x | scripts/generate_upload_policy.php | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/scripts/generate_upload_policy.php b/scripts/generate_upload_policy.php index 194b1c9..ae92ea4 100755 --- a/scripts/generate_upload_policy.php +++ b/scripts/generate_upload_policy.php @@ -9,43 +9,48 @@ * Calculate HMAC-SHA1 according to RFC2104 * See http://www.faqs.org/rfcs/rfc2104.html */ -function hmacsha1($key, $data) { - $blocksize = 64; - $hashfunc = 'sha1'; - if (strlen($key) > $blocksize) { +function hmacsha1($key,$data) { + $blocksize=64; + $hashfunc='sha1'; + if (strlen($key)>$blocksize) $key=pack('H*', $hashfunc($key)); - } - $key = str_pad($key, $blocksize, chr(0x00)); - $ipad = str_repeat(chr(0x36), $blocksize); - $opad = str_repeat(chr(0x5c), $blocksize); + $key=str_pad($key,$blocksize,chr(0x00)); + $ipad=str_repeat(chr(0x36),$blocksize); + $opad=str_repeat(chr(0x5c),$blocksize); $hmac = pack( - 'H*', $hashfunc( - ($key ^ $opad) . pack( - 'H*', $hashfunc( - ($key ^ $ipad) . $data + 'H*',$hashfunc( + ($key^$opad).pack( + 'H*',$hashfunc( + ($key^$ipad).$data + ) + ) ) - ) - ) - ); + ); return bin2hex($hmac); } + /* * Used to encode a field for Amazon Auth * (taken from the Amazon S3 PHP example library) */ -function hex2b64($str) { +function hex2b64($str) +{ $raw = ''; - for ($i = 0; $i < strlen($str); $i += 2) { + for ($i=0; $i < strlen($str); $i+=2) + { $raw .= chr(hexdec(substr($str, $i, 2))); } return base64_encode($raw); } + if (count($argv) != 3) { - echo sprintf('Usage: %s <S3 Policy File> <S3 secret key>%s', $argv[0], PHP_EOL); - exit(1); + echo "Usage: " . $argv[0] . " <S3 Policy File> <S3 secret key>\n"; + exit(1); } + $policy = file_get_contents($argv[1]); $secret = $argv[2]; + /* * Base64 encode the Policy Document and then * create HMAC SHA-1 signature of the base64 encoded policy @@ -53,10 +58,5 @@ $secret = $argv[2]; */ $base64_policy = base64_encode($policy); $signature = hex2b64(hmacsha1($secret, $base64_policy)); -echo sprintf( - 'S3_POLICY="%s"%sS3_SIGNATURE="%s"%s', - $base64_policy, - PHP_EOL, - $signature, - PHP_EOL -);
\ No newline at end of file +echo "S3_POLICY=\"" . $base64_policy . "\"\nS3_SIGNATURE=\"" . $signature . "\"\n" +?> |