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

Binary file not shown.

Binary file not shown.