mirror of
https://github.com/nishiki/manage-password.git
synced 2025-03-19 21:04:35 +00:00
begin rewrite in ruby
This commit is contained in:
parent
e5935e38ae
commit
346d33e013
1 changed files with 61 additions and 0 deletions
61
manage-password.rb
Executable file
61
manage-password.rb
Executable file
|
@ -0,0 +1,61 @@
|
|||
#!/usr/bin/ruby
|
||||
require 'rubygems'
|
||||
require 'gpgme'
|
||||
|
||||
FILE_GPG = './pass.gpg'
|
||||
KEY = 'adrien.waksberg@believedigital.com'
|
||||
FILE_PWD = './tmp_passwd'
|
||||
TIMEOUT_PWD = 10
|
||||
|
||||
class ManagePasswd
|
||||
|
||||
ID = 0
|
||||
TYPE = 1
|
||||
SERVER = 2
|
||||
LOGIN = 3
|
||||
PASSWD = 4
|
||||
PORT = 5
|
||||
COMMENT = 6
|
||||
|
||||
def initialize(key, file_gpg, file_pwd, timeout_pwd=300)
|
||||
@key = key
|
||||
@file_gpg = file_gpg
|
||||
@file_pwd = file_pwd
|
||||
@timeout_pwd = timeout_pwd
|
||||
|
||||
if File.exist?(@file_gpg)
|
||||
self.decrypt()
|
||||
else
|
||||
@data = ""
|
||||
end
|
||||
end
|
||||
|
||||
def decrypt()
|
||||
|
||||
if File.exist?(@file_pwd) && File.stat(@file_pwd).mtime.to_i + @timeout_pwd < Time.now.to_i
|
||||
File.delete(@file_pwd)
|
||||
end
|
||||
|
||||
begin
|
||||
passwd = IO.read(@file_pwd)
|
||||
rescue
|
||||
puts "Password GPG: "
|
||||
passwd = gets
|
||||
file_pwd = File.new(@file_pwd, 'w')
|
||||
file_pwd << passwd
|
||||
file_pwd.close
|
||||
end
|
||||
|
||||
crypto = GPGME::Crypto.new(:armor => true)
|
||||
@data = crypto.decrypt(IO.read(@file_gpg), :password => passwd).read
|
||||
|
||||
end
|
||||
|
||||
def encrypt()
|
||||
crypto = GPGME::Crypto.new(:armor => true)
|
||||
crypto.encrypt(@data, :recipients => @key, :output => @file_gpg)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
manage = ManagePasswd.new(KEY, FILE_GPG, FILE_PWD)
|
Loading…
Add table
Reference in a new issue