Package net.sourceforge.jnlp.security
Class SecurityUtil
- java.lang.Object
-
- net.sourceforge.jnlp.security.SecurityUtil
-
public class SecurityUtil extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description SecurityUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleancheckTrustedCertsFile()Checks the user's home directory to see if the trusted.certs file exists.static java.security.KeyStoregetCacertsKeyStore()static java.lang.StringgetCN(java.lang.String principal)Extracts the CN field from a Certificate principal string.static java.security.KeygetKey(java.security.KeyStore ks, java.lang.String alias)static java.security.KeyStoregetSystemCertStore()static java.lang.StringgetTrustedCertsFilename()static java.security.KeyStoregetUserKeyStore()static voidinitKeyManagerFactory(javax.net.ssl.KeyManagerFactory kmf, java.security.KeyStore ks)static voidloadKeyStore(java.security.KeyStore ks, java.io.File f)static voidsetKeyEntry(java.security.KeyStore ks, java.lang.String alias, java.security.Key key, java.security.cert.Certificate[] certChain)static voidstoreKeyStore(java.security.KeyStore ks, java.io.File f)
-
-
-
Method Detail
-
getTrustedCertsFilename
public static java.lang.String getTrustedCertsFilename() throws java.lang.Exception- Throws:
java.lang.Exception
-
getCN
public static java.lang.String getCN(java.lang.String principal)
Extracts the CN field from a Certificate principal string. Or, if it can't find that, return the principal unmodified. This is a simple (and hence 'wrong') version. See http://www.ietf.org/rfc/rfc2253.txt for all the gory details.- Parameters:
principal- string, CN to be extracted from- Returns:
- extracted CN
-
checkTrustedCertsFile
public static boolean checkTrustedCertsFile() throws java.lang.ExceptionChecks the user's home directory to see if the trusted.certs file exists. If it does not exist, it tries to create an empty keystore.- Returns:
- true if the trusted.certs file exists or a new trusted.certs was created successfully, otherwise false.
- Throws:
java.lang.Exception- if check goes wrong
-
getUserKeyStore
public static java.security.KeyStore getUserKeyStore() throws java.lang.Exception- Returns:
- the keystore associated with the user's trusted.certs file, or null otherwise.
- Throws:
java.lang.Exception- if getting fails
-
getCacertsKeyStore
public static java.security.KeyStore getCacertsKeyStore() throws java.lang.Exception- Returns:
- the keystore associated with the JDK cacerts file, or null otherwise.
- Throws:
java.lang.Exception- if get fails
-
getSystemCertStore
public static java.security.KeyStore getSystemCertStore() throws java.lang.Exception- Returns:
- the keystore associated with the system certs file, or null otherwise.
- Throws:
java.lang.Exception- if get goes wrong
-
initKeyManagerFactory
public static void initKeyManagerFactory(javax.net.ssl.KeyManagerFactory kmf, java.security.KeyStore ks) throws java.security.KeyStoreException, java.security.NoSuchAlgorithmException, java.security.UnrecoverableKeyException- Throws:
java.security.KeyStoreExceptionjava.security.NoSuchAlgorithmExceptionjava.security.UnrecoverableKeyException
-
setKeyEntry
public static void setKeyEntry(java.security.KeyStore ks, java.lang.String alias, java.security.Key key, java.security.cert.Certificate[] certChain) throws java.security.KeyStoreException- Throws:
java.security.KeyStoreException
-
getKey
public static java.security.Key getKey(java.security.KeyStore ks, java.lang.String alias) throws java.security.KeyStoreException, java.security.NoSuchAlgorithmException, java.security.UnrecoverableKeyException- Throws:
java.security.KeyStoreExceptionjava.security.NoSuchAlgorithmExceptionjava.security.UnrecoverableKeyException
-
loadKeyStore
public static void loadKeyStore(java.security.KeyStore ks, java.io.File f) throws java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException- Throws:
java.io.IOExceptionjava.security.NoSuchAlgorithmExceptionjava.security.cert.CertificateException
-
storeKeyStore
public static void storeKeyStore(java.security.KeyStore ks, java.io.File f) throws java.security.KeyStoreException, java.io.IOException, java.security.NoSuchAlgorithmException, java.security.cert.CertificateException- Throws:
java.security.KeyStoreExceptionjava.io.IOExceptionjava.security.NoSuchAlgorithmExceptionjava.security.cert.CertificateException
-
-