summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/com/isode/stroke/base/DateTime.java6
-rw-r--r--src/com/isode/stroke/tls/JavaCertificateFactory.java58
-rw-r--r--src/com/isode/stroke/tls/PlatformTLSFactories.java8
-rw-r--r--src/com/isode/stroke/tls/TLSContextFactory.java3
4 files changed, 67 insertions, 8 deletions
diff --git a/src/com/isode/stroke/base/DateTime.java b/src/com/isode/stroke/base/DateTime.java
index 8a8e31a..4c8310a 100644
--- a/src/com/isode/stroke/base/DateTime.java
+++ b/src/com/isode/stroke/base/DateTime.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014-2015, Isode Limited, London, England.
+ * Copyright (c) 2014-2016, Isode Limited, London, England.
* All rights reserved.
*/
@@ -27,6 +27,6 @@ public class DateTime {
parser.setTimeZone(TimeZone.getTimeZone("UTC"));
return parser.format(date);
}
-
- static private String format = "yyyy-MM-dd'T'HH:mm:ss'Z'";
+
+ static private String format = "yyyy-MM-dd'T'HH:mm:ssXXX";
}
diff --git a/src/com/isode/stroke/tls/JavaCertificateFactory.java b/src/com/isode/stroke/tls/JavaCertificateFactory.java
new file mode 100644
index 0000000..56a183e
--- /dev/null
+++ b/src/com/isode/stroke/tls/JavaCertificateFactory.java
@@ -0,0 +1,58 @@
+/* Copyright (c) 2016, Isode Limited, London, England.
+ * All rights reserved.
+ *
+ * Acquisition and use of this software and related materials for any
+ * purpose requires a written license agreement from Isode Limited,
+ * or a written license from an organisation licensed by Isode Limited
+ * to grant such a license.
+ *
+ */
+package com.isode.stroke.tls;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.logging.Logger;
+import java.util.logging.Level;
+
+import com.isode.stroke.base.ByteArray;
+import com.isode.stroke.tls.java.JavaCertificate;
+
+public class JavaCertificateFactory implements CertificateFactory {
+
+ private final Logger logger = Logger.getLogger(this.getClass().getName());
+
+ private final java.security.cert.CertificateFactory jvmCertFactory;
+
+ public JavaCertificateFactory() {
+ java.security.cert.CertificateFactory temp = null;
+ try {
+ temp = java.security.cert.CertificateFactory.getInstance("X.509");
+ } catch (CertificateException e) {
+ logger.log(Level.WARNING,"Unable to generate X509 certificate factory",e);
+ temp = null;
+ }
+ jvmCertFactory = temp;
+ }
+
+ @Override
+ public Certificate createCertificateFromDER(ByteArray der) {
+ if (jvmCertFactory == null) {
+ return null;
+ }
+ InputStream derInputStream = new ByteArrayInputStream(der.getData());
+ try {
+ X509Certificate x509Cert = (X509Certificate)jvmCertFactory.generateCertificate(derInputStream);
+ return new JavaCertificate(x509Cert);
+ } catch (CertificateException e) {
+ logger.log(Level.WARNING,"Unable to generate certificate from byte array "+der,e);
+ return null;
+ } catch (ClassCastException e) {
+ // Should not get here as factory should return an x509 certificate
+ logger.log(Level.WARNING,"Unable to generate X509 certificate",e);
+ return null;
+ }
+ }
+
+}
diff --git a/src/com/isode/stroke/tls/PlatformTLSFactories.java b/src/com/isode/stroke/tls/PlatformTLSFactories.java
index cbfcfe2..19bb0a3 100644
--- a/src/com/isode/stroke/tls/PlatformTLSFactories.java
+++ b/src/com/isode/stroke/tls/PlatformTLSFactories.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2012-2013 Isode Limited, London, England.
+ * Copyright (c) 2012-2016 Isode Limited, London, England.
* All rights reserved.
*/
/*
@@ -11,14 +11,14 @@ package com.isode.stroke.tls;
import com.isode.stroke.tls.java.JSSEContextFactory;
public class PlatformTLSFactories {
- private JSSEContextFactory contextFactory = new JSSEContextFactory();
+ private final JSSEContextFactory contextFactory = new JSSEContextFactory();
+ private final CertificateFactory certificateFactory = new JavaCertificateFactory();
public TLSContextFactory getTLSContextFactory() {
return contextFactory;
}
public CertificateFactory getCertificateFactory() {
- /*FIXME: Implement*/
- return null;
+ return certificateFactory;
}
}
diff --git a/src/com/isode/stroke/tls/TLSContextFactory.java b/src/com/isode/stroke/tls/TLSContextFactory.java
index f33539b..491893a 100644
--- a/src/com/isode/stroke/tls/TLSContextFactory.java
+++ b/src/com/isode/stroke/tls/TLSContextFactory.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2011, Isode Limited, London, England.
+ * Copyright (c) 2011-2016, Isode Limited, London, England.
* All rights reserved.
*/
/*
@@ -12,6 +12,7 @@ package com.isode.stroke.tls;
public interface TLSContextFactory {
boolean canCreate();
TLSContext createTLSContext(TLSOptions tlsOptions);
+ // These aren't supported in Java
//void setCheckCertificateRevocation(boolean b);
//void setDisconnectOnCardRemoval(boolean b);
}