Re: [websec] HPKP & different encodings of the same public key

Brian Smith <brian@briansmith.org> Sun, 15 May 2016 20:54 UTC

Return-Path: <brian@briansmith.org>
X-Original-To: websec@ietfa.amsl.com
Delivered-To: websec@ietfa.amsl.com
Received: from localhost (localhost [127.0.0.1]) by ietfa.amsl.com (Postfix) with ESMTP id ED3B212D517 for <websec@ietfa.amsl.com>; Sun, 15 May 2016 13:54:03 -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, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001] autolearn=ham autolearn_force=no
Authentication-Results: ietfa.amsl.com (amavisd-new); dkim=pass (2048-bit key) header.d=briansmith-org.20150623.gappssmtp.com
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 wndbF-Qh4SEE for <websec@ietfa.amsl.com>; Sun, 15 May 2016 13:54:02 -0700 (PDT)
Received: from mail-io0-x22b.google.com (mail-io0-x22b.google.com [IPv6:2607:f8b0:4001:c06::22b]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ietfa.amsl.com (Postfix) with ESMTPS id 063D712B046 for <websec@ietf.org>; Sun, 15 May 2016 13:54:02 -0700 (PDT)
Received: by mail-io0-x22b.google.com with SMTP id 190so189506810iow.1 for <websec@ietf.org>; Sun, 15 May 2016 13:54:01 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=briansmith-org.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=4UaOk5l9yAOdZoG5bcE2NHHpODG1x6Ls7Ldh09ZRFVY=; b=bXOaAu00/kDhV96jBZqBMSQ+X1gelaqj1uGlLs3tfG4zwMUg02kt7wextpo6cNjCgM yl4rcA98QvQCvX0yJTvK4FyCFvND1LdXCno/k2E+jxdlikDuhTAEWY1jgFm0hFFU7kQX H+hOUaT2WcWql6tG0vtsiGRI4CBN3ridj3X9V2S805TGcSRvsLpzFSoMOiU3Q4TtCbMx QhQoB6jPz/tis/fZDTNFhOajTotq/dGGji9mUHGcArg0+GHFt8UlC47d5HHSf9ZnWKyv ZG8lEvWM4LtU9oXpFoUs1V+o6m99g6Itxz4YQujsYHh7BiBZY0FoA23RcW1pIo+zPh6L dH6A==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=4UaOk5l9yAOdZoG5bcE2NHHpODG1x6Ls7Ldh09ZRFVY=; b=TZzto/1lESt4hEDzbL1htKIpoa7cirh5Imjv2fQTs1e0qU5XU9wGZDntbYXktuK28j VfwJ+fLqihMLrywjGz49DmgIXlvY6/VZXt0oQS+XNgH3HapJ09ZQV3rkFajUT9FXu+Sj Mof3t0waBdxDsg7B7s7wpJ5iobemAiOMtzjRlbcxz9/rFLIqOXcKZIF2O1adQ4D9bCP/ pBBS+if9owFlSo9SeM/PuoL0paydKKddsrpg0eoWfPXG+BK82IE90TRBVf7Ni1Jzcea0 qF1xbC5+nIHrh3MK/U43v8eqjSL13Y/2KDd9tUwgKJUxRFZ6cuPLcmLxcMy5eN04UZY0 vbsw==
X-Gm-Message-State: AOPr4FWzyXrZddSEpSLOtzLyhh2td4kWYK2fmZUGnzvb3Fs4/K2XnF1rA0/xdQEvfdxVlUfQ29ISTKcySbTdkw==
MIME-Version: 1.0
X-Received: by 10.107.10.208 with SMTP id 77mr18289091iok.51.1463345639857; Sun, 15 May 2016 13:53:59 -0700 (PDT)
Received: by 10.36.253.67 with HTTP; Sun, 15 May 2016 13:53:59 -0700 (PDT)
In-Reply-To: <CAME=j1=QZTFdxaMQ=_Egy296zhAiL--2hcW0_nc-3BLgz7z9XA@mail.gmail.com>
References: <CAME=j1=QZTFdxaMQ=_Egy296zhAiL--2hcW0_nc-3BLgz7z9XA@mail.gmail.com>
Date: Sun, 15 May 2016 10:53:59 -1000
Message-ID: <CAFewVt7u2e6184T_XP7VFJRbz4XJyrxUf2VK8XtZg3FQCquZ3g@mail.gmail.com>
From: Brian Smith <brian@briansmith.org>
To: Jesse Wilson <jesse@swank.ca>
Content-Type: multipart/alternative; boundary="001a113f8d160c443e0532e7b517"
Archived-At: <http://mailarchive.ietf.org/arch/msg/websec/ynPkB41qNEtjPwwtfyXf2GahmzQ>
Cc: IETF WebSec WG <websec@ietf.org>
Subject: Re: [websec] HPKP & different encodings of the same public key
X-BeenThere: websec@ietf.org
X-Mailman-Version: 2.1.17
Precedence: list
List-Id: Web Application Security Minus Authentication and Transport <websec.ietf.org>
List-Unsubscribe: <https://www.ietf.org/mailman/options/websec>, <mailto:websec-request@ietf.org?subject=unsubscribe>
List-Archive: <https://mailarchive.ietf.org/arch/browse/websec/>
List-Post: <mailto:websec@ietf.org>
List-Help: <mailto:websec-request@ietf.org?subject=help>
List-Subscribe: <https://www.ietf.org/mailman/listinfo/websec>, <mailto:websec-request@ietf.org?subject=subscribe>
X-List-Received-Date: Sun, 15 May 2016 20:54:04 -0000

Jesse Wilson <jesse@swank.ca> wrote:

> Older versions of Android (which use BouncyCastle) embed the curve:
>
> SEQUENCE {
>   SEQUENCE {
>     # ecPublicKey
>     OBJECT_IDENTIFIER { 1.2.840.10045.2.1 }
>     SEQUENCE {
>       INTEGER { 1 }
>       SEQUENCE {
>         # prime-field
>         OBJECT_IDENTIFIER { 1.2.840.10045.1.1 }
>         INTEGER { `01ffffffffffffff...` }
>       }
>       SEQUENCE {
>         OCTET_STRING { `01ffffffffffffff...` }
>         OCTET_STRING { `0051953eb9618e1c...` }
>       }
>       OCTET_STRING { `0400c6858e06b704...` }
>       INTEGER { `01ffffffffffffff...` }
>       INTEGER { 1 }
>     }
>   }
>   BIT_STRING { `0004019519de800d...` }
> }
>
> This is invalid. See https://tools.ietf.org/html/rfc5480#section-2.1.1: "implicitCurve
and specifiedCurve MUST NOT be used in PKIX."


> But new versions of Android (which use Conscrypt/OpenSSL) reference the
> curve by name:
>
> SEQUENCE {
>   SEQUENCE {
>     # ecPublicKey
>     OBJECT_IDENTIFIER { 1.2.840.10045.2.1 }
>     # secp521r1
>     OBJECT_IDENTIFIER { 1.3.132.0.35 }
>   }
>   BIT_STRING { `0004019519de800d...` }
> }
>
> The original certificate embeds the curve.
>
This is the only correct encoding.


> The original and roundtripped SPKI bytes are not identical.
>
Does anyone else do ASN.1 encoding in order to compute a certificate’s pin?
>
1. I recommend that you don't decode and then re-encode. Instead, I
recommend that you only verify that the curve is specified using the valid
encoding, and then compute the result using the single valid encoding
directly, without using any encoder.


> Or is it a uniquely Java problem?!
>
IIRC, older versions of OpenSSL have this problem too.


> The spec should warn that a single SPKI may have multiple conflicting
> encodings.
>
No. There's only one valid way to encode each SPKI. This makes sense if you
think about the primary goal of the DER encoding of ASN.1: It's supposed to
allow round-trip decode-encode where the output is the same as the input.


> I suggest that only encoding in the certificate should be pinned. TLS
> server administrators should also be careful to not inadvertently re-encode
> their SPKIs when doing maintenance.
>
Instead, certificates with invalid encodings should be rejected by
verifiers and nobody should produce certificates with invalid encodings.

Cheers,
Brian
-- 
https://briansmith.org/