Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trusted certificate to allow downloads from motherless (fixes issue #2009) #2012

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/main/java/com/rarchives/ripme/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ public static void main(String[] args) throws MalformedURLException {
Proxy.setSocks(Utils.getConfigString("proxy.socks", null));
}

// Attempt to load keystore to enable use of custom certificate authorities
try
{
Utils.setTrustStore ("/custom-certificate-store");
}
catch (Exception e)
{
logger.warn ("Failed to load custom certificate store", e);
}

// This has to be here instead of handleArgs because handleArgs isn't parsed until after a item is ripper
if (cl.hasOption("a")) {
logger.info(cl.getOptionValue("a"));
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/com/rarchives/ripme/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.KeyStore;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand All @@ -34,6 +35,9 @@
import java.util.regex.Pattern;
import java.util.stream.Stream;

import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.Line;
Expand Down Expand Up @@ -886,4 +890,18 @@ public static File shortenSaveAsWindows(String ripsDirPath, String fileName) thr
return new File(fullPath);
}

public static void setTrustStore(String trustStore) throws Exception {
LOGGER.info ("Loading trust store " + trustStore);
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance("X509");
KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream keystoreStream = Utils.class.getResourceAsStream(trustStore);
if (keystoreStream == null) throw new IllegalArgumentException ("trustStore " + trustStore + " not found");
keystore.load(keystoreStream, null);
trustManagerFactory.init(keystore);
TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustManagers, null);
SSLContext.setDefault(sc);
}

}
Binary file added src/main/resources/custom-certificate-store
Binary file not shown.