From 07efc8ce20098611bb4c58ec95a0b19e9701be7d Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Mon, 31 Jan 2022 20:23:11 -0800 Subject: [PATCH 1/2] Fix last-byte calculation of finalChainPEM Signed-off-by: Thomas Stromberg --- pkg/api/ca.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/api/ca.go b/pkg/api/ca.go index c677a1770..16cee8ef8 100644 --- a/pkg/api/ca.go +++ b/pkg/api/ca.go @@ -213,7 +213,7 @@ func (a *api) signingCert(w http.ResponseWriter, req *http.Request) { } if len(finalChainPEM) > 0 { fmt.Fprintf(&ret, "%s", finalChainPEM) - if finalPEM[len(finalChainPEM)-1] != '\n' { + if finalChainPEM[len(finalChainPEM)-1] != '\n' { fmt.Fprintf(&ret, "\n") } } From e358afd10e149bbcb97786afffe599654a731359 Mon Sep 17 00:00:00 2001 From: Thomas Stromberg Date: Tue, 1 Feb 2022 13:55:18 -0800 Subject: [PATCH 2/2] Use bytes.HasSuffix as recommended in code review Signed-off-by: Thomas Stromberg --- pkg/api/ca.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pkg/api/ca.go b/pkg/api/ca.go index 16cee8ef8..605106592 100644 --- a/pkg/api/ca.go +++ b/pkg/api/ca.go @@ -16,6 +16,7 @@ package api import ( + "bytes" "context" "crypto" "crypto/x509" @@ -202,7 +203,7 @@ func (a *api) signingCert(w http.ResponseWriter, req *http.Request) { return } fmt.Fprintf(&ret, "%s", finalPEM) - if finalPEM[len(finalPEM)-1] != '\n' { + if !bytes.HasSuffix(finalPEM, []byte("\n")) { fmt.Fprintf(&ret, "\n") } @@ -213,7 +214,7 @@ func (a *api) signingCert(w http.ResponseWriter, req *http.Request) { } if len(finalChainPEM) > 0 { fmt.Fprintf(&ret, "%s", finalChainPEM) - if finalChainPEM[len(finalChainPEM)-1] != '\n' { + if !bytes.HasSuffix(finalChainPEM, []byte("\n")) { fmt.Fprintf(&ret, "\n") } }