diff --git a/src/builder/builder.go b/src/builder/builder.go index 4d7e068..9c5cf22 100644 --- a/src/builder/builder.go +++ b/src/builder/builder.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "os" "os/exec" + "path/filepath" "reflect" "regexp" "strconv" @@ -172,7 +173,7 @@ 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", "private.pem", + "-signer", b.Cert, "-inkey", filepath.Dir(b.Cert)+"/private.pem", "-outform", "DER", "-out", manifestMOMsig) // OpenSSL gives us useful info here so capture it if needed diff --git a/src/helpers/helpers.go b/src/helpers/helpers.go index a934c29..3f77b5a 100644 --- a/src/helpers/helpers.go +++ b/src/helpers/helpers.go @@ -13,6 +13,7 @@ import ( "net/http" "os" "os/exec" + "path/filepath" "strings" "time" ) @@ -74,7 +75,7 @@ func GenerateCertificate(cert string, template, parent *x509.Certificate, pubkey } // Write the public certficiate out for clients to use - certOut, err := os.Create("Swupd_Root.pem") + certOut, err := os.Create(cert) if err != nil { fmt.Printf("failed to open cert.pem for writing: %v\n", err) PrintError(err) @@ -83,17 +84,17 @@ func GenerateCertificate(cert string, template, parent *x509.Certificate, pubkey certOut.Close() // Write the private signing key out - keyOut, err := os.OpenFile("private.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) + keyOut, err := os.OpenFile(filepath.Dir(cert)+"/private.pem", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0600) if err != nil { fmt.Println("failed to open key.pem for writing") PrintError(err) return err } + defer keyOut.Close() // Need type assertion for Marshal to work priv := privkey.(*rsa.PrivateKey) pem.Encode(keyOut, &pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(priv)}) } - return nil }