You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by cc...@apache.org on 2019/07/03 20:14:41 UTC

[mynewt-artifact] branch master updated (49a78be -> a86ed83)

This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-artifact.git.


    from 49a78be  Add support for ed25519 encrypted signing keys
     new 05cace2  image: return correct key index during sig verify
     new a86ed83  mfg: Verify embedded images separately

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 image/verify.go |  8 ++++----
 mfg/mfg.go      | 41 +++++++++++++++++++++++++++++++++++++++++
 mfg/verify.go   | 42 +++++++-----------------------------------
 3 files changed, 52 insertions(+), 39 deletions(-)


[mynewt-artifact] 02/02: mfg: Verify embedded images separately

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-artifact.git

commit a86ed83af5bab0eeea204b1d02f052b4ddfeef10
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Mon Jul 1 14:29:42 2019 -0700

    mfg: Verify embedded images separately
    
    Prior to this commit, the `"mfg".Mfg.VerifyManifest()` function
    attempted to verify all of an mfg's embedded images.  This resulted in a
    clunky and unfriendly API:
    
    * The caller was required to pass in a set of public signing keys and
    private encryption keys.
    * There was no way to verify the manifest without also checking the
    embedded images.  E.g., if the caller doesn't have access to encryption
    keys, this function would fail even if the mfgimage is correct.
    
    Now `VerifyManifest()` does not verify the embedded images.  To verify
    the embedded images, the caller should call `"mfg".Mfg.ExtractImages()`
    and call the image verification functions on each image separately.
---
 mfg/mfg.go    | 41 +++++++++++++++++++++++++++++++++++++++++
 mfg/verify.go | 42 +++++++-----------------------------------
 2 files changed, 48 insertions(+), 35 deletions(-)

diff --git a/mfg/mfg.go b/mfg/mfg.go
index 2667003..b46fd4f 100644
--- a/mfg/mfg.go
+++ b/mfg/mfg.go
@@ -24,6 +24,8 @@ import (
 
 	"github.com/apache/mynewt-artifact/errors"
 	"github.com/apache/mynewt-artifact/flash"
+	"github.com/apache/mynewt-artifact/image"
+	"github.com/apache/mynewt-artifact/manifest"
 )
 
 const MFG_BIN_IMG_FILENAME = "mfgimg.bin"
@@ -210,3 +212,42 @@ func (m *Mfg) Tlvs() []MetaTlv {
 		return m.Meta.Tlvs
 	}
 }
+
+func (m *Mfg) extractImage(area flash.FlashArea, eraseVal byte) (image.Image, error) {
+	bin, err := m.ExtractFlashArea(area, eraseVal)
+	if err != nil {
+		return image.Image{}, err
+	}
+
+	img, err := image.ParseImage(bin)
+	if err != nil {
+		return image.Image{}, errors.Wrapf(err,
+			"failed to extract image from mfgimage; area=\"%s\"", area.Name)
+	}
+
+	return img, nil
+}
+
+// Constructs the set of images embedded in an mfgimage.
+func (m *Mfg) ExtractImages(man manifest.MfgManifest) ([]image.Image, error) {
+	var imgs []image.Image
+	for _, t := range man.Targets {
+		fa := man.FindFlashAreaDevOff(man.Device, t.Offset)
+		if fa == nil {
+			return nil, errors.Errorf(
+				"no flash area in mfgimage corresponding to target \"%s\"",
+				t.Name)
+		}
+
+		if !t.IsBoot() {
+			img, err := m.extractImage(*fa, man.EraseVal)
+			if err != nil {
+				return nil, err
+			}
+
+			imgs = append(imgs, img)
+		}
+	}
+
+	return imgs, nil
+}
diff --git a/mfg/verify.go b/mfg/verify.go
index cff0a79..5d660d1 100644
--- a/mfg/verify.go
+++ b/mfg/verify.go
@@ -25,7 +25,6 @@ import (
 
 	"github.com/apache/mynewt-artifact/errors"
 	"github.com/apache/mynewt-artifact/flash"
-	"github.com/apache/mynewt-artifact/image"
 	"github.com/apache/mynewt-artifact/manifest"
 	"github.com/apache/mynewt-artifact/sec"
 )
@@ -123,37 +122,6 @@ func (m *Mfg) validateManMmrs(man manifest.MfgManifest) error {
 	return nil
 }
 
-func (m *Mfg) validateManTargets(man manifest.MfgManifest) error {
-	for _, t := range man.Targets {
-		fa := man.FindFlashAreaDevOff(man.Device, t.Offset)
-		if fa == nil {
-			return errors.Errorf(
-				"no flash area in mfgimage corresponding to target \"%s\"",
-				t.Name)
-		}
-
-		data, err := m.ExtractFlashArea(*fa, man.EraseVal)
-		if err != nil {
-			return err
-		}
-
-		if !t.IsBoot() {
-			img, err := image.ParseImage(data)
-			if err != nil {
-				return errors.Wrapf(err,
-					"error parsing build \"%s\" embedded in mfgimage", t.Name)
-			}
-
-			if err := img.VerifyStructure(); err != nil {
-				return errors.Wrapf(err,
-					"mfgimage contains invalid build \"%s\"", t.Name)
-			}
-		}
-	}
-
-	return nil
-}
-
 // VerifyStructure checks an mfgimage's structure and internal consistency.  It
 // returns an error if the mfgimage is incorrect.
 func (m *Mfg) VerifyStructure(eraseVal byte) error {
@@ -213,9 +181,13 @@ func (m *Mfg) VerifyManifest(man manifest.MfgManifest) error {
 		return err
 	}
 
-	// Verify each embedded build.
-	if err := m.validateManTargets(man); err != nil {
-		return err
+	// Make sure each target is fully present.
+	for _, t := range man.Targets {
+		if man.FindFlashAreaDevOff(man.Device, t.Offset) == nil {
+			return errors.Errorf(
+				"no flash area in mfgimage corresponding to target \"%s\"",
+				t.Name)
+		}
 	}
 
 	return nil


[mynewt-artifact] 01/02: image: return correct key index during sig verify

Posted by cc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ccollins pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-artifact.git

commit 05cace2b3fab7b106f2eb6d644663fa92f3bfb62
Author: Christopher Collins <cc...@apache.org>
AuthorDate: Mon Jul 1 14:19:39 2019 -0700

    image: return correct key index during sig verify
    
    This commit fixes a bug involving image signature verification.  The
    `"image".Image.VerifySigs()` function is intended to return the index of
    the key that successfully verified an image's signature.  The bug is:
    this function was returning the index of the signature, not the index of
    the key.
---
 image/verify.go | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/image/verify.go b/image/verify.go
index 19bd585..49d1a1d 100644
--- a/image/verify.go
+++ b/image/verify.go
@@ -155,14 +155,14 @@ func (img *Image) VerifySigs(keys []sec.PubSignKey) (int, error) {
 		return -1, err
 	}
 
-	for _, k := range keys {
-		idx, err := sec.VerifySigs(k, sigs, hash)
+	for keyIdx, k := range keys {
+		sigIdx, err := sec.VerifySigs(k, sigs, hash)
 		if err != nil {
 			return -1, err
 		}
 
-		if idx != -1 {
-			return idx, nil
+		if sigIdx != -1 {
+			return keyIdx, nil
 		}
 	}