1 /* 2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"). 5 * You may not use this file except in compliance with the License. 6 * A copy of the License is located at 7 * 8 * http://aws.amazon.com/apache2.0 9 * 10 * or in the "license" file accompanying this file. This file is distributed 11 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 * express or implied. See the License for the specific language governing 13 * permissions and limitations under the License. 14 */ 15 16 package software.amazon.awssdk.http; 17 18 import java.io.IOException; 19 import java.io.InputStream; 20 import java.nio.file.Files; 21 import java.nio.file.Path; 22 import org.junit.jupiter.api.AfterAll; 23 import org.junit.jupiter.api.BeforeAll; 24 25 abstract class ClientTlsAuthTestBase { 26 protected static final String STORE_PASSWORD = "password"; 27 protected static final String CLIENT_STORE_TYPE = "pkcs12"; 28 protected static final String TEST_KEY_STORE = "/software/amazon/awssdk/http/server-keystore"; 29 protected static final String CLIENT_KEY_STORE = "/software/amazon/awssdk/http/client1.p12"; 30 31 protected static Path tempDir; 32 protected static Path serverKeyStore; 33 protected static Path clientKeyStore; 34 35 @BeforeAll setUp()36 public static void setUp() throws IOException { 37 tempDir = Files.createTempDirectory(ClientTlsAuthTestBase.class.getSimpleName()); 38 copyCertsToTmpDir(); 39 } 40 41 @AfterAll teardown()42 public static void teardown() throws IOException { 43 Files.deleteIfExists(serverKeyStore); 44 Files.deleteIfExists(clientKeyStore); 45 Files.deleteIfExists(tempDir); 46 } 47 copyCertsToTmpDir()48 private static void copyCertsToTmpDir() throws IOException { 49 InputStream sksStream = ClientTlsAuthTestBase.class.getResourceAsStream(TEST_KEY_STORE); 50 Path sks = copyToTmpDir(sksStream, "server-keystore"); 51 52 InputStream cksStream = ClientTlsAuthTestBase.class.getResourceAsStream(CLIENT_KEY_STORE); 53 Path cks = copyToTmpDir(cksStream, "client1.p12"); 54 55 serverKeyStore = sks; 56 clientKeyStore = cks; 57 } 58 copyToTmpDir(InputStream srcStream, String name)59 private static Path copyToTmpDir(InputStream srcStream, String name) throws IOException { 60 Path dst = tempDir.resolve(name); 61 Files.copy(srcStream, dst); 62 return dst; 63 } 64 } 65