Re: [saag] [Spasm] Best practices for applications using X.509 client certificates

Sean Leonard <dev+ietf@seantek.com> Mon, 26 September 2016 20:59 UTC

Return-Path: <dev+ietf@seantek.com>
X-Original-To: saag@ietfa.amsl.com
Delivered-To: saag@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id 2465612B01C; Mon, 26 Sep 2016 13:59:58 -0700 (PDT)
X-Virus-Scanned: amavisd-new at amsl.com
X-Spam-Flag: NO
X-Spam-Score: -2.6
X-Spam-Level:
X-Spam-Status: No, score=-2.6 tagged_above=-999 required=5 tests=[BAYES_00=-1.9, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_PASS=-0.001] autolearn=ham autolearn_force=no
Received: from mail.ietf.org ([4.31.198.44]) by localhost (ietfa.amsl.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id tRgKlOldfg0D; Mon, 26 Sep 2016 13:59:56 -0700 (PDT)
Received: from mxout-08.mxes.net (mxout-08.mxes.net [216.86.168.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id E3DA312B016; Mon, 26 Sep 2016 13:59:55 -0700 (PDT)
Received: from [192.168.123.7] (unknown [75.83.2.34]) (using TLSv1.2 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by smtp.mxes.net (Postfix) with ESMTPSA id 5872B50A87; Mon, 26 Sep 2016 16:59:54 -0400 (EDT)
To: David Woodhouse <dwmw2@infradead.org>, spasm@ietf.org, Security Area Advisory Group <saag@ietf.org>
References: <1474280601.144982.263.camel@infradead.org> <CAPt1N1n_ff_QMYiRoorwvVnnP-Q6oruUE9_pvVr+QabeYJ+WrQ@mail.gmail.com> <CACsn0cnsswBX_-P+=Nd42uXAjPPXedXCefQ+V7R+aZn3U9XNog@mail.gmail.com> <CACsn0c=xHisLqPQzMHKr-0c_MEwM9_Nzq3tKmih5uZTYBnibGg@mail.gmail.com> <CACsn0ckABVfiJ506-uYRG+FXpGQixrS_9nxq6tPXfRu1kG_3pw@mail.gmail.com> <1474314996.144982.391.camel@infradead.org> <22611.1474382971@obiwan.sandelman.ca> <D2D83C89-12A2-4562-970A-92FAD232DD3B@deployingradius.com> <1474387598.144982.452.camel@infradead.org> <6A89750D-EAF8-45A0-97AD-0137A2CB8352@seantek.com> <1474881447.45169.205.camel@infradead.org> <1eb84be4-1c5a-066e-f82d-1cd98c2dddd0@seantek.com> <1474919326.45169.305.camel@infradead.org> <c2144e2e-0fd1-2f48-326f-7d9ec47f2d5c@seantek.com> <1474921558.45169.314.camel@infradead.org>
From: Sean Leonard <dev+ietf@seantek.com>
Message-ID: <d9aa5fd5-f056-0d5e-fd22-85fe3548cae8@seantek.com>
Date: Mon, 26 Sep 2016 14:01:36 -0700
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0
MIME-Version: 1.0
In-Reply-To: <1474921558.45169.314.camel@infradead.org>
Content-Type: multipart/alternative; boundary="------------03FB81F1BBAC8E1DD532BC03"
Archived-At: <https://mailarchive.ietf.org/arch/msg/saag/2_Mqlov83Rgnwoa_tXZIIZqS0bw>
Cc: Michael Richardson <mcr+ietf@sandelman.ca>
Subject: Re: [saag] [Spasm] Best practices for applications using X.509 client certificates
X-BeenThere: saag@ietf.org
X-Mailman-Version: 2.1.17
Precedence: list
List-Id: Security Area Advisory Group <saag.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/saag>, <mailto:saag-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/saag/>
List-Post: <mailto:saag@ietf.org>
List-Help: <mailto:saag-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/saag>, <mailto:saag-request@ietf.org?subject=subscribe>
X-List-Received-Date: Mon, 26 Sep 2016 20:59:58 -0000

On 9/26/2016 1:25 PM, David Woodhouse wrote:
> On Mon, 2016-09-26 at 12:55 -0700, Sean Leonard wrote:
>> On 9/26/2016 12:48 PM, David Woodhouse wrote:
>>>> For interoperable private key formats, I favor PKCS #8 PrivateKeyInfo
>>>> (as .p8) and PKCS #8 EncryptedPrivateKeyInfo (as .p8e). They are
>>>> standardized, widely-supported, and algorithm-agile.
>>> They are also non-portable, because even when RFC5958 was published in
>>> 2010, FFS, it didn't mandate the conversion of the password to UTF-8
>>> (let alone any mention of Unicode normalisation) for the purpose of the
>>> key derivation.
>>>
>>> PKCS#12 at least gets *part* of that right, by mandating UTF16BE (BMP).
>> draft-seantek-pkcs8-encrypted-01
> OK... so now we have can say
>
> Content-Type: application/pkcs8-encrypted; password-mapping=UTF-8
>
> (Did you intend '*pkcs12' to mean UTF16-BE which is BMP, not UTF-16LE?)
Yes, I meant UTF-16BE. That was a typo.

By the way, I've actually done quite a lot of tests on several crypto 
stacks, and none of them enforce that the Unicode code point has to be 
in the BMP. You can use surrogate pairs (which are in the BMP anyway) 
just fine.

>
> But I've *never* seen an application make use of certs/files from any
> container where that Content-Type: header might be present. It's not
> even permitted to put it in PEM files, is it? So does this really buy
> me anything in practice?

As with any "new thing", people have to write code for the "new thing" 
to use the "new thing". If you build it, they will come...

The alternative would be to shoehorn the password mapping into some 
attribute in ASN.1. But there's no practical place for that in PKCS #8 
EncryptedPrivateKeyInfo, which is just:

EncryptedPrivateKeyInfo ::= SEQUENCE {
     encryptionAlgorithm AlgorithmIdentifier {{KeyEncryptionAlgorithms}},
     encryptedData EncryptedData
}


I mean, you *could* put it in the PBKDF2-params, with a new algorithm 
identifier. But that will require writing new code to deal with the "new 
thing". No way around it, sorry.

>
> And it still doesn't cover Unicode normalisation. :)

Actually it does. PRECIS says NFC for password/OpaqueString. See Section 
6.2 of RFC 7613.

There were much earlier draft registrations (see the media-types mailing 
list, it's been kicking around for many months now; see also PRECIS 
mailing list) that went into some detail about NFC and stuff like that. 
The rough consensus was that it's best to let PRECIS handle that stuff: 
doing it in the security space (aka PKCS #8 or similar container) is not 
where the expertise lies.

The other point is that there is only one party that cares about the 
encoding: "you". You = the private key holder. Private keys aren't meant 
to be shared. Frankly, who cares what the octets are, as long as you can 
input the same ones into the decryption process. If you are creating the 
private key and using it on the same computing device, the encoding 
doesn't actually matter. You could record mouse clicks or voice samples 
or raw key scan codes from the kernel, and it wouldn't affect the result.

Annex M.4 of IEEE 802.11-2012 has similar insights (which is why I cited 
it).

Adding the encoding parameter actually facilitates attacks, because it 
tells an eavesdropper what bit patterns will *not* appear. Well-formed 
UTF-8 can never have octets C0, C1, or F5-FF, for example; well-formed 
UTF-8 will also bias the input to make certain bit patterns far more 
likely than others. (The KDF is designed to mitigate against biased 
input anyway, though.) The encoding parameter can also thwart attacks, 
by intentionally mislabeling the encoding. It's not cryptographically 
protected so it is subject to undetectable tampering.

Best regards,

Sean