diff options
author | emusic <emina.music@egiz.gv.at> | 2018-11-22 13:14:28 +0100 |
---|---|---|
committer | emusic <emina.music@egiz.gv.at> | 2018-11-22 13:14:28 +0100 |
commit | f76f559c8c1437a152a4f51b441e4cebe25430f1 (patch) | |
tree | 8930f89863cdc7e564f6a97ac777c133384a8730 /pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/X509Utils.java | |
parent | cd6ff625d48a63e024b05ed1a253be3551e41599 (diff) | |
parent | c87c82009fb07e285d6c9acfd4686efc2cbf21c9 (diff) | |
download | pdf-as-4-f76f559c8c1437a152a4f51b441e4cebe25430f1.tar.gz pdf-as-4-f76f559c8c1437a152a4f51b441e4cebe25430f1.tar.bz2 pdf-as-4-f76f559c8c1437a152a4f51b441e4cebe25430f1.zip |
Merge branch 'SL20_development'
# Conflicts:
# build.gradle
# pdf-as-cli/src/main/java/at/gv/egiz/pdfas/cli/Main.java
# pdf-as-lib/src/configuration/cfg/advancedconfig.properties
# pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/api/IConfigurationConstants.java
# pdf-as-lib/src/main/resources/config/config.zip
# pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/config/WebConfiguration.java
# pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/servlets/PDFData.java
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/X509Utils.java')
-rw-r--r-- | pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/X509Utils.java | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/X509Utils.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/X509Utils.java new file mode 100644 index 00000000..391b8271 --- /dev/null +++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/sl20/X509Utils.java @@ -0,0 +1,62 @@ +package at.gv.egiz.pdfas.web.sl20; + +import java.security.cert.X509Certificate; +import java.util.List; + +import javax.security.auth.x500.X500Principal; + +public class X509Utils { + + /** + * Sorts the Certificate Chain by IssuerDN and SubjectDN. The [0]-Element should be the Hostname, + * the last Element should be the Root Certificate. + * + * @param certs + * The first element must be the correct one. + * @return sorted Certificate Chain + */ + public static List<X509Certificate> sortCertificates( + List<X509Certificate> certs) + { + int length = certs.size(); + if (certs.size() <= 1) + { + return certs; + } + + for (X509Certificate cert : certs) + { + if (cert == null) + { + throw new NullPointerException(); + } + } + + for (int i = 0; i < length; i++) + { + boolean found = false; + X500Principal issuer = certs.get(i).getIssuerX500Principal(); + for (int j = i + 1; j < length; j++) + { + X500Principal subject = certs.get(j).getSubjectX500Principal(); + if (issuer.equals(subject)) + { + // sorting necessary? + if (i + 1 != j) + { + X509Certificate tmp = certs.get(i + 1); + certs.set(i + 1, certs.get(j)); + certs.set(j, tmp); + } + found = true; + } + } + if (!found) + { + break; + } + } + + return certs; + } +} |