amazon web services - AWS signed cookies authentication not working php (AccessDeniedAccess denied) -
i trying access static content s3 bucket using aws cloudfront. able access content using signed url when trying use aws signed cookies authentication giving me accessdeniedaccess denied error. have double check cloudfront , s3 bucket configuration. seems perfect. using custom ssl certificate cloudfront , canned policy access content.
<?php getsignature("http://cdn.******.ca", 300000); echo '<html> <head></head> <body> <iframe src="https://cdn.****/file.pdf"> </body> </html>'; function getsignature($resource = null, $expires = null, $policy = null) { $keypairid = 'ap*****'; $signaturehash = array(); if ($policy) { $policy = preg_replace('/\s/s', '', $policy); $signaturehash['policy'] = encode($policy); header ( "set-cookie: cloudfront-policy=".$signaturehash['policy']."; path=/; domain=***.ca; httponly", false ); } elseif ($resource && $expires) { $policy = createcannedpolicy($resource, $expires); $signaturehash['expires'] = $expires; header ( "set-cookie: cloudfront-expires=".$signaturehash['expires']."; path=/; domain=***.ca; httponly", false ); } else { return false; } $signaturehash['signature'] = encode(sign($policy)); header ( "set-cookie: cloudfront-signature=".$signaturehash['signature']."; path=/; domain=***.ca; httponly", false ); $signaturehash['key-pair-id'] = $keypairid; header ( "set-cookie: cloudfront-key-pair-id=".$signaturehash['key-pair-id']."; path=/; domain=***.ca; httponly", false ); return $signaturehash; } function createcannedpolicy($resource, $expiration) { $json = '{"statement":[{"resource":"'.$resource.'","condition":{"datelessthan":{"aws:epochtime":'.$expiration.'}}}]}'; return $json; } function sign($policy) { $signature = ''; $privatekey = 'path/pk-apk***.pem'; $fp=fopen($privatekey,"r"); $priv_key=fread($fp,8192); fclose($fp); $key = openssl_get_privatekey($priv_key); openssl_sign($policy, $signature, $key); return $signature; } function encode($policy) { return strtr(base64_encode($policy), '+=/', '-_~'); } ?>
Comments
Post a Comment