From 5904cebaa5645ed650c8230d91345c7d71b3473b Mon Sep 17 00:00:00 2001 From: Arjan H Date: Wed, 5 Mar 2025 21:04:01 +0100 Subject: [PATCH] Fix issue where ceremony tool is not compiled in time --- gui/certificate.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/gui/certificate.go b/gui/certificate.go index e3794e2..4a7a676 100644 --- a/gui/certificate.go +++ b/gui/certificate.go @@ -175,6 +175,25 @@ func ceremonyConfig(path string, rewrites map[string]string) (string, error) { return tmp.Name(), nil } +func waitForFile(filePath string) error { + start := time.Now() + for { + if _, err := os.Stat(filePath); err == nil { + return nil // File found + } else if !os.IsNotExist(err) { + return fmt.Errorf("error checking file: %v", err) // Unexpected error + } + + // Check if the timeout has been reached + if time.Since(start) > 2*time.Minute { + return fmt.Errorf("timeout reached while waiting for file") + } + + // Sleep for a short interval before checking again + time.Sleep(5 * time.Second) + } +} + func (ci *CertificateInfo) CeremonyRoot(seqnr string, use_existing_key bool) (string, error) { keytype := "rsa" keyparam := strings.Replace(ci.KeyType, "rsa", "", -1) @@ -230,6 +249,11 @@ func (ci *CertificateInfo) CeremonyRoot(seqnr string, use_existing_key bool) (st } defer os.Remove(ceremonyCfg) + err = waitForFile("/opt/boulder/bin/ceremony") + if err != nil { + return "", fmt.Errorf("could not wait for /opt/boulder/bin/ceremony to exist: %s", err.Error()) + } + if _, err = exeCmd("/opt/boulder/bin/ceremony -config " + ceremonyCfg); err != nil { ci.Errors["Generate"] = "failed to execute root ceremony, see logs for details" cb.Restore() @@ -291,6 +315,11 @@ func (ci *CertificateInfo) CeremonyIssuer(seqnr, rootseqnr string, use_existing_ } defer os.Remove(keyCfg) + err = waitForFile("/opt/boulder/bin/ceremony") + if err != nil { + return "", fmt.Errorf("could not wait for /opt/boulder/bin/ceremony to exist: %s", err.Error()) + } + if _, err = exeCmd("/opt/boulder/bin/ceremony -config " + keyCfg); err != nil { ci.Errors["Generate"] = "failed to execute issuer key ceremony, see logs for details" pb.Restore() @@ -335,6 +364,11 @@ func (ci *CertificateInfo) CeremonyIssuer(seqnr, rootseqnr string, use_existing_ } defer os.Remove(ceremonyCfg) + err = waitForFile("/opt/boulder/bin/ceremony") + if err != nil { + return "", fmt.Errorf("could not wait for /opt/boulder/bin/ceremony to exist: %s", err.Error()) + } + if _, err = exeCmd("/opt/boulder/bin/ceremony -config " + ceremonyCfg); err != nil { ci.Errors["Generate"] = "failed to execute issuer cert ceremony, see logs for details" cb.Restore() @@ -423,6 +457,11 @@ func (ci *CertificateInfo) CeremonyRootCRL(seqnr string) error { } defer os.Remove(keyCfg) + err = waitForFile("/opt/boulder/bin/ceremony") + if err != nil { + return fmt.Errorf("could not wait for /opt/boulder/bin/ceremony to exist: %s", err.Error()) + } + if _, err = exeCmd("/opt/boulder/bin/ceremony -config " + keyCfg); err != nil { ci.Errors["CRL"] = "failed to execute root crl ceremony, see logs for details" cb.Restore()