【问题标题】:Creating with java a CloudFront signed url with getSignedURLWithCustomPolicy instead getSignedURLWithCannedPolicy使用 java 创建一个 CloudFront 签名的 url,使用 getSignedURLWithCustomPolicy 而不是 getSignedURLWithCannedPolicy
【发布时间】:2020-06-26 22:46:31
【问题描述】:

请看下面的代码:

public static void ok() throws InvalidKeySpecException, IOException {
    String privKeyStr = "/path/to/aws/aws-cloudfront-key-pair/pk-APKAJV4KUNWFL43EMJNA.pem";
    File privKey = new File(privKeyStr);

    String url0 = CloudFrontUrlSigner.getSignedURLWithCannedPolicy(
        Protocol.https,                  // protocol
        "example.com",                   // distributionDomain
        privKey,                         // privateKey
        "ok.mp4",                        // objectKey
        "APKAJV4KUNWFL43EMJNA",          // keyId
        new Date(System.currentTimeMillis()+1000*60*60*24) // endDate
    );

    String url1 = CloudFrontUrlSigner.getSignedURLWithCustomPolicy(
        Protocol.https, 
        "example.com", 
        privKey,
        "ok.mp4", 
        "APKAJV4KUNWFL43EMJNA", 
        new Date(System.currentTimeMillis()+1000*60*60*24), // end date
        new Date(System.currentTimeMillis()-1000*60*60*24), // begin date
        "0.0.0.0/0");

    System.out.println(url0);   // This url works perfectly well: it lets me view the video
    System.out.println(url1);   // This does not !!! WHY ????? : it says: access denied
}

当使用“getSignedURLWithCannedPolicy”时,我得到一个按预期工作的功能性网址。但是,当我使用几乎相同的“getSignedURLWithCustomPolicy”时,它不起作用,我从 Cloudfront 得到“拒绝访问”。

谁能告诉我为什么?

【问题讨论】:

  • 生成的 URL 中的 Policy 是 JSON 文档,以 base64 编码,然后将字符 + = / 音译为 - _ ~ (以避免URL 转义问题)。反转该过程,您可以检查 JSON,问题可能会变得明显。

标签: java url amazon-cloudfront signature


【解决方案1】:

我有同样的问题 - 在我的情况下,它是通过提供 IPv6 地址而不是 IPv4 来解决的。我在运行 curl -vvvv aws_url 时发现了它。

【讨论】:

    猜你喜欢
    • 2011-02-07
    • 2013-07-01
    • 1970-01-01
    • 2011-02-04
    • 1970-01-01
    • 2018-12-25
    • 2017-02-26
    • 2017-04-02
    • 2014-03-03
    相关资源
    最近更新 更多