如何在 OSX 钥匙串中使用 fetchmail(或其他电子邮件抓取器)进行身份验证?

bia*_*ias 3 security email password password-management

我读过的许多 fetchmail 教程都说将您的电子邮件帐户密码明文放在配置文件中是安全的。但是,我更喜欢通过层级进行安全[*** 愚蠢的例子:* 如果我的终端已启动并且有人怀疑此类电子邮件愚蠢行为会滑过并简单地输入“grep -i pass ~/.*”,那么,哎呀,我所有的基础都属于给他们!特别是如果我的电子邮件提供商使用 openid(或者我愚蠢到无法为我的银行使用相同的密码) ]**。

现在,使用 msmtp(而不是 sendmail),我可以使用 OSX 钥匙串进行身份验证。是否有免费/开源电子邮件“抓取器”可以让我使用钥匙串(或者至少可以让我对密码进行 MD5)?

med*_*ina 5

从简单实用的角度来看,是的,您可以使用钥匙串。我强烈建议您阅读整个security(1)手册页,其中包含额外的警告。

您可以使用 Keychain 程序或通过命令行输入密码:

# WARNING: exposes password in ps(1), history(1), etc.
$ security add-internet-password -a $USER -s pop3.example.com -w 'Mellon!'
Run Code Online (Sandbox Code Playgroud)

您可以使用以下方法提取它:

# Note: by default, first use will prompt
$ security find-internet-password -s pop3.example.com -a $USER -g
Run Code Online (Sandbox Code Playgroud)

如果您始终允许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
Run Code Online (Sandbox Code Playgroud)

虽然这确实实现了您的既定目标,即不存在带有密码的明显文件,但我确实注意到此配置仍然存在安全风险,您应该考虑这一点。