Remove remaining (non-working) 'androidTest' tests
This commit is contained in:
parent
d38dd84e88
commit
357e197256
3 changed files with 0 additions and 702 deletions
|
@ -1,274 +0,0 @@
|
|||
package com.fsck.k9.mail;
|
||||
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.spongycastle.openpgp.PGPCompressedData;
|
||||
import org.spongycastle.openpgp.PGPException;
|
||||
import org.spongycastle.openpgp.PGPObjectFactory;
|
||||
import org.spongycastle.openpgp.PGPPublicKey;
|
||||
import org.spongycastle.openpgp.PGPPublicKeyRingCollection;
|
||||
import org.spongycastle.openpgp.PGPSignature;
|
||||
import org.spongycastle.openpgp.PGPSignatureList;
|
||||
import org.spongycastle.openpgp.PGPUtil;
|
||||
import org.spongycastle.openpgp.bc.BcPGPObjectFactory;
|
||||
import org.spongycastle.openpgp.bc.BcPGPPublicKeyRingCollection;
|
||||
import org.spongycastle.openpgp.operator.bc.BcPGPContentVerifierBuilderProvider;
|
||||
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class PgpMimeMessageTest {
|
||||
private static final String PUBLIC_KEY = "-----BEGIN PGP PUBLIC KEY BLOCK-----\n" +
|
||||
"Version: GnuPG v1\n" +
|
||||
"\n" +
|
||||
"mQINBE49+OsBEADIu2zVIYllkqLYaCZq2d8r80titzegJiXTaW8fRS0FKGE7KmNt\n" +
|
||||
"tWvWdiyLqvWlP4Py9OZPmEBdz8AaPxqCFmVZfJimf28CW0wz2sRCYmmbQqaHFfpD\n" +
|
||||
"rK+EJofckOu2j81coaFVLbvkvUNhWU7/DKyv4+EBFt9fjxptbfpNKttwI0aeUVCa\n" +
|
||||
"+Z/m18+OLpeE33BXd5POrBb4edAlMCwKk8m4nDXJ3B+KmR0qfCLB79gqEjsDLl+y\n" +
|
||||
"65NcRk5uxIk53NRXHkmQujX1bsf5VFLha4KbUaB7BCtcSi1rY99WXfO/PWzTelOh\n" +
|
||||
"pKDIRq+v3Kl21TipY0t4kco4AUlIx5b1F0EHPpmIDr0gEheZBali5c9wUR8czc/H\n" +
|
||||
"aNkRP81hTPeBtUqp1S7GtJfcuWv6dyfBBVlnev98PCKOJo05meVwf3hkOLrciTfo\n" +
|
||||
"1yuy/9hF18u3GhL8HLrxMQksLhD6sPzDto4jJQDxKAa7v9aLoR7oIdeWkn1TU61E\n" +
|
||||
"ODR/254BRMoq619hqJwSNt6yOjGT2BBvlwbKdS8Xfw7SsBGGW8WnVJrqFCusfjSm\n" +
|
||||
"DBdV/KWstRnOMqw4nhAwNFfXmAL2L8a+rLHxalFggfGcvVpzDhJyTg+/R1y3JMCo\n" +
|
||||
"FfdFuhOTfkMqjGx8FgTmINOt54Wf9Xg6W0hQh3i98Wza3n8NuSPQJtAdqQARAQAB\n" +
|
||||
"tBVja2V0dGkgPGNrQGNrZXR0aS5kZT6JAhwEEAECAAYFAk+6naAACgkQctTBoSHq\n" +
|
||||
"3aHS+g/+MNxxfoEK+zopjWgvJmigOvejIpBWsLYJOJrpOgQuA61dQnQg0eLXPMDc\n" +
|
||||
"xQTrPtIlkn7idtLbaG2FScheOS0RdApL8UJTiU18dzjHUWsLLhEFhOAgw/kqcdG0\n" +
|
||||
"A95apNucybWU9jxynN9arxU6U+HZ67/JKxRjfdPxm+CmjiQwFPU9d6kGU/D08y58\n" +
|
||||
"1VIn7IopHlbqOYRuQcX0p6Q642oRBp4b6+ggov21mgqscKe/eBQ8yUxf61eywLbb\n" +
|
||||
"On63fkF1vl/RvsVcOnxcPLxUH4vmhuGPJ546RN7CCNjVF0QvuH9R8dnxS7/+rLe7\n" +
|
||||
"BVtZ/8sAy9r8LvnehZWVww4Wo9haVQxB69+ns63lEb+dzbBmsKbGvQ98S/Hs62Wj\n" +
|
||||
"nkMy7k+xzoRMa7tbKEtwwppxJVVSW//CVvEsS7DyaZna0udLh16MBCbMDzfAa3T4\n" +
|
||||
"PmgQPmV1BeysHcFOn3p6p2ZRcQGEdvMBYUjqxxExstwZEY8nGagvG7j5YCJKzBNY\n" +
|
||||
"xdBwkHXU3R3iM9o4aCKBsG2DMGHyhkHJXuGv9jFM32tAAf36qUJZ9eTKtoUt4xGt\n" +
|
||||
"LuxgnkS830c7nZBfJARro75SDG9eew91u2aIDGO3aNXeOODrYl2KOWbpXg/NJDwS\n" +
|
||||
"mlUZdwInb0PL6EDij1NtDiap2sIBKxtDjAeilS6vwS8s2P9HZdqJAkEEEwECACsC\n" +
|
||||
"GyMFCRLMAwAGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheABQJOPftbAhkBAAoJEO4v\n" +
|
||||
"7zp9qOKJG+oP/RBN5ahJCpwrk7U05J8x7UOPuP4UElMYoPYZCSp55mH6Xmr2C626\n" +
|
||||
"DvTxhElz1WY7oIOJ7Mgp1RtGqZYV52d6fER10jowGbSkiFTvKb4PhQl4+AcGODMY\n" +
|
||||
"LRVBw90rRhDSXzBQMeiyUf7Wse1jPsBfuOe6V1TsAtqjaAzrUDQOcsjQqW5ezvIj\n" +
|
||||
"GNTFunX6wMUHzSBX6Lh0fLAp5ICp+l3agJ8S41Y4tSuFVil2IRX3o4vqxvU4f0C+\n" +
|
||||
"KDIeJriLAMHajUp0V6VdisRHujjoTkZAGogJhNmNg0YH191a7AAKvVePgMQ/fsoW\n" +
|
||||
"1hm9afwth/HOKvMx8fgKMwkn004V/to7qHByWDND33rgwlv1LYuvumEFd/paIABh\n" +
|
||||
"dLhC6o6moVzwlOqhGfoD8DZAIzNCS4q2uCg8ik4temetPbCc5wMFtd+FO+FOb1tO\n" +
|
||||
"/RahWeBfULreEijnv/zUZPetkJV9jTZXgXqCI9GCf6MTJrOLZ+G3hVxFyyHTKlWt\n" +
|
||||
"iIzJHlX9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qqlxss7JPVsJzD9xSotg+G/Wb7F3HL\n" +
|
||||
"HzpeeqkwzVU=\n" +
|
||||
"=3yEX\n" +
|
||||
"-----END PGP PUBLIC KEY BLOCK-----\n";
|
||||
|
||||
|
||||
@Test
|
||||
public void testSignedMessage() throws IOException, MessagingException, PGPException {
|
||||
String messageSource = "Date: Mon, 08 Dec 2014 17:44:18 +0100\r\n" +
|
||||
"From: cketti <cketti@googlemail.com>\r\n" +
|
||||
"MIME-Version: 1.0\r\n" +
|
||||
"To: test@example.com\r\n" +
|
||||
"Subject: OpenPGP signature test\r\n" +
|
||||
"Content-Type: multipart/signed; micalg=pgp-sha1;\r\n" +
|
||||
" protocol=\"application/pgp-signature\";\r\n" +
|
||||
" boundary=\"24Bem7EnUI1Ipn9jNXuLgsetqa6wOkIxM\"\r\n" +
|
||||
"\r\n" +
|
||||
"This is an OpenPGP/MIME signed message (RFC 4880 and 3156)\r\n" +
|
||||
"--24Bem7EnUI1Ipn9jNXuLgsetqa6wOkIxM\r\n" +
|
||||
"Content-Type: multipart/mixed;\r\n" +
|
||||
" boundary=\"------------030308060900040601010501\"\r\n" +
|
||||
"\r\n" +
|
||||
"This is a multi-part message in MIME format.\r\n" +
|
||||
"--------------030308060900040601010501\r\n" +
|
||||
"Content-Type: text/plain; charset=utf-8\r\n" +
|
||||
"Content-Transfer-Encoding: quoted-printable\r\n" +
|
||||
"\r\n" +
|
||||
"Message body\r\n" +
|
||||
"goes here\r\n" +
|
||||
"\r\n" +
|
||||
"\r\n" +
|
||||
"--------------030308060900040601010501\r\n" +
|
||||
"Content-Type: text/plain; charset=UTF-8;\r\n" +
|
||||
" name=\"attachment.txt\"\r\n" +
|
||||
"Content-Transfer-Encoding: base64\r\n" +
|
||||
"Content-Disposition: attachment;\r\n" +
|
||||
" filename=\"attachment.txt\"\r\n" +
|
||||
"\r\n" +
|
||||
"VGV4dCBhdHRhY2htZW50Cg==\r\n" +
|
||||
"--------------030308060900040601010501--\r\n" +
|
||||
"\r\n" +
|
||||
"--24Bem7EnUI1Ipn9jNXuLgsetqa6wOkIxM\r\n" +
|
||||
"Content-Type: application/pgp-signature; name=\"signature.asc\"\r\n" +
|
||||
"Content-Description: OpenPGP digital signature\r\n" +
|
||||
"Content-Disposition: attachment; filename=\"signature.asc\"\r\n" +
|
||||
"\r\n" +
|
||||
"-----BEGIN PGP SIGNATURE-----\r\n" +
|
||||
"Version: GnuPG v1\r\n" +
|
||||
"\r\n" +
|
||||
"iQIcBAEBAgAGBQJUhdVqAAoJEO4v7zp9qOKJ8DQP/1+JE8UF7UmirnN1ZO+25hFC\r\n" +
|
||||
"jAfFMxRWMWXN0gGB+6ySy6ah0bCwmRwHpRBsW/tNcsmOPKb2XBf9zwF06uk/lLp4\r\n" +
|
||||
"ZmGXxSdQ9XJrlaHk8Sitn9Gi/1L+MNWgrsrLROAZv2jfc9wqN3FOrhN9NC1QXQvO\r\n" +
|
||||
"+D7sMorSr3l94majoIDrzvxEnfJVfrZWNTUaulJofOJ55GBZ3UJNob1WKjrnculL\r\n" +
|
||||
"IwmSERmVUoFBUfe/MBqqZH0WDJq9nt//NZFHLunj6nGsrpush1dQRcbR3zzQfXkk\r\n" +
|
||||
"s7zDLDa8VUv6OxcefjsVN/O7EenoWWgNg6GfW6tY2+oUsLSP2OS3JXvYsylQP4hR\r\n" +
|
||||
"iU1V9vvsu2Ax6bVb0+uTqw3jNiqVFy3o4mBigVUqp1EFIwBYmyNbe5wj4ACs9Avj\r\n" +
|
||||
"9t2reFSfXobWQFUS4s71JeMefNAHHJWZI63wNTxE6LOw01YxdJiDaPWGTOyM75MK\r\n" +
|
||||
"yqn7r5uIfeSv8NypGJaUv4firxKbrcZKk7Wpeh/rZuUSgoPcf3I1IzXfGKKIBHjU\r\n" +
|
||||
"WUMhTF5SoC5kIZyeXvHrhTM8HszcS8EoG2XcmcYArwgCUlOunFwZNqLPsfdMTRL6\r\n" +
|
||||
"9rcioaohEtroqoJiGAToJtIz8kqCaamnP/ASBkp9qqJizRd6fqt+tE8BsmJbuPLS\r\n" +
|
||||
"6lBpS8j0TqmaZMYfB9u4\r\n" +
|
||||
"=QvET\r\n" +
|
||||
"-----END PGP SIGNATURE-----\r\n" +
|
||||
"\r\n" +
|
||||
"--24Bem7EnUI1Ipn9jNXuLgsetqa6wOkIxM--\r\n";
|
||||
|
||||
BinaryTempFileBody.setTempDirectory(InstrumentationRegistry.getTargetContext().getCacheDir());
|
||||
|
||||
InputStream messageInputStream = new ByteArrayInputStream(messageSource.getBytes());
|
||||
MimeMessage message;
|
||||
try {
|
||||
message = MimeMessage.parseMimeMessage(messageInputStream, true);
|
||||
} finally {
|
||||
messageInputStream.close();
|
||||
}
|
||||
|
||||
Multipart multipartSigned = (Multipart) message.getBody();
|
||||
|
||||
BodyPart signedPart = multipartSigned.getBodyPart(0);
|
||||
ByteArrayOutputStream signedPartOutputStream = new ByteArrayOutputStream();
|
||||
signedPart.writeTo(signedPartOutputStream);
|
||||
byte[] signedData = signedPartOutputStream.toByteArray();
|
||||
|
||||
Body signatureBody = multipartSigned.getBodyPart(1).getBody();
|
||||
ByteArrayOutputStream signatureBodyOutputStream = new ByteArrayOutputStream();
|
||||
signatureBody.writeTo(signatureBodyOutputStream);
|
||||
byte[] signatureData = signatureBodyOutputStream.toByteArray();
|
||||
|
||||
assertTrue(verifySignature(signedData, signatureData));
|
||||
}
|
||||
|
||||
private boolean verifySignature(byte[] signedData, byte[] signatureData) throws IOException, PGPException {
|
||||
InputStream signatureInputStream = PGPUtil.getDecoderStream(new ByteArrayInputStream(signatureData));
|
||||
PGPObjectFactory pgpObjectFactory = new BcPGPObjectFactory(signatureInputStream);
|
||||
Object pgpObject = pgpObjectFactory.nextObject();
|
||||
|
||||
PGPSignatureList pgpSignatureList;
|
||||
if (pgpObject instanceof PGPCompressedData) {
|
||||
PGPCompressedData compressedData = (PGPCompressedData) pgpObject;
|
||||
pgpObjectFactory = new BcPGPObjectFactory(compressedData.getDataStream());
|
||||
pgpSignatureList = (PGPSignatureList) pgpObjectFactory.nextObject();
|
||||
} else {
|
||||
pgpSignatureList = (PGPSignatureList) pgpObject;
|
||||
}
|
||||
PGPSignature signature = pgpSignatureList.get(0);
|
||||
|
||||
InputStream keyInputStream = PGPUtil.getDecoderStream(new ByteArrayInputStream(PUBLIC_KEY.getBytes()));
|
||||
PGPPublicKeyRingCollection pgpPublicKeyRingCollection = new BcPGPPublicKeyRingCollection(keyInputStream);
|
||||
PGPPublicKey publicKey = pgpPublicKeyRingCollection.getPublicKey(signature.getKeyID());
|
||||
|
||||
signature.init(new BcPGPContentVerifierBuilderProvider(), publicKey);
|
||||
InputStream signedDataInputStream = new ByteArrayInputStream(signedData);
|
||||
int ch;
|
||||
while ((ch = signedDataInputStream.read()) >= 0) {
|
||||
signature.update((byte) ch);
|
||||
}
|
||||
|
||||
signedDataInputStream.close();
|
||||
keyInputStream.close();
|
||||
signatureInputStream.close();
|
||||
|
||||
return signature.verify();
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
package com.fsck.k9.mail;
|
||||
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ReconstructMessageTest {
|
||||
|
||||
@Test
|
||||
public void testMessage() throws IOException, MessagingException {
|
||||
String messageSource =
|
||||
"From: from@example.com\r\n" +
|
||||
"To: to@example.com\r\n" +
|
||||
"Subject: Test Message \r\n" +
|
||||
"Date: Thu, 13 Nov 2014 17:09:38 +0100\r\n" +
|
||||
"Content-Type: multipart/mixed;\r\n" +
|
||||
" boundary=\"----Boundary\"\r\n" +
|
||||
"Content-Transfer-Encoding: 8bit\r\n" +
|
||||
"MIME-Version: 1.0\r\n" +
|
||||
"\r\n" +
|
||||
"This is a multipart MIME message.\r\n" +
|
||||
"------Boundary\r\n" +
|
||||
"Content-Type: text/plain; charset=utf-8\r\n" +
|
||||
"Content-Transfer-Encoding: 8bit\r\n" +
|
||||
"\r\n" +
|
||||
"Testing.\r\n" +
|
||||
"This is a text body with some greek characters.\r\n" +
|
||||
"αβγδεζηθ\r\n" +
|
||||
"End of test.\r\n" +
|
||||
"\r\n" +
|
||||
"------Boundary\r\n" +
|
||||
"Content-Type: text/plain\r\n" +
|
||||
"Content-Transfer-Encoding: base64\r\n" +
|
||||
"\r\n" +
|
||||
"VGhpcyBpcyBhIHRl\r\n" +
|
||||
"c3QgbWVzc2FnZQ==\r\n" +
|
||||
"\r\n" +
|
||||
"------Boundary--\r\n" +
|
||||
"Hi, I'm the epilogue";
|
||||
|
||||
BinaryTempFileBody.setTempDirectory(InstrumentationRegistry.getTargetContext().getCacheDir());
|
||||
|
||||
InputStream messageInputStream = new ByteArrayInputStream(messageSource.getBytes());
|
||||
MimeMessage message;
|
||||
try {
|
||||
message = MimeMessage.parseMimeMessage(messageInputStream, true);
|
||||
} finally {
|
||||
messageInputStream.close();
|
||||
}
|
||||
|
||||
ByteArrayOutputStream messageOutputStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
message.writeTo(messageOutputStream);
|
||||
} finally {
|
||||
messageOutputStream.close();
|
||||
}
|
||||
|
||||
String reconstructedMessage = new String(messageOutputStream.toByteArray());
|
||||
|
||||
assertEquals(messageSource, reconstructedMessage);
|
||||
}
|
||||
}
|
|
@ -1,354 +0,0 @@
|
|||
package com.fsck.k9.mail.ssl;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.File;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.CertificateFactory;
|
||||
import java.security.cert.X509Certificate;
|
||||
|
||||
import androidx.test.InstrumentationRegistry;
|
||||
import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
|
||||
/**
|
||||
* Test the functionality of {@link TrustManagerFactory}.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TrustManagerFactoryTest {
|
||||
public static final String MATCHING_HOST = "k9.example.com";
|
||||
public static final String NOT_MATCHING_HOST = "bla.example.com";
|
||||
public static final int PORT1 = 993;
|
||||
public static final int PORT2 = 465;
|
||||
|
||||
private static final String K9_EXAMPLE_COM_CERT1 =
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
+ "MIICCTCCAXICCQD/R0TV7d0C5TANBgkqhkiG9w0BAQUFADBJMQswCQYDVQQGEwJD\n"
|
||||
+ "SDETMBEGA1UECBMKU29tZS1TdGF0ZTEMMAoGA1UEChMDSy05MRcwFQYDVQQDEw5r\n"
|
||||
+ "OS5leGFtcGxlLmNvbTAeFw0xMTA5MDYxOTU3MzVaFw0yMTA5MDMxOTU3MzVaMEkx\n"
|
||||
+ "CzAJBgNVBAYTAkNIMRMwEQYDVQQIEwpTb21lLVN0YXRlMQwwCgYDVQQKEwNLLTkx\n"
|
||||
+ "FzAVBgNVBAMTDms5LmV4YW1wbGUuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n"
|
||||
+ "iQKBgQCp7FvHRaQaOIu3iyB5GB0PtPCxy/bLlBxBb8p9QsMimX2Yz3SNjWVUzU5N\n"
|
||||
+ "ggpXmmeGopLAnvZlhWYSx0yIGWwPB44kGK5eaYDRWav+K+XXgdNCJij1UWPSmFwZ\n"
|
||||
+ "hUoNbrahco5AFw0jC1qi+3Dht6Y64nfNzTOYTcm1Pz4tqXiADQIDAQABMA0GCSqG\n"
|
||||
+ "SIb3DQEBBQUAA4GBAIPsgd6fuFRojSOAcUyhaoKaY5hXJf8d7R3AYWxcAPYmn6g7\n"
|
||||
+ "3Zms+f7/CH0y/tM81oBTlq9ZLbrJyLzC7vG1pqWHMNaK7miAho22IRuk+HwvL6OA\n"
|
||||
+ "uH3x3W1/mH4ci268cIFVmofID0nYLTqOxBTczfYhI7q0VBUXqv/bZ+3bVMSh\n"
|
||||
+ "-----END CERTIFICATE-----\n";
|
||||
|
||||
private static final String K9_EXAMPLE_COM_CERT2 =
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
+ "MIICCTCCAXICCQDMryqq0gZ80jANBgkqhkiG9w0BAQUFADBJMQswCQYDVQQGEwJD\n"
|
||||
+ "SDETMBEGA1UECBMKU29tZS1TdGF0ZTEMMAoGA1UEChMDSy05MRcwFQYDVQQDEw5r\n"
|
||||
+ "OS5leGFtcGxlLmNvbTAeFw0xMTA5MDYyMDAwNTVaFw0yMTA5MDMyMDAwNTVaMEkx\n"
|
||||
+ "CzAJBgNVBAYTAkNIMRMwEQYDVQQIEwpTb21lLVN0YXRlMQwwCgYDVQQKEwNLLTkx\n"
|
||||
+ "FzAVBgNVBAMTDms5LmV4YW1wbGUuY29tMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCB\n"
|
||||
+ "iQKBgQDOLzRucC3tuXL/NthnGkgTnVn03balrvYPkABvvrG83Dpp5ipIC/iPsQvw\n"
|
||||
+ "pvqypSNHqrloEB7o3obQ8tiRDtbOsNQ7gKJ+YoD1drDNClV0pBvr7mvRgA2AcDpw\n"
|
||||
+ "CTLKwVIyKmE+rm3vl8CWFd9CqHcYQ3Mc1KXXasN4DEAzZ/sHRwIDAQABMA0GCSqG\n"
|
||||
+ "SIb3DQEBBQUAA4GBAFDcHFpmZ9SUrc0WayrKNUpSaHLRG94uzIx0VUMLROcXEEWU\n"
|
||||
+ "soRw1RfoSBkcy2SEjB4CAvex6qAiOT3ubXuL+BYFav/uU8JPWZ9ovSAYqBZ9aUJo\n"
|
||||
+ "G6A2hvA1lpvP97qQ/NFaGQ38XqSykZamZwSx3PlZUM/i9S9n/3MfuuXWqtLC\n"
|
||||
+ "-----END CERTIFICATE-----\n";
|
||||
|
||||
private static final String CA_CERT =
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
+ "MIIDbTCCAlWgAwIBAgIJANCdQ+Cwnyg+MA0GCSqGSIb3DQEBBQUAME0xCzAJBgNV\n"
|
||||
+ "BAYTAkNIMRMwEQYDVQQIDApTb21lLVN0YXRlMQwwCgYDVQQKDANLLTkxGzAZBgNV\n"
|
||||
+ "BAMMEnRlc3QtY2EuazltYWlsLm9yZzAeFw0xMzEyMDIxMjUwNThaFw0yMzExMzAx\n"
|
||||
+ "MjUwNThaME0xCzAJBgNVBAYTAkNIMRMwEQYDVQQIDApTb21lLVN0YXRlMQwwCgYD\n"
|
||||
+ "VQQKDANLLTkxGzAZBgNVBAMMEnRlc3QtY2EuazltYWlsLm9yZzCCASIwDQYJKoZI\n"
|
||||
+ "hvcNAQEBBQADggEPADCCAQoCggEBAJ+YLg9enfFk5eba6B3LtQzUE7GiR2tIpQSi\n"
|
||||
+ "zHMtHzn8KUnRDiGwC8VnSuWCOX7hXyQ0P6i2+DVRVBYOAeDCNMZHOq1hRqI66B33\n"
|
||||
+ "QqLfkBnJAIDeLqfqlgigHs1+//7eagVA6Z38ZFre3PFuKnK9NCwS+gz7PKw/poIG\n"
|
||||
+ "/FZP+ltMlkwvPww4S8SMlY6RXXH09+S/uM8aG6DUBT298eoAXTbSEIeaNhwBHZPe\n"
|
||||
+ "rXqqzd8QDAIE9BFXSkh/BQiVEFDPSBMSdmUzUAsT2aM8osntnKWY5/G7B60wutvA\n"
|
||||
+ "jYCULgtR6lR6jIDbG3ECHVDsTWR+Pgl+h1zeyERhN5iG1ffOtLUCAwEAAaNQME4w\n"
|
||||
+ "HQYDVR0OBBYEFBlUYiTGlOu9zIPx8Q13xcnDL5QpMB8GA1UdIwQYMBaAFBlUYiTG\n"
|
||||
+ "lOu9zIPx8Q13xcnDL5QpMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQEFBQADggEB\n"
|
||||
+ "AJ6oC6O6I6p0vgA4+7dfyxKX745zl/fK6IVHV/GO75mLjVdyw00USbHGHAmZM5C6\n"
|
||||
+ "eCKVV83m/Re5lHf8ZBjc+3rWdGCEjwyUwvDeUvzpcKF3wPxYDUOOqSI+np1cxj6q\n"
|
||||
+ "6+XI5QXwyUObWtWyw1GOpLuFPbxny/TlRWvk8AfOaLANg3UhvITNZMdMHoQ2sJ3u\n"
|
||||
+ "MrQ+CHe/Tal2MkwiCrYT91f3YWVaswiEAxpqxnwuSXnYyaJpqMCcA1txBDgX84FP\n"
|
||||
+ "dSIM4ut+QltV2Tlx0lpH43dvttAwkPB+iL7ZF6zUki/Nq5aKyNoHOL88TACe18Lq\n"
|
||||
+ "zOztD2HZfxhIz3uH2gXmqUo=\n"
|
||||
+ "-----END CERTIFICATE-----\n";
|
||||
|
||||
private static final String CERT3 =
|
||||
"-----BEGIN CERTIFICATE-----\n"
|
||||
+ "MIIDjDCCAnSgAwIBAgIBATANBgkqhkiG9w0BAQUFADBNMQswCQYDVQQGEwJDSDET\n"
|
||||
+ "MBEGA1UECAwKU29tZS1TdGF0ZTEMMAoGA1UECgwDSy05MRswGQYDVQQDDBJ0ZXN0\n"
|
||||
+ "LWNhLms5bWFpbC5vcmcwHhcNMTMxMjAyMTMxNzEyWhcNMjMxMTMwMTMxNzEyWjBJ\n"
|
||||
+ "MQswCQYDVQQGEwJDSDETMBEGA1UECAwKU29tZS1TdGF0ZTEMMAoGA1UECgwDSy05\n"
|
||||
+ "MRcwFQYDVQQDDA5rOS5leGFtcGxlLmNvbTCCASIwDQYJKoZIhvcNAQEBBQADggEP\n"
|
||||
+ "ADCCAQoCggEBAL9OvWtLcp6bd40Hai6A6cCmJRwn3mwcTB8E41iEQgQexqx/f9RR\n"
|
||||
+ "BuQi2s80k/vXq8QU2GbwGiPkBBXMUHuiT27Lsoj8kMOnH5BXeKLaWDiMpvNqfent\n"
|
||||
+ "UzBXSIOK6Yu9UtlU0MzAuYxXaunrXoS5Dejrbz743P9yW8hx7pANNU0Qfck+ekR7\n"
|
||||
+ "Q4PWNgfbFHrnvcobzuFzJeWg8x9iTTsVGIaX9AVMjMUlIKvhhOWTlcTJHKzU67sp\n"
|
||||
+ "OLzwH9IJ3hqwdmsgZu5D/2AZlYlpFk6AlnoxNhfy9m+T41P8+iWDYCJoxvf3d6gl\n"
|
||||
+ "TlZ1FL0PzPReXeAgugyJ1qx5gJ9Vhf/rBaUCAwEAAaN7MHkwCQYDVR0TBAIwADAs\n"
|
||||
+ "BglghkgBhvhCAQ0EHxYdT3BlblNTTCBHZW5lcmF0ZWQgQ2VydGlmaWNhdGUwHQYD\n"
|
||||
+ "VR0OBBYEFPm9hbTbfmcnjjfOzrec/TrvsS5ZMB8GA1UdIwQYMBaAFBlUYiTGlOu9\n"
|
||||
+ "zIPx8Q13xcnDL5QpMA0GCSqGSIb3DQEBBQUAA4IBAQAgvYQoCEklJNXBwLuWpSMx\n"
|
||||
+ "CQrVxLI1XsYRzqMs0kUgM59OhwAPwdSR+UEuyXQ8QGKwSt1d//DkdhzQDATXSBYc\n"
|
||||
+ "VHr16ocYPGNd/VNo7BoUCvykp3cCH3WxYYpAugXbLU8RBJzQwCM75SLQtFe20qfI\n"
|
||||
+ "LErbrmKONtMk3Rfg6XtLLcaOVh1A3q13CKqDvwtZT4oo56EJOvkBkzlCvTuxJb6s\n"
|
||||
+ "FD9pwROFpIN8O54C333tZzj4TDP4g9zb3sofAJ4U0osfQAXekZJdZETFGJsU6TIM\n"
|
||||
+ "Dcf5/G8bZe2DnavBQfML1wI5d7NUWE8CWb95SsIvFXI0qZE0oIR+axBVl9u97uaO\n"
|
||||
+ "-----END CERTIFICATE-----\n";
|
||||
|
||||
private static final String LINUX_COM_FIRST_PARENT_CERT =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIGNDCCBBygAwIBAgIBGzANBgkqhkiG9w0BA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||||
"gDoMoBTTMI/wnxXwulNPtfgF7/5AtDhA4GNAfB2SddxiNQAF7XkUHtMZ9ff3W6Xk\n" +
|
||||
"FldOG+NlLFqsDBG/KLckyFK36gq+FqNFCbmtmtXBGB5L1fDIeYzcMKG6hFQxhHS0\n" +
|
||||
"oqpdHhp2nWBfLlOnTNqIZNJzOH37OJE6Olk45LNFJtSrqIAZyCCfM6bQgoQvZuIa\n" +
|
||||
"xs9SIp+63ZMk9TxEaQj/KteaOyfaPXI9778U7JElMTz3Bls62mslV2I1C/A73Zyq\n" +
|
||||
"JZWQZ8NU4ds=\n" +
|
||||
"-----END CERTIFICATE-----\n";
|
||||
|
||||
private static final String LINUX_COM_CERT =
|
||||
"-----BEGIN CERTIFICATE-----\n" +
|
||||
"MIIGhjCCBW6gAwIBAgIDAmiWMA0GCSqGSIb3DQEBCwUAMIGMMQswCQYDVQQGEwJJ\n" +
|
||||
"TDEWMBQGA1UEChMNU3RhcnRDb20gTHRkLjErMCkGA1UECxMiU2VjdXJlIERpZ2l0\n" +
|
||||
"YWwgQ2VydGlmaWNhdGUgU2lnbmluZzE4MDYGA1UEAxMvU3RhcnRDb20gQ2xhc3Mg\n" +
|
||||
"MiBQcmltYXJ5IEludGVybWVkaWF0ZSBTZXJ2ZXIgQ0EwHhcNMTQwODIxMjEwMDI4\n" +
|
||||
"WhcNMTYwODIxMDY0NDE0WjCBlDELMAkGA1UEBhMCVVMxEzARBgNVBAgTCkNhbGlm\n" +
|
||||
"b3JuaWExFjAUBgNVBAcTDVNhbiBGcmFuY2lzY28xHTAbBgNVBAoTFFRoZSBMaW51\n" +
|
||||
"eCBGb3VuZGF0aW9uMRQwEgYDVQQDFAsqLmxpbnV4LmNvbTEjMCEGCSqGSIb3DQEJ\n" +
|
||||
"ARYUaG9zdG1hc3RlckBsaW51eC5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw\n" +
|
||||
"ggEKAoIBAQCjvFjOigXyqkSiVv0vz1CSDg08iilLnj8gR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nRlbmRl\n" +
|
||||
"ZCBwdXJwb3NlIGluIGNvbXBsaWFuY2Ugb2YgdGhlIHJlbHlpbmcgcGFydHkgb2Js\n" +
|
||||
"aWdhdGlvbnMuMDUGA1UdHwQuMCwwKqAooCaGJGh0dHA6Ly9jcmwuc3RhcnRzc2wu\n" +
|
||||
"Y29tL2NydDItY3JsLmNybDCBjgYIKwYBBQUHAQEEgYEwfzA5BggrBgEFBQcwAYYt\n" +
|
||||
"aHR0cDovL29jc3Auc3RhcnRzc2wuY29tL3N1Yi9jbGFzczIvc2VydmVyL2NhMEIG\n" +
|
||||
"CCsGAQUFBzAChjZodHRwOi8vYWlhLnN0YXJ0c3NsLmNvbS9jZXJ0cy9zdWIuY2xh\n" +
|
||||
"c3MyLnNlcnZlci5jYS5jcnQwIwYDVR0SBBwwGoYYaHR0cDovL3d3dy5zdGFydHNz\n" +
|
||||
"bC5jb20vMA0GCSqGSIb3DQEBCwUAA4IBAQBVkvlwVLfnTNZh1c8j+PQ1t2n6x1dh\n" +
|
||||
"tQtZiAYWKvZwi+XqLwU8q2zMxKrTDuqyEVyfCtWCiC1Vkpz72pcyXz2dKu7F7ZVL\n" +
|
||||
"86uVHcc1jAGmL59UCXz8LFbfAMcoVQW1f2WtNwsa/WGnPUes3jFSec+shB+XCpvE\n" +
|
||||
"WU6mfcZD5TyvbC79Kn5e3Iq+B4DaXhU/BXASRbORgYd8C+dqj++w0PAcMrmjn3D6\n" +
|
||||
"EmL1ofqpQ8wCJd5C1b5Fr4RbbYpK8v8AASRcp2Qj9WJjyV882FvXOOFj5V2Jjcnh\n" +
|
||||
"G0h67ElS/klu9rPaZ+vr3iIB56wvk08O2Wq1IND3sN+Ke3UsvuPqDxAv\n" +
|
||||
"-----END CERTIFICATE-----\n";
|
||||
|
||||
private File mKeyStoreFile;
|
||||
private LocalKeyStore mKeyStore;
|
||||
private X509Certificate mCert1;
|
||||
private X509Certificate mCert2;
|
||||
private X509Certificate mCaCert;
|
||||
private X509Certificate mCert3;
|
||||
private X509Certificate mLinuxComFirstParentCert;
|
||||
private X509Certificate mLinuxComCert;
|
||||
|
||||
|
||||
public TrustManagerFactoryTest() throws CertificateException {
|
||||
mCert1 = loadCert(K9_EXAMPLE_COM_CERT1);
|
||||
mCert2 = loadCert(K9_EXAMPLE_COM_CERT2);
|
||||
mCaCert = loadCert(CA_CERT);
|
||||
mCert3 = loadCert(CERT3);
|
||||
mLinuxComFirstParentCert = loadCert(LINUX_COM_FIRST_PARENT_CERT);
|
||||
mLinuxComCert = loadCert(LINUX_COM_CERT);
|
||||
}
|
||||
|
||||
private X509Certificate loadCert(String encodedCert) throws CertificateException {
|
||||
CertificateFactory certFactory = CertificateFactory.getInstance("X509");
|
||||
return (X509Certificate) certFactory.generateCertificate(
|
||||
new ByteArrayInputStream(encodedCert.getBytes()));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
mKeyStoreFile = File.createTempFile("localKeyStore", null,
|
||||
InstrumentationRegistry.getTargetContext().getCacheDir());
|
||||
mKeyStore = LocalKeyStore.getInstance();
|
||||
mKeyStore.setKeyStoreFile(mKeyStoreFile);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
if (mKeyStoreFile.exists() && !mKeyStoreFile.delete()) {
|
||||
throw new RuntimeException("Unable to delete key store file: " + mKeyStoreFile.getAbsolutePath());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if TrustManagerFactory supports a host with different certificates for different
|
||||
* services (e.g. SMTP and IMAP).
|
||||
*
|
||||
* <p>
|
||||
* This test is to make sure entries in the keystore file aren't overwritten.
|
||||
* See <a href="https://code.google.com/p/k9mail/issues/detail?id=1326">Issue 1326</a>.
|
||||
* </p>
|
||||
*
|
||||
* @throws Exception
|
||||
* if anything goes wrong
|
||||
*/
|
||||
@Test
|
||||
public void testDifferentCertificatesOnSameServer() throws Exception {
|
||||
mKeyStore.addCertificate(NOT_MATCHING_HOST, PORT1, mCert1);
|
||||
mKeyStore.addCertificate(NOT_MATCHING_HOST, PORT2, mCert2);
|
||||
|
||||
X509TrustManager trustManager1 = TrustManagerFactory.get(NOT_MATCHING_HOST, PORT1);
|
||||
X509TrustManager trustManager2 = TrustManagerFactory.get(NOT_MATCHING_HOST, PORT2);
|
||||
trustManager2.checkServerTrusted(new X509Certificate[] { mCert2 }, "authType");
|
||||
trustManager1.checkServerTrusted(new X509Certificate[] { mCert1 }, "authType");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelfSignedCertificateMatchingHost() throws Exception {
|
||||
mKeyStore.addCertificate(MATCHING_HOST, PORT1, mCert1);
|
||||
X509TrustManager trustManager = TrustManagerFactory.get(MATCHING_HOST, PORT1);
|
||||
trustManager.checkServerTrusted(new X509Certificate[] { mCert1 }, "authType");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSelfSignedCertificateNotMatchingHost() throws Exception {
|
||||
mKeyStore.addCertificate(NOT_MATCHING_HOST, PORT1, mCert1);
|
||||
X509TrustManager trustManager = TrustManagerFactory.get(NOT_MATCHING_HOST, PORT1);
|
||||
trustManager.checkServerTrusted(new X509Certificate[] { mCert1 }, "authType");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWrongCertificate() throws Exception {
|
||||
mKeyStore.addCertificate(MATCHING_HOST, PORT1, mCert1);
|
||||
X509TrustManager trustManager = TrustManagerFactory.get(MATCHING_HOST, PORT1);
|
||||
assertCertificateRejection(trustManager, new X509Certificate[] { mCert2 });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCertificateOfOtherHost() throws Exception {
|
||||
mKeyStore.addCertificate(MATCHING_HOST, PORT1, mCert1);
|
||||
mKeyStore.addCertificate(MATCHING_HOST, PORT2, mCert2);
|
||||
|
||||
X509TrustManager trustManager = TrustManagerFactory.get(MATCHING_HOST, PORT1);
|
||||
assertCertificateRejection(trustManager, new X509Certificate[] { mCert2 });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUntrustedCertificateChain() throws Exception {
|
||||
X509TrustManager trustManager = TrustManagerFactory.get(MATCHING_HOST, PORT1);
|
||||
assertCertificateRejection(trustManager, new X509Certificate[] { mCert3, mCaCert });
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocallyTrustedCertificateChain() throws Exception {
|
||||
mKeyStore.addCertificate(MATCHING_HOST, PORT1, mCert3);
|
||||
|
||||
X509TrustManager trustManager = TrustManagerFactory.get(MATCHING_HOST, PORT1);
|
||||
trustManager.checkServerTrusted(new X509Certificate[] { mCert3, mCaCert }, "authType");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocallyTrustedCertificateChainNotMatchingHost() throws Exception {
|
||||
mKeyStore.addCertificate(NOT_MATCHING_HOST, PORT1, mCert3);
|
||||
|
||||
X509TrustManager trustManager = TrustManagerFactory.get(NOT_MATCHING_HOST, PORT1);
|
||||
trustManager.checkServerTrusted(new X509Certificate[] { mCert3, mCaCert }, "authType");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGloballyTrustedCertificateChain() throws Exception {
|
||||
X509TrustManager trustManager = TrustManagerFactory.get("www.linux.com", PORT1);
|
||||
X509Certificate[] certificates = new X509Certificate[] { mLinuxComCert, mLinuxComFirstParentCert};
|
||||
trustManager.checkServerTrusted(certificates, "authType");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGloballyTrustedCertificateNotMatchingHost() throws Exception {
|
||||
X509TrustManager trustManager = TrustManagerFactory.get(NOT_MATCHING_HOST, PORT1);
|
||||
assertCertificateRejection(trustManager, new X509Certificate[] { mLinuxComCert, mLinuxComFirstParentCert});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGloballyTrustedCertificateNotMatchingHostOverride() throws Exception {
|
||||
mKeyStore.addCertificate(MATCHING_HOST, PORT1, mLinuxComCert);
|
||||
|
||||
X509TrustManager trustManager = TrustManagerFactory.get(MATCHING_HOST, PORT1);
|
||||
X509Certificate[] certificates = new X509Certificate[] { mLinuxComCert, mLinuxComFirstParentCert};
|
||||
trustManager.checkServerTrusted(certificates, "authType");
|
||||
}
|
||||
|
||||
private void assertCertificateRejection(X509TrustManager trustManager,
|
||||
X509Certificate[] certificates) {
|
||||
boolean certificateValid;
|
||||
try {
|
||||
trustManager.checkServerTrusted(certificates, "authType");
|
||||
certificateValid = true;
|
||||
} catch (CertificateException e) {
|
||||
certificateValid = false;
|
||||
}
|
||||
assertFalse("The certificate should have been rejected but wasn't", certificateValid);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testKeyStoreLoading() throws Exception {
|
||||
mKeyStore.addCertificate(MATCHING_HOST, PORT1, mCert1);
|
||||
mKeyStore.addCertificate(NOT_MATCHING_HOST, PORT2, mCert2);
|
||||
assertTrue(mKeyStore.isValidCertificate(mCert1, MATCHING_HOST, PORT1));
|
||||
assertTrue(mKeyStore.isValidCertificate(mCert2, NOT_MATCHING_HOST, PORT2));
|
||||
|
||||
// reload store from same file
|
||||
mKeyStore.setKeyStoreFile(mKeyStoreFile);
|
||||
assertTrue(mKeyStore.isValidCertificate(mCert1, MATCHING_HOST, PORT1));
|
||||
assertTrue(mKeyStore.isValidCertificate(mCert2, NOT_MATCHING_HOST, PORT2));
|
||||
|
||||
// reload store from empty file
|
||||
if (mKeyStoreFile.exists() && !mKeyStoreFile.delete()) {
|
||||
throw new RuntimeException("Unable to delete key store file: " + mKeyStoreFile.getAbsolutePath());
|
||||
}
|
||||
mKeyStore.setKeyStoreFile(mKeyStoreFile);
|
||||
assertFalse(mKeyStore.isValidCertificate(mCert1, MATCHING_HOST, PORT1));
|
||||
assertFalse(mKeyStore.isValidCertificate(mCert2, NOT_MATCHING_HOST, PORT2));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue