我如何使用fetchmail(或其他电子邮件抓取器)与OSX钥匙串进行身份validation?

我读过的许多fetchmail教程都说把你的电子邮件帐户密码明文写入configuration文件是安全的。 但是,我更喜欢通过图层的安全性[愚蠢的例子:*如果我的terminal上来,有人怀疑这样的电子邮件foolery滑过,只是简单地键入“grep -i pass〜/.*”然后,哎呀,我所有的基地都属于给他们! 特别是如果我的电子邮件提供商使用openid(或者我愚蠢到使用相同的密码为我的银行) ] **。

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

如果通过POP3检索邮件对您来说已经足够了,请查看优秀的mpop 。 它来自与msmtp相同的作者,并且还具有用于存储authentication凭证的OSX钥匙串支持。

对于IMAP4,您可以使用非常漂亮的OfflineIMAP,并使用William Snow Orvis的Python钩子将其连接到OSX钥匙串。

我个人更喜欢这些工具通过fetchmail(由于例如下载速度,function设置,configuration),但你的里程可能会有所不同。

从简单的效用angular度来看,是的,你可以使用钥匙串。 我强烈build议您阅读整个security(1)手册页,其中还有一些注意事项。

您可以使用钥匙串程序或通过命令行input密码:

 # 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)将能够取消这些凭据而无需进一步提示。 这可能对您的系统有风险。 但是,您可以select在启动前始终提示input密码。

最后,使用这个函数,你可以使用设置要使用的密码的跳板脚本来包装你的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 

虽然这确实达到了你的明确目标,没有明显的密码文件,但是我注意到了这个configuration中仍然存在的安全风险 ,你应该考虑这个风险

如果密钥链允许明文密码被解除,那么这是可能的,但是你不能在本地密码MD5,因为服务器需要它自己的格式(通常是明文)

要使用标准的imap / smtp / pop3,你需要一个明文密码。 所以如果你想在本地存储它需要在一个可逆的格式,这不是使用钥匙串的好消息。 但是,如果邮件服务器支持它,则可以使用X.509证书和SSL进行身份validation。 该证书可以带或不带密码,并且可以存储在Mac OS X钥匙串中。

我不能回答是否任何软件实际上支持这个设置,因为我不是Mac用户。 另外你还需要你的服务器来支持X509authentication。

@medina,

如果没有“tmpfile = / tmp / fetchmailrc。$$”,我build议使用mktemp(1)。