From commits-return-14984-apmail-activemq-commits-archive=activemq.apache.org@activemq.apache.org Thu Nov 11 13:31:53 2010 Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 61137 invoked from network); 11 Nov 2010 13:31:52 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 11 Nov 2010 13:31:52 -0000 Received: (qmail 39188 invoked by uid 500); 11 Nov 2010 13:32:24 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 39163 invoked by uid 500); 11 Nov 2010 13:32:24 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 39156 invoked by uid 99); 11 Nov 2010 13:32:23 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Nov 2010 13:32:23 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Nov 2010 13:32:22 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3E7BA23889E1; Thu, 11 Nov 2010 13:31:09 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1033935 - in /activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker: Broker.scala Connector.scala KeyStorage.scala Date: Thu, 11 Nov 2010 13:31:09 -0000 To: commits@activemq.apache.org From: chirino@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20101111133109.3E7BA23889E1@eris.apache.org> Author: chirino Date: Thu Nov 11 13:31:08 2010 New Revision: 1033935 URL: http://svn.apache.org/viewvc?rev=1033935&view=rev Log: Broker now loads the key and trust configured so that they can be injected into the connector's transport server if they are needed. Added: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/KeyStorage.scala Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala?rev=1033935&r1=1033934&r2=1033935&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala (original) +++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala Thu Nov 11 13:31:08 2010 @@ -183,6 +183,8 @@ class Broker() extends BaseService with val connector_id_counter = new LongCounter val connection_id_counter = new LongCounter + var key_storage:KeyStorage = _ + override def toString() = "broker: "+id @@ -207,6 +209,12 @@ class Broker() extends BaseService with // create the runtime objects from the config { data_directory = new File(config.basedir) + + if( config.key_storage!=null ) { + key_storage = new KeyStorage + key_storage.config = config.key_storage + } + default_virtual_host = null for (c <- config.virtual_hosts) { val host = new VirtualHost(this, virtual_host_id_counter.incrementAndGet) Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala?rev=1033935&r1=1033934&r2=1033935&view=diff ============================================================================== --- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala (original) +++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala Thu Nov 11 13:31:08 2010 @@ -140,6 +140,10 @@ class Connector(val broker:Broker, val i transportServer = TransportFactory.bind( config.bind ) transportServer.setDispatchQueue(dispatchQueue) transportServer.setAcceptListener(BrokerAcceptListener) + + if( transportServer.isInstanceOf[KeyManagerAware] && broker.key_storage!=null ) { + transportServer.asInstanceOf[KeyManagerAware].setKeyManagers(broker.key_storage.create_key_managers) + } transportServer.start(onCompleted) } Added: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/KeyStorage.scala URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/KeyStorage.scala?rev=1033935&view=auto ============================================================================== --- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/KeyStorage.scala (added) +++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/KeyStorage.scala Thu Nov 11 13:31:08 2010 @@ -0,0 +1,71 @@ +/** + * 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.activemq.apollo.broker + +import org.apache.activemq.apollo.dto.KeyStorageDTO +import javax.net.ssl._ +import java.security.KeyStore +import java.io.FileInputStream + +/** + * + * @author Hiram Chirino + */ +class KeyStorage { + + var config = new KeyStorageDTO + + var key_store:KeyStore = _ + var trust_managers:Array[TrustManager] = _ + var key_managers:Array[KeyManager] = _ + + // a little helper for dealing /w null values. + private def opt[T](value:T):Option[T] = value match { + case null => None + case x => Some(x) + } + + def create_key_store = { + if( trust_managers==null ) { + key_store = { + val store = KeyStore.getInstance(opt(config.store_type).getOrElse("JKS")) + store.load(new FileInputStream(config.file), opt(config.password).getOrElse("").toCharArray()) + store + } + } + key_store + } + + def create_trust_managers = { + if( trust_managers==null ) { + val factory = TrustManagerFactory.getInstance(opt(config.trust_algorithm).getOrElse("SunX509")) + factory.init(create_key_store) + trust_managers = factory.getTrustManagers + } + trust_managers + } + + def create_key_managers = { + if( key_managers==null ) { + val factory = KeyManagerFactory.getInstance(opt(config.key_algorithm).getOrElse("SunX509")) + factory.init(create_key_store, opt(config.key_password).getOrElse("").toCharArray()) + key_managers = factory.getKeyManagers + } + key_managers + } + +} \ No newline at end of file