moved certs inside of project

This commit is contained in:
2024-01-27 23:59:03 +03:00
parent ed45c1eeae
commit b22d4a7f6f
3 changed files with 14 additions and 19 deletions

View File

@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import redis.clients.jedis.*;
import javax.net.ssl.*;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -53,7 +54,7 @@ public class SteamPriceParser
System.out.println("Current id = " + i);
System.out.println(json.toPrettyString());
System.out.println("jedis value for " + i + "\n" + jedis.get(String.valueOf(i)));
System.out.println("jedis value for " + i + "\n" + jedis.get(String.valueOf(i)));
}
}
@ -87,37 +88,31 @@ public class SteamPriceParser
public static DefaultJedisClientConfig prepareRedisConfig() throws GeneralSecurityException, IOException
{
SSLSocketFactory sslFactory = createSslSocketFactory(
"C:\\truststore.jks",
CA_CERT_PASS, // use the password specified for keytool command
"C:\\redis-keystore.p12",
USER_CERT_PASS // use the password specified for openssl command
);
//Hack for building absolute path for user certificate
String keystorePath = new File("src/main/resources/redis-keystore.p12").getAbsolutePath();
return DefaultJedisClientConfig.builder()
.ssl(true)
.sslSocketFactory(sslFactory)
.user("default")
.password(REDIS_PASS)
.build();
//Hack for building absolute path for CA certificate
String truststorePath = new File("src/main/resources/truststore.jks").getAbsolutePath();
SSLSocketFactory sslFactory = createSslSocketFactory(truststorePath, keystorePath);
return DefaultJedisClientConfig.builder().ssl(true).sslSocketFactory(sslFactory).user("default").password(REDIS_PASS).build();
}
private static SSLSocketFactory createSslSocketFactory(
String caCertPath, String caCertPassword, String userCertPath, String userCertPassword)
throws IOException, GeneralSecurityException
private static SSLSocketFactory createSslSocketFactory(String caCertPath, String userCertPath) throws IOException, GeneralSecurityException
{
KeyStore keyStore = KeyStore.getInstance("pkcs12");
keyStore.load(Files.newInputStream(Paths.get(userCertPath)), userCertPassword.toCharArray());
keyStore.load(Files.newInputStream(Paths.get(userCertPath)), USER_CERT_PASS.toCharArray());
KeyStore trustStore = KeyStore.getInstance("jks");
trustStore.load(Files.newInputStream(Paths.get(caCertPath)), caCertPassword.toCharArray());
trustStore.load(Files.newInputStream(Paths.get(caCertPath)), CA_CERT_PASS.toCharArray());
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("X509");
trustManagerFactory.init(trustStore);
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance("PKIX");
keyManagerFactory.init(keyStore, userCertPassword.toCharArray());
keyManagerFactory.init(keyStore, USER_CERT_PASS.toCharArray());
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null);

Binary file not shown.

Binary file not shown.