Description
I submitted a PR in #104 to fix these issues but I thought I'd also open this ticket for broader discussion about how Simple Java Mail is vulnerable and why this is a bad thing even when taking email's inherent lack of security into account.
TransportStrategy.SMTP_TLS
currently gives a false sense of security.
As currently implemented, TransportStrategy.SMTP_TLS
is merely opportunistic and can be easily circumvented by an active attacker. If sending emails via TransportStrategy.SMTP_TLS
it is reasonable to assume that SMTP credentials and email contents will necessarily be protected via TLS (or otherwise an error should be raised), but that's not the current behavior of this library.
The various ways an active attacker could circumvent STARTTLS are outlined in the spec, RFC 2487 § 7:
A man-in-the-middle attack can be launched by deleting the "250
STARTTLS" response from the server. This would cause the client not
to try to start a TLS session. Another man-in-the-middle attack is
to allow the server to announce its STARTTLS capability, but to alter
the client's request to start TLS and the server's response.
TransportStrategy.SMTP_TLS
and TransportStrategy.SMTP_SSL
do not perform certificate identity validation.
At present, any certificate signed by a trusted CA and presented by an upstream SMTP server is accepted when negotiating a TLS session. A certificate issued by a public CA to www.totally-not-spying-on-you.com
would be accepted by JavaMail during a connection attempt to, for example, smtp.gmail.com
.
As noted in the PR, Oracle concedes that this default behavior of JavaMail is bad. As a convenience wrapper, I think Simple Java Mail should make its own default behavior secure. (Since developers should be turning this flag on anyways)
The current behavior is bad even when we consider that SMTP is insecure
SMTP is insecure in that email contents are not guaranteed to be end-to-end encrypted during transit. However, authentication with credentials to an SMTP server should be end-to-end encrypted if SMTPS or STARTTLS is used. The attacks above break this guarantee.