Fail if signing the MoM fails

The error was being ignored, now is propagated. Also made some
cleanups in the function (and its comments).

Fixes #45.

Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
This commit is contained in:
Caio Marcelo de Oliveira Filho
2018-01-02 13:24:25 -08:00
committed by tmarcu
parent 4a204add25
commit 12c320e85b
+19 -15
View File
@@ -179,27 +179,26 @@ func (b *Builder) ReadVersions() {
}
}
// SignManifestMOM will sign the Manifest.Mom file in in place based on the Mix
// SignManifestMoM will sign the Manifest.MoM file in in place based on the Mix
// version read from builder.conf.
// Shelling out to openssl because signing and pkcs7 stuff is not well supported
// in Go yet.. but the command works well and is how things worked previously
func (b *Builder) SignManifestMOM() {
manifestMOM := b.Statedir + "/www/" + b.Mixver + "/Manifest.MoM"
manifestMOMsig := manifestMOM + ".sig"
cmd := exec.Command("openssl", "smime", "-sign", "-binary", "-in", manifestMOM,
"-signer", b.Cert, "-inkey", filepath.Dir(b.Cert)+"/private.pem",
"-outform", "DER", "-out", manifestMOMsig)
func (b *Builder) SignManifestMoM() error {
mom := filepath.Join(b.Statedir, "www", b.Mixver, "Manifest.MoM")
sig := mom + ".sig"
// OpenSSL gives us useful info here so capture it if needed
// Call openssl because signing and pkcs7 stuff is not well supported in Go yet.
cmd := exec.Command("openssl", "smime", "-sign", "-binary", "-in", mom,
"-signer", b.Cert, "-inkey", filepath.Dir(b.Cert)+"/private.pem",
"-outform", "DER", "-out", sig)
// Capture the output as it is useful in case of errors.
var out bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &out
err := cmd.Run()
if err != nil {
fmt.Println("ERROR: Failed to sign Manifest.MoM!")
fmt.Printf("%s\n", out.String())
helpers.PrintError(err)
return fmt.Errorf("failed to sign Manifest.MoM:\n%s", out.String())
}
fmt.Println("Signed Manifest.MoM")
return nil
}
// UpdateRepo will fetch the clr-bundles for our configured Clear Linux version
@@ -616,7 +615,12 @@ func (b *Builder) BuildUpdate(prefixflag string, minvflag int, formatflag string
// Step 1.5: sign the Manifest.MoM that was just created
if signflag == false {
b.SignManifestMOM()
err = b.SignManifestMoM()
if err != nil {
helpers.PrintError(err)
return err
}
fmt.Println("Signed Manifest.MoM")
}
// Step 2: create fullfiles