Re: [Ietf-dkim] Question about lone CR / LF

Jon Callas <jon@callas.org> Thu, 01 February 2024 20:28 UTC

Return-Path: <jon@callas.org>
X-Original-To: ietf-dkim@ietfa.amsl.com
Delivered-To: ietf-dkim@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id CFFA5C14F6E1 for <ietf-dkim@ietfa.amsl.com>; Thu, 1 Feb 2024 12:28:48 -0800 (PST)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -7.106
X-Spam-Level:
X-Spam-Status: No, score=-7.106 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_ZEN_BLOCKED_OPENDNS=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, URIBL_BLOCKED=0.001, URIBL_DBL_BLOCKED_OPENDNS=0.001, URIBL_ZEN_BLOCKED_OPENDNS=0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=callas.org
Received: from mail.ietf.org ([50.223.129.194]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id Cl_TYlcU3iFc for <ietf-dkim@ietfa.amsl.com>; Thu, 1 Feb 2024 12:28:45 -0800 (PST)
Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 1061DC14F61C for <ietf-dkim@ietf.org>; Thu, 1 Feb 2024 12:28:45 -0800 (PST)
Received: by mail-ot1-x330.google.com with SMTP id 46e09a7af769-6e132fef7baso769734a34.3 for <ietf-dkim@ietf.org>; Thu, 01 Feb 2024 12:28:44 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=callas.org; s=google; t=1706819324; x=1707424124; darn=ietf.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=mMEjZzmhDDcVzm5WNhEDteyu42Eb1r82etQsFAZqsDQ=; b=XKU1y/SygWU3A0s5l816NnwTStH8TzRT2u2Uj6tmIdqH9dWisClcRtNd38bGQFHtGO 5zCUKqPOkP3yTUa/DwUxrvRmSoYdUTDYNsNBvXjobeQA4XDVtxFcWhTkKYWe0VK1ftC2 8o6jcitl5iVyunCNkt5khO2cTMvEwTZqPT1Bh+fDGrpOEE76AqY14NvJQfP3WXE7nC6r DjvmOHZNRhDrQwhjL5SVgn9lAx9NYCTge0eQ0ETEXGCT8EdSyboe4tE6WNQOW+ToXR6n qx0uPT2vkW+1Fwx3A8Ts7sRXRUdizp/tluDkIZH8PTPf1+SRewm9cQkN4xGvbniTSgU2 FjCw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706819324; x=1707424124; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mMEjZzmhDDcVzm5WNhEDteyu42Eb1r82etQsFAZqsDQ=; b=AcjEPMCTc9c13p+6v/HzfHMbzhvkuE4hzRgt9MBFSN141STrbYIYTqDoJJA2bGCorA rhd/m8mezUuqH6HZi4VRbhW+hFzJpZhtHWLgQcsSiITEm1on+gbuFNT9EJQsqyFqHvD+ grtn+Xxv7YG0JGqq16JeJBFGf5PP98wniv+4mD5WgBk5DioxlrtdU0tyJQADz02QP0gV YrJUUDropur0J5ySkoyIdsnL7nG0GVufb8oyLFJs7s2O1dQEyIGrnJcCyXANQRW295K6 3FBjtzLwjI8bcv1iLJfy7UwfiFzrkTnwGZUB66dLqCgQayY26zJDRpjMn3Rc1HbCjsQM b89w==
X-Gm-Message-State: AOJu0YwLKh9bK0SMmcTn4rDs2vlbbRsLitcJ73mM62V9tD+n2JFf9E2P MfvO9GBrNw4aAQ71zgeErIhRIOQn6tU/2AETtQn6UNs/f/TbjRLnluZumvaOrkI=
X-Google-Smtp-Source: AGHT+IEyD4TNSKCsLo2LkmvC7RYKHlcCaYhMyvS1cXD1LPER+U8C06eUx9sMuC+5If6IHjnBUJ1siw==
X-Received: by 2002:a9d:5d15:0:b0:6dd:de32:6f62 with SMTP id b21-20020a9d5d15000000b006ddde326f62mr5771028oti.1.1706819324055; Thu, 01 Feb 2024 12:28:44 -0800 (PST)
X-Forwarded-Encrypted: i=0; AJvYcCXEBpWVV3u7u97J0uvCCG+uvQs6dIcB8Lzm7snE1P32CHn7yRZXH0k0PCXLZkESFrWwodxxQrFKZXqOpPQlpIcVS28IAS45gWqts9wPP2n1Yal4P9bA6tY=
Received: from smtpclient.apple ([2600:1700:38c4:12bf:901f:9de0:a600:dc41]) by smtp.gmail.com with ESMTPSA id z27-20020a0568301dbb00b006e11d75f20dsm96483oti.9.2024.02.01.12.28.43 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Feb 2024 12:28:43 -0800 (PST)
Content-Type: text/plain; charset="utf-8"
Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3774.400.31\))
From: Jon Callas <jon@callas.org>
In-Reply-To: <20240201180340.852B6820560B@ary.qy>
Date: Thu, 01 Feb 2024 12:28:32 -0800
Cc: Jon Callas <jon@callas.org>, ietf-dkim@ietf.org, superuser@gmail.com
Content-Transfer-Encoding: quoted-printable
Message-Id: <E8C1422D-4A9C-412A-BF5E-D07CABD2BFE2@callas.org>
References: <20240201180340.852B6820560B@ary.qy>
To: John Levine <johnl@taugh.com>
X-Mailer: Apple Mail (2.3774.400.31)
Archived-At: <https://mailarchive.ietf.org/arch/msg/ietf-dkim/-Uyh8qTIbBFvvH9xpt_oos-v-v4>
Subject: Re: [Ietf-dkim] Question about lone CR / LF
X-BeenThere: ietf-dkim@ietf.org
X-Mailman-Version: 2.1.39
Precedence: list
List-Id: IETF DKIM List <ietf-dkim.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/ietf-dkim>, <mailto:ietf-dkim-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/ietf-dkim/>
List-Post: <mailto:ietf-dkim@ietf.org>
List-Help: <mailto:ietf-dkim-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/ietf-dkim>, <mailto:ietf-dkim-request@ietf.org?subject=subscribe>
X-List-Received-Date: Thu, 01 Feb 2024 20:28:48 -0000


On Feb 1, 2024, at 10:03, John Levine <johnl@taugh.com> wrote:

It appears that Murray S. Kucherawy  <superuser@gmail.com> said:
-=-=-=-=-=-

On Wed, Jan 31, 2024 at 5:44 PM Steffen Nurpmeso <steffen@sdaoden.eu> wrote:

But i cannot read this from RFC 6376.

Sections 2.8 and 3.4.4 don't answer this?

Not really.  They say what to do with CRLF but not with a lone CR or lone LF.

RFC5322 says:

  o  CR and LF MUST only occur together as CRLF; they MUST NOT appear
     independently in the body.

So I think the answer is that a thing with a lone CR or LF is not a
valid message so signers shouldn't sign them and validators shouldn't
validate them. If you want to allow them, OK, but no promises that
anyone at the other end will treat the brokenness the same way you
dod.

We can get into some theological arguments about BINARYMIME which
allows arbitrary bytes in a MIME part but I expect that DKIM
canonicalization code will choke on other stuff in binary MIME before
it gets to a \x0a or \x0d.

I went down the rabbit hole of RFC5322 syntax around CR and LF, and yes, it seems to me that 5322 is definitely saying no bare CR or LF. However. Section 4.0 and 4.1 (in detail) describe obsolete syntax and bare CR and LF is in there with the interesting comment in 4.1:

   Bare CR and bare LF appear in messages with two different meanings.
   In many cases, bare CR or bare LF are used improperly instead of CRLF
   to indicate line separators.  In other cases, bare CR and bare LF are
   used simply as US-ASCII control characters with their traditional
   ASCII meanings.

Which means that yes, it's forbidden, but it's also obsolete, and there's 
this note about how someone might want to use (e.g.) an LF
                                                           for some quote-quote
traditional ASCII meaning, like a real line feed that I emulated here with a 
CRLF and a bunch of spaces. (I am thoroughly amused at how constructing this 
weird paragraph is making my MUA hyperventilate. I'm even wondering if the droll
humor even goes through.)

So that gets to the tacit question -- what should a DKIM implementor do? Me, I would *not* put in code looking for bare CRs or LFs. My major rationale is an appeal to layering, or bluntly, it's not my job to enforce RFC 5322 syntax. Someone else in the pipeline is supposed to do that, and all I can do is screw things up.

5322§4.1 doesn't just talk about CR and LF. It also talks about how NUL is also an obsolete character. §4.2 is all about obsolete folding whitespace. §4.3 is about obsolete time zones, and there's a whole lot more in there of obsolete things. If I'm going to parse for CR, shouldn't I also be parsing for someone saying GMT when they meant UTC? Shouldn't I be checking line lengths, too? And we haven't even gotten to other things like your observation about BINARYMIME.

If I look at it from a failure-mode analysis, if I generate a false positive on 5322 parsing, or even am totally annoyingly correct -- nuh, uh, I'm not going to sign that message because you said GMT -- it's going to piss people off and I'll look at best like a clenchpoop and at worst like a fool. On the other hand if I sign something that was not 5322-compliant and the signature breaks then well, perhaps the MUA should canonicalize it, or the MSA should reject it. I think it's totally reasonable for a DKIM implementation to just declare that the thing it's given is 5322-compliant, and if it is, it's not DKIM's problem.

So I'd assume 5322ness in DKIM, because there are many dragons in the alternative.

    Jon