Allow hsm to use relative paths

This commit is contained in:
Jan Dittberner 2022-08-03 14:31:46 +02:00 committed by Jan Dittberner
parent 0d69a9013d
commit c2b987fd31

View file

@ -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)
}