Skip to content

Commit cd0369c

Browse files
Merge pull request #394 from erikgb/move-default-password-api
refactor: move default truststore passwords to API
2 parents 825c6f6 + a4b8e56 commit cd0369c

File tree

6 files changed

+29
-22
lines changed

6 files changed

+29
-22
lines changed

docs/api/api.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,19 @@ import "github.com/cert-manager/trust-manager/pkg/apis/trust/v1alpha1"
5858

5959
## Constants
6060

61-
<a name="BundleConditionSynced"></a>
61+
<a name="DefaultJKSPassword"></a>
6262

6363
```go
6464
const (
65+
// DefaultJKSPassword is the default password that Java uses; it's a Java convention to use this exact password.
66+
// Since we're not storing anything secret in the JKS files we generate, this password is not a meaningful security measure
67+
// but seems often to be expected by applications consuming JKS files
68+
DefaultJKSPassword = "changeit"
69+
// DefaultPKCS12Password is the empty string, that will create a password-less PKCS12 truststore.
70+
// Password-less PKCS is the new default Java truststore from Java 18.
71+
// By password-less, it means the certificates are not encrypted, and it contains no MacData for integrity check.
72+
DefaultPKCS12Password = ""
73+
6574
// BundleConditionSynced indicates that the Bundle has successfully synced
6675
// all source bundle data to the Bundle target in all Namespaces.
6776
BundleConditionSynced string = "Synced"

pkg/apis/trust/v1alpha1/types_bundle.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,15 @@ type BundleCondition struct {
239239
}
240240

241241
const (
242+
// DefaultJKSPassword is the default password that Java uses; it's a Java convention to use this exact password.
243+
// Since we're not storing anything secret in the JKS files we generate, this password is not a meaningful security measure
244+
// but seems often to be expected by applications consuming JKS files
245+
DefaultJKSPassword = "changeit"
246+
// DefaultPKCS12Password is the empty string, that will create a password-less PKCS12 truststore.
247+
// Password-less PKCS is the new default Java truststore from Java 18.
248+
// By password-less, it means the certificates are not encrypted, and it contains no MacData for integrity check.
249+
DefaultPKCS12Password = ""
250+
242251
// BundleConditionSynced indicates that the Bundle has successfully synced
243252
// all source bundle data to the Bundle target in all Namespaces.
244253
BundleConditionSynced string = "Synced"

pkg/bundle/bundle_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import (
4848
func testEncodeJKS(t *testing.T, data string) []byte {
4949
t.Helper()
5050

51-
encoded, err := jksEncoder{password: DefaultJKSPassword}.encode(data)
51+
encoded, err := jksEncoder{password: trustapi.DefaultJKSPassword}.encode(data)
5252
if err != nil {
5353
t.Error(err)
5454
}
@@ -493,7 +493,7 @@ func Test_Reconcile(t *testing.T) {
493493
KeySelector: trustapi.KeySelector{
494494
Key: "target.jks",
495495
},
496-
Password: ptr.To(DefaultJKSPassword),
496+
Password: ptr.To(trustapi.DefaultJKSPassword),
497497
},
498498
}),
499499
)},
@@ -566,7 +566,7 @@ func Test_Reconcile(t *testing.T) {
566566
KeySelector: trustapi.KeySelector{
567567
Key: "target.jks",
568568
},
569-
Password: ptr.To(DefaultJKSPassword),
569+
Password: ptr.To(trustapi.DefaultJKSPassword),
570570
},
571571
}),
572572
),

pkg/bundle/source.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,6 @@ import (
3737
"github.com/cert-manager/trust-manager/pkg/util"
3838
)
3939

40-
const (
41-
// DefaultJKSPassword is the default password that Java uses; it's a Java convention to use this exact password.
42-
// Since we're not storing anything secret in the JKS files we generate, this password is not a meaningful security measure
43-
// but seems often to be expected by applications consuming JKS files
44-
DefaultJKSPassword = "changeit"
45-
// DefaultPKCS12Password is the empty string, that will create a password-less PKCS12 truststore.
46-
// Password-less PKCS is the new default Java truststore from Java 18.
47-
// By password-less, it means the certificates are not encrypted, and it contains no MacData for integrity check.
48-
DefaultPKCS12Password = ""
49-
)
50-
5140
type notFoundError struct{ error }
5241

5342
// bundleData holds the result of a call to buildSourceBundle. It contains the resulting PEM-encoded

pkg/bundle/source_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func Test_buildSourceBundle(t *testing.T) {
230230
KeySelector: trustapi.KeySelector{
231231
Key: jksKey,
232232
},
233-
Password: ptr.To(DefaultJKSPassword),
233+
Password: ptr.To(trustapi.DefaultJKSPassword),
234234
},
235235
},
236236
objects: []runtime.Object{&corev1.ConfigMap{
@@ -269,7 +269,7 @@ func Test_buildSourceBundle(t *testing.T) {
269269
KeySelector: trustapi.KeySelector{
270270
Key: pkcs12Key,
271271
},
272-
Password: ptr.To(DefaultPKCS12Password),
272+
Password: ptr.To(trustapi.DefaultPKCS12Password),
273273
},
274274
},
275275
objects: []runtime.Object{&corev1.ConfigMap{
@@ -326,14 +326,14 @@ func Test_buildSourceBundle(t *testing.T) {
326326
if test.expPassword != nil {
327327
password = *test.expPassword
328328
} else {
329-
password = DefaultJKSPassword
329+
password = trustapi.DefaultJKSPassword
330330
}
331331
}
332332
if test.expPKCS12 {
333333
if test.expPassword != nil {
334334
password = *test.expPassword
335335
} else {
336-
password = DefaultPKCS12Password
336+
password = trustapi.DefaultPKCS12Password
337337
}
338338
}
339339

@@ -398,7 +398,7 @@ func Test_encodeJKSAliases(t *testing.T) {
398398
// Using different dummy certs would allow this test to pass but wouldn't actually test anything useful!
399399
bundle := dummy.JoinCerts(dummy.TestCertificate1, dummy.TestCertificate2)
400400

401-
jksFile, err := jksEncoder{password: DefaultJKSPassword}.encode(bundle)
401+
jksFile, err := jksEncoder{password: trustapi.DefaultJKSPassword}.encode(bundle)
402402
if err != nil {
403403
t.Fatalf("didn't expect an error but got: %s", err)
404404
}
@@ -407,7 +407,7 @@ func Test_encodeJKSAliases(t *testing.T) {
407407

408408
ks := jks.New()
409409

410-
err = ks.Load(reader, []byte(DefaultJKSPassword))
410+
err = ks.Load(reader, []byte(trustapi.DefaultJKSPassword))
411411
if err != nil {
412412
t.Fatalf("failed to parse generated JKS file: %s", err)
413413
}

test/integration/bundle/suite.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ var _ = Describe("Integration", func() {
352352
jksData, exists := configMap.BinaryData["myfile.jks"]
353353
Expect(exists).To(BeTrue(), "should find an entry called myfile.jks")
354354

355-
Expect(testenv.CheckJKSFileSynced(jksData, bundle.DefaultJKSPassword, dummy.DefaultJoinedCerts())).ToNot(HaveOccurred())
355+
Expect(testenv.CheckJKSFileSynced(jksData, trustapi.DefaultJKSPassword, dummy.DefaultJoinedCerts())).ToNot(HaveOccurred())
356356
}
357357
})
358358

0 commit comments

Comments
 (0)