I have what seems a strange issue, where emails with vastly different email bodies end up with an identical body hash which invariably fail with DKIM result: fail (wrong body hash) [I also get the very same body hash for all variations of the c= signature tag]
Taken from app debugging output: HeaderAndBody (before canonicalisation): Return-Path: <[email protected]> Received: by xxxxx.com for <[email protected]>; Fri, 20 Sep 2013 06:27:50 GMT Message-ID: <[email protected]> Date: Fri, 20 Sep 2013 06:27:50 GMT From: "Postmaster" <[email protected]> To: <[email protected]> Subject: HTMLText-Sep20 X-Mailer: GroupFiO Mailer MIME-Version: 1.0 Content-Type: text/plain; This is a plain text message. HeaderAndBody (before canonicalisation): Return-Path: <[email protected]> Received: by xxxxx.com for <[email protected]>; Fri, 20 Sep 2013 06:27:50 GMT Message-ID: <[email protected]> Date: Fri, 20 Sep 2013 06:27:50 GMT From: "Postmaster" <[email protected]> To: <[email protected]> Subject: HTMLText-Sep20 X-Mailer: GroupFiO Mailer MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-==AGNITASOUTERxxxxx==" ---==AGNITASOUTERxxxxx== Content-Type: text/plain; 1234567890 ---==AGNITASOUTERxxxxx== Content-Type: text/html; <h1>1234567890</h1> ---==AGNITASOUTERxxxxx==-- dkimSignature: [DKIM-Signature: v=1; d=xxxxx.com; b=j1VXaZhwNySRkWj33fVcmjS0VfRZVaWV7s+NeK24HjG22Nzr7GcD/l4J9qpm4CTAYJLO8SIOoKeei2wqfgpWhOlzxN/RaMQAtQLgucZmrXBFD5A5luXcsz4s9yiEyxZ5w0b+w/lEH9rpmBIPw5BZQkVacYjY7cd/tJor08QJjLI=; s=rms; c=simple/relaxed; a=rsa-sha1; bh=uoq1oCgLlTqpdDX/iUbLy7J1Wic=; h=from:subject:date:message-id:to:mime-version:content-type;] dkimSignature: [DKIM-Signature: v=1; d=xxxxx.com; b=Qinz/pK8/yZ8MsKs84ZCk8/b2W+FlyahRCe90YZsoQvJSoU8rNFJJ1YKk1weUcOv4kVxgYwUbWNcucGhIGeMghjUiGH9mbvypsgLV06nHHjaattcotGOEsDQnSgzg1NzB7G8eqU3yfBuz/mxtBPgMm5Nfk2xSPAAylEDfjVJY1I=; s=rms; c=simple/relaxed; a=rsa-sha1; bh=uoq1oCgLlTqpdDX/iUbLy7J1Wic=; h=from:subject:date:message-id:to:mime-version:content-type;] Implementation Code: InputStream is = null; try { is = new EOLConvertingInputStream(headerAndBodyInputStream); } catch (IOException e2) { e2.printStackTrace(); return false; } String dkimSignature = null; try { dkimSignature = buildSigner(getPrivateKey()).sign(is); } catch (UnrecoverableKeyException e1) { e1.printStackTrace(); } catch (KeyStoreException e1) { e1.printStackTrace(); } catch (NoSuchAlgorithmException e1) { e1.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (FailException e) { e.printStackTrace(); } catch (MimeException e) { e.printStackTrace(); }finally{ try { is.close(); } catch (IOException e) { e.printStackTrace(); } } System.out.println("dkimSignature: [" + dkimSignature.trim() + "]"); } private DKIMSigner buildSigner(PrivateKey key) throws PermFailException, IOException, MimeException { String signatureRecordTemplate = SignatureRecordTemplateBuilder.getSignatureRecordTemplate(true); DKIMSigner signer = new DKIMSigner(signatureRecordTemplate, key); return signer; }
