Class: Leeloo::GpgPrivateLocalFileSystemKeystore
Instance Attribute Summary
#path
Attributes inherited from Keystore
#name
Instance Method Summary
collapse
#==, #find_secrets, #secrets
Methods inherited from Keystore
#==, #footprint, #secrets, #sync
Constructor Details
Returns a new instance of GpgPrivateLocalFileSystemKeystore.
125
126
127
128
129
|
# File 'lib/leeloo/keystore.rb', line 125
def initialize name, path
super name, path
FileUtils.mkdir_p "#{@path}/keys"
populate_recipients
end
|
Instance Method Details
#add_key(email) ⇒ Object
148
149
150
151
152
153
154
155
|
# File 'lib/leeloo/keystore.rb', line 148
def add_key email
paths = []
GPGME::Key.find(:public, email).each do |key|
key.export(:output => File.open("#{path}/keys/#{key.uids.first.email}", "w+"))
paths << "#{path}/keys/#{key.uids.first.email}"
end
return paths
end
|
174
175
176
177
178
|
# File 'lib/leeloo/keystore.rb', line 174
def name
= super name
["sign"] = Base64.strict_encode64 GPGME::Crypto.new.sign(["footprint"]).to_s
end
|
#init ⇒ Object
137
138
139
140
|
# File 'lib/leeloo/keystore.rb', line 137
def init
super
File.write("#{@path}/keys/do_not_remove_me", "do not remove me")
end
|
#keys ⇒ Object
142
143
144
145
146
|
# File 'lib/leeloo/keystore.rb', line 142
def keys
available = GPGME::Key.find(:public, nil, ).map { |key| key.email }
actual = Dir.glob("#{@path}/keys/**").map { |path| path.split('/').last }
available.map { |email| actual.include?(email) ? "#{email}::true" : "#{email}::false" }
end
|
#populate_recipients ⇒ Object
131
132
133
134
135
|
# File 'lib/leeloo/keystore.rb', line 131
def populate_recipients
@recipients = []
Dir.glob("#{path}/keys/*") { |key| @recipients << File.basename(key) }
@recipients.each { |key| GPGME::Key.import(File.open("#{path}/keys/#{key}")) }
end
|
#remove_key(email) ⇒ Object
157
158
159
160
161
162
163
|
# File 'lib/leeloo/keystore.rb', line 157
def remove_key email
if File.exist?("#{path}/keys/#{email}")
File.delete("#{path}/keys/#{email}")
return "#{path}/keys/#{email}"
end
return nil
end
|
180
181
182
183
184
185
186
187
|
# File 'lib/leeloo/keystore.rb', line 180
def
data = GPGME::Crypto.new.verify(Base64.strict_decode64 ["sign"]) { |signature| signature.valid? }
if data.read == ["footprint"]
super
else
raise "signature is not valid"
end
end
|
#secret_from_name(name) ⇒ Object
170
171
172
|
# File 'lib/leeloo/keystore.rb', line 170
def secret_from_name name
secret_of "#{path}/secrets/#{name}.gpg"
end
|
#secret_of(path) ⇒ Object
165
166
167
168
|
# File 'lib/leeloo/keystore.rb', line 165
def secret_of path
name = path.gsub("#{@path}/secrets/", "").gsub(".gpg", "")
GpgLocalFileSystemSecret.new path, name, @recipients
end
|