summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku
diff options
context:
space:
mode:
authorBianca Schnalzer <bianca.schnalzer@egiz.gv.at>2017-08-07 08:13:09 +0200
committerBianca Schnalzer <bianca.schnalzer@egiz.gv.at>2017-08-07 08:13:09 +0200
commitc1d04c110f717521d0f6bed3e57fdcd39b5d0498 (patch)
tree4e37dc1fda02f8c78961527d418f262e8442a4cf /pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku
parent59fe25941355ef5cf58ea1c1436e276f604cfab7 (diff)
downloadpdf-over-c1d04c110f717521d0f6bed3e57fdcd39b5d0498.tar.gz
pdf-over-c1d04c110f717521d0f6bed3e57fdcd39b5d0498.tar.bz2
pdf-over-c1d04c110f717521d0f6bed3e57fdcd39b5d0498.zip
Certificate Download Server + Searching for Placeholder
Diffstat (limited to 'pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java43
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java1
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/SimpleXMLTrustManager.java55
3 files changed, 84 insertions, 15 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java
index 427afad5..82d6f07d 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/BKUHelper.java
@@ -15,9 +15,9 @@
*/
package at.asit.pdfover.gui.bku;
-// Imports
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.UsernamePasswordCredentials;
+// Imports
import org.apache.commons.httpclient.auth.AuthScope;
import org.apache.http.client.config.CookieSpecs;
import org.slf4j.Logger;
@@ -35,6 +35,30 @@ public class BKUHelper {
@SuppressWarnings("unused")
private static final Logger log = LoggerFactory.getLogger(BKUHelper.class);
+ /* public static HttpClient getHttpClient(boolean useProxy) {
+ HttpClient client = new HttpClient();
+ client.getParams().setParameter("http.useragent", //$NON-NLS-1$
+ Constants.USER_AGENT_STRING);
+
+ if (useProxy) {
+ String host = System.getProperty("http.proxyHost"); //$NON-NLS-1$
+ String port = System.getProperty("http.proxyPort"); //$NON-NLS-1$
+ if (host != null && !host.isEmpty() &&
+ port != null && !port.isEmpty()) {
+ int p = Integer.parseInt(port);
+ client.getHostConfiguration().setProxy(host, p);
+ String user = System.getProperty("http.proxyUser"); //$NON-NLS-1$
+ String pass = System.getProperty("http.proxyPassword"); //$NON-NLS-1$
+ if (user != null && !user.isEmpty() && pass != null) {
+ client.getState().setProxyCredentials(new AuthScope(host, p),
+ new UsernamePasswordCredentials(user, pass));
+ }
+ }
+ }
+
+ return client;
+ }*/
+
/**
* Get a HTTP Client instance
*
@@ -42,25 +66,23 @@ public class BKUHelper {
* whether to use a potentially set proxy
* @return the HttpClient
*/
+ @SuppressWarnings("deprecation")
public static HttpClient getHttpClient(boolean useProxy) {
HttpClient client = new HttpClient();
client.getParams().setParameter("http.useragent", //$NON-NLS-1$
Constants.USER_AGENT_STRING);
- client.getParams().setParameter("http.protocol.cookie-policy", CookieSpecs.BROWSER_COMPATIBILITY);
+
+ client.getParams().setParameter("http.protocol.cookie-policy", CookieSpecs.BROWSER_COMPATIBILITY); //$NON-NLS-1$
if (useProxy) {
- String host = System.getProperty("http.proxyHost");
- // $NON-NLS-1$
- String port = System.getProperty("http.proxyPort");
- // $NON-NLS-1$
+ String host = System.getProperty("http.proxyHost");//$NON-NLS-1$
+ String port = System.getProperty("http.proxyPort");//$NON-NLS-1$
if (host != null && !host.isEmpty() && port != null && !port.isEmpty()) {
int p = Integer.parseInt(port);
client.getHostConfiguration().setProxy(host, p);
- String user = System.getProperty("http.proxyUser");
- // $NON-NLS-1$
- String pass = System.getProperty("http.proxyPassword");
- // $NON-NLS-1$
+ String user = System.getProperty("http.proxyUser");//$NON-NLS-1$
+ String pass = System.getProperty("http.proxyPassword");//$NON-NLS-1$
if (user != null && !user.isEmpty() && pass != null) {
client.getState().setProxyCredentials(new AuthScope(host, p),
new UsernamePasswordCredentials(user, pass));
@@ -69,6 +91,7 @@ public class BKUHelper {
}
return client;
+
}
/**
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java
index eb1b57d6..1c88499a 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/LocalBKUConnector.java
@@ -18,6 +18,7 @@ package at.asit.pdfover.gui.bku;
// Imports
import java.io.IOException;
+
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethod;
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/SimpleXMLTrustManager.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/SimpleXMLTrustManager.java
index bceb59fb..ec4b674b 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/SimpleXMLTrustManager.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/bku/mobile/SimpleXMLTrustManager.java
@@ -15,12 +15,15 @@
*/
package at.asit.pdfover.gui.bku.mobile;
+import java.io.File;
+import java.io.FileInputStream;
// Imports
import java.security.KeyStore;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Arrays;
+import java.util.List;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
@@ -82,7 +85,7 @@ public class SimpleXMLTrustManager implements X509TrustManager {
}
/*
- * A-Trust Certificates
+ *Certificates
*/
KeyStore myKeyStore = KeyStore.getInstance(KeyStore
@@ -93,16 +96,25 @@ public class SimpleXMLTrustManager implements X509TrustManager {
Document doc = DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.parse(this.getClass().getResourceAsStream(Constants.RES_CERT_LIST));
-
+
+
+ File added_cert = new File(Constants.RES_CERT_LIST_ADDED);
+
+ Document doc_added = DocumentBuilderFactory.newInstance()
+ .newDocumentBuilder()
+ .parse(added_cert);
+
+ Node certificates_added = doc_added.getFirstChild();
Node certificates = doc.getFirstChild();
- if (!certificates.getNodeName().equals("certificates")) { //$NON-NLS-1$
+ if (!certificates.getNodeName().equals("certificates") && !certificates_added.getNodeName().equals("certificates")) { //$NON-NLS-1$
throw new Exception(
"Used certificates xml is invalid! no certificates node"); //$NON-NLS-1$
}
+ NodeList certificates_added_list = certificates_added.getChildNodes();
NodeList certificateList = certificates.getChildNodes();
-
+
for (int i = 0; i < certificateList.getLength(); i++) {
try {
@@ -117,7 +129,7 @@ public class SimpleXMLTrustManager implements X509TrustManager {
continue;
}
- String certResource = Constants.RES_CERT_PATH + certificateNode.getTextContent();
+ String certResource = Constants.RES_CERT_PATH_ADDED + certificateNode.getTextContent();
X509Certificate cert = (X509Certificate) CertificateFactory
.getInstance("X509"). //$NON-NLS-1$
@@ -133,6 +145,39 @@ public class SimpleXMLTrustManager implements X509TrustManager {
log.error("Failed to load certificate [" + "]", ex); //$NON-NLS-1$ //$NON-NLS-2$
}
}
+
+ for (int i = 0; i < certificates_added_list.getLength(); i++) {
+ try {
+
+ Node certificateNode = certificates_added_list.item(i);
+
+ if (certificateNode.getNodeName().equals("#text")) { //$NON-NLS-1$
+ continue; // Ignore dummy text node ..
+ }
+
+ if (!certificateNode.getNodeName().equals("certificate")) { //$NON-NLS-1$
+ log.warn("Ignoring XML node: " + certificateNode.getNodeName()); //$NON-NLS-1$
+ continue;
+ }
+
+ String certResource = Constants.RES_CERT_PATH_ADDED + certificateNode.getTextContent();
+
+ FileInputStream addedNode = new FileInputStream(certResource);
+
+ X509Certificate cert = (X509Certificate) CertificateFactory
+ .getInstance("X509"). //$NON-NLS-1$
+ generateCertificate(
+ addedNode);
+
+ myKeyStore.setCertificateEntry(certificateNode.getTextContent(), cert);
+
+ log.debug("Loaded certificate : " + certResource); //$NON-NLS-1$
+
+ } catch (Exception ex) {
+ log.error("Failed to load certificate [" + "]", ex); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
tmf.init(myKeyStore);