1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-27 07:33:05 +00:00

fix the issue 3, bad password

This commit is contained in:
nishiki 2014-04-21 22:30:41 +02:00
parent 57d1a700c6
commit 08fbd25846

View file

@ -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,17 +160,42 @@ 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
def set_last_update def set_last_update