1 Puppet::Type.type(:odl_keystore).provide(:jks) do
2 commands :keytool => 'keytool'
8 keystore_dir = File.dirname(@resource[:keystore_path])
9 if File.file?("#{keystore_dir}/ctl.p12")
10 FileUtils.rm("#{keystore_dir}/ctl.p12")
15 keystore_dir = File.dirname(@resource[:keystore_path])
16 unless File.directory?(keystore_dir)
17 FileUtils.mkdir_p(keystore_dir, :mode => 0755)
18 FileUtils.chown('odl', 'odl', keystore_dir)
21 key = OpenSSL::PKey::RSA.new File.read(@resource[:key_file])
22 raw_cert = File.read(@resource[:cert_file])
23 certificate = OpenSSL::X509::Certificate.new(raw_cert)
24 if @resource[:ca_file]
25 p12_ks = OpenSSL::PKCS12.create(@resource[:password], @resource[:name], \
26 key, certificate, [@resource[:ca_file]])
28 p12_ks = OpenSSL::PKCS12.create(@resource[:password], @resource[:name], \
31 open "#{keystore_dir}/ctl1.p12", 'w', 0644 do |io|
32 io.write p12_ks.to_der()
35 keytool('-importkeystore', '-deststorepass', @resource[:password], \
36 '-destkeypass', @resource[:password], '-destkeystore', \
37 @resource[:keystore_path], '-srckeystore', "#{keystore_dir}/ctl1.p12", \
38 '-srcstoretype', 'PKCS12', '-srcstorepass', @resource[:password], \
39 '-alias', @resource[:name])
41 unless File.file?(@resource[:keystore_path])
42 raise Puppet::Error, 'JKS keystore creation failed'
44 FileUtils.chown('odl', 'odl', @resource[:keystore_path])
48 FileUtils.rm(@resource[:keystore_path])
52 return File.file?(@resource[:keystore_path])
56 return @resource[:key_file]
59 def key_file=(key_file)
65 return @resource[:cert_file]
68 def cert_file=(cert_file)
74 return @resource[:ca_file]
84 return @resource[:keystore_path]
88 def keystore_path=(keystore_path)
95 keytool('-list', '-keystore', @resource[:keystore_path], '-storepass', \
97 return @resource[:password]
103 def password=(password)