1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-23 13:57:52 +00:00

add public key in wallet

This commit is contained in:
nishiki 2016-05-07 14:36:57 +02:00
parent 27c4162aa9
commit 22676a8b79
3 changed files with 30 additions and 4 deletions

10
bin/mpw
View file

@ -92,6 +92,10 @@ OptionParser.new do |opts|
options[:import] = file options[:import] = file
end end
opts.on('-k', '--key KEY', I18n.t('option.import')) do |key|
options[:key] = key
end
opts.on('-N', '--no-sync', I18n.t('option.no_sync')) do opts.on('-N', '--no-sync', I18n.t('option.no_sync')) do
options[:sync] = false options[:sync] = false
end end
@ -150,9 +154,13 @@ elsif not options[:update].nil? and not options[:id].nil?
cli.update(options[:id]) cli.update(options[:id])
# Add a new item # Add a new item
elsif not options[:add].nil? elsif not options[:add].nil? and options[:key].nil?
cli.add cli.add
# Add a new public key in wallet
elsif not options[:add].nil? and not options[:key].nil?
cli.add_key(options[:key])
# Export # Export
elsif not options[:export].nil? elsif not options[:export].nil?
cli.export(options[:export]) cli.export(options[:export])

View file

@ -112,7 +112,7 @@ class MPW
@keys.each do |id, key| @keys.each do |id, key|
tar.add_file_simple("wallet/keys/#{id}.pub", 0400, key.length) do |io| tar.add_file_simple("wallet/keys/#{id}.pub", 0400, key.length) do |io|
io.write(password) io.write(key)
end end
end end
end end
@ -131,6 +131,18 @@ class MPW
@passwords[id] = encrypt(password) @passwords[id] = encrypt(password)
end end
# Add public key
# args: key -> new public key
def add_key(key)
data = GPGME::Key.export(key).read
if data.to_s.empty?
raise I18n.t('error.export_key')
end
@keys[key] = data
end
# TODO # TODO
def check_config def check_config
if false if false
@ -150,7 +162,6 @@ class MPW
end end
end end
# Search in some csv data # Search in some csv data
# @args: options -> a hash with paramaters # @args: options -> a hash with paramaters
# @rtrn: a list with the resultat of the search # @rtrn: a list with the resultat of the search

View file

@ -157,7 +157,6 @@ class Cli
def get_wallet(wallet=nil) def get_wallet(wallet=nil)
if wallet.to_s.empty? if wallet.to_s.empty?
wallets = Dir.glob("#{@config.wallet_dir}/*.mpw") wallets = Dir.glob("#{@config.wallet_dir}/*.mpw")
puts wallets
case wallets.length case wallets.length
when 0 when 0
@ -186,6 +185,14 @@ class Cli
end end
end end
# Add new public key
def add_key(key)
@mpw.add_key(key)
@mpw.write_data
rescue Exception => e
puts "#{I18n.t('display.error')} #13: #{e}".red
end
# Form to add a new item # Form to add a new item
def add def add
options = {} options = {}