S3 Query String Authentication Generator
I was trying out a feature of S3, called query string authentication today. It basically means that you can access a file on S3 that wouldn’t normally be accessible to the public by providing s3 with a cocktail of encrypted information so it can decide that it’s you (or someone you allowed to use the file).
Or, more accurately, I was trying too. You see, to access it like that you need to generate a certificate, which is really complicated. I couldn’t find anything on the developer website documenting this. So, naturally, I made my own.
I should note at this point that I took one that wasn’t working and fixed it, made sure it didn’t send my details anywhere, and added a bit of authentication and security to it.
The new script will take your information, and form a perfect URL for accessing any file you can find on your S3 account. It requires your S3 public and private keys, though - that’s how you encrypt the information you send. In essence, you access the script like this:
s3querystringauthentication.php?key=key&path=directory/anotherdir/filename
Where the key is a predefined checkword you put into the script so it doesn’t just generate for anyone, and path is the relative address to the file inside your bucket. For instance, my file is gsp.s3.amazonaws.com/directory/file.jpg. The path is directory/file.jpg.
And it gives you a link that you can use to access it. And that link expires after about a year (modifyable in the script). I made it so I could give clients access to their work while it was still safe online.
Okay, onwards. To configure the script, you open it up, edit the two s3 key values near the top, set the authentication key to whatever you want (right at the top) and input your bucket name. Then you’re ready to go, load it on any php server* and it’ll run.
* - The server must be able to run hash_hmac. You should ask your host about this.
Some Important Notes:
This script is released under the GNU GPL license. I’m not liable for anything that happens either directly or indirectly because of it’s use, but look at it this way- I use it for my work.
You should store the script somewhere that the general public won’t see it, or are unlikely to go. LIke yourdomain/589523478092/adjdsalfkf/3824935/somename.php . Just in case :)
If you have any problems, hit the contact button on this site, and I’ll do my best to help out.