我正在尝试为我的 S3 存储桶中的内容构建 Amazone cloudfront 的签名 URL。我已按照从http://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/private-content-creating-signed-url-custom-policy.html# private-content-custom-policy-creating-signature-download-procedure但我正在构建的 url 的某些原因是收到此消息“AccessDeniedAccess denied”。
我还从分发设置的行为中将“受信任的签名者”添加为“自我”,并为该 分发添加了一个来源。我不确定我错过了什么。这是我的php代码
<?php
function rsa_sha1_sign($policy, $private_key_filename)
{
$signature = "";
// load the private key
$fp = fopen($private_key_filename, "r");
$priv_key = fread($fp, 8192);
fclose($fp);
//echo $priv_key;
$pkeyid = openssl_get_privatekey($priv_key);
// compute signature
openssl_sign($policy, $signature, $pkeyid);
// free the key from memory
openssl_free_key($pkeyid);
//echo $signature;
return $signature;
}
function url_safe_base64_encode($value)
{
$encoded = base64_encode($value);
// replace unsafe characters +, = and / with
// the safe characters -, _ and ~
return str_replace(
array('+', '=', '/'),
array('-', '_', '~'),
$encoded);
}
$key_pair_id = "MY_KEY_PAIR_ID";
$donwload_cname = "MY_DOWNLOAD_CNAME";
$download_url = "MY_DOMAIN_NAME/download/2012/01/FILE_NAME.mp3";
$DateLessThan = time() + (24*7*60*60);
$policy = '{"Statement":[{"Resource":"'.$download_url.'","Condition":{"DateLessThan":{"AWS:EpochTime":'.$DateLessThan.'}}}]}';
$private_key_file = "MY_PRIVATE_KEY_FILE.pem";
$signature = rsa_sha1_sign($policy, $private_key_file);
$signature = url_safe_base64_encode($signature);
$final_url = $download_url.'?Policy='.url_safe_base64_encode($policy).'&Signature='.$signature.'&Key-Pair-Id='.$key_pair_id;
echo $final_url;
?>
我已尝试使用 download_url 的域名和 cname 但没有效果。那就是我尝试了两种url格式
$download_url = "MY_DOMAIN_NAME/download/2012/01/FILE_NAME.mp3"
$download_url = "MY_DOWNLOAD_CNAME/download/2012/01/FILE_NAME.mp3"
但没有工作。谁可以帮我这个事 。我确信这里缺少一些非常小的东西,或者需要对存储桶设置进行一些处理,但现在不知道该怎么做。需要紧急帮助