From 35e984fbba4a968bf04f25342dd730f35d7d747a Mon Sep 17 00:00:00 2001 From: Adnan Maolood Date: Tue, 24 Nov 2020 20:24:38 -0500 Subject: [PATCH] Escape path character in certificate scopes --- cert.go | 4 ++++ client.go | 1 + 2 files changed, 5 insertions(+) diff --git a/cert.go b/cert.go index 3cfcb41..7cadbd9 100644 --- a/cert.go +++ b/cert.go @@ -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 diff --git a/client.go b/client.go index debd744..53fe3c3 100644 --- a/client.go +++ b/client.go @@ -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) }