public class SSLFTPCertificateStore
extends java.lang.Object
implements java.util.List
SSLFTPCertificates.
The primary purchase of SSLFTPCertificateStore is to maintain
a collection of root certificates for SSLFTPClient.
SSLFTPClient has an instance of SSLFTPCertificateStore
(accessible via SSLFTPClient.getRootCertificateStore())
which contains the root certificates that will be used to validate the
certificate that a server presents during connection establishment.
SSLFTPCertificateStore implements the List
interface and thus provides broad flexibility for managing individual
certificates in the collection.
It also provides methods for importing from and exporting to Java KeyStores (JKS)
and PEM files.
Java certificates (i.e. Certificate) may be added to
a SSLFTPCertificateStore by wrapping it in an
SSLFTPCertificate as follows:
certStore.add(new SSLFTPCertificate(myJavaCert));
where certStore is an instance of SSLFTPCertificateStore
and myJavaCert is an instance of Certificate.| Constructor and Description |
|---|
SSLFTPCertificateStore()
Creates a empty certificate store.
|
| Modifier and Type | Method and Description |
|---|---|
void |
add(int index,
java.lang.Object certificate)
Adds the given certificate
SSLFTPCertificate to the store
at the given position. |
boolean |
add(java.lang.Object certificate)
Adds the given certificate
SSLFTPCertificate to the store. |
boolean |
addAll(java.util.Collection certificates)
Add all the
SSLFTPCertificates in the given collection to the
store. |
boolean |
addAll(int index,
java.util.Collection certificates)
Add all the
SSLFTPCertificates in the given collection to the
store at the given position. |
void |
clear()
Removes all certificates from the collection.
|
boolean |
contains(java.lang.Object certificate)
Returns
true if the given certificate is present in
the collection. |
boolean |
containsAll(java.util.Collection certificates)
Returns
true if all of the given certificates are present in
the collection. |
void |
exportKeyStore(java.security.KeyStore keyStore)
Exports all certificates in the store to the given Java KeyStore.
|
void |
exportPEMFile(java.io.OutputStream outputStream)
Writes all the certificates in the store to the output-stream.
|
void |
exportPEMFile(java.lang.String fileName)
Writes all the certificates in the store to the given file.
|
java.lang.Object |
get(int index)
Returns the requested certificate in the store as an
Object reference. |
SSLFTPCertificate |
getCertificate(int index)
Returns the requested certificate in the store as an
SSLFTPCertificate reference. |
void |
importCertificates(java.lang.String fileName)
Import certificates from PEM file (see
importPEMFile(String))
or from Java key store (see importPEMFile(String)). |
void |
importDefaultKeyStore()
Imports all certificates in the default key-store for the platform on which
the software is running.
|
void |
importKeyStore(java.security.KeyStore keyStore)
Imports all the certificates from the given Java KeyStore into this certificate store.
|
void |
importKeyStore(java.lang.String keystoreFile)
Imports all the certificates from the given Java KeyStore file into this certificate store.
|
void |
importKeyStore(java.lang.String keystoreFile,
java.lang.String password)
Imports all the certificates from the given Java KeyStore file into this certificate store.
|
void |
importPEMFile(java.io.InputStream inputStream)
Imports all the certificates in the given input-stream, into the store.
|
void |
importPEMFile(java.lang.String fileName)
Imports all the certificates in the given file into the store.
|
int |
indexOf(java.lang.Object certificate)
Returns the index of the given certificate or -1 if it's not in the store.
|
boolean |
isEmpty()
Returns
true if the store is empty. |
java.util.Iterator |
iterator()
Returns an
Iterator that may be used to iterate
through all the certificates in the store. |
int |
lastIndexOf(java.lang.Object certificate)
Returns the index of the given certificate or -1 if it's not in the store.
|
java.util.ListIterator |
listIterator()
Returns an
ListIterator that may be used to iterate
through all the certificates in the store. |
java.util.ListIterator |
listIterator(int index)
Returns an
ListIterator that may be used to iterate
through all the certificates in the store that come after the
given index. |
java.lang.Object |
remove(int index)
Removes the certificate at the given index.
|
boolean |
remove(java.lang.Object certificate)
Removes the given certificate from the collection.
|
boolean |
removeAll(java.util.Collection certificates)
Removes from this Vector all of its elements that are contained in the specified Collection.
|
SSLFTPCertificate |
removeCertificate(int index)
Removes the certificate at the given index.
|
boolean |
retainAll(java.util.Collection certificates)
Retains only the elements in this Vector that are contained in the specified Collection.
|
java.lang.Object |
set(int index,
java.lang.Object certificate)
Places the given certificate at the given position in the store, replacing
any existing certifcate at the position.
|
int |
size()
Returns the number of components in this vector.
|
java.util.List |
subList(int fromIndex,
int toIndex)
Returns a view of the portion of this List between fromIndex, inclusive,
and toIndex, exclusive.
|
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this Vector in the correct order.
|
java.lang.Object[] |
toArray(java.lang.Object[] certificates)
Returns an array containing all of the elements in this Vector in
the correct order.
|
SSLFTPCertificate[] |
toCertificateArray()
Returns an
SSLFTPCertificate array containing all of
the elements in this Vector in the correct order. |
public SSLFTPCertificateStore()
public void importCertificates(java.lang.String fileName)
throws java.io.FileNotFoundException,
java.io.IOException
importPEMFile(String))
or from Java key store (see importPEMFile(String)).fileName - path to certificate file or key storejava.io.FileNotFoundExceptionjava.io.IOExceptionpublic void importPEMFile(java.lang.String fileName)
throws java.io.FileNotFoundException,
java.io.IOException,
SSLFTPCertificateException
-----BEGIN CERTIFICATE----- ... first certificate ... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- ... second certificate ... -----END CERTIFICATE----- etc
fileName - Name of the file to import.java.io.FileNotFoundException - Thrown if the file could not be found.java.io.IOException - Thrown if there was an error while reading the file.SSLFTPException - Thrown if a certificate could not be read.SSLFTPCertificateExceptionpublic void importPEMFile(java.io.InputStream inputStream)
throws java.io.IOException,
SSLFTPCertificateException
-----BEGIN CERTIFICATE----- ... first certificate ... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- ... second certificate ... -----END CERTIFICATE----- etc
inputStream - InputStream to read.java.io.FileNotFoundException - Thrown if the file could not be found.java.io.IOException - Thrown if there was an error while reading the file.SSLFTPException - Thrown if a certificate could not be read.SSLFTPCertificateExceptionpublic void exportPEMFile(java.lang.String fileName)
throws java.io.IOException
-----BEGIN CERTIFICATE----- ... first certificate ... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- ... second certificate ... -----END CERTIFICATE----- etc
fileName - Name of the file to write to.java.io.IOException - Thrown if the file could not be created.public void exportPEMFile(java.io.OutputStream outputStream)
throws java.io.IOException
-----BEGIN CERTIFICATE----- ... first certificate ... -----END CERTIFICATE----- -----BEGIN CERTIFICATE----- ... second certificate ... -----END CERTIFICATE----- etc
outputStream - Output-stream to write to.java.io.IOException - Thrown if there was an error writing to the stream.public void importKeyStore(java.security.KeyStore keyStore)
throws java.security.KeyStoreException,
SSLFTPCertificateException
keyStore - KeyStore to import from.java.security.KeyStoreException - Thrown if there was a problem accessing the keystore.SSLFTPCertificateException - Thrown if there was an error while inserting a certificate
into the certificate store.public void importKeyStore(java.lang.String keystoreFile,
java.lang.String password)
throws java.security.KeyStoreException,
java.io.IOException,
SSLFTPCertificateException
keystoreFile - name of the file containing the KeyStore to importpassword - keystore passwordjava.security.KeyStoreException - Thrown if there was a problem accessing the keystore.SSLFTPException - Thrown if there was an error while inserting a certificate
into the certificate store.java.io.IOException - Thrown if there was a problem while accessing the file.SSLFTPCertificateExceptionpublic void importKeyStore(java.lang.String keystoreFile)
throws java.security.KeyStoreException,
java.io.IOException,
SSLFTPCertificateException
keystoreFile - name of the file containing the KeyStore to import.java.security.KeyStoreException - Thrown if there was a problem accessing the keystore.SSLFTPException - Thrown if there was an error while inserting a certificate
into the certificate store.java.io.IOException - Thrown if there was a problem while accessing the file.SSLFTPCertificateExceptionpublic void exportKeyStore(java.security.KeyStore keyStore)
throws java.security.cert.CertificateException,
java.security.KeyStoreException
null or the Organisation Name if the CN is null.
Note that Java KeyStores impose some restrictions on the type of
certificate that may be added. It can be useful to experiment with
importing certificates using the JDK's keytool utility (-import option).keyStore - Keystore to export certificates to.java.security.cert.CertificateException - Thrown if there was a problem with the
certificate being extracted from the certificate store.java.security.KeyStoreException - Thrown if there was an error while adding
the certificate to the keystore.public void importDefaultKeyStore()
throws java.security.KeyStoreException,
java.io.IOException,
SSLFTPException
{java.home}/lib/security/jssecacerts> and then
{java.home}/lib/security/cacerts.java.security.KeyStoreException - Thrown if there was a problem accessing the keystore.SSLFTPException - Thrown if there was an error while inserting a certificate
into the certificate store.java.io.IOException - Thrown if there was a problem while accessing the file.public void add(int index,
java.lang.Object certificate)
SSLFTPCertificate to the store
at the given position.add in interface java.util.Listindex - Position to add the certificate at.certificate - SSLFTPCertificate to add.java.lang.ArrayStoreException - Thrown if an object other than SSLFTPCertificate
is added.public boolean add(java.lang.Object certificate)
SSLFTPCertificate to the store.add in interface java.util.Collectionadd in interface java.util.Listcertificate - SSLFTPCertificate to add.java.lang.ArrayStoreException - Thrown if an object other than SSLFTPCertificate
is added.public boolean addAll(java.util.Collection certificates)
SSLFTPCertificates in the given collection to the
store.addAll in interface java.util.CollectionaddAll in interface java.util.Listcertificates - SSLFTPCertificates to add.java.lang.ArrayStoreException - Thrown if an object other than SSLFTPCertificate
is added.public boolean addAll(int index,
java.util.Collection certificates)
SSLFTPCertificates in the given collection to the
store at the given position.addAll in interface java.util.Listindex - Position at which to add the certificates.certificates - SSLFTPCertificates to add.java.lang.ArrayStoreException - Thrown if an object other than SSLFTPCertificate
is added.public void clear()
clear in interface java.util.Collectionclear in interface java.util.Listpublic boolean contains(java.lang.Object certificate)
true if the given certificate is present in
the collection.contains in interface java.util.Collectioncontains in interface java.util.Listpublic boolean containsAll(java.util.Collection certificates)
true if all of the given certificates are present in
the collection.containsAll in interface java.util.CollectioncontainsAll in interface java.util.Listpublic java.lang.Object get(int index)
Object reference.get in interface java.util.Listindex - Position of certificate to return.public SSLFTPCertificate getCertificate(int index)
SSLFTPCertificate reference.index - Position of certificate to return.public int indexOf(java.lang.Object certificate)
indexOf in interface java.util.Listpublic int lastIndexOf(java.lang.Object certificate)
lastIndexOf in interface java.util.Listpublic boolean isEmpty()
true if the store is empty.isEmpty in interface java.util.CollectionisEmpty in interface java.util.Listpublic java.util.Iterator iterator()
Iterator that may be used to iterate
through all the certificates in the store.iterator in interface java.lang.Iterableiterator in interface java.util.Collectioniterator in interface java.util.Listpublic java.util.ListIterator listIterator()
ListIterator that may be used to iterate
through all the certificates in the store.listIterator in interface java.util.Listpublic java.util.ListIterator listIterator(int index)
ListIterator that may be used to iterate
through all the certificates in the store that come after the
given index.listIterator in interface java.util.Listindex - Index of first certificate to return.public java.lang.Object remove(int index)
remove in interface java.util.Listindex - Index of certificate to remove.public SSLFTPCertificate removeCertificate(int index)
index - Index of certificate to remove.public boolean remove(java.lang.Object certificate)
remove in interface java.util.Collectionremove in interface java.util.Listcertificate - reference of certificate to remove.true if the certificate was removed and false
otherwise.public boolean removeAll(java.util.Collection certificates)
removeAll in interface java.util.CollectionremoveAll in interface java.util.Listpublic boolean retainAll(java.util.Collection certificates)
retainAll in interface java.util.CollectionretainAll in interface java.util.Listcertificates - Certificates to retain.true if this Vector changed as a result of the call.public java.lang.Object set(int index,
java.lang.Object certificate)
set in interface java.util.Listindex - Position to place the certificate at.certificate - Certificate to place.java.lang.ArrayStoreException - Thrown if an object other than SSLFTPCertificate
is set.public int size()
size in interface java.util.Collectionsize in interface java.util.Listpublic java.util.List subList(int fromIndex,
int toIndex)
subList in interface java.util.ListfromIndex - low endpoint (inclusive) of the subList.toIndex - high endpoint (exclusive) of the subList.public java.lang.Object[] toArray()
toArray in interface java.util.CollectiontoArray in interface java.util.Listpublic java.lang.Object[] toArray(java.lang.Object[] certificates)
toArray in interface java.util.CollectiontoArray in interface java.util.Listpublic SSLFTPCertificate[] toCertificateArray()
SSLFTPCertificate array containing all of
the elements in this Vector in the correct order.Copyright © 2001-2014 Enterprise Distributed Technologies Ltd. All Rights Reserved.