You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2011/10/05 12:23:51 UTC
svn commit: r1179143 - in
/karaf/branches/karaf-2.2.x/jaas/config/src/main/java/org/apache/karaf/jaas/config:
KeystoreManager.java impl/OsgiKeystoreManager.java
Author: jbonofre
Date: Wed Oct 5 10:23:51 2011
New Revision: 1179143
URL: http://svn.apache.org/viewvc?rev=1179143&view=rev
Log:
[KARAF-756] KeystoreManager supports timeout
Modified:
karaf/branches/karaf-2.2.x/jaas/config/src/main/java/org/apache/karaf/jaas/config/KeystoreManager.java
karaf/branches/karaf-2.2.x/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/OsgiKeystoreManager.java
Modified: karaf/branches/karaf-2.2.x/jaas/config/src/main/java/org/apache/karaf/jaas/config/KeystoreManager.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/jaas/config/src/main/java/org/apache/karaf/jaas/config/KeystoreManager.java?rev=1179143&r1=1179142&r2=1179143&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/jaas/config/src/main/java/org/apache/karaf/jaas/config/KeystoreManager.java (original)
+++ karaf/branches/karaf-2.2.x/jaas/config/src/main/java/org/apache/karaf/jaas/config/KeystoreManager.java Wed Oct 5 10:23:51 2011
@@ -45,6 +45,33 @@ public interface KeystoreManager {
* @param trustStore The trust keystore name as provided by listKeystores.
* The KeystoreInstance for this keystore must have
* unlocked this key.
+ * @param timeout Amount of time waiting for keyStore and keyAlias to be available.
+ *
+ * @throws KeystoreIsLocked Occurs when the requested key keystore cannot
+ * be used because it has not been unlocked.
+ * @throws KeyIsLocked Occurs when the requested private key in the key
+ * keystore cannot be used because it has not been
+ * unlocked.
+ */
+ SSLContext createSSLContext(String provider, String protocol,
+ String algorithm, String keyStore,
+ String keyAlias, String trustStore,
+ long timeout) throws GeneralSecurityException;
+
+ /**
+ * Gets a SSLContext using one Keystore to access the private key
+ * and another to provide the list of trusted certificate authorities.
+ * @param provider
+ * @param protocol The SSL protocol to use
+ * @param algorithm The SSL algorithm to use
+ * @param keyStore The key keystore name as provided by listKeystores. The
+ * KeystoreInstance for this keystore must be unlocked.
+ * @param keyAlias The name of the private key in the keystore. The
+ * KeystoreInstance for this keystore must have unlocked
+ * this key.
+ * @param trustStore The trust keystore name as provided by listKeystores.
+ * The KeystoreInstance for this keystore must have
+ * unlocked this key.
*
* @throws KeystoreIsLocked Occurs when the requested key keystore cannot
* be used because it has not been unlocked.
@@ -70,6 +97,33 @@ public interface KeystoreManager {
* @param trustStore The trust keystore name as provided by listKeystores.
* The KeystoreInstance for this keystore must have
* unlocked this key.
+ * @param timeout Amount of time waiting for keyStore and keyAlias to be available.
+ *
+ * @throws KeystoreIsLocked Occurs when the requested key keystore cannot
+ * be used because it has not been unlocked.
+ * @throws KeyIsLocked Occurs when the requested private key in the key
+ * keystore cannot be used because it has not been
+ * unlocked.
+ */
+ SSLServerSocketFactory createSSLServerFactory(String provider, String protocol,
+ String algorithm, String keyStore,
+ String keyAlias, String trustStore,
+ long timeout) throws GeneralSecurityException;
+
+ /**
+ * Gets a ServerSocketFactory using one Keystore to access the private key
+ * and another to provide the list of trusted certificate authorities.
+ * @param provider
+ * @param protocol The SSL protocol to use
+ * @param algorithm The SSL algorithm to use
+ * @param keyStore The key keystore name as provided by listKeystores. The
+ * KeystoreInstance for this keystore must be unlocked.
+ * @param keyAlias The name of the private key in the keystore. The
+ * KeystoreInstance for this keystore must have unlocked
+ * this key.
+ * @param trustStore The trust keystore name as provided by listKeystores.
+ * The KeystoreInstance for this keystore must have
+ * unlocked this key.
*
* @throws KeystoreIsLocked Occurs when the requested key keystore cannot
* be used because it has not been unlocked.
@@ -95,6 +149,34 @@ public interface KeystoreManager {
* @param trustStore The trust keystore name as provided by listKeystores.
* The KeystoreInstance for this keystore must have
* unlocked this key.
+ * @param timeout Amount of time waiting for keyStore and keyAlias to be available.
+ *
+ * @throws KeystoreIsLocked Occurs when the requested key keystore cannot
+ * be used because it has not been unlocked.
+ * @throws KeyIsLocked Occurs when the requested private key in the key
+ * keystore cannot be used because it has not been
+ * unlocked.
+ * @throws GeneralSecurityException
+ */
+ SSLSocketFactory createSSLFactory(String provider, String protocol,
+ String algorithm, String keyStore,
+ String keyAlias, String trustStore,
+ long timeout) throws GeneralSecurityException;
+
+ /**
+ * Gets a SocketFactory using one Keystore to access the private key
+ * and another to provide the list of trusted certificate authorities.
+ * @param provider The SSL provider to use, or null for the default
+ * @param protocol The SSL protocol to use
+ * @param algorithm The SSL algorithm to use
+ * @param keyStore The key keystore name as provided by listKeystores. The
+ * KeystoreInstance for this keystore must be unlocked.
+ * @param keyAlias The name of the private key in the keystore. The
+ * KeystoreInstance for this keystore must have unlocked
+ * this key.
+ * @param trustStore The trust keystore name as provided by listKeystores.
+ * The KeystoreInstance for this keystore must have
+ * unlocked this key.
*
* @throws KeystoreIsLocked Occurs when the requested key keystore cannot
* be used because it has not been unlocked.
Modified: karaf/branches/karaf-2.2.x/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/OsgiKeystoreManager.java
URL: http://svn.apache.org/viewvc/karaf/branches/karaf-2.2.x/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/OsgiKeystoreManager.java?rev=1179143&r1=1179142&r2=1179143&view=diff
==============================================================================
--- karaf/branches/karaf-2.2.x/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/OsgiKeystoreManager.java (original)
+++ karaf/branches/karaf-2.2.x/jaas/config/src/main/java/org/apache/karaf/jaas/config/impl/OsgiKeystoreManager.java Wed Oct 5 10:23:51 2011
@@ -29,12 +29,16 @@ import javax.net.ssl.SSLSocketFactory;
import org.apache.karaf.jaas.config.KeystoreInstance;
import org.apache.karaf.jaas.config.KeystoreIsLocked;
import org.apache.karaf.jaas.config.KeystoreManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Implementation of KeystoreManager
*/
public class OsgiKeystoreManager implements KeystoreManager {
+ private final static transient Logger logger = LoggerFactory.getLogger(OsgiKeystoreManager.class);
+
private List<KeystoreInstance> keystores = new CopyOnWriteArrayList<KeystoreInstance>();
public void register(KeystoreInstance keystore, Map<String,?> properties) {
@@ -58,6 +62,13 @@ public class OsgiKeystoreManager impleme
}
public SSLContext createSSLContext(String provider, String protocol, String algorithm, String keyStore, String keyAlias, String trustStore) throws GeneralSecurityException {
+ return createSSLContext(provider, protocol, algorithm, keyStore, keyAlias, trustStore, 0);
+ }
+
+ public SSLContext createSSLContext(String provider, String protocol, String algorithm, String keyStore, String keyAlias, String trustStore, long timeout) throws GeneralSecurityException {
+
+ this.checkForKeystoresAvailability(keyStore, keyAlias, trustStore, timeout);
+
KeystoreInstance keyInstance = getKeystore(keyStore);
if (keyInstance != null && keyInstance.isKeystoreLocked()) {
throw new KeystoreIsLocked("Keystore '" + keyStore + "' is locked");
@@ -81,12 +92,61 @@ public class OsgiKeystoreManager impleme
}
public SSLServerSocketFactory createSSLServerFactory(String provider, String protocol, String algorithm, String keyStore, String keyAlias, String trustStore) throws GeneralSecurityException {
- SSLContext context = createSSLContext(provider, protocol, algorithm, keyStore, keyAlias, trustStore);
+ return createSSLServerFactory(provider, protocol, algorithm, keyStore, keyAlias, trustStore, 0);
+ }
+
+ public SSLServerSocketFactory createSSLServerFactory(String provider, String protocol, String algorithm, String keyStore, String keyAlias, String trustStore, long timeout) throws GeneralSecurityException {
+ SSLContext context = createSSLContext(provider, protocol, algorithm, keyStore, keyAlias, trustStore, timeout);
return context.getServerSocketFactory();
}
public SSLSocketFactory createSSLFactory(String provider, String protocol, String algorithm, String keyStore, String keyAlias, String trustStore) throws GeneralSecurityException {
- SSLContext context = createSSLContext(provider, protocol, algorithm, keyStore, keyAlias, trustStore);
+ return createSSLFactory(provider, protocol, algorithm, keyStore, keyAlias, trustStore, 0);
+ }
+
+ public SSLSocketFactory createSSLFactory(String provider, String protocol, String algorithm, String keyStore, String keyAlias, String trustStore, long timeout) throws GeneralSecurityException {
+ SSLContext context = createSSLContext(provider, protocol, algorithm, keyStore, keyAlias, trustStore, timeout);
return context.getSocketFactory();
}
+
+ private void sleep(long time) {
+ try {
+ Thread.sleep(time);
+ } catch (InterruptedException e) {
+
+ }
+ }
+
+ /**
+ * Purely check for the availability of provided key stores and key
+
+ * @param keyStore
+ * @param keyAlias
+ * @param trustStore
+ * @param timeout
+ */
+ private void checkForKeystoresAvailability( String keyStore, String keyAlias, String trustStore, long timeout ) {
+ for (int i = 0 ; i < timeout/1000; ++i) {
+ KeystoreInstance keyInstance = getKeystore(keyStore);
+ if (keyInstance != null && keyInstance.isKeystoreLocked()) {
+ sleep(1000);
+ logger.info( "Looking for keystore: {}...", keyStore );
+ continue;
+ }
+ if (keyInstance != null && keyInstance.isKeyLocked(keyAlias)) {
+ sleep(1000);
+ logger.info( "Looking for keystore's key: {}...", keyAlias );
+ continue;
+ }
+
+ KeystoreInstance trustInstance = trustStore == null ? null : getKeystore(trustStore);
+ if (trustInstance != null && trustInstance.isKeystoreLocked()) {
+ sleep(1000);
+ logger.info( "Looking for truststore: {}...", trustStore );
+ continue;
+ }
+
+ }
+ }
+
}