mpw 2.0.3 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +3 -5
- data/README.md +115 -6
- data/VERSION +1 -1
- data/bin/mpw +90 -58
- data/i18n/{cli/en.yml → en.yml} +43 -49
- data/i18n/{cli/fr.yml → fr.yml} +45 -51
- data/lib/mpw/config.rb +117 -206
- data/lib/mpw/item.rb +98 -88
- data/lib/mpw/mpw.rb +416 -288
- data/lib/mpw/sync/ftp.rb +55 -68
- data/lib/mpw/sync/ssh.rb +52 -65
- data/lib/mpw/ui/cli.rb +201 -175
- data/mpw.gemspec +9 -8
- metadata +28 -29
- data/bin/mpw-server +0 -78
- data/bin/mpw-ssh +0 -89
- data/i18n/server/en.yml +0 -26
- data/i18n/server/fr.yml +0 -26
- data/lib/mpw/server.rb +0 -343
- data/lib/mpw/sync/mpw.rb +0 -124
- data/lib/mpw/sync.rb +0 -138
- data/lib/mpw/ui/clissh.rb +0 -42
data/i18n/{cli/fr.yml → fr.yml}
RENAMED
@@ -1,8 +1,6 @@
|
|
1
1
|
---
|
2
2
|
fr:
|
3
3
|
error:
|
4
|
-
client:
|
5
|
-
no_authorized: "Vous n'êtes pas autorisé!"
|
6
4
|
config:
|
7
5
|
write: "Impossible d'écrire le fichier de configuration!"
|
8
6
|
check: "Le fichier de configuration est invalide!"
|
@@ -14,52 +12,56 @@ fr:
|
|
14
12
|
password: "Vous devez définir un mot de passe pour votre clé GPG!"
|
15
13
|
delete:
|
16
14
|
id_no_exist: "Impossible de supprimer l'élément %{id}, car il n'existe pas!"
|
17
|
-
export:
|
18
|
-
unknown_type: "Le type de donnée %{type} est inconnu!"
|
19
|
-
write: "Impossible d'exporter les données dans le fichier %{file}!"
|
15
|
+
export: "Impossible d'exporter les données dans le fichier %{file}!"
|
20
16
|
gpg_file:
|
21
17
|
decrypt: "Impossible de déchiffrer le fichier GPG!"
|
22
18
|
encrypt: "Impossible de chiffrer le fichier GPG!"
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
mpw_file:
|
20
|
+
read_data: "Impossible de lire le fichier MPW!"
|
21
|
+
write_data: "Impossible d'écrire le fichier MPW!"
|
22
|
+
import: "Impossible d'importer le fichier %{file}, car il n'est pas lisible!"
|
26
23
|
update:
|
27
24
|
name_empty: "Vous devez définir un nom!"
|
28
25
|
sync:
|
26
|
+
general: "Une erreur est survenue durant la synchronisation"
|
29
27
|
connection: "La connexion n'a pu être établie!"
|
30
28
|
communication: "Un problème de communication avec le serveur est apparu!"
|
31
29
|
download: "Impossible de télécharger le fichier!"
|
32
30
|
not_authorized: "Vous n'avez pas les autorisations d'accès au fichier distant!"
|
33
31
|
upload: "Impossible d'envoyer le fichier sur le serveur!"
|
34
|
-
unknown: "Une erreur inconnue est survenue!"
|
35
|
-
|
32
|
+
unknown: "Une erreur inconnue est survenue!"
|
33
|
+
unknown_type: "Le type de synchronisation est inconnu"
|
36
34
|
|
37
35
|
warning:
|
38
36
|
select: "Votre choix n'est pas un élément valide!"
|
39
37
|
|
40
38
|
option:
|
41
|
-
|
42
|
-
show: "Recherche et affiche les éléments"
|
43
|
-
show_all: "Affiche tous les éléments"
|
44
|
-
update: "Met à jour un élément"
|
45
|
-
remove: "Supprime un élément"
|
46
|
-
group: "Recherche les éléments appartenant au groupe spécifié"
|
47
|
-
add: "Ajoute un élément"
|
39
|
+
add: "Ajoute un élément ou une clé"
|
48
40
|
config: "Spécifie le fichier de configuration à utiliser"
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
type: "Format des données du fichier d'export [csv|yaml]"
|
53
|
-
import: "Importe des éléments depuis un fichier yaml ou csv"
|
54
|
-
force: "Force une action, l'action ne demandera pas de confirmation"
|
55
|
-
no_sync: "Désactive la synchronisation avec le serveur"
|
56
|
-
format: "Change le format d'affichage des éléments par un alternatif"
|
41
|
+
export: "Exporte un portefeuille dans un fichier yaml"
|
42
|
+
file: "Spécifie un fichier, à utiliser avec les options [--import | --export | --add]"
|
43
|
+
force: "Ne demande pas de confirmation pour la suppression d'un élément"
|
57
44
|
generate_password: "Génére un mot de passe aléatoire (défaut 8 caractères)"
|
45
|
+
group: "Recherche les éléments appartenant au groupe spécifié"
|
58
46
|
help: "Affiche ce message d'aide"
|
47
|
+
id: "Spécifie un identifiant, à utiliser avec les options [--delete | --update]"
|
48
|
+
import: "Importe des éléments depuis un fichier yaml"
|
49
|
+
key: "Spécifie le nom d'une clé, à utiliser avec les options [--add | --delete | --update]"
|
50
|
+
no_sync: "Désactive la synchronisation avec le serveur"
|
51
|
+
setup: "Création d'un nouveau fichier de configuration"
|
52
|
+
setup_wallet: "Création d'un nouveau fichier de configuration pour un portefeuille"
|
53
|
+
show: "Recherche et affiche les éléments"
|
54
|
+
show_all: "Affiche tous les éléments"
|
55
|
+
remove: "Supprime un élément"
|
56
|
+
update: "Met à jour un élément"
|
57
|
+
usage: "Utilisation"
|
58
|
+
wallet: "Spécifie le portefeuille à utiliser"
|
59
59
|
|
60
60
|
form:
|
61
61
|
select: "Sélectionner l'élément: "
|
62
|
-
|
62
|
+
add_key:
|
63
|
+
valid: "La clé a bien été ajoutée!"
|
64
|
+
add_item:
|
63
65
|
title: "Ajout d'un nouvel élément"
|
64
66
|
name: "Entrez le nom: "
|
65
67
|
group: "Entrez le groupe (optionnel): "
|
@@ -70,7 +72,9 @@ fr:
|
|
70
72
|
port: "Entrez le port de connexion (optionnel): "
|
71
73
|
comment: "Entrez un commentaire (optionnel): "
|
72
74
|
valid: "L'élément a bien été ajouté!"
|
73
|
-
|
75
|
+
delete_key:
|
76
|
+
valid: "La clé a bien été supprimée!"
|
77
|
+
delete_item:
|
74
78
|
ask: "Êtes vous sûre de vouloir supprimer l'élément %{id} ?"
|
75
79
|
valid: "L'élément %{id} a bien été supprimé!"
|
76
80
|
not_valid: "L'élément %{id} n'a pu être supprimé, car il n'existe pas!"
|
@@ -78,22 +82,23 @@ fr:
|
|
78
82
|
ask: "Êtes vous sûre de vouloir importer le fichier %{file} ?"
|
79
83
|
valid: "L'import est un succès!"
|
80
84
|
not_valid: "Aucune donnée à importer!"
|
81
|
-
|
85
|
+
setup_config:
|
82
86
|
title: "Création d'un nouveau fichier de configuration"
|
83
87
|
lang: "Choisissez votre langue (en, fr, ...) [défaut=%{lang}]: "
|
84
|
-
gpg_key: "Entrez la clé GPG: "
|
85
|
-
|
86
|
-
gpg_file: "Entrez le chemin du fichier qui sera chiffré [défaut=%{home}/db/default.gpg]: "
|
87
|
-
timeout: "Entrez le temps (en seconde) du mot de passe GPG [défaut=60]: "
|
88
|
-
sync_type: "Type de synchronisation (mpw, ssh, ftp, or nil): "
|
89
|
-
sync_host: "Serveur de synchronisation: "
|
90
|
-
sync_port: "Port du serveur de synchronisation: "
|
91
|
-
sync_user: "Utilisateur pour la synchronisation: "
|
92
|
-
sync_pwd: "Mot de passe pour la synchronisation: "
|
93
|
-
sync_path: "Chemin du fichier pour la synchronisation: "
|
88
|
+
gpg_key: "Entrez la clé GPG [ex: test@host.local]: "
|
89
|
+
wallet_dir: "Entrez le chemin du répertoire qui contiendra les porte-feuilles de mot de passe [défaut=%{home}/wallets]: "
|
94
90
|
valid: "Le fichier de configuration a bien été créé!"
|
91
|
+
setup_wallet:
|
92
|
+
title: "Configuration du porte-feuille"
|
93
|
+
sync_type: "Type de synchronisation (ssh, ftp): "
|
94
|
+
sync_host: "Serveur: "
|
95
|
+
sync_port: "Port: "
|
96
|
+
sync_user: "Utilisateur: "
|
97
|
+
sync_pwd: "Mot de passe: "
|
98
|
+
sync_path: "Chemin du fichier: "
|
99
|
+
valid: "Le fichier de configuration du porte-feuille a bien été créé!"
|
95
100
|
setup_gpg_key:
|
96
|
-
title: "Configuration d'une clé GPG"
|
101
|
+
title: "Configuration d'une nouvelle clé GPG"
|
97
102
|
ask: "Voulez vous créer votre clé GPG ? (O/n)"
|
98
103
|
no_create: "Veuillez créer manuellement votre clé GPG ou relancer le logiciel."
|
99
104
|
name: "Votre nom et prénom: "
|
@@ -104,7 +109,7 @@ fr:
|
|
104
109
|
expire: "Expiration de la clé GPG [défaut=0 (illimité)]: "
|
105
110
|
wait: "Veuillez patienter durant la génération de votre clé GPG, ce processus peut prendre quelques minutes."
|
106
111
|
valid: "Votre clé GPG a bien été créée ;-)"
|
107
|
-
|
112
|
+
update_item:
|
108
113
|
title: "Mis à jour d'un élément"
|
109
114
|
name: "Entrez le nom [%{name}]: "
|
110
115
|
group: "Entrez le groupe [%{group}]: "
|
@@ -132,17 +137,6 @@ fr:
|
|
132
137
|
server: "Serveur"
|
133
138
|
warning: "Warning"
|
134
139
|
|
135
|
-
ssh:
|
136
|
-
option:
|
137
|
-
usage: "Utilisation"
|
138
|
-
login: "Change l'identifiant de connexion"
|
139
|
-
server: "Change le nom de domaine ou l'ip du serveur"
|
140
|
-
port: "Change le port de connexion"
|
141
|
-
help: "Affiche ce message d'aide"
|
142
|
-
display:
|
143
|
-
connect: "Connexion à:"
|
144
|
-
nothing: "Aucun résultat!"
|
145
|
-
|
146
140
|
formats:
|
147
141
|
default: ! '%Y-%m-%d'
|
148
142
|
long: ! '%B %d, %Y'
|
data/lib/mpw/config.rb
CHANGED
@@ -1,231 +1,142 @@
|
|
1
1
|
#!/usr/bin/ruby
|
2
|
-
#
|
3
|
-
#
|
2
|
+
# MPW is a software to crypt and manage your passwords
|
3
|
+
# Copyright (C) 2016 Adrien Waksberg <mpw@yae.im>
|
4
|
+
#
|
5
|
+
# This program is free software; you can redistribute it and/or
|
6
|
+
# modify it under the terms of the GNU General Public License
|
7
|
+
# as published by the Free Software Foundation; either version 2
|
8
|
+
# of the License, or (at your option) any later version.
|
9
|
+
#
|
10
|
+
# This program is distributed in the hope that it will be useful,
|
11
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
+
# GNU General Public License for more details.
|
14
|
+
#
|
15
|
+
# You should have received a copy of the GNU General Public License
|
16
|
+
# along with this program; if not, write to the Free Software
|
17
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
4
18
|
|
5
|
-
require 'rubygems'
|
6
19
|
require 'gpgme'
|
7
20
|
require 'yaml'
|
8
21
|
require 'i18n'
|
22
|
+
require 'fileutils'
|
9
23
|
|
10
24
|
module MPW
|
11
|
-
|
12
|
-
|
13
|
-
attr_accessor :error_msg
|
14
|
-
|
15
|
-
attr_accessor :key
|
16
|
-
attr_accessor :share_keys
|
17
|
-
attr_accessor :lang
|
18
|
-
attr_accessor :file_gpg
|
19
|
-
attr_accessor :last_update
|
20
|
-
attr_accessor :sync_type
|
21
|
-
attr_accessor :sync_host
|
22
|
-
attr_accessor :sync_port
|
23
|
-
attr_accessor :sync_user
|
24
|
-
attr_accessor :sync_pwd
|
25
|
-
attr_accessor :sync_path
|
26
|
-
attr_accessor :last_sync
|
27
|
-
attr_accessor :dir_config
|
25
|
+
class Config
|
28
26
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
@
|
43
|
-
|
44
|
-
|
45
|
-
|
27
|
+
attr_accessor :error_msg
|
28
|
+
|
29
|
+
attr_accessor :key
|
30
|
+
attr_accessor :lang
|
31
|
+
attr_accessor :config_dir
|
32
|
+
attr_accessor :wallet_dir
|
33
|
+
|
34
|
+
# Constructor
|
35
|
+
# @args: config_file -> the specify config file
|
36
|
+
def initialize(config_file=nil)
|
37
|
+
@config_file = config_file
|
38
|
+
|
39
|
+
if /darwin/ =~ RUBY_PLATFORM
|
40
|
+
@config_dir = "#{Dir.home}/Library/Preferences/mpw"
|
41
|
+
elsif /cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM
|
42
|
+
@config_dir = "#{Dir.home}/AppData/Local/mpw"
|
43
|
+
else
|
44
|
+
@config_dir = "#{Dir.home}/.config/mpw"
|
46
45
|
end
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
# share_keys -> multiple keys to share the password with other people
|
51
|
-
# lang -> the software language
|
52
|
-
# file_gpg -> the file who is encrypted
|
53
|
-
# sync_type -> the type to synchronization
|
54
|
-
# sync_host -> the server host for synchronization
|
55
|
-
# sync_port -> the server port for synchronization
|
56
|
-
# sync_user -> the user for synchronization
|
57
|
-
# sync_pwd -> the password for synchronization
|
58
|
-
# sync_suffix -> the suffix file (optionnal)
|
59
|
-
# @rtrn: true if le config file is create
|
60
|
-
def setup(key, share_keys, lang, file_gpg, sync_type, sync_host, sync_port, sync_user, sync_pwd, sync_path)
|
61
|
-
|
62
|
-
if not key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
|
63
|
-
@error_msg = I18n.t('error.config.key_bad_format')
|
64
|
-
return false
|
65
|
-
end
|
66
|
-
|
67
|
-
if not check_public_gpg_key(share_keys)
|
68
|
-
return false
|
69
|
-
end
|
70
|
-
|
71
|
-
if file_gpg.empty?
|
72
|
-
file_gpg = "#{@dir_config}/db/default.gpg"
|
73
|
-
end
|
74
|
-
|
75
|
-
config = {'config' => {'key' => key,
|
76
|
-
'share_keys' => share_keys,
|
77
|
-
'lang' => lang,
|
78
|
-
'file_gpg' => file_gpg,
|
79
|
-
'sync_type' => sync_type,
|
80
|
-
'sync_host' => sync_host,
|
81
|
-
'sync_port' => sync_port,
|
82
|
-
'sync_user' => sync_user,
|
83
|
-
'sync_pwd' => sync_pwd,
|
84
|
-
'sync_path' => sync_path,
|
85
|
-
'last_sync' => 0
|
86
|
-
}
|
87
|
-
}
|
88
|
-
|
89
|
-
Dir.mkdir("#{@config_dir}/conf", 700)
|
90
|
-
Dir.mkdir("#{@config_dir}/db", 700)
|
91
|
-
File.open(@file_config, 'w') do |file|
|
92
|
-
file << config.to_yaml
|
93
|
-
end
|
94
|
-
|
95
|
-
return true
|
96
|
-
rescue Exception => e
|
97
|
-
@error_msg = "#{I18n.t('error.config.write')}\n#{e}"
|
98
|
-
return false
|
46
|
+
|
47
|
+
if @config_file.nil? or @config_file.empty?
|
48
|
+
@config_file = "#{@config_dir}/mpw.cfg"
|
99
49
|
end
|
50
|
+
end
|
100
51
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
def setup_gpg_key(password, name, length = 2048, expire = 0)
|
108
|
-
if name.nil? or name.empty?
|
109
|
-
@error_msg = "#{I18n.t('error.config.genkey_gpg.name')}"
|
110
|
-
return false
|
111
|
-
elsif password.nil? or password.empty?
|
112
|
-
@error_msg = "#{I18n.t('error.config.genkey_gpg.password')}"
|
113
|
-
return false
|
114
|
-
end
|
115
|
-
|
116
|
-
param = ''
|
117
|
-
param << '<GnupgKeyParms format="internal">' + "\n"
|
118
|
-
param << "Key-Type: DSA\n"
|
119
|
-
param << "Key-Length: #{length}\n"
|
120
|
-
param << "Subkey-Type: ELG-E\n"
|
121
|
-
param << "Subkey-Length: #{length}\n"
|
122
|
-
param << "Name-Real: #{name}\n"
|
123
|
-
param << "Name-Comment: #{name}\n"
|
124
|
-
param << "Name-Email: #{@key}\n"
|
125
|
-
param << "Expire-Date: #{expire}\n"
|
126
|
-
param << "Passphrase: #{password}\n"
|
127
|
-
param << "</GnupgKeyParms>\n"
|
128
|
-
|
129
|
-
ctx = GPGME::Ctx.new
|
130
|
-
ctx.genkey(param, nil, nil)
|
52
|
+
# Create a new config file
|
53
|
+
# @args: key -> the gpg key to encrypt
|
54
|
+
# lang -> the software language
|
55
|
+
# wallet_dir -> the directory where are the wallets password
|
56
|
+
# @rtrn: true if le config file is create
|
57
|
+
def setup(key, lang, wallet_dir)
|
131
58
|
|
132
|
-
|
133
|
-
|
134
|
-
@error_msg = "#{I18n.t('error.config.genkey_gpg.exception')}\n#{e}"
|
135
|
-
return false
|
59
|
+
if not key =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
|
60
|
+
raise I18n.t('error.config.key_bad_format')
|
136
61
|
end
|
137
|
-
|
138
|
-
# Check the config file
|
139
|
-
# @rtrn: true if the config file is correct
|
140
|
-
def checkconfig
|
141
|
-
config = YAML::load_file(@file_config)
|
142
|
-
@key = config['config']['key']
|
143
|
-
@share_keys = config['config']['share_keys']
|
144
|
-
@lang = config['config']['lang']
|
145
|
-
@file_gpg = config['config']['file_gpg']
|
146
|
-
@sync_type = config['config']['sync_type']
|
147
|
-
@sync_host = config['config']['sync_host']
|
148
|
-
@sync_port = config['config']['sync_port']
|
149
|
-
@sync_user = config['config']['sync_user']
|
150
|
-
@sync_pwd = config['config']['sync_pwd']
|
151
|
-
@sync_path = config['config']['sync_path']
|
152
|
-
@last_sync = config['config']['last_sync'].to_i
|
153
|
-
|
154
|
-
if @key.empty? or @file_gpg.empty?
|
155
|
-
@error_msg = I18n.t('error.config.check')
|
156
|
-
return false
|
157
|
-
end
|
158
|
-
I18n.locale = @lang.to_sym
|
159
62
|
|
160
|
-
|
161
|
-
|
162
|
-
@error_msg = "#{I18n.t('error.config.check')}\n#{e}"
|
163
|
-
return false
|
63
|
+
if wallet_dir.empty?
|
64
|
+
wallet_dir = "#{@config_dir}/wallets"
|
164
65
|
end
|
165
66
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
return true
|
172
|
-
end
|
67
|
+
config = {'config' => {'key' => key,
|
68
|
+
'lang' => lang,
|
69
|
+
'wallet_dir' => wallet_dir,
|
70
|
+
}
|
71
|
+
}
|
173
72
|
|
174
|
-
|
73
|
+
FileUtils.mkdir_p(wallet_dir, mode: 0700)
|
74
|
+
File.open(@config_file, 'w') do |file|
|
75
|
+
file << config.to_yaml
|
175
76
|
end
|
77
|
+
|
78
|
+
rescue Exception => e
|
79
|
+
raise "#{I18n.t('error.config.write')}\n#{e}"
|
80
|
+
end
|
176
81
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
return false
|
189
|
-
end
|
190
|
-
|
191
|
-
ctx.each_key(key, false) do
|
192
|
-
next
|
193
|
-
end
|
194
|
-
|
195
|
-
@error_msg = I18n.t('error.config.no_key_public', key: k)
|
196
|
-
return false
|
197
|
-
end
|
198
|
-
end
|
199
|
-
|
200
|
-
return true
|
82
|
+
# Setup a new gpg key
|
83
|
+
# @args: password -> the GPG key password
|
84
|
+
# name -> the name of user
|
85
|
+
# length -> length of the GPG key
|
86
|
+
# expire -> the time of expire to GPG key
|
87
|
+
# @rtrn: true if the GPG key is create, else false
|
88
|
+
def setup_gpg_key(password, name, length = 4096, expire = 0)
|
89
|
+
if name.nil? or name.empty?
|
90
|
+
raise "#{I18n.t('error.config.genkey_gpg.name')}"
|
91
|
+
elsif password.nil? or password.empty?
|
92
|
+
raise "#{I18n.t('error.config.genkey_gpg.password')}"
|
201
93
|
end
|
202
|
-
|
203
|
-
# Set the last update when there is a sync
|
204
|
-
# @rtrn: true is the file has been updated
|
205
|
-
def set_last_sync
|
206
|
-
config = {'config' => {'key' => @key,
|
207
|
-
'share_keys' => @share_keys,
|
208
|
-
'lang' => @lang,
|
209
|
-
'file_gpg' => @file_gpg,
|
210
|
-
'sync_type' => @sync_type,
|
211
|
-
'sync_host' => @sync_host,
|
212
|
-
'sync_port' => @sync_port,
|
213
|
-
'sync_user' => @sync_user,
|
214
|
-
'sync_pwd' => @sync_pwd,
|
215
|
-
'sync_path' => @sync_path,
|
216
|
-
'last_sync' => Time.now.to_i
|
217
|
-
}
|
218
|
-
}
|
219
|
-
|
220
|
-
File.open(@file_config, 'w') do |file|
|
221
|
-
file << config.to_yaml
|
222
|
-
end
|
223
94
|
|
95
|
+
param = ''
|
96
|
+
param << '<GnupgKeyParms format="internal">' + "\n"
|
97
|
+
param << "Key-Type: DSA\n"
|
98
|
+
param << "Key-Length: #{length}\n"
|
99
|
+
param << "Subkey-Type: ELG-E\n"
|
100
|
+
param << "Subkey-Length: #{length}\n"
|
101
|
+
param << "Name-Real: #{name}\n"
|
102
|
+
param << "Name-Comment: #{name}\n"
|
103
|
+
param << "Name-Email: #{@key}\n"
|
104
|
+
param << "Expire-Date: #{expire}\n"
|
105
|
+
param << "Passphrase: #{password}\n"
|
106
|
+
param << "</GnupgKeyParms>\n"
|
107
|
+
|
108
|
+
ctx = GPGME::Ctx.new
|
109
|
+
ctx.genkey(param, nil, nil)
|
110
|
+
rescue Exception => e
|
111
|
+
raise "#{I18n.t('error.config.genkey_gpg.exception')}\n#{e}"
|
112
|
+
end
|
113
|
+
|
114
|
+
# Check the config file
|
115
|
+
# @rtrn: true if the config file is correct
|
116
|
+
def is_valid?
|
117
|
+
config = YAML::load_file(@config_file)
|
118
|
+
@key = config['config']['key']
|
119
|
+
@lang = config['config']['lang']
|
120
|
+
@wallet_dir = config['config']['wallet_dir']
|
121
|
+
|
122
|
+
raise if @key.empty? or @wallet_dir.empty?
|
123
|
+
|
124
|
+
I18n.locale = @lang.to_sym
|
125
|
+
|
126
|
+
return true
|
127
|
+
rescue
|
128
|
+
return false
|
129
|
+
end
|
130
|
+
|
131
|
+
# Check if private key exist
|
132
|
+
# @rtrn: true if the key exist, else false
|
133
|
+
def check_gpg_key?
|
134
|
+
ctx = GPGME::Ctx.new
|
135
|
+
ctx.each_key(@key, true) do
|
224
136
|
return true
|
225
|
-
rescue Exception => e
|
226
|
-
@error_msg = "#{I18n.t('error.config.write')}\n#{e}"
|
227
|
-
return false
|
228
137
|
end
|
229
|
-
|
138
|
+
|
139
|
+
return false
|
230
140
|
end
|
231
141
|
end
|
142
|
+
end
|