Skip to content

Commit

Permalink
Remove trailing whitespaces from certificates (#155) (#156)
Browse files Browse the repository at this point in the history
Co-authored-by: lazensky.jiri@feg.eu <lazensky.jiri@feg.eu>
  • Loading branch information
jiri-lazensky and lazensky.jiri@feg.eu authored Jan 18, 2024
1 parent 28bb9e5 commit 488f789
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/exporters/certHelpers.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package exporters

import (
"fmt"
"time"

"crypto/x509"
"encoding/base64"
"encoding/pem"
"fmt"
"os"

"software.sslmate.com/src/go-pkcs12"
"strings"
"time"
"unicode"
)

type certMetric struct {
Expand Down Expand Up @@ -96,6 +96,8 @@ func parseAsPEM(certBytes []byte) (bool, []certMetric, error) {
if block == nil {
return false, metrics, fmt.Errorf("Failed to parse as a pem")
}
// Remove trailing whitespaces to prevent possible error in loop
rest = []byte(strings.TrimRightFunc(string(rest), unicode.IsSpace))
blocks = append(blocks, block)
// Export the remaining certificates in the certificate chain
for len(rest) != 0 {
Expand Down

0 comments on commit 488f789

Please sign in to comment.