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&amp_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("&amp_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

url produced app looks this: https://amp--frontend-dpo-styria--publishing-com.cdn.ampproject.org/update-cache/c/s/amp-frontend.dpo.styria-publishing.com/octopus/5267614?amp_action=flush&amp_ts=1505218616&amp_url_signature=yiq_zexq-fyotqfk4ydl-n3rr0jqf6pq8j86icbcynfino7t5_zssqlr4vdonz6o9bj_5ubyfdpra-j04mol_-mizxo6m8oftcgbkjbnfgvxjg4sizkzgxvwkbiwblaoaexqnkaeesyyjbaxmx7z3o4_gay77rqdb4vgktbszsk5qhkmhazrryunu2wmlykpnta_3yyhazzps0crpksrdhlabzbgkglumtl1lbkpsye1xk_9pbneatismsklxuiyvqefwlxwmgzey5gz9qzcr0tv1gvozv6dagqxnvr9t2vb2oynqrr0_wo9bunwpru3sz1oa1_fuukbl5g41cuj2w

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

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -