1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-23 13:57:52 +00:00

add share_keys

This commit is contained in:
nishiki 2014-02-02 17:34:05 +01:00
parent 076aedeb3c
commit bed8cbb8b6
4 changed files with 22 additions and 10 deletions

View file

@ -58,7 +58,8 @@ module MPW
return false
end
if !share_keys.nil? && !share_keys.empty?
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')

View file

@ -26,10 +26,11 @@ module MPW
attr_accessor :error_msg
# Constructor
def initialize(file_gpg, key=nil)
def initialize(file_gpg, key=nil, share_keys='')
@error_msg = nil
@file_gpg = file_gpg
@key = key
@share_keys = share_keys
end
# Decrypt a gpg file
@ -64,7 +65,13 @@ module MPW
data_to_encrypt << row.to_csv
end
crypto.encrypt(data_to_encrypt, :recipients => @key, :output => file_gpg)
recipients = []
recipients.push(@key)
if !@share_keys.nil?
@share_keys.split.each { |k| recipients.push(k) }
end
crypto.encrypt(data_to_encrypt, :recipients => recipients, :output => file_gpg)
file_gpg.close
return true

View file

@ -31,11 +31,13 @@ module MPW
# suffix -> the suffix file
# @rtrn: false if the connection fail
def connect(host, user, password, path, port=nil)
@host = host
@port = !port.instance_of?(Integer) ? 2201 : port
@gpg_key = user
@password = password
@suffix = path
TCPSocket.new(host, port.to_i) do
TCPSocket.open(@host, @port) do
@enable = true
end
rescue Exception => e
@ -53,7 +55,8 @@ module MPW
return nil
end
TCPSocket.new(host, port.to_i) do |socket|
msg = nil
TCPSocket.open(@host, @port) do |socket|
send_msg = {:action => 'get',
:gpg_key => @gpg_key,
:password => @password,
@ -95,7 +98,8 @@ module MPW
return true
end
TCPSocket.new(host, port.to_i) do |socket|
msg = nil
TCPSocket.open(@host, @port) do |socket|
send_msg = {:action => 'update',
:gpg_key => @gpg_key,
:password => @password,

View file

@ -117,7 +117,7 @@ class Cli
# Request the GPG password and decrypt the file
def decrypt
if !defined?(@mpw)
@mpw = MPW::MPW.new(@config.file_gpg, @config.key)
@mpw = MPW::MPW.new(@config.file_gpg, @config.key, @config.share_keys)
end
@passwd = ask(I18n.t('display.gpg_password')) {|q| q.echo = false}