Skip to content

Commit

Permalink
Merge pull request #161 from paketo-buildpacks/java-18-keystore
Browse files Browse the repository at this point in the history
Disabled reading of cacerts at build & run time for Java 18
  • Loading branch information
Daniel Mikusa authored Apr 6, 2022
2 parents 4832b7f + 67740d6 commit 0c23ab4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 8 deletions.
6 changes: 5 additions & 1 deletion build.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {

if IsLaunchContribution(jrePlanEntry.Metadata) {
helpers := []string{"active-processor-count", "java-opts", "jvm-heap", "link-local-dns", "memory-calculator",
"openssl-certificate-loader", "security-providers-configurer", "jmx", "jfr"}
"security-providers-configurer", "jmx", "jfr"}

if IsBeforeJava9(depJRE.Version) {
helpers = append(helpers, "security-providers-classpath-8")
Expand All @@ -141,6 +141,10 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) {
helpers = append(helpers, "debug-9")
helpers = append(helpers, "nmt")
}
// Java 18 bug - cacerts keystore type not readable
if IsBeforeJava18(depJRE.Version) {
helpers = append(helpers, "openssl-certificate-loader")
}

h, be := libpak.NewHelperLayer(context.Buildpack, helpers...)
h.Logger = b.Logger
Expand Down
4 changes: 2 additions & 2 deletions build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,12 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
"jvm-heap",
"link-local-dns",
"memory-calculator",
"openssl-certificate-loader",
"security-providers-configurer",
"jmx",
"jfr",
"security-providers-classpath-8",
"debug-8",
"openssl-certificate-loader",
}))
})

Expand All @@ -142,13 +142,13 @@ func testBuild(t *testing.T, context spec.G, it spec.S) {
"jvm-heap",
"link-local-dns",
"memory-calculator",
"openssl-certificate-loader",
"security-providers-configurer",
"jmx",
"jfr",
"security-providers-classpath-9",
"debug-9",
"nmt",
"openssl-certificate-loader",
}))
})

Expand Down
12 changes: 9 additions & 3 deletions jdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"os"
"path/filepath"

"github.com/heroku/color"

"github.com/buildpacks/libcnb"
"github.com/paketo-buildpacks/libpak"
"github.com/paketo-buildpacks/libpak/bard"
Expand Down Expand Up @@ -77,10 +79,14 @@ func (j JDK) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
} else {
keyStorePath = filepath.Join(layer.Path, "lib", "security", "cacerts")
}
if err := j.CertificateLoader.Load(keyStorePath, "changeit"); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to load certificates\n%w", err)
}

if IsBeforeJava18(j.LayerContributor.Dependency.Version) {
if err := j.CertificateLoader.Load(keyStorePath, "changeit"); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to load certificates\n%w", err)
}
} else {
j.Logger.Bodyf("%s: The JVM cacerts entries cannot be loaded with Java 18, for more information see: https://github.com/paketo-buildpacks/libjvm/issues/158", color.YellowString("Warning"))
}
return layer, nil
})
}
Expand Down
10 changes: 8 additions & 2 deletions jre.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ import (
"sort"
"strings"

"github.com/heroku/color"

"github.com/buildpacks/libcnb"
"github.com/magiconair/properties"
"github.com/paketo-buildpacks/libpak"
Expand Down Expand Up @@ -84,8 +86,12 @@ func (j JRE) Contribute(layer libcnb.Layer) (libcnb.Layer, error) {
cacertsPath = filepath.Join(layer.Path, "lib", "security", "cacerts")
}

if err := j.CertificateLoader.Load(cacertsPath, "changeit"); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to load certificates\n%w", err)
if IsBeforeJava18(j.LayerContributor.Dependency.Version) {
if err := j.CertificateLoader.Load(cacertsPath, "changeit"); err != nil {
return libcnb.Layer{}, fmt.Errorf("unable to load certificates\n%w", err)
}
} else {
j.Logger.Bodyf("%s: The JVM cacerts entries cannot be loaded with Java 18, for more information see: https://github.com/paketo-buildpacks/libjvm/issues/158", color.YellowString("Warning"))
}

if IsBuildContribution(j.Metadata) {
Expand Down
10 changes: 10 additions & 0 deletions versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
)

var Java9, _ = semver.NewVersion("9")
var Java18, _ = semver.NewVersion("18")

func IsBeforeJava9(candidate string) bool {
v, err := semver.NewVersion(candidate)
Expand All @@ -30,3 +31,12 @@ func IsBeforeJava9(candidate string) bool {

return v.LessThan(Java9)
}

func IsBeforeJava18(candidate string) bool {
v, err := semver.NewVersion(candidate)
if err != nil {
return false
}

return v.LessThan(Java18)
}

0 comments on commit 0c23ab4

Please sign in to comment.