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 5E9377371 for ; Wed, 28 Sep 2011 08:30:27 +0000 (UTC) Received: (qmail 78713 invoked by uid 500); 28 Sep 2011 08:30:25 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 78667 invoked by uid 500); 28 Sep 2011 08:30:25 -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 78657 invoked by uid 99); 28 Sep 2011 08:30:25 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Sep 2011 08:30:25 +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 (athena.apache.org: domain of mpost@eclipsesource.com designates 209.85.218.52 as permitted sender) Received: from [209.85.218.52] (HELO mail-yi0-f52.google.com) (209.85.218.52) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Sep 2011 08:30:21 +0000 Received: by yie30 with SMTP id 30so9240558yie.11 for ; Wed, 28 Sep 2011 01:30:00 -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=hBMWhQ0++pREMVv315rzIozWBRUfgKoKJQvXpPvAFZE=; b=MiQVDZSRAAlwF1h7oplGudFJ/Yx30fqlysR/WTjcoVcE77zXzJ/JWyBW9m+nWjmXpi XW+g8XXbIUj+BJfG9gCRZyamBCLPc8gF3mBiCOLPvqNsHpqW5qXe4ENApUQ/gTYyvhh0 5+A8+9sKqpPgEH/grG3BQT39a3PwKFHdzKhec= MIME-Version: 1.0 Received: by 10.150.169.3 with SMTP id r3mr995390ybe.318.1317198599791; Wed, 28 Sep 2011 01:29:59 -0700 (PDT) Received: by 10.150.185.6 with HTTP; Wed, 28 Sep 2011 01:29:59 -0700 (PDT) In-Reply-To: References: Date: Wed, 28 Sep 2011 10:29:59 +0200 Message-ID: Subject: Re: Create Content-MD5 hash From: Moritz Post To: user@couchdb.apache.org Content-Type: multipart/alternative; boundary=000e0cd56cd6a3a7c804adfc3271 --000e0cd56cd6a3a7c804adfc3271 Content-Type: text/plain; charset=ISO-8859-1 Hi Robert Ok, thanks for clarifying. Regards Moritz Post On Wed, Sep 28, 2011 at 12:00 AM, Robert Newson wrote: > I'm pretty sure MD5 verification is only available for standalone > attachments right now. > > B. > > On 27 September 2011 18:32, Moritz Post wrote: > > 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 < > ziggy@ignition-project.com > >> >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 < > mpost@eclipsesource.com > >> >> >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 > > > ============================================================================ > > > -- ----------------------------------- 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 ============================================================================ --000e0cd56cd6a3a7c804adfc3271--