You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@river.apache.org by si...@apache.org on 2010/09/02 09:53:19 UTC
svn commit: r991834 - in /incubator/river/jtsk/skunk/sijskes/river-extra: ./
src/org/apache/river/extra/dynatrust/DynamicTrustFactory.java
src/org/apache/river/extra/dynatrust/DynamicTrustProvider.java
Author: sijskes
Date: Thu Sep 2 07:53:19 2010
New Revision: 991834
URL: http://svn.apache.org/viewvc?rev=991834&view=rev
Log:
initial code
Added:
incubator/river/jtsk/skunk/sijskes/river-extra/src/org/apache/river/extra/dynatrust/DynamicTrustFactory.java
incubator/river/jtsk/skunk/sijskes/river-extra/src/org/apache/river/extra/dynatrust/DynamicTrustProvider.java
Modified:
incubator/river/jtsk/skunk/sijskes/river-extra/ (props changed)
Propchange: incubator/river/jtsk/skunk/sijskes/river-extra/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Thu Sep 2 07:53:19 2010
@@ -0,0 +1,2 @@
+build
+dist
Added: incubator/river/jtsk/skunk/sijskes/river-extra/src/org/apache/river/extra/dynatrust/DynamicTrustFactory.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/sijskes/river-extra/src/org/apache/river/extra/dynatrust/DynamicTrustFactory.java?rev=991834&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/sijskes/river-extra/src/org/apache/river/extra/dynatrust/DynamicTrustFactory.java (added)
+++ incubator/river/jtsk/skunk/sijskes/river-extra/src/org/apache/river/extra/dynatrust/DynamicTrustFactory.java Thu Sep 2 07:53:19 2010
@@ -0,0 +1,141 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.extra.dynatrust;
+
+import java.security.GeneralSecurityException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.security.cert.X509Certificate;
+import java.util.logging.Logger;
+import javax.net.ssl.ManagerFactoryParameters;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+import javax.net.ssl.TrustManagerFactorySpi;
+import javax.net.ssl.X509TrustManager;
+
+/**
+ *
+ * @author sim
+ */
+public final class DynamicTrustFactory
+ extends TrustManagerFactorySpi
+{
+ private final static Logger logger = Logger.getLogger( DynamicTrustFactory.class.getName() );
+
+ private DynaTrustManager trustManager;
+
+ private static X509TrustManager parent;
+
+ public DynamicTrustFactory() throws NoSuchAlgorithmException, KeyStoreException
+ {
+ //logger.severe("");
+
+ trustManager = new DynaTrustManager();
+ }
+
+ public static String getAlgorithm()
+ {
+ return "DynaTrust";
+ }
+
+ @Override
+ protected void engineInit(KeyStore keystore)
+ throws KeyStoreException
+ {
+ //logger.severe("");
+
+ if( keystore != null ) {
+ throw new UnsupportedOperationException("non null keystore");
+ }
+ }
+
+ @Override
+ protected void engineInit(ManagerFactoryParameters mgrparams)
+ throws InvalidAlgorithmParameterException
+ {
+ //logger.severe("");
+
+ throw new InvalidAlgorithmParameterException();
+ }
+
+ @Override
+ protected TrustManager[] engineGetTrustManagers()
+ {
+ //logger.severe("");
+
+ return new TrustManager[] { trustManager } ;
+ }
+
+ private static synchronized X509TrustManager getParent()
+ {
+ if( parent == null ) {
+ try {
+ initKeystore(null);
+ } catch (GeneralSecurityException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ return parent ;
+ }
+
+ public static synchronized void initKeystore( KeyStore keystore )
+ throws GeneralSecurityException
+ {
+ logger.severe(""+keystore);
+
+ TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
+ tmf.init(keystore);
+ parent = (X509TrustManager) tmf.getTrustManagers()[0];
+ }
+
+ class DynaTrustManager
+ implements X509TrustManager
+ {
+ public DynaTrustManager()
+ {
+ }
+
+ @Override
+ public X509Certificate[] getAcceptedIssuers()
+ {
+ //logger.severe("");
+ return getParent().getAcceptedIssuers();
+ }
+
+ @Override
+ public void checkClientTrusted(X509Certificate[] certs, String authType)
+ throws CertificateException
+ {
+ //logger.severe("");
+ getParent().checkClientTrusted(certs, authType);
+ }
+
+ @Override
+ public void checkServerTrusted(X509Certificate[] certs, String authType)
+ throws CertificateException
+ {
+ //logger.severe("");
+ getParent().checkServerTrusted(certs, authType);
+ }
+ }
+
+}
Added: incubator/river/jtsk/skunk/sijskes/river-extra/src/org/apache/river/extra/dynatrust/DynamicTrustProvider.java
URL: http://svn.apache.org/viewvc/incubator/river/jtsk/skunk/sijskes/river-extra/src/org/apache/river/extra/dynatrust/DynamicTrustProvider.java?rev=991834&view=auto
==============================================================================
--- incubator/river/jtsk/skunk/sijskes/river-extra/src/org/apache/river/extra/dynatrust/DynamicTrustProvider.java (added)
+++ incubator/river/jtsk/skunk/sijskes/river-extra/src/org/apache/river/extra/dynatrust/DynamicTrustProvider.java Thu Sep 2 07:53:19 2010
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.extra.dynatrust;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.Provider;
+import java.util.logging.Logger;
+
+/**
+ *
+ * @author sim
+ */
+public final class DynamicTrustProvider
+ extends Provider
+{
+ private final static Logger logger = Logger.getLogger( DynamicTrustProvider.class.getName() );
+
+ private final static String NAME = "DYNATRUST";
+ private final static String INFO = "Dynamic trust provider";
+ private final static double VERSION = 1.0;
+
+ public DynamicTrustProvider()
+ {
+ super(NAME,VERSION,INFO);
+
+ AccessController.doPrivileged(new PrivilegedAction() {
+ @Override
+ public Object run()
+ {
+ put("TrustManagerFactory." + DynamicTrustFactory.getAlgorithm(), DynamicTrustFactory.class.getName());
+ return null;
+ }
+
+ });
+ }
+
+}