forked from cloudfoundry/java-buildpack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontainer_certificate_trust_store.rb
More file actions
106 lines (83 loc) · 3.1 KB
/
container_certificate_trust_store.rb
File metadata and controls
106 lines (83 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# Cloud Foundry Java Buildpack
# Copyright 2013-2017 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
require 'java_buildpack/component/versioned_dependency_component'
require 'java_buildpack/framework'
require 'fileutils'
module JavaBuildpack
module Framework
# Encapsulates the functionality for contributing container-based certificates to an application.
class ContainerCertificateTrustStore < JavaBuildpack::Component::VersionedDependencyComponent
# (see JavaBuildpack::Component::BaseComponent#compile)
def compile
download_jar
with_timing("Adding certificates to #{trust_store.relative_path_from(@droplet.root)}") do
FileUtils.mkdir_p trust_store.parent
shell command
end
end
# (see JavaBuildpack::Component::BaseComponent#release)
def release
@droplet
.java_opts
.add_system_property('javax.net.ssl.trustStore', trust_store)
.add_system_property('javax.net.ssl.trustStorePassword', password)
end
protected
# (see JavaBuildpack::Component::VersionedDependencyComponent#supports?)
def supports?
supports_configuration? && supports_file?
end
private
DARWIN_CERTIFICATES = Pathname.new('/etc/ssl/cert.pem').freeze
UNIX_CERTIFICATES = Pathname.new('/etc/ssl/certs/ca-certificates.crt').freeze
private_constant :DARWIN_CERTIFICATES, :UNIX_CERTIFICATES
def ca_certificates
if `uname -s` =~ /Darwin/
DARWIN_CERTIFICATES
else
UNIX_CERTIFICATES
end
end
def command
command = "#{java} -jar #{@droplet.sandbox + jar_name} --container-source #{ca_certificates} --destination " \
"#{trust_store} --destination-password #{password}"
command += " --jre-source #{jre_cacerts} --jre-source-password changeit" if jre_cacerts.exist?
command += " --jre-source #{server_jre_cacerts} --jre-source-password changeit" if server_jre_cacerts.exist?
command
end
def java
@droplet.java_home.root + 'bin/java'
end
def jre_cacerts
@droplet.java_home.root + 'lib/security/cacerts'
end
def password
'java-buildpack-trust-store-password'
end
def server_jre_cacerts
@droplet.java_home.root + 'jre/lib/security/cacerts'
end
def supports_configuration?
@configuration['enabled']
end
def supports_file?
ca_certificates.exist?
end
def trust_store
@droplet.sandbox + 'truststore.jks'
end
end
end
end