Package com.codedx.security
Class SingleCertManager
- java.lang.Object
-
- com.codedx.security.SingleCertManager
-
- All Implemented Interfaces:
ExtraCertManager
public class SingleCertManager extends Object implements ExtraCertManager
ExtraCertManager implementation that only allows a single accepted certificate at once. Any time a certificate is added (be it temporarily or permanently), any previous certificates will be forgotten. At any given time, theasKeyStore()
method should return a KeyStore with 0 or 1 certificates registered.
-
-
Constructor Summary
Constructors Constructor Description SingleCertManager(String password)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addPermanentCert(Certificate cert)
Add a certificate that will be accepted until this manager is "purged".void
addTemporaryCert(Certificate cert)
Add a certificate that will be accepted until some event (as determined by the implementation of this interface) occurs, causing it to be "forgotten".KeyStore
asKeyStore()
Return a representation of this manager as a KeyStore instance.void
purgeAllCerts()
Remove all certificates that have been added either byExtraCertManager.addTemporaryCert(Certificate)
orExtraCertManager.addPermanentCert(Certificate)
.void
purgePermanentCerts()
Remove all certificates that have been added viaExtraCertManager.addPermanentCert(Certificate)
.void
purgeTemporaryCerts()
Remove all certificates that have been added viaExtraCertManager.addTemporaryCert(Certificate)
.
-
-
-
Constructor Detail
-
SingleCertManager
public SingleCertManager(String password)
-
-
Method Detail
-
addTemporaryCert
public void addTemporaryCert(Certificate cert)
Description copied from interface:ExtraCertManager
Add a certificate that will be accepted until some event (as determined by the implementation of this interface) occurs, causing it to be "forgotten".- Specified by:
addTemporaryCert
in interfaceExtraCertManager
- Parameters:
cert
- The certificate to add
-
addPermanentCert
public void addPermanentCert(Certificate cert) throws IOException, GeneralSecurityException
Description copied from interface:ExtraCertManager
Add a certificate that will be accepted until this manager is "purged". Certificates added in this way will generally be written to disk, and will be available upon restarting the program.- Specified by:
addPermanentCert
in interfaceExtraCertManager
- Parameters:
cert
- The certificate to add- Throws:
IOException
- if there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrectGeneralSecurityException
- if there is a problem reading/writing data within the keystore
-
purgeTemporaryCerts
public void purgeTemporaryCerts()
Description copied from interface:ExtraCertManager
Remove all certificates that have been added viaExtraCertManager.addTemporaryCert(Certificate)
.- Specified by:
purgeTemporaryCerts
in interfaceExtraCertManager
-
purgePermanentCerts
public void purgePermanentCerts()
Description copied from interface:ExtraCertManager
Remove all certificates that have been added viaExtraCertManager.addPermanentCert(Certificate)
.- Specified by:
purgePermanentCerts
in interfaceExtraCertManager
-
purgeAllCerts
public void purgeAllCerts()
Description copied from interface:ExtraCertManager
Remove all certificates that have been added either byExtraCertManager.addTemporaryCert(Certificate)
orExtraCertManager.addPermanentCert(Certificate)
.- Specified by:
purgeAllCerts
in interfaceExtraCertManager
-
asKeyStore
public KeyStore asKeyStore() throws GeneralSecurityException
Description copied from interface:ExtraCertManager
Return a representation of this manager as a KeyStore instance.- Specified by:
asKeyStore
in interfaceExtraCertManager
- Returns:
- A new KeyStore that represents the contents of this certificate manager
- Throws:
GeneralSecurityException
- if there is a problem reading/writing data within the keystore
-
-