java - AMP update-cache request returns 403 -
i trying implement google amp update-cache request using this documentation.
my implementation
as suggested in tutorial, firstly cache information https://cdn.ampproject.org/caches.json , iterate through these caches perform update.
simplified code single cache (as there 1 @ moment anyways):
main logic
string firstparturl = "https://amp--frontend-dpo-styria--publishing-com.cdn.ampproject.org" string secondparturl = "/update-cache/c/s/amp-frontend.dpo.styria-publishing.com/octopus/5267614?amp_action=flush&_ts=1505218616" secondparturl = signrequesturl(secondparturl); performrequest(firstparturl, secondparturl);
signing function
private string signrequesturl(string requesturl) throws exception { url url = resources.getresource("rsa/private-key-pcks8.pem"); string privatekey = resources.tostring(url, charsets.utf_8); string signature = signsha256rsa(requesturl, privatekey); stringbuilder builder = new stringbuilder(requesturl); builder.append("&_url_signature="); builder.append(signature); return builder.tostring(); } public static string signsha256rsa(string input, string privatekey) throws exception { // remove markers , new line characters in private key string realpk = privatekey.replaceall("-----end private key-----", "") .replaceall("-----begin private key-----", "") .replaceall("\r\n", "")//windows .replaceall("\n", "");//unix byte[] b1 = base64.getdecoder().decode(realpk); pkcs8encodedkeyspec spec = new pkcs8encodedkeyspec(b1); keyfactory kf = keyfactory.getinstance("rsa"); signature privatesignature = signature.getinstance("sha256withrsa"); privatesignature.initsign(kf.generateprivate(spec)); privatesignature.update(input.getbytes()); byte[] s = privatesignature.sign(); return base64.geturlencoder().withoutpadding().encodetostring(s); }
my public key published here: https://amp-frontend.dpo.styria-publishing.com/.well-known/amphtml/apikey.pub
what tried
i tried follow signing steps in command line, after url obtained returned 403.
i tried following tips this question (making sure use sha256 , setting content-type of apikey text/plain, did not help)
my question
do know why google amp still returning 403? suspected, there might issue base64 encoding, because documentation not clear that, not sure.
edit
i realized there might problem implementation of function building secondparturl
- timestamp. created timestamp using zoneddatetime.now()
, wrong, in different timezone utc. however, changing instant.now()
did not help.
Comments
Post a Comment