From c2b987fd3176522697f9e8e08f23e58d2670c804 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Wed, 3 Aug 2022 14:31:46 +0200 Subject: [PATCH] Allow hsm to use relative paths --- pkg/hsm/hsm.go | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/pkg/hsm/hsm.go b/pkg/hsm/hsm.go index efb58bf..93e1985 100644 --- a/pkg/hsm/hsm.go +++ b/pkg/hsm/hsm.go @@ -69,21 +69,18 @@ func NewAccess(infoLog *log.Logger, options ...ConfigOption) (*Access, error) { return access, nil } -func (c *caFile) buildCertificatePath(caDirectory string) (string, error) { +func (c *caFile) buildCertificatePath(caDirectory string) string { fileName := c.sc.CertificateFileName(c.label) if caDirectory == "" { - return "", errors.New("CA directory is not set") + return fileName } - return path.Join(caDirectory, fileName), nil + return path.Join(caDirectory, fileName) } func (c *caFile) loadCertificate(caDirectory string) (*x509.Certificate, error) { - certFile, err := c.buildCertificatePath(caDirectory) - if err != nil { - return nil, err - } + certFile := c.buildCertificatePath(caDirectory) certFileInfo, err := os.Stat(certFile) if err != nil { @@ -121,12 +118,9 @@ func (c *caFile) loadCertificate(caDirectory string) (*x509.Certificate, error) } func (c *caFile) storeCertificate(caDirectory string, certificate []byte) error { - certFile, err := c.buildCertificatePath(caDirectory) - if err != nil { - return err - } + certFile := c.buildCertificatePath(caDirectory) - err = os.WriteFile(certFile, certificate, 0o600) + err := os.WriteFile(certFile, certificate, 0o600) if err != nil { return fmt.Errorf("could not write certificate file %s: %w", certFile, err) }