Skip to content

Commit

Permalink
fixed bug in the sorting of the results of multiple DKIM signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
lieser committed Mar 21, 2015
1 parent 28c1a0b commit 1604c03
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
11 changes: 5 additions & 6 deletions modules/dkimPolicy.jsm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* dkimPolicy.jsm
*
* Version: 1.2.1 (10 December 2014)
* Version: 1.2.2 (21 March 2015)
*
* Copyright (c) 2013-2014 Philippe Lieser
* Copyright (c) 2013-2015 Philippe Lieser
*
* This software is licensed under the terms of the MIT License.
*
Expand All @@ -19,7 +19,7 @@
/* global addrIsInDomain, exceptionToStr, getBaseDomainFromAddr, readStringFrom, stringEndsWith, stringEqual, DKIM_SigError, DKIM_InternalError */
/* exported EXPORTED_SYMBOLS, Policy */

const module_version = "1.2.0";
const module_version = "1.2.2";

var EXPORTED_SYMBOLS = [
"Policy"
Expand Down Expand Up @@ -80,7 +80,7 @@ var dbInitialized = false;
var dbInitializedDefer = Promise.defer();

var Policy = {
get version() { return module_version; },
get version() { "use strict"; return module_version; },

/**
* init DB
Expand Down Expand Up @@ -426,8 +426,7 @@ var Policy = {

// return if fromAddress is not in SDID
// and options state it should
if (!(stringEndsWith(fromAddress, "@"+sdid) ||
stringEndsWith(fromAddress, "."+sdid)) &&
if (!addrIsInDomain(fromAddress, sdid) &&
prefs.getBoolPref("signRules.autoAddRule.onlyIfFromAddressInSDID")) {
log.trace("fromAddress is not in SDID");
return;
Expand Down
24 changes: 14 additions & 10 deletions modules/dkimVerifier.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
* Verifies the DKIM-Signatures as specified in RFC 6376
* http://tools.ietf.org/html/rfc6376
*
* Version: 1.3.0 (08 December 2014)
* Version: 1.3.1 (21 March 2015)
*
* Copyright (c) 2013-2014 Philippe Lieser
* Copyright (c) 2013-2015 Philippe Lieser
*
* This software is licensed under the terms of the MIT License.
*
Expand All @@ -28,10 +28,10 @@
/* jshint unused:true */ // allow unused parameters that are followed by a used parameter.
/* global Components, Dict, Services, Task */
/* global Logging, Key, Policy, MsgReader */
/* global dkimStrings, addrIsInDomain, domainIsInDomain, exceptionToStr, stringEndsWith, stringEqual, writeStringToTmpFile, DKIM_SigError, DKIM_InternalError */
/* global dkimStrings, addrIsInDomain2, domainIsInDomain, exceptionToStr, stringEndsWith, stringEqual, writeStringToTmpFile, DKIM_SigError, DKIM_InternalError */
/* exported EXPORTED_SYMBOLS, Verifier */

const module_version = "1.3.0";
const module_version = "1.3.1";

var EXPORTED_SYMBOLS = [
"Verifier"
Expand Down Expand Up @@ -1443,17 +1443,21 @@ var that = {
return 0;
}

if (addrIsInDomain(msg.from, sig1.sdid)) {
if (addrIsInDomain2(msg.from, sig1.sdid)) {
return -1;
} else if (addrIsInDomain(msg.from, sig2.sdid)) {
} else if (addrIsInDomain2(msg.from, sig2.sdid)) {
return 1;
}

if (domainIsInDomain(msg.listId, sig1.sdid)) {
return -1;
} else if (domainIsInDomain(msg.listId, sig2.sdid)) {
return 1;
if (msg.listId) {
if (domainIsInDomain(msg.listId, sig1.sdid)) {
return -1;
} else if (domainIsInDomain(msg.listId, sig2.sdid)) {
return 1;
}
}

return 0;
}

signatures.sort(function (sig1, sig2) {
Expand Down
24 changes: 21 additions & 3 deletions modules/helper.jsm
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/*
* helper.jsm
*
* Version: 1.3.1 (10 December 2014)
* Version: 1.4.0 (21 March 2015)
*
* Copyright (c) 2013-2014 Philippe Lieser
* Copyright (c) 2013-2015 Philippe Lieser
*
* This software is licensed under the terms of the MIT License.
*
Expand All @@ -15,11 +15,12 @@
/* jshint strict:true, moz:true, smarttabs:true */
/* global Components, FileUtils, NetUtil, Promise, Services, CommonUtils */
/* global ModuleGetter, Logging */
/* exported EXPORTED_SYMBOLS, addrIsInDomain, domainIsInDomain, exceptionToStr, getBaseDomainFromAddr, getDomainFromAddr, readStringFrom, stringEndsWith, stringEqual, tryGetString, tryGetFormattedString, writeStringToTmpFile, DKIM_SigError, DKIM_InternalError */
/* exported EXPORTED_SYMBOLS, addrIsInDomain, addrIsInDomain2, domainIsInDomain, exceptionToStr, getBaseDomainFromAddr, getDomainFromAddr, readStringFrom, stringEndsWith, stringEqual, tryGetString, tryGetFormattedString, writeStringToTmpFile, DKIM_SigError, DKIM_InternalError */

var EXPORTED_SYMBOLS = [
"dkimStrings",
"addrIsInDomain",
"addrIsInDomain2",
"domainIsInDomain",
"exceptionToStr",
"getBaseDomainFromAddr",
Expand Down Expand Up @@ -85,6 +86,23 @@ function addrIsInDomain(addr, domain) {
stringEndsWith(addr, "." + domain);
}

/**
* Returns true if e-mail address is from the domain or a subdomain of it or if
* the domain is a subdomain of the e-mail address.
*
* @param {String} addr
* @param {String} domain
*
* @return {Boolean}
*/
function addrIsInDomain2(addr, domain) {
"use strict";

return stringEndsWith(addr, "@" + domain) ||
stringEndsWith(addr, "." + domain) ||
stringEndsWith(domain, "." + getDomainFromAddr(addr));
}

/**
* Returns true if domain1 is the same or a subdomain of domain2.
*
Expand Down

0 comments on commit 1604c03

Please sign in to comment.