mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 05:47:53 +00:00
commit
318d0d357a
8 changed files with 77 additions and 13 deletions
|
@ -26,15 +26,25 @@ require 'mpw/cli'
|
|||
|
||||
options = {}
|
||||
options[:sync] = {}
|
||||
options[:delete] = false
|
||||
values = {}
|
||||
|
||||
OptionParser.new do |opts|
|
||||
opts.banner = "#{I18n.t('option.usage')}: mpw wallet [options]"
|
||||
|
||||
opts.on('-a', '--add-gpg-key NAME', I18n.t('option.add_gpg_key')) do |gpg_key|
|
||||
options[:gpg_key] = gpg_key
|
||||
end
|
||||
|
||||
opts.on('-c', '--config PATH', I18n.t('option.config')) do |config|
|
||||
options[:config] = config
|
||||
end
|
||||
|
||||
opts.on('-d', '--delete-gpg-key NAME', I18n.t('option.delete_gpg_key')) do |gpg_key|
|
||||
options[:gpg_key] = gpg_key
|
||||
options[:delete] = true
|
||||
end
|
||||
|
||||
opts.on('-h', '--help', I18n.t('option.help')) do
|
||||
puts opts
|
||||
exit 0
|
||||
|
@ -84,6 +94,12 @@ cli.load_config
|
|||
|
||||
if not options[:list].nil?
|
||||
cli.list_wallet
|
||||
elsif not options[:gpg_key].nil?
|
||||
if options[:delete]
|
||||
cli.delete_key(options[:gpg_key])
|
||||
else
|
||||
cli.add_key(options[:gpg_key])
|
||||
end
|
||||
else
|
||||
cli.get_wallet(options[:wallet])
|
||||
cli.decrypt
|
||||
|
|
|
@ -50,9 +50,11 @@ en:
|
|||
|
||||
option:
|
||||
add: "Add an item or key"
|
||||
add_gpg_key: "Share the wallet with an other GPG key"
|
||||
alpha: "Use letter to generate a password"
|
||||
config: "Specify the configuration file to use"
|
||||
clipboard: "Disable the clipboard feature"
|
||||
delete_gpg_key: "Delete the wallet's share with an other GPG key"
|
||||
export: "Export a wallet in an yaml file"
|
||||
file_export: "Specify the file where export data"
|
||||
file_import: "Specify the file to import"
|
||||
|
|
|
@ -50,9 +50,11 @@ fr:
|
|||
|
||||
option:
|
||||
add: "Ajoute un élément ou une clé"
|
||||
add_gpg_key: "Partage le portefeuille avec une autre clé GPG"
|
||||
alpha: "Utilise des lettres dans la génération d'un mot de passe"
|
||||
config: "Spécifie le fichier de configuration à utiliser"
|
||||
clipboard: "Désactive la fonction presse papier"
|
||||
delete_gpg_key: "Supprime le partage le portefeuille avec une autre clé GPG"
|
||||
export: "Exporte un portefeuille dans un fichier yaml"
|
||||
file_export: "Spécifie le fichier où exporter les données"
|
||||
file_import: "Spécifie le fichier à importer"
|
||||
|
|
|
@ -334,10 +334,9 @@ class Cli
|
|||
end
|
||||
|
||||
# Add a new public key
|
||||
# args: key -> the key name to add
|
||||
# file -> gpg public file to import
|
||||
def add_key(key, file=nil)
|
||||
@mpw.add_key(key, file)
|
||||
# args: key -> the key name or key file to add
|
||||
def add_key(key)
|
||||
@mpw.add_key(key)
|
||||
@mpw.write_data
|
||||
@mpw.sync(true) if @sync
|
||||
|
||||
|
|
|
@ -184,13 +184,19 @@ class MPW
|
|||
@passwords[id] = encrypt(password)
|
||||
end
|
||||
|
||||
# Return the list of all gpg keys
|
||||
# rtrn: an array with the gpg keys name
|
||||
def list_keys
|
||||
return @keys.keys
|
||||
end
|
||||
|
||||
# Add a public key
|
||||
# args: key -> new public key
|
||||
# file -> public gpg file to import
|
||||
def add_key(key, file=nil)
|
||||
if not file.nil? and File.exists?(file)
|
||||
data = File.open(file).read
|
||||
GPGME::Key.import(data, armor: true)
|
||||
# args: key -> new public key file or name
|
||||
def add_key(key)
|
||||
if File.exists?(key)
|
||||
data = File.open(key).read
|
||||
key_import = GPGME::Key.import(data, armor: true)
|
||||
key = GPGME::Key.get(key_import.imports[0].fpr).uids[0].email
|
||||
else
|
||||
data = GPGME::Key.export(key, armor: true).read
|
||||
end
|
||||
|
|
19
test/init.rb
Normal file
19
test/init.rb
Normal file
|
@ -0,0 +1,19 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require 'gpgme'
|
||||
|
||||
param = ''
|
||||
param << '<GnupgKeyParms format="internal">' + "\n"
|
||||
param << "Key-Type: RSA\n"
|
||||
param << "Key-Length: 2048\n"
|
||||
param << "Subkey-Type: ELG-E\n"
|
||||
param << "Subkey-Length: 2048\n"
|
||||
param << "Name-Real: test\n"
|
||||
param << "Name-Comment: test\n"
|
||||
param << "Name-Email: test2@example.com\n"
|
||||
param << "Expire-Date: 0\n"
|
||||
param << "Passphrase: password\n"
|
||||
param << "</GnupgKeyParms>\n"
|
||||
|
||||
ctx = GPGME::Ctx.new
|
||||
ctx.genkey(param, nil, nil)
|
|
@ -118,4 +118,23 @@ class TestMPW < Test::Unit::TestCase
|
|||
assert_equal(1, @mpw.list(pattern: 'existing').length)
|
||||
assert_equal(2, @mpw.list(pattern: 'host_[eu]').length)
|
||||
end
|
||||
|
||||
def test_06_add_gpg_key
|
||||
@mpw.read_data
|
||||
|
||||
@mpw.add_key('test2@example.com')
|
||||
assert_equal(2, @mpw.list_keys.length)
|
||||
|
||||
@mpw.write_data
|
||||
end
|
||||
|
||||
def test_07_delete_gpg_key
|
||||
@mpw.read_data
|
||||
assert_equal(2, @mpw.list_keys.length)
|
||||
|
||||
@mpw.delete_key('test2@example.com')
|
||||
assert_equal(1, @mpw.list_keys.length)
|
||||
|
||||
@mpw.write_data
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/ruby
|
||||
|
||||
require_relative 'init.rb'
|
||||
require_relative 'test_config.rb'
|
||||
require_relative 'test_item.rb'
|
||||
require_relative 'test_mpw.rb'
|
||||
|
|
Loading…
Reference in a new issue