Commit Graph

136 Commits

Author SHA1 Message Date
Jan Berkel 0f476978ce mail.store.* cleanups 2014-12-18 09:33:09 +01:00
Jan Berkel 2f30b3956d Dependency Inversion, remove K9.app references 2014-12-17 17:42:22 +01:00
Jan Berkel b36c788ce0 Move ImapConnection out 2014-12-17 17:16:18 +01:00
Jan Berkel 16f8a3ef14 Remove trusted socket factory statics 2014-12-17 16:43:55 +01:00
Jan Berkel 27e0c75021 Move exception error strings out of mail package 2014-12-17 16:24:52 +01:00
Jan Berkel 231684936b break/centralize dependencies to K9 2014-12-16 12:54:12 +01:00
Jan Berkel 7d6e6b8abe MimeUtility / Message refactor
* break MimeUtility class into manageable pieces (MessageExtractor/CharsetSupport)
 * move HTML related code out of the mail package
2014-12-15 12:26:06 +01:00
Jan Berkel 238c1650c5 Remove URLEncodingHelper dependency 2014-12-14 15:54:27 +00:00
Jan Berkel 54d62eb7b9 Naming 2014-12-12 15:19:13 +00:00
Jan Berkel 40041ac0e0 Move local message code to local package
+ cut some helper dependencies
2014-12-12 15:02:59 +00:00
Jan Berkel 9f16b9f465 Move SSL code into package 2014-12-12 12:35:17 +00:00
Jan Berkel 9fd722d7cd Split message code into Local/Remote
The remote network code does not need to be aware of concepts like
Accounts etc.
2014-12-12 06:47:26 +00:00
Art O Cathain 02c0b5f2a3 Use collections instead of arrays to enable stronger typing and reduce cruft 2014-10-05 10:37:36 +01:00
Art O Cathain 203dcfe2c3 use interfaces, not implementions 2014-10-04 12:00:48 +01:00
tobiasbaum dadf5e0865 Merge pull request #7 from artbristol/art/tidying
Art/tidying
2014-09-29 22:15:59 +02:00
Art O Cathain 010d8c9f7e always use import for UrlEncodingHelper 2014-09-29 18:06:21 +01:00
Art O Cathain c438bc1222 remove some more catches 2014-09-28 12:09:34 +01:00
Tobias Baum b6079d6460 UCDetector warnings: Made things private, deleted unused methods and fields 2014-09-22 21:52:59 +02:00
Tobias Baum 1ea34d2378 Flagged some code with TODOs, added Javadoc for Body 2014-09-14 11:20:18 +02:00
cketti 601e2880ac Merge remote-tracking branch 'upstream/master'
Conflicts:
	src/com/fsck/k9/mail/transport/SmtpTransport.java
2014-09-12 07:11:32 +02:00
Christian Frommeyer 91ef5fa816 Extracted LocalFolder and LocalMessage definition from LocalStore 2014-09-11 20:26:40 +02:00
Christian Frommeyer 038fceabf0 Move LocalStore to new subpackage to prepare decomposition of nested
classes.
2014-09-11 20:26:39 +02:00
Joe Steele 6f14294164 Remove SslHelper. Don't use SecureRandom.
SslHelper has been removed, and its functionality has been transferred
into TrustedSocketFactory.  The added layer of indirection wasn't really
simplifying anything.  It's now easier to see what happens when
createSocket() is invoked.

A new instance of SecureRandom is no longer passed to SSLContext.init().
Instead, null is passed.

The (default) provider of the TLS SSLContext used is OpenSSLProvider,
which provides an SSLSocket instance of type OpenSSLSocketImpl.  The only
use of SecureRandom is in OpenSSLSocketImpl.startHandshake(), where it is
used to seed the OpenSSL PRNG with additional random data.  But if
SecureRandom is null, then /dev/urandom is used for seeding instead.

Meanwhile, the default provider for the SecureRandom service is
OpenSSLRandom, which uses the OpenSSL PRNG as its data source.  So we were
effectively seeding the OpenSSL PRNG with itself.  That's probably okay
(we trust that the OpenSSL PRNG was properly initialized with random data
before first use), but using /dev/urandom would seem like a better source
(or at least as good a source) for the additional seed data added with
each new connection.

Note that our PRNGFixes class replaces the default SecureRandom service
with one whose data source is /dev/urandom for certain vulnerable API
levels anyway.  (It also makes sure that the OpenSSL PRNG is properly
seeded before first use for certain vulnerable API levels.)
2014-09-06 18:15:25 -04:00
Joe Steele 1783dd1a63 Merge branch 'master' into tls-client-cert-auth
Conflicts:
	res/layout/account_setup_basics.xml
	res/values/strings.xml
	src/com/fsck/k9/activity/setup/AccountSetupBasics.java
2014-08-19 16:19:02 -04:00
Joe Steele f7fb0cca41 Compare Enum types with ==, !=
Per comments in PR #473

https://github.com/k9mail/k-9/pull/474#commitcomment-7416979

https://github.com/k9mail/k-9/pull/474#commitcomment-7416999
2014-08-18 18:12:39 -04:00
Joe Steele c8f6c4d625 Eliminate searching for '3' in exception message
This was dead code.  The exception message will always start with either
"SMTP response is 0 length" from checkLine() or else "Negative SMTP reply"
from NegativeSmtpReplyException().

The problem originated from way back before 4.904.
2014-08-11 11:08:51 -04:00
Joe Steele 301ac48a38 Throw CertificateValidationException if EXTERNAL authentication fails
This is done when the SASL EXTERNAL mechanism isn't advertised (indicating
the possibility that the server did not accept the client certificate) or
when the command for authenticating with SASL EXTERNAL fails.

The CertificateValidationException will trigger a notification to the user
that there's an authentication problem that needs addressing.

Also, there were instances where CertificateValidationException was being
thrown with a new CertificateException as the cause for the purpose of
notifying the user when STARTTLS is not available.  This has been slightly
simplified by eliminating the need to include a new CertificateException
as a cause.
2014-08-11 11:07:54 -04:00
Joe Steele b557ba008c Implement SMTP AUTH EXTERNAL
Also, simplify by using Utility.base64Encode(String) in lieu of
new String(Base64.encodeBase64(String.getBytes())
2014-08-11 11:07:53 -04:00
Matthias Wächter acd756e642 Fixed https://github.com/typingArtist/k-9/issues/1. HELO/EHLO IPv6 address literals
are now conforming to RFC5321.
2014-07-05 18:59:48 +02:00
Dominik Schürmann aad171ff7e Client Certificate Authentication 2014-06-05 21:03:18 +02:00
Joe Steele bd4b7d3664 Issue 6280 -- SMTP Setup: ArrayIndexOutOfBoundsException: length=0; index=0
When the outgoing server settings don't require
authentication, userInfoParts.length == 0.
2014-03-20 10:56:02 -04:00
cketti 617123c58b Remove SimpleX509TrustManager because it's no longer used 2014-03-05 06:03:06 +01:00
Joe Steele 094318dacb Use buffered output streams for all output
POP3 already does this.

This is a more general solution to the problem
addressed in commit 8bfd6ca.
2014-03-03 17:31:26 -05:00
Joe Steele 14a0a7a2a7 Provide notification if STARTTLS is not available 2014-03-03 17:29:48 -05:00
Joe Steele daea7f1ecd Eliminate the 'if available' connection security options
These options originated in the AOSP email client from which K-9 Mail was
forked.  They provide an odd combination of 2 features:

1. Don't bother to authenticate the server's certificate (applies to both
SSL/TLS and STARTTLS); i.e., blindly accept all certificates.  This is
generally a bad security policy which is susceptible to MITM attacks.

2. If STARTTLS is selected but the server doesn't claim to support
STARTTLS, then proceed without using encryption.  This, too, is a bad
security policy which is susceptible to MITM attacks.

Since the time that K-9 Mail was forked, a couple things have changed:

> K-9 Mail has implemented the ability for users to review and permanently
accept individual certificates that would otherwise fail authentication.
With this ability, there is no need for a user to subject themselves to
the ongoing risks of feature 1. above.  Hence, this commit removes feature
1.

> The AOSP email client has changed its behavior and no longer permits a
security downgrade to an unencrypted connection if the server doesn't
claim to support STARTTLS (i.e., they eliminated feature 2. above). K-9
Mail should do the same.  It's unlikely that a server is going to provide
STARTTLS on an intermittent basis, so providing a contingency for such
unusual behavior is an unnecessary risk.  Hence, this commit removes that
feature as well.

Effect on existing users:

If the old connection security setting was "SSL/TLS (if available)" (which
now gets remapped to "SSL/TLS"), and the server does not provide a
certificate that can be authenticated, then a "Certificate error for
<account name>" notification is generated telling the user to check their
server settings.  Tapping the notification takes the user to the relevant
server settings, where the user can tap "Next" to review the certificate
and choose to permanently accept it.  This process would occur during the
first syncing of folders after application upgrade or (in the case of
SMTP) during the first attempt to send a message.

If the connection security setting was "STARTTLS (if available)" (which
now gets remapped to "STARTTLS"), and the server does not provide a
certificate that can be authenticated, then the same process as above
would occur.

If the old connection security setting was "STARTTLS (if available)", and
the server doesn't claim to support STARTTLS, then the user would get a
certificate error notification which would lead them to the server's
settings.  There they would need to choose a different connection security
-- most likely "NONE".  If they didn't change anything but instead just
tapped "Next", the server settings would be checked again and a dialog
would pop up saying, "Cannot connect to server. (STARTTLS connection
security not available)". (The implementation of notifications when
STARTTLS is not available is not actually included here -- it's in the
commit that follows.)

Regarding the changes to providers.xml:  in cases where the scheme ended
with "+ssl", the schemes were simply updated by appending "+".  In cases
where the scheme ended with "+tls", a check of the server was made to
assure that STARTTLS was available before appending "+" to the scheme.
Domains paran.com and nate.com failed the check and were removed because
no current information could be found.  Domains me.com and mac.com also
failed and were updated based on http://support.apple.com/kb/ht4864.
2014-03-03 17:23:00 -05:00
Joe Steele 0509e1541c Use Locale.US where appropriate 2014-03-03 10:08:07 -05:00
Joe Steele f7d397ea09 Eliminate SMTP AUTOMATIC authentication
The server settings for IMAP and POP3 have no such AUTOMATIC setting.
(Nor does Thunderbird have any such setting.)

The AUTOMATIC option is no longer offered to users as a choice.  A
pre-existing setting will continue to be honored, but only to the extent
that it doesn't result in insecure password transmission.  Users in such a
situation will get a "Failed to send some messages" notification
containing the exception text that says to update their outgoing server
authentication setting.

One of the problems with "AUTOMATIC" is that users may not fully
understand its security implications.  For example, a MITM attack could
mask a server's support for STARTTLS and CRAM-MD5, resulting in password
disclosure in certain configurations.

This commit also makes changes to the SMTP authentication process.  No
attempt is made to authenticate using methods that the server does not
profess to support in its EHLO response.  This is the same behavior as
found in Thunderbird.
2014-02-25 15:22:43 -05:00
Joe Steele c7e46faf0a Simplify code with better use of enum ConnectionSecurity 2014-02-25 15:22:38 -05:00
Joe Steele 90fedf7125 Eliminate the LOGIN authentication option from SMTP
The LOGIN option is no longer offered to users as a choice.  This does
*not* eliminate the SASL LOGIN authentication mechanism.  Any pre-existing
LOGIN setting or any imported LOGIN setting will still be recognized.  In
all cases, a user setting of either "Normal password" or "LOGIN" will
result in the SASL PLAIN mechanism being tried first if available,
otherwise SASL LOGIN will be tried if available.

This mirrors similar behavior that exists for IMAP.
2014-02-25 15:22:37 -05:00
Joe Steele dc9720ca13 Use localized strings for authentication type
AUTOMATIC = "Automatic"
PLAIN = "Normal password"
CRAM_MD5 = "Encrypted password"

SMTP also uses LOGIN.  No localized text was associated with that because
a future commit will remove that option.

(The text is similar to that of Thunderbird's)
2014-02-25 15:22:35 -05:00
Joe Steele f24ac67e4d Ignore case for SMTP extension keywords
The server is permitted to use mixed case keywords.
This converts them to upper case on receipt.
2014-02-25 15:22:33 -05:00
Joe Steele 26491676fa Retrict use of AuthenticationFailedException
In AccountSetupCheckSettings.onCreate(Bundle), the account settings are
checked.

If an AuthenticationFailedException occurs, A dialog saying "Username or
password incorrect." pops up.  We don't want to say this if the cause is
not related to an incorrect user name or password.  Instead we want to say
the more generic "Cannot connect to server" which pops up for other
exception types.

This commit attempts to eliminate the use of AuthenticationFailedException
in instances where it could not be due to "Username or password
incorrect."
2014-02-25 15:22:30 -05:00
András Veres-Szentkirályi 0c7740ce86 removed unread field mAccount 2014-02-15 21:30:44 +01:00
Joe Steele 40404c3700 Move some classes out of com.fsck.k9.mail.store
The classes are just as much related to com.fsck.k9.mail.transport
as com.fsck.k9.mail.store, so having them in
com.fsck.k9.mail.store doesn't seem appropriate.

Move LocalKeyStore to com.fsck.k9.security

Move TrustManagerFactory and TrustedSocketFactory to com.fsck.k9.net.ssl
2013-12-02 14:07:57 -05:00
Joe Steele a4440b4042 Fix inadequate certificate validation
Proper host name validation was not being performed for certificates
kept in the local keystore.  If an attacker could convince a user to
accept and store an attacker's certificate, then that certificate
could be used for MITM attacks, giving the attacker access to all
connections to all servers in all accounts in K-9.

This commit changes how the certificates are stored.  Previously, an
entire certificate chain was stored for a server (and any of those
certificates in the chain were available for validating signatures on
certificates received when connecting).  Now just the single
certificate for the server is stored.

This commit changes how locally stored certificates are retrieved.
They can only be retrieved using the host:port that the user
configured for the server.

This also fixes issue 1326.  Users can now use different certificates
for different servers on the same host (listening to different ports).

The above changes mean that users might have to re-accept certificates
that they had previously accepted and are still using (but only if the
certificate's Subject doesn't match the host that they are connecting
to).

This commit modifies AccountSetupBasics so that it now calls
AccountSetupCheckSettings twice -- once for checking the incoming
settings and once for the outgoing settings.  Otherwise, an exception
could occur while checking incoming settings, the user could say
continue (or the user could accept a certificate key), and the
outgoing settings would not be checked.  This also helps with
determining if a certificate exception was for the incoming or
outgoing server, which is needed if the user decides to add the
certificate to the keystore.
2013-11-23 13:26:57 -05:00
brian m. carlson 1bfb78ee51 Use TrustedSocketFactory for STARTTLS.
The TrustedSocketFactory, which provides goodies like better cipher suites and
TLSv1.2, was only being used for tunnelled connections.  Use it for STARTTLS
connections as well.
2013-11-10 00:27:01 +00:00
cketti a97705ffa9 Refactor TrustedSocketFactory 2013-10-29 04:37:52 +01:00
András Veres-Szentkirályi 105d3b3c4e filter TLS protocol versions by support as well 2013-10-20 10:42:39 +02:00
András Veres-Szentkirályi 77d43fb7bd extracted method filterBySupport 2013-10-20 10:30:33 +02:00
András Veres-Szentkirályi dbc47c7297 filter enabled cipher suites by availability 2013-10-20 10:22:53 +02:00