Note that there are some explanatory texts on larger screens.

plurals
  1. POcloudfront signed urls ip address
    primarykey
    data
    text
    <p>I have Signed URLs on Cloudfront working fine in PHP. Bucket policies work with HTTP referrers on S3 but because Cloudfront doesn't support HTTP referrer checks I need to serve a file to one IP address only (the client that requested the file and generated the signed URL or my web server ideally).</p> <p>Can someone please help me add the IP Address element to the JSON code so it works? </p> <pre><code>"IpAddress":{"AWS:SourceIp":"192.0.2.0/24"}, </code></pre> <p>I'm lost with the PHP and Policy Statement but think it might be easy for someone who knows: <a href="http://tinyurl.com/9czr5lp" rel="nofollow">http://tinyurl.com/9czr5lp</a></p> <p>It does encoding/signing a bit differently for a custom policy: <a href="http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-custom-policy.html#private-content-custom-policy-statement" rel="nofollow">http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-custom-policy.html#private-content-custom-policy-statement</a></p> <p>The below is an AWS example and works except not for the IP Address lock in.</p> <p>I can test this very quickly if someone can please give me a hand for two minutes!</p> <p>Thanks MASSIVELY for any help :)</p> <p>Jon</p> <pre><code> function getSignedURL($resource, $timeout) { $keyPairId = "XXXXXXXXXXXX"; $expires = time() + $timeout; $json = '{"Statement":[{"Resource":"'.$resource.'","Condition":{"DateLessThan": {"AWS:EpochTime":'.$expires.'}}}]}'; $fp=fopen("pk-XXXXXXXX.pem","r"); $priv_key=fread($fp,8192); fclose($fp); $key = openssl_get_privatekey($priv_key); if(!$key) { echo "&lt;p&gt;Failed to load private key!&lt;/p&gt;"; return; } //Sign the policy with the private key if(!openssl_sign($json, $signed_policy, $key, OPENSSL_ALGO_SHA1)) { echo '&lt;p&gt;Failed to sign policy: '.openssl_error_string().'&lt;/p&gt;'; return; } //Create url safe signed policy $base64_signed_policy = base64_encode($signed_policy); $signature = str_replace(array('+','=','/'), array('-','_','~'), $base64_signed_policy); //Construct the URL $url = $resource.'?Expires='.$expires.'&amp;Signature='.$signature.'&amp;Key-Pair-Id='.$keyPairId; return $url; } $url = getSignedURL("http://s675765.cloudfront.net/filename.mp4", 600); print $url; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload