
我讀過的許多 fetchmail 教學都說將您的電子郵件帳戶密碼明文放在設定檔中是安全的。但是,我更喜歡透過層層來實現安全性[***愚蠢的例子:*如果我的終端啟動了,有人懷疑這種電子郵件愚蠢的行為,然後簡單地輸入“grep -i pass ~/.*”,那麼,哎呀,我的所有基地都屬於他們!特別是如果我的電子郵件提供者使用 openid(或者我愚蠢到對我的銀行使用相同的密碼)]**。
現在,透過 msmtp(而不是 sendmail),我可以使用 OSX 鑰匙圈進行身份驗證。是否有免費/開源電子郵件「抓取器」可以讓我使用鑰匙圈(或至少可以讓我對密碼進行 MD5 處理)?
答案1
如果透過 POP3 檢索郵件對您來說足夠了,請查看優秀的流行音樂。它與 msmtp 來自同一作者,並且還支援用於儲存身份驗證憑證的 OSX 鑰匙圈。
對於 IMAP4,您可以使用非常好的離線IMAP並將其連接到 OSX 鑰匙圈使用威廉·斯諾·奧維斯的 Python 鉤子。
我個人更喜歡這些工具而不是 fetchmail(因為例如下載速度、功能集、配置),但您的情況可能會有所不同。
答案2
從簡單實用的角度來看,是的,您可以使用鑰匙圈。我強烈建議您閱讀整個security(1)
手冊頁,其中包含其他注意事項。
您可以使用 Keychain 程式或透過命令列輸入密碼:
# WARNING: exposes password in ps(1), history(1), etc.
$ security add-internet-password -a $USER -s pop3.example.com -w 'Mellon!'
您可以使用以下命令提取它:
# Note: by default, first use will prompt
$ security find-internet-password -s pop3.example.com -a $USER -g
如果你總是允許,security(1)
將能夠提取這些憑證而無需進一步提示。這可能會為您的系統帶來風險。不過,您可以選擇在啟動之前始終提示您輸入密碼。
最後,使用它,您可以fetchmail
使用設定要使用的密碼的跳板腳本來包裝您的呼叫。
user=$USER
server=pop3.example.com
# WARNING: insecure tmpfile creation and usage
# As [DAM][1] mentions, see mkstemp(3)
tmpfile=/tmp/fetchmailrc.$$
password=$(security find-internet-password -s $server -a $USER -g 2>&1 \
| perl -ne '/password: "(\S*)"/ and print $1')
# create temporary fetchmailrc and pass to fetchmail, etc...
cat <<EoF > $tmpfile
poll $server with proto POP3 and options no dns
user $user with pass '$password' is $user here
options keep mda '/usr/bin/procmail -d %T'
EoF
fetchmail -d -f $tmpfile
rm -f $tmpfile
雖然這確實實現了您所說的沒有明顯的帶有密碼的文件的目標,但我做到了注意安全風險仍然存在此配置,您應該考慮這一點。
答案3
如果鑰匙圈允許解除明文密碼,那麼這是可能的,但你不能在本地使用 MD5 密碼,因為伺服器希望它採用自己的格式(通常是明文)
答案4
@麥地那,
我建議使用 mktemp(1)(如果可用),而不是「tmpfile=/tmp/fetchmailrc.$$」。