Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3161 - adding trust managers for server connection too #1295

Merged
merged 1 commit into from Apr 3, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,6 +14,7 @@ import java.io.{ IOException, FileNotFoundException, FileInputStream }
import java.security._ import java.security._
import javax.net.ssl.{ KeyManagerFactory, TrustManager, TrustManagerFactory, SSLContext } import javax.net.ssl.{ KeyManagerFactory, TrustManager, TrustManagerFactory, SSLContext }
import org.jboss.netty.handler.ssl.SslHandler import org.jboss.netty.handler.ssl.SslHandler
import scala.util.Try


/** /**
* INTERNAL API * INTERNAL API
Expand Down Expand Up @@ -92,7 +93,7 @@ private[akka] object NettySSLSupport {
trustManagerFactory.init({ trustManagerFactory.init({
val trustStore = KeyStore.getInstance(KeyStore.getDefaultType) val trustStore = KeyStore.getInstance(KeyStore.getDefaultType)
val fin = new FileInputStream(trustStorePath) val fin = new FileInputStream(trustStorePath)
try trustStore.load(fin, trustStorePassword.toCharArray) finally fin.close() try trustStore.load(fin, trustStorePassword.toCharArray) finally Try(fin.close())
trustStore trustStore
}) })
trustManagerFactory.getTrustManagers trustManagerFactory.getTrustManagers
Expand Down Expand Up @@ -140,10 +141,23 @@ private[akka] object NettySSLSupport {
factory.init({ factory.init({
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType) val keyStore = KeyStore.getInstance(KeyStore.getDefaultType)
val fin = new FileInputStream(keyStorePath) val fin = new FileInputStream(keyStorePath)
try keyStore.load(fin, keyStorePassword.toCharArray) finally fin.close() try keyStore.load(fin, keyStorePassword.toCharArray) finally Try(fin.close())
keyStore keyStore
}, keyStorePassword.toCharArray) }, keyStorePassword.toCharArray)
Option(SSLContext.getInstance(protocol)) map { ctx ⇒ ctx.init(factory.getKeyManagers, null, rng); ctx }
val trustManagers: Option[Array[TrustManager]] = settings.SSLTrustStore map {
path ⇒
val pwd = settings.SSLTrustStorePassword.map(_.toCharArray).orNull
val trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm)
trustManagerFactory.init({
val trustStore = KeyStore.getInstance(KeyStore.getDefaultType)
val fin = new FileInputStream(path)
try trustStore.load(fin, pwd) finally Try(fin.close())
trustStore
})
trustManagerFactory.getTrustManagers
}
Option(SSLContext.getInstance(protocol)) map { ctx ⇒ ctx.init(factory.getKeyManagers, trustManagers.orNull, rng); ctx }
} catch { } catch {
case e: FileNotFoundException ⇒ throw new RemoteTransportException("Server SSL connection could not be established because key store could not be loaded", e) case e: FileNotFoundException ⇒ throw new RemoteTransportException("Server SSL connection could not be established because key store could not be loaded", e)
case e: IOException ⇒ throw new RemoteTransportException("Server SSL connection could not be established because: " + e.getMessage, e) case e: IOException ⇒ throw new RemoteTransportException("Server SSL connection could not be established because: " + e.getMessage, e)
Expand Down