You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by Justin Robinson <dk...@fluidnotions.com> on 2013/09/24 21:03:18 UTC

BUG: apache-jdkim-0.2 2 content-type: multipart/* emails cause java.lang.ClassCastException

The reason (see original email bellow) for this seems to be because the
code in  org.apache.james.jdkim.DKIMSigner line 85
DKIMCommon.streamCopy(message.getBodyInputStream(), bhj..getOutputStream());

when run on a multipart produces the exception (I added a try/catch -
throwable):

java.lang.ClassCastException: org.apache.james.mime4j.message.MultipartImpl
cannot be cast to org.apache.james.mime4j.dom.SingleBody
at org.apache.james.jdkim.impl.Message.getBodyInputStream(Message.java:80)
at org.apache.james.jdkim.DKIMSigner.sign(DKIMSigner.java:85)

leading to the message.getBodyInputStream() parameter of
org.apache.james.jdkim.DKIMCommon.streamCopy(InputStream, OutputStream)
being entirely empty, hence the identical body hash for every message.

On Tue, Sep 24, 2013 at 6:02 PM, Justin Robinson <
dkim-project@fluidnotions.com> wrote:

> 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: <po...@xxxxx.com>
> Received: by xxxxx.com for <aa...@appmaildev.com>; Fri, 20 Sep
> 2013 06:27:50 GMT
> Message-ID: <20...@xxxxx.com>
> Date: Fri, 20 Sep 2013 06:27:50 GMT
> From: "Postmaster" <po...@xxxxx.com>
> To: <aa...@appmaildev.com>
> 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: <po...@xxxxx.com>
> Received: by xxxxx.com for <aa...@appmaildev.com>; Fri, 20 Sep
> 2013 06:27:50 GMT
> Message-ID: <20...@xxxxx.com>
> Date: Fri, 20 Sep 2013 06:27:50 GMT
> From: "Postmaster" <po...@xxxxx.com>
> To: <aa...@appmaildev.com>
> 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;
>
> }
>