summaryrefslogtreecommitdiff
path: root/lib/license/management/shell.rb
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-04-23 12:53:19 -0600
committermo khan <mo.khan@gmail.com>2020-04-29 23:20:55 -0600
commitdb4c74a3275cafd8fdd5f1534f04b1969da31524 (patch)
tree2573572fcc1443fa77caa9068ef01ad3fbc4c436 /lib/license/management/shell.rb
parent86950d555fc22d88134360fdc7c3da87ba5f8895 (diff)
Allow gradle to fetch from TLS endpoint with custom cert
* Add CHANGELOG entry * Avoid shell expansion errors * Add gradle-license-plugin to local gradle cache * Download gradle plugin dependencies and use backwards compatible syntax in init.gradle * Use latest gradle v2
Diffstat (limited to 'lib/license/management/shell.rb')
-rw-r--r--lib/license/management/shell.rb26
1 files changed, 22 insertions, 4 deletions
diff --git a/lib/license/management/shell.rb b/lib/license/management/shell.rb
index f16537d..9ff59c4 100644
--- a/lib/license/management/shell.rb
+++ b/lib/license/management/shell.rb
@@ -3,6 +3,7 @@
module License
module Management
class Shell
+ SPLIT_SCRIPT = "'BEGIN {x=0;} /BEGIN CERT/{x++} { print > \"custom.\" x \".crt\" }'"
attr_reader :custom_certificate_path, :logger
def initialize(logger: License::Management.logger, certificate: ENV['ADDITIONAL_CA_CERT_BUNDLE'])
@@ -18,7 +19,7 @@ module License
stdout, stderr, status = Open3.capture3(env, expanded_command)
logger.debug(stdout) unless stdout.nil? || stdout.empty?
- logger.error(stderr) unless status.success?
+ logger.error(stderr) unless stderr.nil? || stderr.empty?
[stdout, stderr, status]
end
@@ -40,9 +41,26 @@ module License
return unless present?(certificate)
custom_certificate_path.write(certificate)
- execute("openssl x509 -in #{custom_certificate_path} -text -noout")
- execute('update-ca-certificates -v')
- execute("keytool -importcert -file #{custom_certificate_path} -trustcacerts -noprompt")
+ Dir.chdir custom_certificate_path.dirname do
+ execute([:awk, SPLIT_SCRIPT, '<', custom_certificate_path])
+ execute('update-ca-certificates -v')
+
+ Dir.glob('custom.*.crt').each do |path|
+ full_path = File.expand_path(path)
+ execute([:openssl, :x509, '-in', full_path, '-text', '-noout'])
+ execute([
+ :keytool,
+ '-importcert',
+ '-alias', Time.now.to_i,
+ '-file', full_path,
+ '-trustcacerts',
+ '-noprompt',
+ '-storepass', 'changeit',
+ '-keystore', "#{ENV['JAVA_HOME']}/jre/lib/security/cacerts"
+ ])
+ execute(["keytool -list -v -storepass changeit"])
+ end
+ end
end
def present?(item)