google-cloud-php icon indicating copy to clipboard operation
google-cloud-php copied to clipboard

$StorageObject->signedUrl($expired) results in SignatureDoesNotMatch

Open YarmoM opened this issue 9 years ago • 4 comments

ENVIRONMENT Windows 10 PHP -v 7.1.2 (cli)

BUG Get all the objects in the bucket, iterate over them and generate signed urls

$objects = $bucket->objects();
foreach ($objects as $object) {
  $url = $object->signedUrl($timestamp_expiration);
}

For testing purposes, I put a file in the root of the bucket. For this one file, $url returns:

https://storage.googleapis.com/some_notebook/some_file.html?GoogleAccessId=some-id@some-service-account.iam.gserviceaccount.com&Expires=1500715006&Signature=qbAro7pRtQ%2BQbS8Zz%2FAuBnREcl6G4oMMwPMKV0xe0rGv3VlDcy42zXPAdTePJ9rq6IPaL%2BUg5KAokTGt6NZHFIVT47p1eUkIigvWdlsCuCoCrJWHjRUuh3akLE0PeBEWK52xXA28BWMC1POqjRKxEMUH0jazy6rgapaX4mfTN9nhIgK01lFGknRVhOKteGgL9x3uNNvuI4EwiAwkoww2Tx3aa0Ul8XzsRWockWK1Ekrq250WlTZ%2BqgGXvUuRZqE46OFauESG9UjsYocQ5oiNeQMCLDwNYzGE5wjTO4oDdV5%2B0p8eODZ0M8DnlMm1d2cIj4p1BUBPBGzGW2896tritjA%3D%3D&generation=1499850986997638

As the URL is being generated, I assume everything related to the Service Account registration is successful. However, going to this url returns the following XML:

<Error>
  <script/>
  <Code>SignatureDoesNotMatch</Code>
  <Message>
    The request signature we calculated does not match the signature you provided. Check your Google 
    secret key and signing method.
  </Message>
  <StringToSign>GET 1500715006 /some_notebook/some_file.html</StringToSign>
</Error>

Debugging the source code reveals that $string (StorageObject.php, line 792) is largely similar to the StringToSign in the XML response (except that the spaces are replaced by newlines). $signature (StorageObject.php, line 793) is a string filled with non-displayable characters: I don't know if this is expected behavior, but it's the only thing I found that seemed out of the ordinary.

I have had this problem for two days, been relentlessly searching Google and SO, no solution.

Thank you, Yarmo

YarmoM avatar Jul 12 '17 09:07 YarmoM

Thanks for the report @YarmoM! We'll look into this today.

dwsupplee avatar Jul 12 '17 14:07 dwsupplee

Hey @YarmoM, I just opened a PR to fix this. Please take a look and let me know if that does the trick!

jdpedrie avatar Jul 12 '17 17:07 jdpedrie

Thanks @jdpedrie, changing PHP_EOL to \n solved the issue, looking forward to the next release ;)

YarmoM avatar Jul 12 '17 18:07 YarmoM

@YarmoM we have just published a release containing the bug fix: https://github.com/GoogleCloudPlatform/google-cloud-php/releases/tag/v0.34.1

dwsupplee avatar Jul 12 '17 18:07 dwsupplee