Repository: incubator-mynewt-newt Updated Branches: refs/heads/develop b0a50a688 -> 4fc6247a1
newt: image: Handle ecdsa keys from openssl Openssl sometimes prepends an "EC PARAMETERS" block to the PEM format for EC private keys. Allow this key to still be used by detecting this block, and decoding the subsequent block as the key. Project: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/commit/1855170f Tree: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/tree/1855170f Diff: http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/diff/1855170f Branch: refs/heads/develop Commit: 1855170fce17423884ee6631527d6fa5aa6ed1c9 Parents: 85da72b Author: David Brown <[email protected]> Authored: Fri Jan 27 17:49:34 2017 -0700 Committer: David Brown <[email protected]> Committed: Fri Jan 27 18:07:49 2017 -0700 ---------------------------------------------------------------------- newt/image/image.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-mynewt-newt/blob/1855170f/newt/image/image.go ---------------------------------------------------------------------- diff --git a/newt/image/image.go b/newt/image/image.go index 49134d1..87d01de 100644 --- a/newt/image/image.go +++ b/newt/image/image.go @@ -230,7 +230,15 @@ func (image *Image) SetSigningKey(fileName string, keyId uint8) error { return util.NewNewtError(fmt.Sprintf("Error reading key file: %s", err)) } - block, _ := pem.Decode(data) + block, data := pem.Decode(data) + if block != nil && block.Type == "EC PARAMETERS" { + /* + * Openssl prepends an EC PARAMETERS block before the + * key itself. If we see this first, just skip it, + * and go on to the data block. + */ + block, _ = pem.Decode(data) + } if block != nil && block.Type == "RSA PRIVATE KEY" { /* * ParsePKCS1PrivateKey returns an RSA private key from its ASN.1
