| 61 | import org.junit.runners.JUnit4; |
| 62 | |
| 63 | @RunWith(JUnit4.class) |
| 64 | public class AdvancedTlsTest { |
| 65 | private static final String SERVER_0_KEY_FILE = "server0.key"; |
| 66 | private static final String SERVER_0_PEM_FILE = "server0.pem"; |
| 67 | private static final String CLIENT_0_KEY_FILE = "client.key"; |
| 68 | private static final String CLIENT_0_PEM_FILE = "client.pem"; |
| 69 | private static final String CA_PEM_FILE = "ca.pem"; |
| 70 | private static final String SERVER_BAD_KEY_FILE = "badserver.key"; |
| 71 | private static final String SERVER_BAD_PEM_FILE = "badserver.pem"; |
| 72 | |
| 73 | private ScheduledExecutorService executor; |
| 74 | private Server server; |
| 75 | private ManagedChannel channel; |
| 76 | |
| 77 | private File caCertFile; |
| 78 | private File serverKey0File; |
| 79 | private File serverCert0File; |
| 80 | private File clientKey0File; |
| 81 | private File clientCert0File; |
| 82 | private X509Certificate[] caCert; |
| 83 | private PrivateKey serverKey0; |
| 84 | private X509Certificate[] serverCert0; |
| 85 | private PrivateKey clientKey0; |
| 86 | private X509Certificate[] clientCert0; |
| 87 | private PrivateKey serverKeyBad; |
| 88 | private X509Certificate[] serverCertBad; |
| 89 | |
| 90 | @Before |
| 91 | public void setUp() |
| 92 | throws Exception { |
| 93 | executor = Executors.newSingleThreadScheduledExecutor(); |
| 94 | caCertFile = TestUtils.loadCert(CA_PEM_FILE); |
| 95 | serverKey0File = TestUtils.loadCert(SERVER_0_KEY_FILE); |
| 96 | serverCert0File = TestUtils.loadCert(SERVER_0_PEM_FILE); |
| 97 | clientKey0File = TestUtils.loadCert(CLIENT_0_KEY_FILE); |
| 98 | clientCert0File = TestUtils.loadCert(CLIENT_0_PEM_FILE); |
| 99 | caCert = CertificateUtils.getX509Certificates(TlsTesting.loadCert(CA_PEM_FILE)); |
| 100 | serverKey0 = CertificateUtils.getPrivateKey(TlsTesting.loadCert(SERVER_0_KEY_FILE)); |
| 101 | serverCert0 = CertificateUtils.getX509Certificates(TlsTesting.loadCert(SERVER_0_PEM_FILE)); |
| 102 | clientKey0 = CertificateUtils.getPrivateKey(TlsTesting.loadCert(CLIENT_0_KEY_FILE)); |
| 103 | clientCert0 = CertificateUtils.getX509Certificates(TlsTesting.loadCert(CLIENT_0_PEM_FILE)); |
| 104 | serverKeyBad = CertificateUtils.getPrivateKey(TlsTesting.loadCert(SERVER_BAD_KEY_FILE)); |
| 105 | serverCertBad = CertificateUtils.getX509Certificates(TlsTesting.loadCert(SERVER_BAD_PEM_FILE)); |
| 106 | } |
| 107 | |
| 108 | @After |
| 109 | public void tearDown() { |
| 110 | if (server != null) { |
| 111 | server.shutdown(); |
| 112 | } |
| 113 | if (channel != null) { |
| 114 | channel.shutdown(); |
| 115 | } |
| 116 | MoreExecutors.shutdownAndAwaitTermination(executor, 5, TimeUnit.SECONDS); |
| 117 | } |
| 118 | |
| 119 | @Test |
| 120 | public void basicMutualTlsTest() throws Exception { |
nothing calls this directly
no outgoing calls
no test coverage detected