1
0
Fork 0
mirror of https://github.com/nishiki/manage-password.git synced 2024-11-30 08:53:05 +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 return false
end 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| share_keys.split.each do |k|
if not k =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/ if not k =~ /[a-zA-Z0-9.-_]+\@[a-zA-Z0-9]+\.[a-zA-Z]+/
@error_msg = I18n.t('error.config.key_bad_format') @error_msg = I18n.t('error.config.key_bad_format')

View file

@ -26,10 +26,11 @@ module MPW
attr_accessor :error_msg attr_accessor :error_msg
# Constructor # Constructor
def initialize(file_gpg, key=nil) def initialize(file_gpg, key=nil, share_keys='')
@error_msg = nil @error_msg = nil
@file_gpg = file_gpg @file_gpg = file_gpg
@key = key @key = key
@share_keys = share_keys
end end
# Decrypt a gpg file # Decrypt a gpg file
@ -64,7 +65,13 @@ module MPW
data_to_encrypt << row.to_csv data_to_encrypt << row.to_csv
end 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 file_gpg.close
return true return true

View file

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

View file

@ -117,7 +117,7 @@ class Cli
# Request the GPG password and decrypt the file # Request the GPG password and decrypt the file
def decrypt def decrypt
if !defined?(@mpw) 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 end
@passwd = ask(I18n.t('display.gpg_password')) {|q| q.echo = false} @passwd = ask(I18n.t('display.gpg_password')) {|q| q.echo = false}