public class SSLUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static void |
addCertToTempStore(byte[] certificate)
Add a new certificate to the temporary storage
|
static void |
addCertToTempStore(byte[] certificate,
boolean reload)
Add a new certificate to the temporary store
|
static void |
addConfidenceLink(POPNode node,
java.security.cert.Certificate certificate,
java.lang.String networkUUID)
Add a new certificate to the keystore, this will be written anew on disk.
|
static void |
addKeyEntryToKeyStore(KeyStoreDetails ksOptions,
KeyPairDetails keyOptions,
java.security.KeyStore.PrivateKeyEntry privateKeyEntry)
Given the keystore information, the key pair details and a real Priva Key /
Certificate pair, add it to the keystore.
|
static byte[] |
certificateBytes(java.security.cert.Certificate cert)
Get the bytes of a certificate
|
static java.lang.String |
certificateFingerprint(byte[] certificate)
Get the SHA-1 fingerprint of a certificate from its byte array representation
|
static java.lang.String |
certificateFingerprint(java.security.cert.Certificate cert)
Get the SHA-1 fingerprint of a certificate
See
https://stackoverflow.com/questions/1270703/how-to-retrieve-compute-an-x509-certificates-thumbprint-in-java
|
static java.security.cert.Certificate |
certificateFromBytes(byte[] certificate)
Transform a certificate byte array to a real certificate.
|
static java.security.KeyStore.PrivateKeyEntry |
ensureKeyPairGeneration(KeyPairDetails options)
Call
generateKeyPair(ch.icosys.popjava.core.util.ssl.KeyPairDetails)
until the operation does not fail. |
static java.security.KeyStore.PrivateKeyEntry |
generateKeyPair(KeyPairDetails options)
Generate a Private Key and a corresponding public certificate.
|
static boolean |
generateKeyStore(KeyStoreDetails ksOptions,
KeyPairDetails keyOptions)
Create a new KeyStore with a new Private Key and Certificate
|
static java.security.cert.Certificate |
getCertificate(java.lang.String fingerprint)
Given a fingerprint (SHA1) it will return the Public Key associated with it.
|
static java.security.cert.Certificate |
getCertificateFromAlias(java.lang.String uuid)
Given a UUID it will return the matching local public certificate for this
network.
|
static java.lang.String |
getNetworkFromFingerprint(java.lang.String fingerprint)
Try to extract the network certificate from the fingerprint, and the alias
inside the KeyStore.
|
static javax.net.ssl.SSLContext |
getSSLContext()
Get a correctly initialized SSLContext
|
static void |
invalidateSSLSessions()
Invalidate all open SSL Sessions because there was a change in certificate
somewhere.
|
static boolean |
isCertificateKnown(java.security.cert.Certificate certificate)
Check if the given certificate is inside the Trust Manager.
|
static boolean |
isConfidenceLink(java.lang.String fingerprint)
Return if a given fingerprint certificate is part of the Confidence Link
group.
|
static void |
reloadPOPManagers()
Forcefully reload the Trust and Key Managers if they exists.
|
static void |
removeAlias(java.lang.String alias)
Remove form the KeyStore the specified alias.
|
static void |
removeConfidenceLink(POPNode node,
java.lang.String networkUUID)
Remove an entry from the keystore, this will be written anew on disk.
|
static void |
replaceConfidenceLink(POPNode node,
java.security.cert.Certificate certificate,
java.lang.String networkUUID)
Add a new certificate to the keystore, this will be written anew on disk.
|
public static javax.net.ssl.SSLContext getSSLContext()
throws java.security.KeyStoreException,
java.io.IOException,
java.security.NoSuchAlgorithmException,
java.security.cert.CertificateException,
java.security.UnrecoverableKeyException,
java.security.KeyManagementException
java.security.KeyStoreException - if we fail to open the keystorejava.io.IOException - if any I/O problem occursjava.security.NoSuchAlgorithmException - if we can't find the algorithm to check for the key store
integrityjava.security.cert.CertificateException - if we can't load some of the certificatesjava.security.UnrecoverableKeyException - if we can't load some of the private keys in the key storejava.security.KeyManagementException - if we can't instantiate the ssl context correctlypublic static void invalidateSSLSessions()
public static void reloadPOPManagers()
public static void addConfidenceLink(POPNode node, java.security.cert.Certificate certificate, java.lang.String networkUUID) throws java.io.IOException
node - A node created somehow, directly or with the factorycertificate - The certificate we want to add as a confidence linknetworkUUID - The network associated to this certificatejava.io.IOException - If we were not able to write to filepublic static void replaceConfidenceLink(POPNode node, java.security.cert.Certificate certificate, java.lang.String networkUUID) throws java.io.IOException
node - A node created somehow, directly or with the factorycertificate - The certificate we want to add as a confidence linknetworkUUID - The network associated to this certificatejava.io.IOException - If we were not able to write to filepublic static void removeConfidenceLink(POPNode node, java.lang.String networkUUID) throws java.io.IOException
node - A node created somehow, directly or with the factorynetworkUUID - The ID of the networkjava.io.IOException - Manypublic static void removeAlias(java.lang.String alias)
throws java.io.IOException
alias - the alias to remove from the keystorejava.io.IOException - if we fail to save the changed keystorepublic static java.lang.String certificateFingerprint(byte[] certificate)
certificate - the certificate we want the fingerprint ofpublic static java.lang.String certificateFingerprint(java.security.cert.Certificate cert)
cert - the certificate we want to know the fingerprintpublic static byte[] certificateBytes(java.security.cert.Certificate cert)
cert - the certificate we want in bytespublic static java.security.cert.Certificate certificateFromBytes(byte[] certificate)
throws java.security.cert.CertificateException
certificate - A byte array in PEM formatjava.security.cert.CertificateException - if the given bytes can't be converted to a certificatepublic static boolean isCertificateKnown(java.security.cert.Certificate certificate)
certificate - the certificate to checkpublic static java.lang.String getNetworkFromFingerprint(java.lang.String fingerprint)
fingerprint - the fingerprint we want to know the network ofpublic static java.security.cert.Certificate getCertificate(java.lang.String fingerprint)
fingerprint - the fingerprint of the certificate we wantpublic static java.security.cert.Certificate getCertificateFromAlias(java.lang.String uuid)
uuid - the alias in the keystore, usually the network UUIDpublic static boolean isConfidenceLink(java.lang.String fingerprint)
fingerprint - the fingerprint of the certificatepublic static void addCertToTempStore(byte[] certificate)
certificate - the certificate to add to the temporary storeaddCertToTempStore(byte[], boolean)public static void addCertToTempStore(byte[] certificate,
boolean reload)
certificate - the bytes of the certificate to addreload - if we have to reload the keystore now or let the parallel event do
itpublic static boolean generateKeyStore(KeyStoreDetails ksOptions, KeyPairDetails keyOptions)
ksOptions - details on the key storekeyOptions - details on the key we want to generatepublic static void addKeyEntryToKeyStore(KeyStoreDetails ksOptions, KeyPairDetails keyOptions, java.security.KeyStore.PrivateKeyEntry privateKeyEntry) throws java.io.IOException, java.security.KeyStoreException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException, java.security.UnrecoverableKeyException
ksOptions - the key store informationkeyOptions - the private key informationprivateKeyEntry - the private key itselfjava.io.IOException - if we fail any operation on diskjava.security.KeyStoreException - if we fail any operation on the keystorejava.security.NoSuchAlgorithmException - if we fail to validate the keystorejava.security.cert.CertificateException - if we fail to parse any certificatejava.security.UnrecoverableKeyException - if we fail to create the key manager (for the private keys)public static java.security.KeyStore.PrivateKeyEntry ensureKeyPairGeneration(KeyPairDetails options)
generateKeyPair(ch.icosys.popjava.core.util.ssl.KeyPairDetails)
until the operation does not fail.options - the information regarding the private keypublic static java.security.KeyStore.PrivateKeyEntry generateKeyPair(KeyPairDetails options) throws java.security.NoSuchAlgorithmException, java.io.IOException, org.bouncycastle.operator.OperatorCreationException, java.security.cert.CertificateException, java.lang.IllegalArgumentException
options - the information regarding the private keyjava.security.NoSuchAlgorithmException - if there is a missing algorithm to generate certificatejava.io.IOException - if any I/O problem occursorg.bouncycastle.operator.OperatorCreationException - if we can't sign the certificatejava.security.cert.CertificateException - if we can't create the certificatejava.lang.IllegalArgumentException