Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing of PKCS#8 encoded Elliptic Curve keys. #1379

Merged
merged 1 commit into from Mar 29, 2018

Commits on Mar 23, 2018

  1. Fix parsing of PKCS#8 encoded Elliptic Curve keys.

    The relevant ASN.1 definitions for a PKCS#8 encoded Elliptic Curve key are:
    
    PrivateKeyInfo ::= SEQUENCE {
      version                   Version,
      privateKeyAlgorithm       PrivateKeyAlgorithmIdentifier,
      privateKey                PrivateKey,
      attributes           [0]  IMPLICIT Attributes OPTIONAL
    }
    
    AlgorithmIdentifier  ::=  SEQUENCE  {
      algorithm   OBJECT IDENTIFIER,
      parameters  ANY DEFINED BY algorithm OPTIONAL
    }
    
    ECParameters ::= CHOICE {
      namedCurve         OBJECT IDENTIFIER
      -- implicitCurve   NULL
      -- specifiedCurve  SpecifiedECDomain
    }
    
    ECPrivateKey ::= SEQUENCE {
      version        INTEGER { ecPrivkeyVer1(1) } (ecPrivkeyVer1),
      privateKey     OCTET STRING,
      parameters [0] ECParameters {{ NamedCurve }} OPTIONAL,
      publicKey  [1] BIT STRING OPTIONAL
    }
    
    Because of the two optional fields, there are 4 possible variants that need to
    be parsed: no optional fields, only parameters, only public key, and both
    optional fields. Previously mbedTLS was unable to parse keys with "only
    parameters". Also, only "only public key" was tested. There was a test for "no
    optional fields", but it was labelled incorrectly as SEC.1 and not run because
    of a great renaming mixup.
    Jethro Beekman committed Mar 23, 2018
    Configuration menu
    Copy the full SHA
    d2df936 View commit details
    Browse the repository at this point in the history