mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 13:57:52 +00:00
commit
318d0d357a
8 changed files with 77 additions and 13 deletions
|
@ -24,17 +24,27 @@ require 'mpw/cli'
|
||||||
# Options
|
# Options
|
||||||
# --------------------------------------------------------- #
|
# --------------------------------------------------------- #
|
||||||
|
|
||||||
options = {}
|
options = {}
|
||||||
options[:sync] = {}
|
options[:sync] = {}
|
||||||
values = {}
|
options[:delete] = false
|
||||||
|
values = {}
|
||||||
|
|
||||||
OptionParser.new do |opts|
|
OptionParser.new do |opts|
|
||||||
opts.banner = "#{I18n.t('option.usage')}: mpw wallet [options]"
|
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|
|
opts.on('-c', '--config PATH', I18n.t('option.config')) do |config|
|
||||||
options[:config] = config
|
options[:config] = config
|
||||||
end
|
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
|
opts.on('-h', '--help', I18n.t('option.help')) do
|
||||||
puts opts
|
puts opts
|
||||||
exit 0
|
exit 0
|
||||||
|
@ -84,6 +94,12 @@ cli.load_config
|
||||||
|
|
||||||
if not options[:list].nil?
|
if not options[:list].nil?
|
||||||
cli.list_wallet
|
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
|
else
|
||||||
cli.get_wallet(options[:wallet])
|
cli.get_wallet(options[:wallet])
|
||||||
cli.decrypt
|
cli.decrypt
|
||||||
|
|
|
@ -50,9 +50,11 @@ en:
|
||||||
|
|
||||||
option:
|
option:
|
||||||
add: "Add an item or key"
|
add: "Add an item or key"
|
||||||
|
add_gpg_key: "Share the wallet with an other GPG key"
|
||||||
alpha: "Use letter to generate a password"
|
alpha: "Use letter to generate a password"
|
||||||
config: "Specify the configuration file to use"
|
config: "Specify the configuration file to use"
|
||||||
clipboard: "Disable the clipboard feature"
|
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"
|
export: "Export a wallet in an yaml file"
|
||||||
file_export: "Specify the file where export data"
|
file_export: "Specify the file where export data"
|
||||||
file_import: "Specify the file to import"
|
file_import: "Specify the file to import"
|
||||||
|
|
|
@ -50,9 +50,11 @@ fr:
|
||||||
|
|
||||||
option:
|
option:
|
||||||
add: "Ajoute un élément ou une clé"
|
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"
|
alpha: "Utilise des lettres dans la génération d'un mot de passe"
|
||||||
config: "Spécifie le fichier de configuration à utiliser"
|
config: "Spécifie le fichier de configuration à utiliser"
|
||||||
clipboard: "Désactive la fonction presse papier"
|
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"
|
export: "Exporte un portefeuille dans un fichier yaml"
|
||||||
file_export: "Spécifie le fichier où exporter les données"
|
file_export: "Spécifie le fichier où exporter les données"
|
||||||
file_import: "Spécifie le fichier à importer"
|
file_import: "Spécifie le fichier à importer"
|
||||||
|
|
|
@ -334,10 +334,9 @@ class Cli
|
||||||
end
|
end
|
||||||
|
|
||||||
# Add a new public key
|
# Add a new public key
|
||||||
# args: key -> the key name to add
|
# args: key -> the key name or key file to add
|
||||||
# file -> gpg public file to import
|
def add_key(key)
|
||||||
def add_key(key, file=nil)
|
@mpw.add_key(key)
|
||||||
@mpw.add_key(key, file)
|
|
||||||
@mpw.write_data
|
@mpw.write_data
|
||||||
@mpw.sync(true) if @sync
|
@mpw.sync(true) if @sync
|
||||||
|
|
||||||
|
|
|
@ -184,13 +184,19 @@ class MPW
|
||||||
@passwords[id] = encrypt(password)
|
@passwords[id] = encrypt(password)
|
||||||
end
|
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
|
# Add a public key
|
||||||
# args: key -> new public key
|
# args: key -> new public key file or name
|
||||||
# file -> public gpg file to import
|
def add_key(key)
|
||||||
def add_key(key, file=nil)
|
if File.exists?(key)
|
||||||
if not file.nil? and File.exists?(file)
|
data = File.open(key).read
|
||||||
data = File.open(file).read
|
key_import = GPGME::Key.import(data, armor: true)
|
||||||
GPGME::Key.import(data, armor: true)
|
key = GPGME::Key.get(key_import.imports[0].fpr).uids[0].email
|
||||||
else
|
else
|
||||||
data = GPGME::Key.export(key, armor: true).read
|
data = GPGME::Key.export(key, armor: true).read
|
||||||
end
|
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(1, @mpw.list(pattern: 'existing').length)
|
||||||
assert_equal(2, @mpw.list(pattern: 'host_[eu]').length)
|
assert_equal(2, @mpw.list(pattern: 'host_[eu]').length)
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/ruby
|
#!/usr/bin/ruby
|
||||||
|
|
||||||
|
require_relative 'init.rb'
|
||||||
require_relative 'test_config.rb'
|
require_relative 'test_config.rb'
|
||||||
require_relative 'test_item.rb'
|
require_relative 'test_item.rb'
|
||||||
require_relative 'test_mpw.rb'
|
require_relative 'test_mpw.rb'
|
||||||
|
|
Loading…
Reference in a new issue