mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Remove LocalKeyStore's dependency on K9.app
This commit is contained in:
parent
2a9ac867b9
commit
765b390eb5
@ -1873,15 +1873,16 @@ public class Account implements BaseAccount {
|
||||
/**
|
||||
* Add a new certificate for the incoming or outgoing server to the local key store.
|
||||
*/
|
||||
public void addCertificate(CheckDirection direction, X509Certificate certificate)
|
||||
throws CertificateException {
|
||||
public void addCertificate(Context context, CheckDirection direction,
|
||||
X509Certificate certificate) throws CertificateException {
|
||||
Uri uri;
|
||||
if (direction.equals(CheckDirection.INCOMING)) {
|
||||
uri = Uri.parse(getStoreUri());
|
||||
} else {
|
||||
uri = Uri.parse(getTransportUri());
|
||||
}
|
||||
LocalKeyStore.getInstance().addCertificate(uri.getHost(), uri.getPort(), certificate);
|
||||
LocalKeyStore localKeyStore = LocalKeyStore.getInstance(context);
|
||||
localKeyStore.addCertificate(uri.getHost(), uri.getPort(), certificate);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1889,7 +1890,8 @@ public class Account implements BaseAccount {
|
||||
* new host/port, then try and delete any (possibly non-existent) certificate stored for the
|
||||
* old host/port.
|
||||
*/
|
||||
public void deleteCertificate(String newHost, int newPort, CheckDirection direction) {
|
||||
public void deleteCertificate(Context context, String newHost, int newPort,
|
||||
CheckDirection direction) {
|
||||
Uri uri;
|
||||
if (direction.equals(CheckDirection.INCOMING)) {
|
||||
uri = Uri.parse(getStoreUri());
|
||||
@ -1899,7 +1901,8 @@ public class Account implements BaseAccount {
|
||||
String oldHost = uri.getHost();
|
||||
int oldPort = uri.getPort();
|
||||
if (!newHost.equals(oldHost) || newPort != oldPort) {
|
||||
LocalKeyStore.getInstance().deleteCertificate(oldHost, oldPort);
|
||||
LocalKeyStore localKeyStore = LocalKeyStore.getInstance(context);
|
||||
localKeyStore.deleteCertificate(oldHost, oldPort);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1907,8 +1910,8 @@ public class Account implements BaseAccount {
|
||||
* Examine the settings for the account and attempt to delete (possibly non-existent)
|
||||
* certificates for the incoming and outgoing servers.
|
||||
*/
|
||||
public void deleteCertificates() {
|
||||
LocalKeyStore localKeyStore = LocalKeyStore.getInstance();
|
||||
public void deleteCertificates(Context context) {
|
||||
LocalKeyStore localKeyStore = LocalKeyStore.getInstance(context);
|
||||
|
||||
Uri uri = Uri.parse(getStoreUri());
|
||||
localKeyStore.deleteCertificate(uri.getHost(), uri.getPort());
|
||||
|
@ -128,7 +128,7 @@ public class Preferences {
|
||||
|
||||
Store.removeAccount(account);
|
||||
|
||||
account.deleteCertificates();
|
||||
account.deleteCertificates(mContext);
|
||||
account.delete(this);
|
||||
|
||||
if (newAccount == account) {
|
||||
|
@ -363,7 +363,7 @@ public class AccountSetupCheckSettings extends K9Activity implements OnClickList
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
try {
|
||||
mAccount.addCertificate(mDirection, chain[0]);
|
||||
mAccount.addCertificate(getApplicationContext(), mDirection, chain[0]);
|
||||
} catch (CertificateException e) {
|
||||
showErrorDialog(
|
||||
R.string.account_setup_failed_dlg_certificate_message_fmt,
|
||||
|
@ -428,7 +428,7 @@ public class AccountSetupIncoming extends K9Activity implements OnClickListener
|
||||
mWebdavMailboxPathView.getText().toString());
|
||||
}
|
||||
|
||||
mAccount.deleteCertificate(host, port, CheckDirection.INCOMING);
|
||||
mAccount.deleteCertificate(this, host, port, CheckDirection.INCOMING);
|
||||
ServerSettings settings = new ServerSettings(mStoreType, host, port,
|
||||
connectionSecurity, authType, username, password, extra);
|
||||
|
||||
|
@ -312,7 +312,7 @@ public class AccountSetupOutgoing extends K9Activity implements OnClickListener,
|
||||
String newHost = mServerView.getText().toString();
|
||||
int newPort = Integer.parseInt(mPortView.getText().toString());
|
||||
uri = new URI(smtpSchemes[securityType], userInfo, newHost, newPort, null, null, null);
|
||||
mAccount.deleteCertificate(newHost, newPort, CheckDirection.OUTGOING);
|
||||
mAccount.deleteCertificate(this, newHost, newPort, CheckDirection.OUTGOING);
|
||||
mAccount.setTransportUri(uri.toString());
|
||||
AccountSetupCheckSettings.actionCheckSettings(this, mAccount, CheckDirection.OUTGOING);
|
||||
} catch (UnsupportedEncodingException enc) {
|
||||
|
@ -2,6 +2,8 @@
|
||||
package com.fsck.k9.net.ssl;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.fsck.k9.K9;
|
||||
import com.fsck.k9.helper.DomainNameChecker;
|
||||
import com.fsck.k9.mail.CertificateChainException;
|
||||
import com.fsck.k9.security.LocalKeyStore;
|
||||
@ -100,7 +102,7 @@ public final class TrustManagerFactory {
|
||||
|
||||
static {
|
||||
try {
|
||||
keyStore = LocalKeyStore.getInstance();
|
||||
keyStore = LocalKeyStore.getInstance(K9.app);
|
||||
|
||||
javax.net.ssl.TrustManagerFactory tmf = javax.net.ssl.TrustManagerFactory.getInstance("X509");
|
||||
tmf.init((KeyStore) null);
|
||||
|
@ -20,15 +20,25 @@ import com.fsck.k9.K9;
|
||||
|
||||
public class LocalKeyStore {
|
||||
private static final int KEY_STORE_FILE_VERSION = 1;
|
||||
private static final LocalKeyStore sInstance = new LocalKeyStore();
|
||||
private File mKeyStoreFile;
|
||||
private KeyStore mKeyStore;
|
||||
|
||||
public static LocalKeyStore getInstance() {
|
||||
private static LocalKeyStore sInstance;
|
||||
|
||||
|
||||
public static LocalKeyStore getInstance(Context context) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new LocalKeyStore(context);
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
private LocalKeyStore() {
|
||||
|
||||
private final Context mContext;
|
||||
private File mKeyStoreFile;
|
||||
private KeyStore mKeyStore;
|
||||
|
||||
|
||||
private LocalKeyStore(Context context) {
|
||||
mContext = context.getApplicationContext();
|
||||
upgradeKeyStoreFile();
|
||||
setKeyStoreFile(null);
|
||||
}
|
||||
@ -157,12 +167,11 @@ public class LocalKeyStore {
|
||||
}
|
||||
|
||||
private String getKeyStoreFilePath(int version) {
|
||||
File dir = mContext.getDir("KeyStore", Context.MODE_PRIVATE);
|
||||
if (version < 1) {
|
||||
return K9.app.getDir("KeyStore", Context.MODE_PRIVATE)
|
||||
+ File.separator + "KeyStore.bks";
|
||||
return dir + File.separator + "KeyStore.bks";
|
||||
} else {
|
||||
return K9.app.getDir("KeyStore", Context.MODE_PRIVATE)
|
||||
+ File.separator + "KeyStore_v" + version + ".bks";
|
||||
return dir + File.separator + "KeyStore_v" + version + ".bks";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package com.fsck.k9.net.ssl;
|
||||
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
|
||||
import com.fsck.k9.net.ssl.TrustManagerFactory;
|
||||
import com.fsck.k9.security.LocalKeyStore;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
@ -208,9 +207,8 @@ public class TrustManagerFactoryTest extends AndroidTestCase {
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
mKeyStoreFile = File.createTempFile("localKeyStore", null, getContext()
|
||||
.getCacheDir());
|
||||
mKeyStore = LocalKeyStore.getInstance();
|
||||
mKeyStoreFile = File.createTempFile("localKeyStore", null, getContext().getCacheDir());
|
||||
mKeyStore = LocalKeyStore.getInstance(getContext());
|
||||
mKeyStore.setKeyStoreFile(mKeyStoreFile);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user