Skip to content

Commit

Permalink
InitialiZe
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorklang committed Jun 18, 2012
1 parent e656ea7 commit da5862a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ private[akka] object NettySSLSupport {
* Construct a SSLHandler which can be inserted into a Netty server/client pipeline
*/
def apply(settings: NettySettings, log: LoggingAdapter, isClient: Boolean): SslHandler =
if (isClient) initialiseClientSSL(settings, log) else initialiseServerSSL(settings, log)
if (isClient) initializeClientSSL(settings, log) else initializeServerSSL(settings, log)

def initialiseCustomSecureRandom(rngName: Option[String], sourceOfRandomness: Option[String], log: LoggingAdapter): SecureRandom = {
def initializeCustomSecureRandom(rngName: Option[String], sourceOfRandomness: Option[String], log: LoggingAdapter): SecureRandom = {
/**
* According to this bug report: http://bugs.sun.com/view_bug.do?bug_id=6202721
* Using /dev/./urandom is only necessary when using SHA1PRNG on Linux
Expand Down Expand Up @@ -53,7 +53,7 @@ private[akka] object NettySSLSupport {
rng
}

private def initialiseClientSSL(settings: NettySettings, log: LoggingAdapter): SslHandler = {
private def initializeClientSSL(settings: NettySettings, log: LoggingAdapter): SslHandler = {
log.debug("Client SSL is enabled, initialising ...")
((settings.SSLTrustStore, settings.SSLTrustStorePassword, settings.SSLProtocol) match {
case (Some(trustStore), Some(password), Some(protocol)) constructClientContext(settings, log, trustStore, password, protocol)
Expand All @@ -71,7 +71,7 @@ private[akka] object NettySSLSupport {
new SslHandler(sslEngine)
case None
throw new GeneralSecurityException(
"""Failed to initialise client SSL because SSL context could not be found." +
"""Failed to initialize client SSL because SSL context could not be found." +
"Make sure your settings are correct: [trust-store: %s] [trust-store-password: %s] [protocol: %s]""".format(
settings.SSLTrustStore,
settings.SSLTrustStorePassword,
Expand All @@ -86,15 +86,15 @@ private[akka] object NettySSLSupport {
trustStore.load(new FileInputStream(trustStorePath), trustStorePassword.toCharArray) //FIXME does the FileInputStream need to be closed?
trustManagerFactory.init(trustStore)
val trustManagers: Array[TrustManager] = trustManagerFactory.getTrustManagers
Option(SSLContext.getInstance(protocol)) map { ctx ctx.init(null, trustManagers, initialiseCustomSecureRandom(settings.SSLRandomNumberGenerator, settings.SSLRandomSource, log)); ctx }
Option(SSLContext.getInstance(protocol)) map { ctx ctx.init(null, trustManagers, initializeCustomSecureRandom(settings.SSLRandomNumberGenerator, settings.SSLRandomSource, log)); ctx }
} catch {
case e: FileNotFoundException throw new RemoteTransportException("Client SSL connection could not be established because trust store could not be loaded", e)
case e: IOException throw new RemoteTransportException("Client SSL connection could not be established because: " + e.getMessage, e)
case e: GeneralSecurityException throw new RemoteTransportException("Client SSL connection could not be established because SSL context could not be constructed", e)
}
}

private def initialiseServerSSL(settings: NettySettings, log: LoggingAdapter): SslHandler = {
private def initializeServerSSL(settings: NettySettings, log: LoggingAdapter): SslHandler = {
log.debug("Server SSL is enabled, initialising ...")

((settings.SSLKeyStore, settings.SSLKeyStorePassword, settings.SSLProtocol) match {
Expand All @@ -109,7 +109,7 @@ private[akka] object NettySSLSupport {
sslEngine.setEnabledCipherSuites(settings.SSLSupportedAlgorithms.toArray.map(_.toString))
new SslHandler(sslEngine)
case None throw new GeneralSecurityException(
"""Failed to initialise server SSL because SSL context could not be found.
"""Failed to initialize server SSL because SSL context could not be found.
Make sure your settings are correct: [key-store: %s] [key-store-password: %s] [protocol: %s]""".format(
settings.SSLKeyStore,
settings.SSLKeyStorePassword,
Expand All @@ -123,7 +123,7 @@ private[akka] object NettySSLSupport {
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType)
keyStore.load(new FileInputStream(keyStorePath), keyStorePassword.toCharArray) //FIXME does the FileInputStream need to be closed?
factory.init(keyStore, keyStorePassword.toCharArray)
Option(SSLContext.getInstance(protocol)) map { ctx ctx.init(factory.getKeyManagers, null, initialiseCustomSecureRandom(settings.SSLRandomNumberGenerator, settings.SSLRandomSource, log)); ctx }
Option(SSLContext.getInstance(protocol)) map { ctx ctx.init(factory.getKeyManagers, null, initializeCustomSecureRandom(settings.SSLRandomNumberGenerator, settings.SSLRandomSource, log)); ctx }
} catch {
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ object Configuration {
"""

def getCipherConfig(cipher: String, enabled: String*): (String, Boolean, Config) = if (try {
NettySSLSupport.initialiseCustomSecureRandom(Some(cipher), None, NoLogging) ne null
NettySSLSupport.initializeCustomSecureRandom(Some(cipher), None, NoLogging) ne null
} catch {
case _: IllegalArgumentException false // Cannot match against the message since the message might be localized :S
case _: java.security.NoSuchAlgorithmException false
Expand Down Expand Up @@ -80,23 +80,18 @@ abstract class Ticket1978CommunicationSpec(val cipherEnabledconfig: (String, Boo

import RemoteCommunicationSpec._

val conf = ConfigFactory.parseString("akka.remote.netty.port=12346").withFallback(system.settings.config)
val other = ActorSystem("remote-sys", conf)

val remote = other.actorOf(Props(new Actor {
def receive = {
case "ping" sender ! (("pong", sender))
}
}), "echo")

val here = system.actorFor("akka://remote-sys@localhost:12346/user/echo")
val other = ActorSystem("remote-sys", ConfigFactory.parseString("akka.remote.netty.port=12346").withFallback(system.settings.config))

override def atTermination() {
other.shutdown()
}

"SSL Remoting" must {
if (cipherEnabledconfig._2) {
val remote = other.actorOf(Props(new Actor { def receive = { case "ping" sender ! (("pong", sender)) } }), "echo")

val here = system.actorFor("akka://remote-sys@localhost:12346/user/echo")

"support remote look-ups" in {
here ! "ping"
expectMsgPF() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static void afterAll() {
Timeout timeout = new Timeout(timeoutSeconds, TimeUnit.SECONDS);

@Before
public void initialise() {
public void initialize() {
counters = new ArrayList<ActorRef>();
for (int i = 1; i <= numCounters; i++) {
final String name = "counter" + i;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void afterAll() {
Timeout timeout = new Timeout(timeoutSeconds, TimeUnit.SECONDS);

@Before
public void initialise() {
public void initialize() {
counters = new ArrayList<ActorRef>();
for (int i = 1; i <= numCounters; i++) {
final String name = "counter" + i;
Expand Down

0 comments on commit da5862a

Please sign in to comment.