Return-Path: X-Original-To: apmail-couchdb-user-archive@www.apache.org Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 88B2291EA for ; Tue, 27 Sep 2011 17:32:37 +0000 (UTC) Received: (qmail 82318 invoked by uid 500); 27 Sep 2011 17:32:35 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 82266 invoked by uid 500); 27 Sep 2011 17:32:35 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 82257 invoked by uid 99); 27 Sep 2011 17:32:35 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Sep 2011 17:32:35 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,NORMAL_HTTP_TO_IP,RCVD_IN_DNSWL_LOW,SPF_PASS,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of mpost@eclipsesource.com designates 209.85.160.180 as permitted sender) Received: from [209.85.160.180] (HELO mail-gy0-f180.google.com) (209.85.160.180) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 27 Sep 2011 17:32:29 +0000 Received: by gyd8 with SMTP id 8so8366555gyd.11 for ; Tue, 27 Sep 2011 10:32:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=eclipsesource.com; s=eclipsesource; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=eV6TtI3msDoTM+vxgipVF59NVZccqVmsZAs0pRMi/nI=; b=DF6hWlg5h4ocni0mcbpujjOZzM321zDovLwLT/gs0qf6HwpNZ2lnHVkwfRWUYniuOx oI701WdTuXnzWTxQ/0cn3pked1RR+ArV9DY5Qt7k3mkFwLbFkLBoWxiBmAcF3LncdGg0 LNZ6w1pv5MEaHd5jc+By+oNFxdLjOKCapTgUM= MIME-Version: 1.0 Received: by 10.150.99.16 with SMTP id w16mr8157883ybb.261.1317144727869; Tue, 27 Sep 2011 10:32:07 -0700 (PDT) Received: by 10.150.185.6 with HTTP; Tue, 27 Sep 2011 10:32:07 -0700 (PDT) In-Reply-To: References: Date: Tue, 27 Sep 2011 19:32:07 +0200 Message-ID: Subject: Re: Create Content-MD5 hash From: Moritz Post To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=000e0cd289aa9f5b5104adefa78c X-Virus-Checked: Checked by ClamAV on apache.org --000e0cd289aa9f5b5104adefa78c Content-Type: text/plain; charset=ISO-8859-1 Hi Robert No problem. The issue has been solved. So how about validating newly created documents? Greets Moritz On Tue, Sep 27, 2011 at 5:52 PM, Robert Newson wrote: > Heh, I totally missed that you hadn't converted to hex in the middle, > sorry. > > On 27 September 2011 16:18, Moritz Post wrote: > > Hi Keith > > > > Thanks for the hint. I have actually applied it onto a java > implementation > > of the hash generation and it produced a correct hash value. Here is my > > implementation: > > > > MessageDigest md5 = MessageDigest.getInstance("MD5"); > > byte[] digest = md5.digest("{ \"valid\": \"json\" }".getBytes()); > > byte[] hash = Base64.encodeBase64(digest); > > System.out.println(new String(hash)); > > > > Output: S/OqwXHe0WedNQHMvT4NhQ== > > > > It uses Base64 from the apache commons project. I have used that has > value > > > > Now onto my final question: can i also validated the content of a couchdb > > document i create by uploading a json document? > > > > Regards > > Moritz Post > > > > On Tue, Sep 27, 2011 at 4:57 PM, Keith Gable >wrote: > > > >> According to RFC2616 ( > >> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html), > >> section 14.15, you need the Base64 encoding of the actual MD5 bits, not > the > >> base64 encoding of the hex encoding of MD5 bits. > >> > >> In Ruby, after you require the base64 and digest/md5 libraries, you can > >> generate a Base64 of the raw bits by doing this: > >> > >> Base64.encode64(Digest::MD5.digest(your_file_iostream)) > >> > >> > >> Hope that helps. > >> > >> --- > >> Keith Gable > >> A+ Certified Professional > >> Network+ Certified Professional > >> Web Developer > >> > >> > >> > >> On Tue, Sep 27, 2011 at 9:47 AM, Moritz Post >> >wrote: > >> > >> > Hi Robert > >> > > >> > Thanks for the reply. Using -n does produce a different echo output > but > >> it > >> > does not produce a hash consumable by the couchdb: > >> > > >> > $ echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64 > >> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODU= > >> > > >> > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64 > >> > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK > >> > > >> > Using the hash with the = at the end i still get the response: > >> > {"error":"content_md5_mismatch","reason":"Possible message > corruption."} > >> > > >> > Greets > >> > Moritz > >> > > >> > On Tue, Sep 27, 2011 at 4:19 PM, Robert Newson > >> wrote: > >> > > >> > > try > >> > > > >> > > echo -n 4bf3aac171ded1679d3501ccbd3e0d85 | base64 > >> > > > >> > > as echo includes a new line unless you use -n. > >> > > > >> > > B. > >> > > > >> > > On 27 September 2011 14:29, Moritz Post > >> wrote: > >> > > > Hallo CouchDB > >> > > > > >> > > > I am trying to validate the integrity of data i upload to the > >> couchdb. > >> > > > Therefore i provide a valid MD5 hash alongside my PUT request. > From > >> > what > >> > > i > >> > > > have gathered this md5 has to be base64 encoded. My problem is > that i > >> > am > >> > > not > >> > > > able to create a valid hash. All i get is: > >> > > > > >> > > > {"error":"content_md5_mismatch","reason":"Possible message > >> > corruption."} > >> > > > > >> > > > I am currently experimenting with a CURL based approach but will > need > >> > > > to incorporate the hash creation into a java program later. Here > is > >> > what > >> > > is > >> > > > did do create the md5 hash: > >> > > > > >> > > > $ md5sum test.json > >> > > > 4bf3aac171ded1679d3501ccbd3e0d85 test.json > >> > > > $ echo 4bf3aac171ded1679d3501ccbd3e0d85 | base64 > >> > > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK > >> > > > > >> > > > So i have a hash value and now use it in my PUT request (verbose > >> > output): > >> > > > > >> > > > $ curl -X PUT -H "Content-MD5: > >> > > NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK" > >> > > > -H "Content-Type: application/json" -v -d @test.json > >> > > > > >> > > > >> > > >> > http://localhost:5984/test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb > >> > > > * About to connect() to 192.168.6.168 port 5984 (#0) > >> > > > * Trying 192.168.6.168... connected > >> > > > * Connected to 192.168.6.168 (192.168.6.168) port 5984 (#0) > >> > > > * Server auth using Basic with user 'admin' > >> > > >> PUT /test/doc/test.json?rev=3-dd5bf35d8e95a0ccc5e2a1e0adf26ffb > >> > HTTP/1.1 > >> > > >> User-Agent: curl/7.21.3 (i686-pc-linux-gnu) libcurl/7.21.3 > >> > > OpenSSL/0.9.8o > >> > > > zlib/1.2.3.4 libidn/1.18 > >> > > >> Host: 192.168.6.168:5984 > >> > > >> Accept: */* > >> > > >> Content-MD5: NGJmM2FhYzE3MWRlZDE2NzlkMzUwMWNjYmQzZTBkODUK > >> > > >> Content-Type: application/json > >> > > >> Content-Length: 19 > >> > > >> > >> > > > < HTTP/1.1 400 Bad Request > >> > > > < Server: CouchDB/1.0.2 (Erlang OTP/R14B) > >> > > > < Date: Tue, 27 Sep 2011 13:23:38 GMT > >> > > > < Content-Type: text/plain;charset=utf-8 > >> > > > < Content-Length: 73 > >> > > > < Cache-Control: must-revalidate > >> > > > < > >> > > > {"error":"content_md5_mismatch","reason":"Possible message > >> > corruption."} > >> > > > * Connection #0 to host 192.168.6.168 left intact > >> > > > * Closing connection #0 > >> > > > > >> > > > I am running a couchdb 1.0.3. > >> > > > > >> > > > The question is: how to properly create a md5 hash that validates > the > >> > > > upload. > >> > > > > >> > > > Additionally i would like to know if it is only possible to > validated > >> > > > attachment uploads or is it also possible to validated the > uploaded > >> > json > >> > > > documents one creates in the couchdb? > >> > > > > >> > > > Thank you > >> > > > Moritz Post > >> > > > > >> > > > -- > >> > > > ----------------------------------- > >> > > > Moritz Post > >> > > > EclipseSource > >> > > > Email: mpost@eclipsesource.com > >> > > > Tel: +49-721-66-47-33-33 > >> > > > Fax: +49-721-66-47-33-29 > >> > > > http://www.eclipsesource.com/ > >> > > > ========================= Legal Disclaimer > >> > > ================================= > >> > > > According to Section 80 of the German Corporation Act > >> > > > Innoopract Informationssysteme GmbH must indicate the following > >> > > information: > >> > > > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany > >> > > > General Manager: Jochen Krause > >> > > > Registered Office: Commercial Register Mannheim HRB 107883 > >> > > > > >> > > > >> > > >> > ============================================================================ > >> > > > > >> > > > >> > > >> > > >> > > >> > -- > >> > ----------------------------------- > >> > Moritz Post > >> > EclipseSource > >> > Email: mpost@eclipsesource.com > >> > Tel: +49-721-66-47-33-33 > >> > Fax: +49-721-66-47-33-29 > >> > http://www.eclipsesource.com/ > >> > ========================= Legal Disclaimer > >> > ================================= > >> > According to Section 80 of the German Corporation Act > >> > Innoopract Informationssysteme GmbH must indicate the following > >> > information: > >> > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany > >> > General Manager: Jochen Krause > >> > Registered Office: Commercial Register Mannheim HRB 107883 > >> > > >> > > >> > ============================================================================ > >> > > >> > > > > > > > > -- > > ----------------------------------- > > Moritz Post > > EclipseSource > > Email: mpost@eclipsesource.com > > Tel: +49-721-66-47-33-33 > > Fax: +49-721-66-47-33-29 > > http://www.eclipsesource.com/ > > ========================= Legal Disclaimer > ================================= > > According to Section 80 of the German Corporation Act > > Innoopract Informationssysteme GmbH must indicate the following > information: > > Address: Stephanienstrasse 20, 76133 Karlsruhe Germany > > General Manager: Jochen Krause > > Registered Office: Commercial Register Mannheim HRB 107883 > > > ============================================================================ > > > -- ----------------------------------- Moritz Post EclipseSource Email: mpost@eclipsesource.com Tel: +49-721-66-47-33-33 Fax: +49-721-66-47-33-29 http://www.eclipsesource.com/ ========================= Legal Disclaimer ================================= According to Section 80 of the German Corporation Act Innoopract Informationssysteme GmbH must indicate the following information: Address: Stephanienstrasse 20, 76133 Karlsruhe Germany General Manager: Jochen Krause Registered Office: Commercial Register Mannheim HRB 107883 ============================================================================ --000e0cd289aa9f5b5104adefa78c--