Skip to content

Commit

Permalink
Merge pull request #78 from m-terra/feature/allow-same-name-certs
Browse files Browse the repository at this point in the history
Feature/allow same name certs
  • Loading branch information
bakito committed Sep 22, 2022
2 parents 5883e8f + 9df81bf commit 77100d9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build the manager binary
FROM golang:1.18 as builder
FROM golang:1.19 as builder
RUN apt-get update && apt-get install -y upx

WORKDIR /workspace
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/bakito/java-truststore-injection-webhook

go 1.18
go 1.19

require (
github.com/onsi/ginkgo/v2 v2.2.0
Expand Down
6 changes: 3 additions & 3 deletions pkg/configmap/jks.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ func exportCerts(pems []*pem.Block, jksPassword string, t time.Time) ([]byte, er
func alias(pem []byte, i int) string {
c, err := x509.ParseCertificate(pem)
if err != nil || c.Subject.CommonName == "" {
return fmt.Sprintf("truststore-injector_%d", +i)
return fmt.Sprintf("truststore-injector_%d", i)
}
// inspired by: https://github.com/kaikramer/keystore-explorer/blob/79600e0e5cb5799dfc700df0989c5ba04f3d1db1/kse/src/org/kse/crypto/x509/X509CertUtil.java#L651

if c.Issuer.CommonName == "" || c.Subject.CommonName == c.Issuer.CommonName {
return strings.ToLower(c.Subject.CommonName)
return strings.ToLower(fmt.Sprintf("%s %d", c.Subject.CommonName, i))
}
return strings.ToLower(fmt.Sprintf("%s (%s)", c.Subject.CommonName, c.Issuer.CommonName))
return strings.ToLower(fmt.Sprintf("%s (%s) %d", c.Subject.CommonName, c.Issuer.CommonName, i))
}

0 comments on commit 77100d9

Please sign in to comment.