From 8e4027c82216e304f11a4f60b43ade4fe0b54a53 Mon Sep 17 00:00:00 2001 From: nishiki Date: Tue, 5 Jul 2016 22:03:55 +0200 Subject: [PATCH] switch gpg2 to gpg1 --- i18n/en.yml | 1 + i18n/fr.yml | 1 + lib/mpw/config.rb | 6 +++++- lib/mpw/mpw.rb | 9 +++++++-- lib/mpw/ui/cli.rb | 5 +++-- 5 files changed, 17 insertions(+), 5 deletions(-) diff --git a/i18n/en.yml b/i18n/en.yml index 5c36344..9121813 100644 --- a/i18n/en.yml +++ b/i18n/en.yml @@ -86,6 +86,7 @@ en: title: "Setup a new config file" lang: "Choose your language (en, fr, ...) [default=%{lang}]: " gpg_key: "Enter the GPG key [ex: test@host.local]: " + gpg_exe: "Enter the executable GPG path (optional): " wallet_dir: "Enter the wallets's folder path [default=%{home}/wallets]: " valid: "The config file has been created!" setup_wallet: diff --git a/i18n/fr.yml b/i18n/fr.yml index f273aff..155a177 100644 --- a/i18n/fr.yml +++ b/i18n/fr.yml @@ -86,6 +86,7 @@ fr: title: "Création d'un nouveau fichier de configuration" lang: "Choisissez votre langue (en, fr, ...) [défaut=%{lang}]: " gpg_key: "Entrez la clé GPG [ex: test@host.local]: " + gpg_exe: "Entrez le chemin de l'exécutable GPG (optionnel): " wallet_dir: "Entrez le chemin du répertoire qui contiendra les porte-feuilles de mot de passe [défaut=%{home}/wallets]: " valid: "Le fichier de configuration a bien été créé!" setup_wallet: diff --git a/lib/mpw/config.rb b/lib/mpw/config.rb index 49345d7..90df409 100644 --- a/lib/mpw/config.rb +++ b/lib/mpw/config.rb @@ -30,6 +30,7 @@ class Config attr_accessor :lang attr_accessor :config_dir attr_accessor :wallet_dir + attr_accessor :gpg_exe # Constructor # @args: config_file -> the specify config file @@ -53,8 +54,9 @@ class Config # @args: key -> the gpg key to encrypt # lang -> the software language # wallet_dir -> the directory where are the wallets password + # gpg_exe -> the path of gpg executable # @rtrn: true if le config file is create - def setup(key, lang, wallet_dir) + def setup(key, lang, wallet_dir, gpg_exe) if not key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/ raise I18n.t('error.config.key_bad_format') @@ -67,6 +69,7 @@ class Config config = {'config' => {'key' => key, 'lang' => lang, 'wallet_dir' => wallet_dir, + 'gpg_exe' => gpg_exe, } } @@ -118,6 +121,7 @@ class Config @key = config['config']['key'] @lang = config['config']['lang'] @wallet_dir = config['config']['wallet_dir'] + @gpg_exe = config['config']['gpg_exe'] raise if @key.empty? or @wallet_dir.empty? diff --git a/lib/mpw/mpw.rb b/lib/mpw/mpw.rb index a07061c..f2b2ddc 100644 --- a/lib/mpw/mpw.rb +++ b/lib/mpw/mpw.rb @@ -28,10 +28,15 @@ module MPW class MPW # Constructor - def initialize(key, wallet_file, gpg_pass=nil) + def initialize(key, wallet_file, gpg_pass=nil, gpg_exe=nil) @key = key @gpg_pass = gpg_pass + @gpg_exe = gpg_exe @wallet_file = wallet_file + + if @gpg_exe + GPGME::Engine.set_info(GPGME::PROTOCOL_OpenPGP, @gpg_exe, "#{Dir.home}/.gnupg") + end end # Read mpw file @@ -331,7 +336,7 @@ class MPW sync.connect sync.get(tmp_file) - remote = MPW.new(@key, tmp_file, @gpg_pass) + remote = MPW.new(@key, tmp_file, @gpg_pass, @gpg_exe) remote.read_data File.unlink(tmp_file) if File.exist?(tmp_file) diff --git a/lib/mpw/ui/cli.rb b/lib/mpw/ui/cli.rb index 3bfe30a..d72d597 100644 --- a/lib/mpw/ui/cli.rb +++ b/lib/mpw/ui/cli.rb @@ -44,13 +44,14 @@ class Cli language = ask(I18n.t('form.setup_config.lang', lang: lang)).to_s key = ask(I18n.t('form.setup_config.gpg_key')).to_s wallet_dir = ask(I18n.t('form.setup_config.wallet_dir', home: "#{@config.config_dir}")).to_s + gpg_exe = ask(I18n.t('form.setup_config.gpg_exe')).to_s if language.nil? or language.empty? language = lang end I18n.locale = language.to_sym - @config.setup(key, lang, wallet_dir) + @config.setup(key, lang, wallet_dir, gpg_exe) raise I18n.t('error.config.check') if not @config.is_valid? @@ -122,7 +123,7 @@ class Cli def decrypt if not defined?(@mpw) @password = ask(I18n.t('display.gpg_password')) {|q| q.echo = false} - @mpw = MPW.new(@config.key, @wallet_file, @password) + @mpw = MPW.new(@config.key, @wallet_file, @password, @config.gpg_exe) end @mpw.read_data