From 8a37a4d192da32644fd72144aa35e70b9bc2347f Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 7 Dec 2016 23:55:20 +0000 Subject: [PATCH 1/4] Dyadic first commit --- config/components.yml | 1 + config/dyadic_ekm_security_provider.yml | 20 ++ .../framework/dyadic_ekm_security_provider.rb | 243 ++++++++++++++++++ 3 files changed, 264 insertions(+) create mode 100644 config/dyadic_ekm_security_provider.yml create mode 100644 lib/java_buildpack/framework/dyadic_ekm_security_provider.rb diff --git a/config/components.yml b/config/components.yml index 835331e7da..ed68956e19 100644 --- a/config/components.yml +++ b/config/components.yml @@ -47,6 +47,7 @@ frameworks: - "JavaBuildpack::Framework::Jmx" - "JavaBuildpack::Framework::JrebelAgent" - "JavaBuildpack::Framework::LunaSecurityProvider" + - "JavaBuildpack::Framework::DyadicEkmSecurityProvider" - "JavaBuildpack::Framework::MariaDbJDBC" - "JavaBuildpack::Framework::NewRelicAgent" - "JavaBuildpack::Framework::PlayFrameworkAutoReconfiguration" diff --git a/config/dyadic_ekm_security_provider.yml b/config/dyadic_ekm_security_provider.yml new file mode 100644 index 0000000000..17988f33df --- /dev/null +++ b/config/dyadic_ekm_security_provider.yml @@ -0,0 +1,20 @@ +# Cloud Foundry Java Buildpack +# Copyright 2013-2016 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. + +# Configuration for the Luna Security Provider framework +--- +version: 1.+ +repository_root: http://do-not-give-this-url-to-anyone.download.pivotal.io.s3.amazonaws.com/dyadic/ +logging_enabled: false diff --git a/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb b/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb new file mode 100644 index 0000000000..d67f3c69ad --- /dev/null +++ b/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb @@ -0,0 +1,243 @@ +# Encoding: utf-8 +# Cloud Foundry Java Buildpack +# Copyright 2013-2016 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 'fileutils' +require 'java_buildpack/component/versioned_dependency_component' +require 'java_buildpack/framework' +require 'java_buildpack/util/qualify_path' + +module JavaBuildpack + module Framework + + # Encapsulates the functionality for enabling zero-touch Safenet Luna HSM Java Security Provider support. + class DyadicEkmSecurityProvider < JavaBuildpack::Component::VersionedDependencyComponent + include JavaBuildpack::Util + + # (see JavaBuildpack::Component::BaseComponent#compile) + def compile + download_tar + # setup_ext_dir + + # @droplet.copy_resources + + # credentials = @application.services.find_service(FILTER)['credentials'] + # write_client credentials['client'] + # write_servers credentials['servers'] + # write_configuration credentials['servers'], credentials['groups'] + end + + # (see JavaBuildpack::Component::BaseComponent#release) + def release + @droplet + .java_opts + .add_system_property('java.library.path', @droplet.sandbox + 'usr/lib') + @droplet.environment_variables.add_environment_variable 'LD_LIBRARY_PATH', @droplet.sandbox + 'usr/lib' + #@droplet.environment_variables.add_environment_variable 'ChrystokiConfigurationPath', @droplet.sandbox + + #@droplet + # .java_opts + # .add_system_property('java.security.properties', @droplet.sandbox + 'java.security') + # .add_system_property('java.ext.dirs', ext_dirs) + @droplet.additional_libraries << (@droplet.sandbox + 'usr/lib/dsm/dsm-advapi-1.0.jar') + end + + protected + + # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) + def supports? + #@application.services.one_service? FILTER, 'client', 'servers', 'groups' + true + end + + private + + FILTER = /luna/ + + private_constant :FILTER + + def chrystoki + @droplet.sandbox + 'Chrystoki.conf' + end + + def client_certificate + @droplet.sandbox + 'client-certificate.pem' + end + + def client_private_key + @droplet.sandbox + 'client-private-key.pem' + end + + def ext_dir + @droplet.sandbox + 'ext' + end + + def luna_provider_jar + @droplet.sandbox + 'jsp/LunaProvider.jar' + end + + def luna_api_so + @droplet.sandbox + 'jsp/64/libLunaAPI.so' + end + + def lib_cryptoki + @droplet.sandbox + 'libs/64/libCryptoki2.so' + end + + def lib_cklog + @droplet.sandbox + 'libs/64/libcklog2.so' + end + + def setup_ext_dir + FileUtils.mkdir ext_dir + [luna_provider_jar, luna_api_so].each do |file| + FileUtils.ln_s file.relative_path_from(ext_dir), ext_dir, force: true + end + end + + def ext_dirs + "#{qualify_path(@droplet.java_home.root + 'lib/ext', @droplet.root)}:" \ + "#{qualify_path(ext_dir, @droplet.root)}" + end + + def logging? + @configuration['logging_enabled'] + end + + def padded_index(index) + index.to_s.rjust(2, '0') + end + + def relative(path) + path.relative_path_from(@droplet.root) + end + + def server_certificates + @droplet.sandbox + 'server-certificates.pem' + end + + def write_client(client) + FileUtils.mkdir_p client_certificate.parent + client_certificate.open(File::CREAT | File::WRONLY) do |f| + f.write "#{client['certificate']}\n" + end + + FileUtils.mkdir_p client_private_key.parent + client_private_key.open(File::CREAT | File::WRONLY) do |f| + f.write "#{client['private-key']}\n" + end + end + + def write_configuration(servers, groups) + chrystoki.open(File::APPEND | File::WRONLY) do |f| + write_prologue f + servers.each_with_index { |server, index| write_server f, index, server } + f.write < Date: Thu, 8 Dec 2016 02:36:54 +0000 Subject: [PATCH 2/4] Daydic second commit --- config/dyadic_ekm_security_provider.yml | 2 +- .../framework/dyadic_ekm_security_provider.rb | 42 +++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/config/dyadic_ekm_security_provider.yml b/config/dyadic_ekm_security_provider.yml index 17988f33df..4961adef38 100644 --- a/config/dyadic_ekm_security_provider.yml +++ b/config/dyadic_ekm_security_provider.yml @@ -16,5 +16,5 @@ # Configuration for the Luna Security Provider framework --- version: 1.+ -repository_root: http://do-not-give-this-url-to-anyone.download.pivotal.io.s3.amazonaws.com/dyadic/ +repository_root: https://repo.dyadicsec.com/cust/pcf logging_enabled: false diff --git a/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb b/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb index d67f3c69ad..a1ef1d9666 100644 --- a/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb +++ b/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb @@ -33,8 +33,11 @@ def compile # @droplet.copy_resources - # credentials = @application.services.find_service(FILTER)['credentials'] - # write_client credentials['client'] + credentials = @application.services.find_service(FILTER)['credentials'] + write_ekm_key credentials['key'] + write_ekm_cert credentials['ca'] + write_ekm_conf credentials['servers'], credentials['send_timeout'], credentials['recv_timeout'], credentials['retries'] + # key credentials['client'] # write_servers credentials['servers'] # write_configuration credentials['servers'], credentials['groups'] end @@ -64,7 +67,7 @@ def supports? private - FILTER = /luna/ + FILTER = /dyadic/ private_constant :FILTER @@ -127,7 +130,19 @@ def relative(path) def server_certificates @droplet.sandbox + 'server-certificates.pem' end + + def ekm_key + @droplet.sandbox + 'etc/dsm/key.pem' + end + + def ekm_cert + @droplet.sandbox + 'etc/dsm/ca.crt' + end + def ekm_conf + @droplet.sandbox + 'etc/dsm/client.conf' + end + def write_client(client) FileUtils.mkdir_p client_certificate.parent client_certificate.open(File::CREAT | File::WRONLY) do |f| @@ -237,6 +252,27 @@ def write_servers(servers) servers.each { |server| f.write "#{server['certificate']}\n" } end end + + def write_ekm_key(key) + ekm_key.open(File::CREAT | File::WRONLY) do |f| + f.write key + end + end + + def write_ekm_cert(cert) + ekm_cert.open(File::CREAT | File::WRONLY) do |f| + f.write cert + end + end + + def write_ekm_conf(servers,send_timeout,recv_timeout,retries) + ekm_conf.open(File::CREAT | File::WRONLY) do |f| + f.write "servers = " + servers + "\n" + f.write "send_timeout = " + send_timeout + "\n" + f.write "recv_timeout = " + recv_timeout + "\n" + f.write "retries = " + retries + "\n" + end + end end end From 93061bb5870b8929b9a1ce6705e693532eaf1c29 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Thu, 8 Dec 2016 19:11:33 +0000 Subject: [PATCH 3/4] Add ext folder --- .../framework/dyadic_ekm_security_provider.rb | 27 ++++++++++--------- .../java.security | 1 + 2 files changed, 16 insertions(+), 12 deletions(-) create mode 100644 resources/dyadic_ekm_security_provider/java.security diff --git a/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb b/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb index a1ef1d9666..7cc6eb81fb 100644 --- a/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb +++ b/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb @@ -29,9 +29,9 @@ class DyadicEkmSecurityProvider < JavaBuildpack::Component::VersionedDependencyC # (see JavaBuildpack::Component::BaseComponent#compile) def compile download_tar - # setup_ext_dir + setup_ext_dir - # @droplet.copy_resources + @droplet.copy_resources credentials = @application.services.find_service(FILTER)['credentials'] write_ekm_key credentials['key'] @@ -40,7 +40,8 @@ def compile # key credentials['client'] # write_servers credentials['servers'] # write_configuration credentials['servers'], credentials['groups'] - end + # @droplet.additional_libraries << (@droplet.sandbox + 'usr/lib/dsm/dsm-advapi-1.0.jar') + end # (see JavaBuildpack::Component::BaseComponent#release) def release @@ -50,11 +51,11 @@ def release @droplet.environment_variables.add_environment_variable 'LD_LIBRARY_PATH', @droplet.sandbox + 'usr/lib' #@droplet.environment_variables.add_environment_variable 'ChrystokiConfigurationPath', @droplet.sandbox - #@droplet - # .java_opts - # .add_system_property('java.security.properties', @droplet.sandbox + 'java.security') - # .add_system_property('java.ext.dirs', ext_dirs) - @droplet.additional_libraries << (@droplet.sandbox + 'usr/lib/dsm/dsm-advapi-1.0.jar') + @droplet + .java_opts + .add_system_property('java.security.properties', @droplet.sandbox + 'java.security') + .add_system_property('java.ext.dirs', ext_dirs) + #@droplet.additional_libraries << (@droplet.sandbox + 'usr/lib/dsm/dsm-advapi-1.0.jar') end protected @@ -102,12 +103,14 @@ def lib_cryptoki def lib_cklog @droplet.sandbox + 'libs/64/libcklog2.so' end + + def dyadic_jar + @droplet.sandbox + 'usr/lib/dsm/dsm-advapi-1.0.jar' + end def setup_ext_dir - FileUtils.mkdir ext_dir - [luna_provider_jar, luna_api_so].each do |file| - FileUtils.ln_s file.relative_path_from(ext_dir), ext_dir, force: true - end + FileUtils.mkdir ext_dir + FileUtils.ln_s dyadic_jar.relative_path_from(ext_dir), ext_dir, force: true end def ext_dirs diff --git a/resources/dyadic_ekm_security_provider/java.security b/resources/dyadic_ekm_security_provider/java.security new file mode 100644 index 0000000000..a4d2eacaf5 --- /dev/null +++ b/resources/dyadic_ekm_security_provider/java.security @@ -0,0 +1 @@ +security.provider.10=com.dyadicsec.provider.DYCryptoProvider From ab199c409e00acdb0b1d53eeedf8f30d9e8883cb Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Sun, 18 Dec 2016 14:25:37 +0000 Subject: [PATCH 4/4] =?UTF-8?q?Clean=20the=20dyadic=20rb=20file=D7=AA:=20R?= =?UTF-8?q?emoves=20all=20Luna=20related=20code?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/dyadic_ekm_security_provider.rb | 192 ++---------------- 1 file changed, 16 insertions(+), 176 deletions(-) diff --git a/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb b/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb index 7cc6eb81fb..e42bf397b3 100644 --- a/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb +++ b/lib/java_buildpack/framework/dyadic_ekm_security_provider.rb @@ -22,7 +22,7 @@ module JavaBuildpack module Framework - # Encapsulates the functionality for enabling zero-touch Safenet Luna HSM Java Security Provider support. + # Encapsulates the functionality for enabling zero-touch Dyadic EKM Java Security Provider support. class DyadicEkmSecurityProvider < JavaBuildpack::Component::VersionedDependencyComponent include JavaBuildpack::Util @@ -34,13 +34,9 @@ def compile @droplet.copy_resources credentials = @application.services.find_service(FILTER)['credentials'] - write_ekm_key credentials['key'] - write_ekm_cert credentials['ca'] - write_ekm_conf credentials['servers'], credentials['send_timeout'], credentials['recv_timeout'], credentials['retries'] - # key credentials['client'] - # write_servers credentials['servers'] - # write_configuration credentials['servers'], credentials['groups'] - # @droplet.additional_libraries << (@droplet.sandbox + 'usr/lib/dsm/dsm-advapi-1.0.jar') + write_key credentials['key'] + write_cert credentials['ca'] + write_conf credentials['servers'], credentials['send_timeout'], credentials['recv_timeout'], credentials['retries'] end # (see JavaBuildpack::Component::BaseComponent#release) @@ -49,21 +45,19 @@ def release .java_opts .add_system_property('java.library.path', @droplet.sandbox + 'usr/lib') @droplet.environment_variables.add_environment_variable 'LD_LIBRARY_PATH', @droplet.sandbox + 'usr/lib' - #@droplet.environment_variables.add_environment_variable 'ChrystokiConfigurationPath', @droplet.sandbox @droplet .java_opts .add_system_property('java.security.properties', @droplet.sandbox + 'java.security') .add_system_property('java.ext.dirs', ext_dirs) - #@droplet.additional_libraries << (@droplet.sandbox + 'usr/lib/dsm/dsm-advapi-1.0.jar') end protected # (see JavaBuildpack::Component::VersionedDependencyComponent#supports?) def supports? - #@application.services.one_service? FILTER, 'client', 'servers', 'groups' - true + @application.services.one_service? FILTER + #true end private @@ -72,37 +66,9 @@ def supports? private_constant :FILTER - def chrystoki - @droplet.sandbox + 'Chrystoki.conf' - end - - def client_certificate - @droplet.sandbox + 'client-certificate.pem' - end - - def client_private_key - @droplet.sandbox + 'client-private-key.pem' - end - def ext_dir @droplet.sandbox + 'ext' end - - def luna_provider_jar - @droplet.sandbox + 'jsp/LunaProvider.jar' - end - - def luna_api_so - @droplet.sandbox + 'jsp/64/libLunaAPI.so' - end - - def lib_cryptoki - @droplet.sandbox + 'libs/64/libCryptoki2.so' - end - - def lib_cklog - @droplet.sandbox + 'libs/64/libcklog2.so' - end def dyadic_jar @droplet.sandbox + 'usr/lib/dsm/dsm-advapi-1.0.jar' @@ -117,159 +83,33 @@ def ext_dirs "#{qualify_path(@droplet.java_home.root + 'lib/ext', @droplet.root)}:" \ "#{qualify_path(ext_dir, @droplet.root)}" end - - def logging? - @configuration['logging_enabled'] - end - - def padded_index(index) - index.to_s.rjust(2, '0') - end - - def relative(path) - path.relative_path_from(@droplet.root) - end - - def server_certificates - @droplet.sandbox + 'server-certificates.pem' - end - def ekm_key + def key_file @droplet.sandbox + 'etc/dsm/key.pem' end - def ekm_cert + def cert_file @droplet.sandbox + 'etc/dsm/ca.crt' end - def ekm_conf + def conf_file @droplet.sandbox + 'etc/dsm/client.conf' end - - def write_client(client) - FileUtils.mkdir_p client_certificate.parent - client_certificate.open(File::CREAT | File::WRONLY) do |f| - f.write "#{client['certificate']}\n" - end - - FileUtils.mkdir_p client_private_key.parent - client_private_key.open(File::CREAT | File::WRONLY) do |f| - f.write "#{client['private-key']}\n" - end - end - - def write_configuration(servers, groups) - chrystoki.open(File::APPEND | File::WRONLY) do |f| - write_prologue f - servers.each_with_index { |server, index| write_server f, index, server } - f.write <