Fix use of GPG by using it with gpg agent
This commit is contained in:
parent
58c70237e9
commit
447d08d6be
3 changed files with 25 additions and 6 deletions
|
@ -168,7 +168,7 @@ function get_imap_password(file)
|
|||
end
|
||||
|
||||
function get_pwd_victor()
|
||||
local cmd = "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.victor.gpg"
|
||||
local cmd = "gpg --use-agent --quiet --batch --decrypt ~/.victor.gpg"
|
||||
local fd = io.popen(cmd, 'r')
|
||||
pass = fd:read("*a")
|
||||
fd:close()
|
||||
|
@ -176,7 +176,7 @@ function get_pwd_victor()
|
|||
end
|
||||
|
||||
function get_pwd_sanchayan()
|
||||
local cmd = "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.sanchayan.gpg"
|
||||
local cmd = "gpg --use-agent --quiet --batch --decrypt ~/.sanchayan.gpg"
|
||||
local fd = io.popen(cmd, 'r')
|
||||
pass = fd:read("*a")
|
||||
fd:close()
|
||||
|
|
6
msmtprc
6
msmtprc
|
@ -11,19 +11,19 @@ account Sanchayan
|
|||
host smtp.gmail.com
|
||||
from maitysanchayan@gmail.com
|
||||
user maitysanchayan@gmail.com
|
||||
passwordeval "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.sanchayan.gpg"
|
||||
passwordeval "gpg --use-agent --batch --quiet --no-greeting --no-tty --for-your-eyes-only --homedir /home/sanchayan/.gnupg --decrypt ~/.sanchayan.gpg"
|
||||
|
||||
account Victor
|
||||
host smtp.gmail.com
|
||||
from victorascroft@gmail.com
|
||||
user victorascroft@gmail.com
|
||||
passwordeval "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.victor.gpg"
|
||||
passwordeval "gpg --use-agent --batch --quiet --no-greeting --no-tty --for-your-eyes-only --homedir /home/sanchayan/.gnupg --decrypt ~/.victor.gpg"
|
||||
|
||||
account Toradex
|
||||
host smtp.office365.com
|
||||
from sanchayan.maity@toradex.com
|
||||
user sanchayan.maity@toradex.com
|
||||
passwordeval "gpg --quiet --for-your-eyes-only --no-tty --decrypt ~/.toradex.gpg"
|
||||
passwordeval "gpg --use-agent --batch --quiet --no-greeting --no-tty --for-your-eyes-only --homedir /home/sanchayan/.gnupg --decrypt ~/.toradex.gpg"
|
||||
|
||||
# Set a default account
|
||||
account default : Sanchayan
|
||||
|
|
|
@ -2,4 +2,23 @@ import subprocess
|
|||
|
||||
def mailpasswd(account):
|
||||
path = "/home/sanchayan/.%s.gpg" % account
|
||||
return subprocess.check_output(["gpg", "--quiet", "--batch", "-d", path]).strip()
|
||||
args = ["gpg", "--use-agent", "--quiet", "--batch", "-d", path]
|
||||
try:
|
||||
return subprocess.check_output(["gpg", "--batch", "-d", path]).strip()
|
||||
except subprocess.CalledProcessError:
|
||||
return ""
|
||||
|
||||
# http://unix.stackexchange.com/questions/44214/encrypt-offlineimap-password
|
||||
def prime_gpg_agent():
|
||||
ret = False
|
||||
i = 1
|
||||
while not ret:
|
||||
ret = (mailpasswd("prime") == "prime")
|
||||
if i > 2:
|
||||
from offlineimap.ui import getglobalui
|
||||
sys.stderr.write("Error reading in passwords. Terminating.\n")
|
||||
getglobalui().terminate()
|
||||
i += 1
|
||||
return ret
|
||||
|
||||
prime_gpg_agent()
|
||||
|
|
Loading…
Reference in a new issue