Escape path character in certificate scopes

This commit is contained in:
Adnan Maolood 2020-11-24 20:24:38 -05:00
parent cab23032c0
commit 35e984fbba
2 changed files with 5 additions and 0 deletions

View File

@ -48,6 +48,8 @@ func (c *CertificateDir) Add(scope string, cert tls.Certificate) {
// Write writes the provided certificate to the certificate directory.
func (c *CertificateDir) Write(scope string, cert tls.Certificate) error {
if c.dir {
// Escape slash character
scope = strings.ReplaceAll(scope, "/", ":")
certPath := filepath.Join(c.path, scope+".crt")
keyPath := filepath.Join(c.path, scope+".key")
if err := WriteCertificate(cert, certPath, keyPath); err != nil {
@ -81,6 +83,8 @@ func (c *CertificateDir) Load(path string) error {
continue
}
scope := strings.TrimSuffix(filepath.Base(crtPath), ".crt")
// Unescape slash character
scope = strings.ReplaceAll(scope, ":", "/")
c.Add(scope, cert)
}
c.dir = true

View File

@ -134,6 +134,7 @@ func (c *Client) do(req *Request, via []*Request) (*Response, error) {
return resp, err
}
c.Certificates.Add(hostname+path, cert)
c.Certificates.Write(hostname+path, cert)
req.Certificate = &cert
return c.do(req, via)
}