Skip to content

Commit

Permalink
linux support
Browse files Browse the repository at this point in the history
  • Loading branch information
monkeyWie committed Sep 10, 2018
1 parent 562b105 commit af1b9ea
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
2 changes: 1 addition & 1 deletion main/src/main/java/org/pdown/gui/DownApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ public void loadUri(String uri, boolean isTray) {
}
} else {
Platform.runLater(() -> {
show(isTray);
if (uri != null || !browser.isLoad()) {
browser.load(url);
}
show(isTray);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public static boolean isInstalledCert(File file) throws Exception {
if (!file.exists()) {
return false;
}
if (OsUtil.isUnix()) {
return true;
}
X509Certificate cert = CertUtil.loadCert(file.toURI());
String subjectName = ((X500Name) cert.getSubjectDN()).getCommonName();
String sha1 = getCertSHA1(cert);
if (OsUtil.isWindows() || OsUtil.isMac()) {
return findCertList(subjectName).toUpperCase().replaceAll("\\s", "").indexOf(":" + sha1.toUpperCase()) != -1;
}
return false;
return findCertList(subjectName).toUpperCase().replaceAll("\\s", "").indexOf(":" + sha1.toUpperCase()) != -1;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,28 @@ public FullHttpResponse checkCert(Channel channel, FullHttpRequest request) thro
public FullHttpResponse installCert(Channel channel, FullHttpRequest request) throws Exception {
Map<String, Object> data = new HashMap<>();
boolean status;
//再检测一次,确保不重复安装
if (!AppUtil.checkIsInstalledCert()) {
if (ExtensionCertUtil.existsCert(AppUtil.SUBJECT)) {
//存在无用证书需要卸载
ExtensionCertUtil.uninstallCert(AppUtil.SUBJECT);
if (OsUtil.isUnix()) {
if (!AppUtil.checkIsInstalledCert()) {
ExtensionCertUtil.buildCert(AppUtil.SSL_PATH, AppUtil.SUBJECT);
}
//生成新的证书
ExtensionCertUtil.buildCert(AppUtil.SSL_PATH, AppUtil.SUBJECT);
//安装
ExtensionCertUtil.installCert(new File(AppUtil.CERT_PATH));
//检测是否安装成功,可能点了取消就没安装成功
status = AppUtil.checkIsInstalledCert();
} else {
Desktop.getDesktop().open(new File(AppUtil.SSL_PATH));
status = true;
} else {
//再检测一次,确保不重复安装
if (!AppUtil.checkIsInstalledCert()) {
if (ExtensionCertUtil.existsCert(AppUtil.SUBJECT)) {
//存在无用证书需要卸载
ExtensionCertUtil.uninstallCert(AppUtil.SUBJECT);
}
//生成新的证书
ExtensionCertUtil.buildCert(AppUtil.SSL_PATH, AppUtil.SUBJECT);
//安装
ExtensionCertUtil.installCert(new File(AppUtil.CERT_PATH));
//检测是否安装成功,可能点了取消就没安装成功
status = AppUtil.checkIsInstalledCert();
} else {
status = true;
}
}
data.put("status", status);
if (status && !PDownProxyServer.isStart) {
Expand Down
2 changes: 1 addition & 1 deletion main/src/main/java/org/pdown/gui/util/AppUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public static void startProxyServer() throws IOException {
/**
* 下载http资源
*/
public static void download(String url,String path) throws IOException {
public static void download(String url, String path) throws IOException {
URL u = new URL(url);
HttpURLConnection connection = (HttpURLConnection) u.openConnection();
connection.setConnectTimeout(30000);
Expand Down

0 comments on commit af1b9ea

Please sign in to comment.