From 376760c24f7e7e46a189e557618321f5e05e8f4c Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Thu, 24 Mar 2022 01:47:04 +0100 Subject: [PATCH 1/3] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f719dbf8742..a62785db499 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,6 @@ For IntelliJ IDEA, just import the project via a Gradle Import by pointing at th ## Sponsoring -JabRef development is powered by YourKit Java Profiler [![YourKit Java Profiler](https://www.yourkit.com/images/yk_logo.png)](https://www.yourkit.com/java/profiler/) +JabRef development is by YourKit Java Profiler [![YourKit Java Profiler](https://www.yourkit.com/images/yk_logo.png)](https://www.yourkit.com/java/profiler/) [JabRef]: https://www.jabref.org From 099f9a945f103ee9afad4aabe0cc0a4c9bc293e7 Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Thu, 31 Mar 2022 23:56:21 +0100 Subject: [PATCH 2/3] Ensure truststore file is present at startup. --- src/main/java/org/jabref/gui/JabRefMain.java | 2 ++ .../logic/net/ssl/TrustStoreManager.java | 35 ++++++++++++------- 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/jabref/gui/JabRefMain.java b/src/main/java/org/jabref/gui/JabRefMain.java index ce9ea5b4546..665f38d18b4 100644 --- a/src/main/java/org/jabref/gui/JabRefMain.java +++ b/src/main/java/org/jabref/gui/JabRefMain.java @@ -22,6 +22,7 @@ import org.jabref.logic.net.ProxyPreferences; import org.jabref.logic.net.ProxyRegisterer; import org.jabref.logic.net.ssl.SSLPreferences; +import org.jabref.logic.net.ssl.TrustStoreManager; import org.jabref.logic.protectedterms.ProtectedTermsLoader; import org.jabref.logic.remote.RemotePreferences; import org.jabref.logic.remote.client.RemoteClient; @@ -151,6 +152,7 @@ private static void configureProxy(ProxyPreferences proxyPreferences) { } private static void configureSSL(SSLPreferences sslPreferences) { + TrustStoreManager.createTruststoreFileIfNotExist(Path.of(sslPreferences.getTruststorePath())); System.setProperty("javax.net.ssl.trustStore", sslPreferences.getTruststorePath()); System.setProperty("javax.net.ssl.trustStorePassword", "changeit"); } diff --git a/src/main/java/org/jabref/logic/net/ssl/TrustStoreManager.java b/src/main/java/org/jabref/logic/net/ssl/TrustStoreManager.java index 9aa5c8a881e..01e71b2d30e 100644 --- a/src/main/java/org/jabref/logic/net/ssl/TrustStoreManager.java +++ b/src/main/java/org/jabref/logic/net/ssl/TrustStoreManager.java @@ -31,19 +31,7 @@ public class TrustStoreManager { public TrustStoreManager(Path storePath) { this.storePath = storePath; - try { - LOGGER.info("Trust store path: {}", storePath.toAbsolutePath()); - Path storeResourcePath = Path.of(TrustStoreManager.class.getResource("/ssl/truststore.jks").toURI()); - Files.createDirectories(storePath.getParent()); - if (Files.notExists(storePath)) { - Files.copy(storeResourcePath, storePath); - } - } catch (IOException e) { - LOGGER.warn("Bad truststore path", e); - } catch (URISyntaxException e) { - LOGGER.warn("Bad resource path", e); - } - + createTruststoreFileIfNotExist(storePath); try { store = KeyStore.getInstance(KeyStore.getDefaultType()); store.load(new FileInputStream(storePath.toFile()), STORE_PASSWORD.toCharArray()); @@ -141,4 +129,25 @@ public X509Certificate getCertificate(String alias) { } return null; } + + /** + * This method checks to see if the truststore is present in {@code storePath}, + * and if it isn't, it copies the default JDK truststore to the specified location. + * + * @param storePath path of the truststore + */ + public static void createTruststoreFileIfNotExist(Path storePath) { + try { + LOGGER.info("Trust store path: {}", storePath.toAbsolutePath()); + Path storeResourcePath = Path.of(TrustStoreManager.class.getResource("/ssl/truststore.jks").toURI()); + Files.createDirectories(storePath.getParent()); + if (Files.notExists(storePath)) { + Files.copy(storeResourcePath, storePath); + } + } catch (IOException e) { + LOGGER.warn("Bad truststore path", e); + } catch (URISyntaxException e) { + LOGGER.warn("Bad resource path", e); + } + } } From c3b1d1882db195e8d7f110c729ef8abb87173577 Mon Sep 17 00:00:00 2001 From: Houssem Nasri Date: Thu, 31 Mar 2022 23:58:05 +0100 Subject: [PATCH 3/3] Cleanup --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a62785db499..f719dbf8742 100644 --- a/README.md +++ b/README.md @@ -98,6 +98,6 @@ For IntelliJ IDEA, just import the project via a Gradle Import by pointing at th ## Sponsoring -JabRef development is by YourKit Java Profiler [![YourKit Java Profiler](https://www.yourkit.com/images/yk_logo.png)](https://www.yourkit.com/java/profiler/) +JabRef development is powered by YourKit Java Profiler [![YourKit Java Profiler](https://www.yourkit.com/images/yk_logo.png)](https://www.yourkit.com/java/profiler/) [JabRef]: https://www.jabref.org