/* * GetPublicKey() * * Get the publickey from supported sources (ie. dns/txt) */ void Validatory::GetPublicKey(const DKIM::Signature& sig, DKIM::PublicKey& pubkey) throw (DKIM::PermanentError, DKIM::TemporaryError) { if (sig.GetQueryType() == DKIM::Signature::DKIM_Q_DNSTXT) { std::string query = sig.GetSelector() + "._domainkey." + sig.GetDomain(); std::string publicKey; if ((CustomDNSResolver? CustomDNSResolver(query, publicKey, CustomDNSData): DKIM::Util::Resolver().GetTXT(query, publicKey) )) { if (publicKey.empty()) throw DKIM::PermanentError(StringFormat("No key for signature %s._domainkey.%s", sig.GetSelector().c_str(), sig.GetDomain().c_str() ) ); pubkey.Parse(publicKey); return; } throw DKIM::TemporaryError(StringFormat("DNS query failed for %s._domainkey.%s", sig.GetSelector().c_str(), sig.GetDomain().c_str() ) ); } throw DKIM::PermanentError(StringFormat("Unsupported query type %d", (int)sig.GetQueryType() ) ); }
void _SignMailTest(const SignatoryOptions& options, const std::string& mail) { std::string head; std::stringstream fp; std::stringstream fp2; std::string DKIMPublicKey = "v=DKIM1; p=" DKIM_PUBLICKEY "; t=s"; fp.str(mail); CPPUNIT_ASSERT_NO_THROW ( head = Signatory(fp).CreateSignature(options) ); fp2.str(head + "\r\n" + mail); Validatory myValidatory(fp2); const Validatory::SignatureList& siglist = myValidatory.GetSignatures(); CPPUNIT_ASSERT ( siglist.size() == 1 ); DKIM::Signature sig; CPPUNIT_ASSERT_NO_THROW ( myValidatory.GetSignature(siglist.begin(), sig) ); DKIM::PublicKey pub; CPPUNIT_ASSERT_NO_THROW ( pub.Parse(DKIMPublicKey) ); CPPUNIT_ASSERT_NO_THROW ( myValidatory.CheckSignature(siglist.begin(), sig, pub) ); CPPUNIT_ASSERT_NO_THROW ( myValidatory.CheckSignature(*(siglist.begin()), sig, pub) ); }