diff options
author | Alex Clayton <alex.clayton@isode.com> | 2016-02-26 11:19:56 (GMT) |
---|---|---|
committer | Alex Clayton <alex.clayton@isode.com> | 2016-03-07 10:58:38 (GMT) |
commit | 8fe752626726ca8d058ce437127a37d5d738a5eb (patch) | |
tree | e5e6ed4552cdac9c25101bd4f42f6b1a65a31cfb /src/com/isode/stroke/tls/JavaCertificateFactory.java | |
parent | 16fb1d46d48b46627272275ec46b19f68375e778 (diff) | |
download | stroke-8fe752626726ca8d058ce437127a37d5d738a5eb.zip stroke-8fe752626726ca8d058ce437127a37d5d738a5eb.tar.bz2 |
Add missing TLS and Base classes
Add missing methods and classes in the TLS and Base packages where
possible. In the case of TLSContextFactory the methods could not be
implemented in java so added a not saying they are not supported in
java.
Test-information:
Unit tests still build and run ok.
Change-Id: I9be2035f092875fcdc02644a3c0082739f26949a
Diffstat (limited to 'src/com/isode/stroke/tls/JavaCertificateFactory.java')
-rw-r--r-- | src/com/isode/stroke/tls/JavaCertificateFactory.java | 58 |
1 files changed, 58 insertions, 0 deletions
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; + } + } + +} |