mirror of
https://github.com/nishiki/manage-password.git
synced 2024-11-23 13:57:52 +00:00
fix the issue 3, bad password
This commit is contained in:
parent
57d1a700c6
commit
08fbd25846
1 changed files with 31 additions and 17 deletions
|
@ -59,19 +59,8 @@ module MPW
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
share_keys = share_keys.nil? ? '' : share_keys
|
if !check_public_gpg_key(share_keys)
|
||||||
if !share_keys.empty?
|
return false
|
||||||
share_keys.split.each do |k|
|
|
||||||
if not k =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
|
|
||||||
@error_msg = I18n.t('error.config.key_bad_format')
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
if !check_gpg_key?(k, false)
|
|
||||||
@error_msg = I18n.t('error.config.no_key_public', :key => k)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if file_gpg.empty?
|
if file_gpg.empty?
|
||||||
|
@ -128,7 +117,7 @@ module MPW
|
||||||
param << "Name-Comment: #{name}\n"
|
param << "Name-Comment: #{name}\n"
|
||||||
param << "Name-Email: #{@key}\n"
|
param << "Name-Email: #{@key}\n"
|
||||||
param << "Expire-Date: #{expire}\n"
|
param << "Expire-Date: #{expire}\n"
|
||||||
param << "Passphrase: apc\n"
|
param << "Passphrase: #{password}\n"
|
||||||
param << "</GnupgKeyParms>\n"
|
param << "</GnupgKeyParms>\n"
|
||||||
|
|
||||||
ctx = GPGME::Ctx.new
|
ctx = GPGME::Ctx.new
|
||||||
|
@ -171,16 +160,41 @@ module MPW
|
||||||
end
|
end
|
||||||
|
|
||||||
# Check if private key exist
|
# Check if private key exist
|
||||||
# @args: only_private -> search only private key
|
|
||||||
# @rtrn: true if the key exist, else false
|
# @rtrn: true if the key exist, else false
|
||||||
def check_gpg_key?(key = @key, only_private = true)
|
def check_gpg_key?
|
||||||
ctx = GPGME::Ctx.new
|
ctx = GPGME::Ctx.new
|
||||||
ctx.each_key(key, only_private) do
|
ctx.each_key(key, true) do
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Check if private key exist
|
||||||
|
# @args: share_keys -> string with all public keys
|
||||||
|
# @rtrn: true if the key exist, else false
|
||||||
|
def check_public_gpg_key(share_keys = @share_keys)
|
||||||
|
ctx = GPGME::Ctx.new
|
||||||
|
|
||||||
|
share_keys = share_keys.nil? ? '' : share_keys
|
||||||
|
if !share_keys.empty?
|
||||||
|
share_keys.split.each do |k|
|
||||||
|
if not k =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
|
||||||
|
@error_msg = I18n.t('error.config.key_bad_format')
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
ctx.each_key(key, false) do
|
||||||
|
next
|
||||||
|
end
|
||||||
|
|
||||||
|
@error_msg = I18n.t('error.config.no_key_public', :key => k)
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
# Set the last update when there is a sync
|
# Set the last update when there is a sync
|
||||||
# @rtrn: true is the file has been updated
|
# @rtrn: true is the file has been updated
|
||||||
|
|
Loading…
Reference in a new issue