-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
932 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Brand Indicators for Message Identification (BIMI). | ||
* https://datatracker.ietf.org/doc/draft-brand-indicators-for-message-identification/04/ | ||
* | ||
* BIMI implementation for a Mail User Agent (MUA). | ||
* Gets the BIMI Indicator based on the information the receiving | ||
* Mail Transfer Agent (MTA) writes into the headers of the message. | ||
* | ||
* This is not a complete implementation of BIMI. | ||
* | ||
* Copyright (c) 2023 Philippe Lieser | ||
* | ||
* This software is licensed under the terms of the MIT License. | ||
* | ||
* The above copyright and license notice shall be | ||
* included in all copies or substantial portions of the Software. | ||
*/ | ||
|
||
// @ts-check | ||
|
||
import Logging from "./logging.mjs.js"; | ||
import RfcParser from "./rfcParser.mjs.js"; | ||
|
||
const log = Logging.getLogger("BIMI"); | ||
|
||
|
||
/** | ||
* Try to get the BIMI Indicator if available. | ||
* | ||
* @param {Map<string, string[]>} headers | ||
* @param {import("./arhParser.mjs.js").ArhResInfo[]} arhBIMI - Trusted ARHs containing a BIMI result. | ||
* @returns {string|null} | ||
*/ | ||
export function getBimiIndicator(headers, arhBIMI) { | ||
// Assuming: | ||
// 1. We only get ARHs that can be trusted (i.e. from the receiving MTA). | ||
// 2. If the receiving MTA does not supports BIMI, | ||
// we will not see an ARH with a BIMI result (because of 1) | ||
// 3. If the receiving MTA supports BIMI, | ||
// it will make sure we only see his BIMI-Indicator headers (as required by the RFC). | ||
// | ||
// Given the above, it should be safe to trust the BIMI indicator from the BIMI-Indicator header | ||
// if we have a passing BIMI result there the MTA claims to have checked the Authority Evidence. | ||
const hasAuthorityPassBIMI = arhBIMI.some( | ||
arh => arh.method === "bimi" && | ||
arh.result === "pass" && | ||
arh.propertys.policy.authority === "pass" | ||
); | ||
if (!hasAuthorityPassBIMI) { | ||
return null; | ||
} | ||
|
||
const bimiIndicators = headers.get("bimi-indicator") ?? []; | ||
if (bimiIndicators.length > 1) { | ||
log.warn("Message contains more than one BIMI-Indicator header"); | ||
return null; | ||
} | ||
let bimiIndicator = bimiIndicators[0]; | ||
if (!bimiIndicator) { | ||
log.warn("Message contains an ARH with passing BIMI but does not have a BIMI-Indicator header"); | ||
return null; | ||
} | ||
|
||
// TODO: If in the future we support ARC we might want to check the policy.indicator-hash | ||
|
||
// Remove header name and new line at end | ||
bimiIndicator = bimiIndicator.slice("bimi-indicator:".length, -"\r\n".length); | ||
// Remove all whitespace | ||
bimiIndicator = bimiIndicator.replace(new RegExp(`${RfcParser.FWS}`, "g"), ""); | ||
|
||
return bimiIndicator; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Authentication-Results: mx5.messagingengine.com; | ||
bimi=pass header.d=example.com header.selector=default policy.authority=pass | ||
BIMI-Indicator: PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiICBzdGFuZGFsb25l | ||
PSJ5ZXMiPz4KPHN2ZyB2ZXJzaW9uPSIxLjIiIGJhc2VQcm9maWxlPSJ0aW55LXBzIiB2aWV3Qm94 | ||
PSIwIDAgMTAwIDEwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPHRpdGxl | ||
PkV4YW1wbGU8L3RpdGxlPgo8Y2lyY2xlIGN4PSI1MCIgY3k9IjUwIiByPSI0MCIgc3Ryb2tlPSJi | ||
bGFjayIgc3Ryb2tlLXdpZHRoPSIzIiBmaWxsPSJyZWQiIC8+Cjwvc3ZnPg== | ||
DKIM-Signature: v=1; a=rsa-sha256; s=brisbane; d=example.com; | ||
c=simple/simple; q=dns/txt; i=[email protected]; | ||
h=Received : From : To : Subject : Date : Message-ID; | ||
bh=2jUSOH9NhtVGCQWNr9BrIAPreKQjO6Sn7XIkfJVOzv8=; | ||
b=AuUoFEfDxTDkHlLXSZEpZj79LICEps6eda7W3deTVFOk4yAUoqOB | ||
4nujc7YopdG5dWLSdNg6xNAZpOPr+kHxt1IrE+NahM6L/LbvaHut | ||
KVdkLLkpVaVVQPzeRDI009SO2Il5Lu7rDNH6mZckBdrIx0orEtZV | ||
4bmp/YzhwvcubU4=; | ||
Received: from client1.football.example.com [192.0.2.1] | ||
by submitserver.example.com with SUBMISSION; | ||
Fri, 11 Jul 2003 21:01:54 -0700 (PDT) | ||
From: Joe SixPack <[email protected]> | ||
To: Suzie Q <[email protected]> | ||
Subject: Is dinner ready? | ||
Date: Fri, 11 Jul 2003 21:00:37 -0700 (PDT) | ||
Message-ID: <[email protected]> | ||
|
||
Hi. | ||
|
||
We lost the game. Are you hungry yet? | ||
|
||
Joe. |
Oops, something went wrong.