From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 392A4BC57 for ; Thu, 13 May 2010 00:26:41 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApACANfH6kvRVdS0kGdsb2JhbACeHwgVAQEBAQkJDAcRAx+tFIIAhScuiE4BAQMFglyCMQQ X-IronPort-AV: E=Sophos;i="4.53,217,1272837600"; d="scan'208";a="62773009" Received: from mail-px0-f180.google.com ([209.85.212.180]) by mail4-smtp-sop.national.inria.fr with ESMTP; 13 May 2010 00:26:40 +0200 Received: by pxi17 with SMTP id 17so292408pxi.39 for ; Wed, 12 May 2010 15:26:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=k9D5L87Z1MkkZrDYUJF3OoFcP3WgAbmKOcpEN6F3dWc=; b=X2xd4nbhHJ2r84mcIknwKBSTS+/jufihvyRDB4SYexiE02ZT8Wr3n3kOpX5/P0BOdv gA8uwYw7ThODCPerpD5u2Ux/0UYVWd6jtS9SxI/4Sz9O8fJLJGazFpsPeKK7uohNUkBU lkJukiEkM7Mo01fIx86ihwNfZYETkbcJXwvN8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=FIxav3XIbtJ4jAZbzlu+YyDuwadZi51hZhKQ7NENZFYvMorVdvxIe0b12cqELNCbCt vYcQDBxnAq0RQnjN7tHgSWOtjSjswX4iERMJ2oqQ1XRxzqysLA9MAEQ2GIuSwXfMiFCo Yw2DUYtYuvFHuS5qCBwx6rG7UsBmTzjFJZ4X8= MIME-Version: 1.0 Received: by 10.142.152.34 with SMTP id z34mr5866102wfd.176.1273703199034; Wed, 12 May 2010 15:26:39 -0700 (PDT) Received: by 10.142.173.10 with HTTP; Wed, 12 May 2010 15:26:39 -0700 (PDT) Date: Wed, 12 May 2010 18:26:39 -0400 Message-ID: Subject: OCaml S3 Library? From: Daniel Patterson To: caml-list@yquem.inria.fr Content-Type: multipart/alternative; boundary=000e0cd2e44aba4c1f04866d220c X-Spam: no; 0.00; ocaml:01 netencoding:01 hash:01 printf:01 printf:01 hash:01 verbose:01 verbose:01 netencoding:01 req:98 req:98 unix:01 unix:01 cryptokit:01 cryptokit:01 --000e0cd2e44aba4c1f04866d220c Content-Type: text/plain; charset=ISO-8859-1 Has anyone written a library to interact with amazon web services (specifically, S3)? I started writing one, but something about the authentication is not working properly, and I thought I'd check to see if anyone had already done this before I try to figure out what is going wrong. Sample code follows, as if there does not already exist a library, I'd be curious if anyone else sees what is wrong with the authentication signature (what I assume is not working), as now it 403's every time. open Netencoding.Base64 open Cryptokit open Cryptokit.MAC open Http_client let id = "___PUT_YOUR_ID_HERE____" let key = "__PUT_YOUR_SECRET_KEY_HERE____" let sign verb content_type date bucket url = let hash = hmac_sha1 key in let str_to_sign = verb ^ "\n\n" ^ content_type ^ "\n" ^ date ^ "\n" ^ "/" ^ bucket ^ url in begin Printf.printf "---------\n%s\n---------\n" str_to_sign; "AWS " ^ id ^ ":" ^ encode (hash_string hash str_to_sign) end let date () = Netdate.mk_mail_date (Unix.time ()) let text_put_s3 bucket url contents = let uri = "http://" ^ bucket ^ ".s3.amazonaws.com" ^ url in let req = new put uri contents in let head = req#request_header `Base in let content_type = "text/plain" in let now = date () in let pipeline = new pipeline in begin pipeline#set_options {pipeline#get_options with verbose_status=true; verbose_request_header=true; verbose_response_header=true; verbose_request_contents=true; verbose_response_contents=true; verbose_connection=true}; head#set_fields [("Date", now); ("Content-Type", content_type); ("Authentication", sign "PUT" content_type now bucket url)]; req#set_request_header head; pipeline#add req; pipeline#run (); (req#response_status_code, req#response_status_text) end let _ = text_put_s3 "__BUCKET_NAME__" "/test" "This is a Test." --000e0cd2e44aba4c1f04866d220c Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Has anyone written a library to interact with amazon web services (specific= ally, S3)?=A0

I started writing one, but something about= the authentication is not working properly, and I thought I'd check to= see if anyone had already done this before I try to figure out what is goi= ng wrong. Sample code follows, as if there does not already exist a library= , I'd be curious if anyone else sees what is wrong with the authenticat= ion signature (what I assume is not working), as now it 403's every tim= e.

open Netencoding.Base64
open Cryptokit
open Cryptokit.MAC
open Http_client

=
let id =3D "___PUT_YOUR_ID_HERE____"
let key =3D &= quot;__PUT_YOUR_SECRET_KEY_HERE____"

let sign verb content_type date bucket url =3D=A0
=
=A0=A0let hash =3D hmac_sha1 key in
=A0=A0let str_to_sign = =3D verb ^ "\n\n" ^ content_type ^ "\n" ^ =A0date ^ &qu= ot;\n" ^ =A0"/" ^ bucket ^ url =A0in
=A0=A0 =A0begin
=A0=A0 =A0 =A0Printf.printf "---------\= n%s\n---------\n" str_to_sign;
=A0=A0 =A0 =A0"AWS "= ; ^ id ^ ":" ^ encode (hash_string hash str_to_sign)
= =A0=A0 =A0end

let date () =3D Netdate.mk_mail_date (Unix.time ())
let text_put_s3 bucket url contents =3D=A0
=A0=A0let= uri =3D "http://" ^ bucket ^ ".s3.amazonaws.com" ^ url in
=A0=A0let req =3D new put uri contents in
=A0=A0let head =3D= req#request_header `Base in
=A0=A0let content_type =3D "tex= t/plain" in
=A0=A0let now =3D date () in
=A0=A0let= pipeline =3D new pipeline in
=A0=A0 =A0begin
=A0=A0 =A0 =A0pipeline#set_options {pipeline= #get_options with verbose_status=3Dtrue; verbose_request_header=3Dtrue; ver= bose_response_header=3Dtrue;=A0
=A0=A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0verbose_request_contents=3Dt= rue; verbose_response_contents=3Dtrue; verbose_connection=3Dtrue};
=A0=A0 =A0 =A0head#set_fields [("Date", now); ("Content= -Type", content_type); ("Authentication", sign "PUT&quo= t; content_type now bucket url)];
=A0=A0 =A0 =A0req#set_request_h= eader head;
=A0=A0 =A0 =A0pipeline#add req;
=A0=A0 =A0 =A0pipeline#run (= );
=A0=A0 =A0 =A0(req#response_status_code, req#response_status_t= ext)
=A0=A0 =A0end

let _ =3D text_= put_s3 "__BUCKET_NAME__" "/test" "This is a Test.&= quot;
--000e0cd2e44aba4c1f04866d220c--