aboutsummaryrefslogtreecommitdiff
path: root/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/utils/CertificateReader.java
diff options
context:
space:
mode:
Diffstat (limited to 'moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/utils/CertificateReader.java')
-rw-r--r--moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/utils/CertificateReader.java198
1 files changed, 99 insertions, 99 deletions
diff --git a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/utils/CertificateReader.java b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/utils/CertificateReader.java
index 763382a..eeff27c 100644
--- a/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/utils/CertificateReader.java
+++ b/moaSig/moa-sig-lib/src/main/java/at/gv/egovernment/moa/spss/tsl/utils/CertificateReader.java
@@ -1,10 +1,4 @@
package at.gv.egovernment.moa.spss.tsl.utils;
-import iaik.pkcs.PKCS7CertList;
-import iaik.pkcs.PKCSParsingException;
-import iaik.security.provider.IAIK;
-import iaik.utils.Util;
-import iaik.x509.X509Certificate;
-import iaik.xml.crypto.EccProviderAdapter;
import java.io.BufferedInputStream;
import java.io.File;
@@ -18,6 +12,13 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import iaik.pkcs.PKCS7CertList;
+import iaik.pkcs.PKCSParsingException;
+import iaik.security.provider.IAIK;
+import iaik.utils.Util;
+import iaik.x509.X509Certificate;
+import iaik.xml.crypto.EccProviderAdapter;
+
// Copyright (C) 2011 IAIK
// http://jce.iaik.at
//
@@ -49,107 +50,106 @@ import java.util.List;
public class CertificateReader {
+ /**
+ * Filter for reading certificate files from a directory. The filter accepts a
+ * file if its name ends with ".cer", ".der",
+ * ".crt" or ".pem".
+ *
+ * @author Harald Bratko
+ * @author Konrad Lanz
+ */
+ static class CertificateFileFilter implements FileFilter {
+
/**
- * Filter for reading certificate files from a directory.
- * The filter accepts a file if its name ends with
- * ".cer", ".der", ".crt"
- * or ".pem".
+ * Accepts a file if it is not a directory and its name ends with
+ * ".cer", ".der", ".crt" or ".pem".
*
- * @author Harald Bratko
- * @author Konrad Lanz
+ * @see java.io.FileFilter#accept(java.io.File)
*/
- static class CertificateFileFilter implements FileFilter {
-
- /**
- * Accepts a file if it is not a directory and its name ends with
- * ".cer", ".der", ".crt" or ".pem".
- *
- * @see java.io.FileFilter#accept(java.io.File)
- */
- public boolean accept(File file) {
- String name = file.getName();
- if (name.endsWith(".der") ||
+ @Override
+ public boolean accept(File file) {
+ final String name = file.getName();
+ if (name.endsWith(".der") ||
name.endsWith(".cer") ||
name.endsWith(".crt") ||
- name.endsWith(".pem"))
- {
- return true;
- } else {
- return false;
- }
+ name.endsWith(".pem")) {
+ return true;
+ } else {
+ return false;
}
}
-
-
-
- /**
- * Reads the certificates from the given directory and
- * returns the certificates as sorted list (end user certificate first).
- * @param directory
- * @return
- * @throws IOException
- * @throws FileNotFoundException
- * @throws CertificateException
- * @throws Exception
- */
- public static X509Certificate[] readCertificatesIntoArray(String directory) throws CertificateException, FileNotFoundException, IOException{
- File file = new File(directory);
- File[] certificateFiles = file.listFiles(new CertificateFileFilter());
- int l = certificateFiles.length;
- X509Certificate[] certs = new X509Certificate[l];
- for (int i=0; i<certificateFiles.length; i++) {
- X509Certificate certificate = new X509Certificate(new FileInputStream(certificateFiles[i]));
- certs[i] = certificate;
- }
- return Util.arrangeCertificateChain(certs, false);
+ }
+
+ /**
+ * Reads the certificates from the given directory and returns the certificates
+ * as sorted list (end user certificate first).
+ *
+ * @param directory
+ * @return
+ * @throws IOException
+ * @throws FileNotFoundException
+ * @throws CertificateException
+ * @throws Exception
+ */
+ public static X509Certificate[] readCertificatesIntoArray(String directory) throws CertificateException,
+ FileNotFoundException, IOException {
+ final File file = new File(directory);
+ final File[] certificateFiles = file.listFiles(new CertificateFileFilter());
+ final int l = certificateFiles.length;
+ final X509Certificate[] certs = new X509Certificate[l];
+ for (int i = 0; i < certificateFiles.length; i++) {
+ final X509Certificate certificate = new X509Certificate(new FileInputStream(certificateFiles[i]));
+ certs[i] = certificate;
}
-
- /**
- * Reads the certificates from the given directory and
- * returns the certificates as sorted list (end user certificate first).
- * @param directory
- * @return
- * @throws IOException
- * @throws FileNotFoundException
- * @throws CertificateException
- * @throws Exception
- */
- public static List<X509Certificate> readCertificates(String directory) throws CertificateException, FileNotFoundException, IOException{
-
- return Arrays.asList(readCertificatesIntoArray(directory));
- }
-
- public static void main(String[] args) {
- try {
-
- IAIK.addAsJDK14Provider();
- //IAIK.addAsProvider();
- //Security.addProvider(new IAIK());
-
- // install ECC provider
- Security.addProvider(EccProviderAdapter.getEccProvider());
-
- String dir = "spec/examples/EU/AT/certs/on-tsl/chain/";
- List l = readCertificates(dir);
- Iterator<X509Certificate> it = l.iterator();
- while (it.hasNext()) {
- System.out.println(((X509Certificate)it.next()).getSubjectDN().getName());
- }
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(1);
+ return Util.arrangeCertificateChain(certs, false);
+ }
+
+ /**
+ * Reads the certificates from the given directory and returns the certificates
+ * as sorted list (end user certificate first).
+ *
+ * @param directory
+ * @return
+ * @throws IOException
+ * @throws FileNotFoundException
+ * @throws CertificateException
+ * @throws Exception
+ */
+ public static List<X509Certificate> readCertificates(String directory) throws CertificateException,
+ FileNotFoundException, IOException {
+
+ return Arrays.asList(readCertificatesIntoArray(directory));
+ }
+
+ public static void main(String[] args) {
+ try {
+
+ IAIK.addAsJDK14Provider();
+ // IAIK.addAsProvider();
+ // Security.addProvider(new IAIK());
+
+ // install ECC provider
+ Security.addProvider(EccProviderAdapter.getEccProvider());
+
+ final String dir = "spec/examples/EU/AT/certs/on-tsl/chain/";
+ final List l = readCertificates(dir);
+ final Iterator<X509Certificate> it = l.iterator();
+ while (it.hasNext()) {
+ System.out.println(it.next().getSubjectDN().getName());
}
-
+ } catch (final Exception e) {
+ e.printStackTrace();
+ System.exit(1);
}
- public static X509Certificate[] p7read(File path) throws PKCSParsingException, FileNotFoundException, IOException {
- PKCS7CertList p7certList = new PKCS7CertList(
- new BufferedInputStream(
- new FileInputStream(
- path
- )
- )
- );
- return p7certList.getCertificateList();
- }
- } \ No newline at end of file
+ }
+
+ public static X509Certificate[] p7read(File path) throws PKCSParsingException, FileNotFoundException,
+ IOException {
+ final PKCS7CertList p7certList = new PKCS7CertList(
+ new BufferedInputStream(
+ new FileInputStream(
+ path)));
+ return p7certList.getCertificateList();
+ }
+} \ No newline at end of file