DKIMVerifier extends DKIMCommon { public static void apply(PublicKeyRecord pkr, SignatureRecord sign) throws PermFailException { try { if (!pkr.getGranularityPattern().matcher(sign.getIdentityLocalPart()) .matches()) { throw new PermFailException("inapplicable key identity local=" + sign.getIdentityLocalPart() + " Pattern: " + pkr.getGranularityPattern().pattern(), sign.getIdentity().toString()); } if (!pkr.isHashMethodSupported(sign.getHashMethod())) { throw new PermFailException("inappropriate hash for a=" + sign.getHashKeyType() + "/" + sign.getHashMethod(), sign.getIdentity().toString()); } if (!pkr.isKeyTypeSupported(sign.getHashKeyType())) { throw new PermFailException("inappropriate key type for a=" + sign.getHashKeyType() + "/" + sign.getHashMethod(), sign.getIdentity().toString()); } if (pkr.isDenySubdomains()) { if (!sign.getIdentity().toString().toLowerCase().endsWith( ("@" + sign.getDToken()).toLowerCase())) { throw new PermFailException( "AUID in subdomain of SDID is not allowed by the public key record.", sign.getIdentity().toString()); } } } catch (IllegalStateException e) { throw new PermFailException("Invalid public key: " + e.getMessage(), sign.getIdentity().toString()); } } DKIMVerifier();  DKIMVerifier(PublicKeyRecordRetriever publicKeyRecordRetriever); SignatureRecord newSignatureRecord(String record); PublicKeyRecord publicKeySelector(List<String> records); static void apply(PublicKeyRecord pkr, SignatureRecord sign); PublicKeyRecord publicRecordLookup(SignatureRecord sign); List<SignatureRecord> verify(InputStream is); BodyHasher newBodyHasher(Headers messageHeaders); List<SignatureRecord> verify(Headers messageHeaders,
                                        InputStream bodyInputStream); List<SignatureRecord> verify(BodyHasher bh);  }
@Test public void testApply() throws PermFailException { PublicKeyRecord pkr = new PublicKeyRecordImpl( "k=rsa; t=y; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIhyR3oItOy22ZOaBrIVe9m/iME3RqOJeasANSpg2YTHTYV+Xtp4xwf5gTjCmHQEMOs0qYu0FYiNQPQogJ2t0Mfx9zNu06rfRBDjiIU9tpx2T+NGlWZ8qhbiLo5By8apJavLyqTLavyPSrvsx0B3YzC63T4Age2CDqZYA+OwSMWQIDAQAB"); pkr.validate(); DKIMVerifier .apply( pkr, new SignatureRecordImpl( "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject:from:to:content-type; bh=AbPsrGRdyVjM2e5ZZdhQA/aLe305f2bPvPRohUxrGjo=; b=ksNsfQJv20M9/Vf66sMJT1WHM/fUfcqli1NfkyxSOjr8jlNTH4JNCGacb2neWuwMN4C4TFXqMR8BENkn+XrCV1FjrlW1mCxlLDilVypP/uqqq04KzJpVyJG6zZLd/0DeknSLN6sDGKdCvIdS+YpHEhUxoEuf6QizCs8PTXhnJiA=")); try { DKIMVerifier .apply( pkr, new SignatureRecordImpl( "v=1; a=dsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject:from:to:content-type; bh=AbPsrGRdyVjM2e5ZZdhQA/aLe305f2bPvPRohUxrGjo=; b=ksNsfQJv20M9/Vf66sMJT1WHM/fUfcqli1NfkyxSOjr8jlNTH4JNCGacb2neWuwMN4C4TFXqMR8BENkn+XrCV1FjrlW1mCxlLDilVypP/uqqq04KzJpVyJG6zZLd/0DeknSLN6sDGKdCvIdS+YpHEhUxoEuf6QizCs8PTXhnJiA=")); fail("This is not a signature for that key"); } catch (PermFailException e) { } pkr = new PublicKeyRecordImpl( "k=rsa; t=y:s; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIhyR3oItOy22ZOaBrIVe9m/iME3RqOJeasANSpg2YTHTYV+Xtp4xwf5gTjCmHQEMOs0qYu0FYiNQPQogJ2t0Mfx9zNu06rfRBDjiIU9tpx2T+NGlWZ8qhbiLo5By8apJavLyqTLavyPSrvsx0B3YzC63T4Age2CDqZYA+OwSMWQIDAQAB"); pkr.validate(); DKIMVerifier .apply( pkr, new SignatureRecordImpl( "v=1; a=rsa-sha256; c=relaxed/relaxed; i=test@gmail.com; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject:from:to:content-type; bh=AbPsrGRdyVjM2e5ZZdhQA/aLe305f2bPvPRohUxrGjo=; b=ksNsfQJv20M9/Vf66sMJT1WHM/fUfcqli1NfkyxSOjr8jlNTH4JNCGacb2neWuwMN4C4TFXqMR8BENkn+XrCV1FjrlW1mCxlLDilVypP/uqqq04KzJpVyJG6zZLd/0DeknSLN6sDGKdCvIdS+YpHEhUxoEuf6QizCs8PTXhnJiA=")); try { DKIMVerifier .apply( pkr, new SignatureRecordImpl( "v=1; a=rsa-sha256; c=relaxed/relaxed; i=test@subdomain.gmail.com; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject:from:to:content-type; bh=AbPsrGRdyVjM2e5ZZdhQA/aLe305f2bPvPRohUxrGjo=; b=ksNsfQJv20M9/Vf66sMJT1WHM/fUfcqli1NfkyxSOjr8jlNTH4JNCGacb2neWuwMN4C4TFXqMR8BENkn+XrCV1FjrlW1mCxlLDilVypP/uqqq04KzJpVyJG6zZLd/0DeknSLN6sDGKdCvIdS+YpHEhUxoEuf6QizCs8PTXhnJiA=")); fail("This is not a signature for that key"); } catch (PermFailException e) { } pkr = new PublicKeyRecordImpl( "k=rsa; g=test*; t=y; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIhyR3oItOy22ZOaBrIVe9m/iME3RqOJeasANSpg2YTHTYV+Xtp4xwf5gTjCmHQEMOs0qYu0FYiNQPQogJ2t0Mfx9zNu06rfRBDjiIU9tpx2T+NGlWZ8qhbiLo5By8apJavLyqTLavyPSrvsx0B3YzC63T4Age2CDqZYA+OwSMWQIDAQAB"); pkr.validate(); DKIMVerifier .apply( pkr, new SignatureRecordImpl( "v=1; a=rsa-sha256; c=relaxed/relaxed; i=test@gmail.com; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject:from:to:content-type; bh=AbPsrGRdyVjM2e5ZZdhQA/aLe305f2bPvPRohUxrGjo=; b=ksNsfQJv20M9/Vf66sMJT1WHM/fUfcqli1NfkyxSOjr8jlNTH4JNCGacb2neWuwMN4C4TFXqMR8BENkn+XrCV1FjrlW1mCxlLDilVypP/uqqq04KzJpVyJG6zZLd/0DeknSLN6sDGKdCvIdS+YpHEhUxoEuf6QizCs8PTXhnJiA=")); try { DKIMVerifier .apply( pkr, new SignatureRecordImpl( "v=1; a=rsa-sha256; c=relaxed/relaxed; i=bad@subdomain.gmail.com; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject:from:to:content-type; bh=AbPsrGRdyVjM2e5ZZdhQA/aLe305f2bPvPRohUxrGjo=; b=ksNsfQJv20M9/Vf66sMJT1WHM/fUfcqli1NfkyxSOjr8jlNTH4JNCGacb2neWuwMN4C4TFXqMR8BENkn+XrCV1FjrlW1mCxlLDilVypP/uqqq04KzJpVyJG6zZLd/0DeknSLN6sDGKdCvIdS+YpHEhUxoEuf6QizCs8PTXhnJiA=")); fail("This is not a signature for that key"); } catch (PermFailException e) { } pkr = new PublicKeyRecordImpl( "k=rsa; g=test*; t=y; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIhyR3oItOy22ZOaBrIVe9m/iME3RqOJeasANSpg2YTHTYV+Xtp4xwf5gTjCmHQEMOs0qYu0FYiNQPQogJ2t0Mfx9zNu06rfRBDjiIU9tpx2T+NGlWZ8qhbiLo5By8apJavLyqTLavyPSrvsx0B3YzC63T4Age2CDqZYA+OwSMWQIDAQAB"); pkr.validate(); pkr = new PublicKeyRecordImpl( "k=rsa; h=sha1; t=y; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDIhyR3oItOy22ZOaBrIVe9m/iME3RqOJeasANSpg2YTHTYV+Xtp4xwf5gTjCmHQEMOs0qYu0FYiNQPQogJ2t0Mfx9zNu06rfRBDjiIU9tpx2T+NGlWZ8qhbiLo5By8apJavLyqTLavyPSrvsx0B3YzC63T4Age2CDqZYA+OwSMWQIDAQAB"); pkr.validate(); try { DKIMVerifier .apply( pkr, new SignatureRecordImpl( "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject:from:to:content-type; bh=AbPsrGRdyVjM2e5ZZdhQA/aLe305f2bPvPRohUxrGjo=; b=ksNsfQJv20M9/Vf66sMJT1WHM/fUfcqli1NfkyxSOjr8jlNTH4JNCGacb2neWuwMN4C4TFXqMR8BENkn+XrCV1FjrlW1mCxlLDilVypP/uqqq04KzJpVyJG6zZLd/0DeknSLN6sDGKdCvIdS+YpHEhUxoEuf6QizCs8PTXhnJiA=")); fail("This hash method is not supported for that publick key"); } catch (PermFailException e) { } }