Module: Ccrypto::Java::Keystore
- Defined in:
- lib/ccrypto/java/keystore/keystore.rb,
lib/ccrypto/java/keystore/jce_keystore.rb,
lib/ccrypto/java/keystore/jks_keystore.rb,
lib/ccrypto/java/keystore/pem_keystore.rb,
lib/ccrypto/java/keystore/pkcs12_keystore.rb
Defined Under Namespace
Classes: JCEKeystore, JKSKeystore, PEMKeystore, PKCS12Keystore
Class Method Summary
collapse
-
.convert_keystore(bin, fromEng, toEng, &block) ⇒ Object
-
.convert_keystore_file(path, fromEng, toEng, &block) ⇒ Object
-
.load_keystore(bin, eng, &block) ⇒ Object
-
.load_keystore_file(path, eng, &block) ⇒ Object
-
.map_keystore_type(key) ⇒ Object
Class Method Details
.convert_keystore(bin, fromEng, toEng, &block) ⇒ Object
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
|
# File 'lib/ccrypto/java/keystore/keystore.rb', line 39
def self.convert_keystore(bin, fromEng, toEng, &block)
srcEng = map_keystore_type(fromEng)
mtEng = map_keystore_type(toEng)
kp, cert, chain = load_keystore(bin, srcEng) do |opt|
case opt
when :store_pass
block.call(:source_store_pass)
else
block.call(opt)
end
end
outEng = map_keystore_type(mtEng)
case outEng
when :pkcs12
PKCS12Keystore.to_p12 do |k|
case k
when :keypair
kp
when :cert
cert
when :cert_chain
chain
when :store_pass
block.call(:dest_store_pass)
else
block.call(k)
end
end
when :jks
JKSKeystore.to_jks do |k|
case k
when :keypair
kp
when :cert
cert
when :cert_chain
chain
when :store_pass
block.call(:dest_store_pass)
else
block.call(k)
end
end
else
raise Ccrypto::Keystore::KeystoreException, "Unsupported keystore type '#{eng}'"
end
end
|
.convert_keystore_file(path, fromEng, toEng, &block) ⇒ Object
89
90
91
92
93
|
# File 'lib/ccrypto/java/keystore/keystore.rb', line 89
def self.convert_keystore_file(path, fromEng, toEng, &block)
raise Ccrypto::Keystore::KeystoreException, "Given keystore path to load '#{path}' does not exist" if not File.exist?(path)
raise Ccrypto::Keystore::KeystoreException, "Given keystore path to load '#{path}' cannot be read" if not File.readable?(path)
convert_keystore(File.read(path), fromEng, toEng, &block)
end
|
.load_keystore(bin, eng, &block) ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/ccrypto/java/keystore/keystore.rb', line 21
def self.load_keystore(bin, eng, &block)
mEng = map_keystore_type(eng)
case mEng
when :pkcs12
PKCS12Keystore.from_p12(bin, &block)
when :jks
JKSKeystore.from_jks(bin, &block)
else
raise Ccrypto::Keystore::KeystoreException, "Unsupported keystore type '#{eng}'"
end
end
|
.load_keystore_file(path, eng, &block) ⇒ Object
33
34
35
36
37
|
# File 'lib/ccrypto/java/keystore/keystore.rb', line 33
def self.load_keystore_file(path, eng, &block)
raise Ccrypto::Keystore::KeystoreException, "Given keystore path to load '#{path}' does not exist" if not File.exist?(path)
raise Ccrypto::Keystore::KeystoreException, "Given keystore path to load '#{path}' cannot be read" if not File.readable?(path)
load_keystore(File.read(path), eng, &block)
end
|
.map_keystore_type(key) ⇒ Object
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/ccrypto/java/keystore/keystore.rb', line 10
def self.map_keystore_type(key)
case key.to_sym
when :pkcs12, :p12, :PKCS12, :P12, :Pkcs12
:pkcs12
when :jks, :Jks, :JKS, :java
:jks
else
raise Ccrypto::Keystore::KeystoreException, "Unsupported keystore type '#{key}'"
end
end
|