From 5ab5933ca47cfc69127b1c0904f0bfc5baab67d6 Mon Sep 17 00:00:00 2001 From: Shailesh Patil Date: Wed, 12 Jun 2019 09:28:55 +0100 Subject: [PATCH] common config chnages for selsigned certificate --- .../scalanet/peergroup/TLSPeerGroup.scala | 3 ++- src/io/iohk/scalanet/test/NetUtils.scala | 16 +++++++++---- .../test/peergroup/DTLSPeerGroupSpec.scala | 2 -- .../test/peergroup/TLSPeerGroupSpec.scala | 23 +++++++++---------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/io/iohk/scalanet/peergroup/TLSPeerGroup.scala b/src/io/iohk/scalanet/peergroup/TLSPeerGroup.scala index 98f15a56..35f6f9a3 100644 --- a/src/io/iohk/scalanet/peergroup/TLSPeerGroup.scala +++ b/src/io/iohk/scalanet/peergroup/TLSPeerGroup.scala @@ -39,7 +39,8 @@ import scala.collection.JavaConverters._ * @param codec a decco codec for reading writing messages to NIO ByteBuffer. * @tparam M the message type. */ -class TLSPeerGroup[M](val config: Config)(implicit codec: Codec[M],bufferInstantiator: BufferInstantiator[ByteBuffer]) extends TerminalPeerGroup[InetMultiAddress, M]() { +class TLSPeerGroup[M](val config: Config)(implicit codec: Codec[M], bufferInstantiator: BufferInstantiator[ByteBuffer]) + extends TerminalPeerGroup[InetMultiAddress, M]() { private val log = LoggerFactory.getLogger(getClass) diff --git a/src/io/iohk/scalanet/test/NetUtils.scala b/src/io/iohk/scalanet/test/NetUtils.scala index 68f2fcd8..61a504fc 100644 --- a/src/io/iohk/scalanet/test/NetUtils.scala +++ b/src/io/iohk/scalanet/test/NetUtils.scala @@ -115,7 +115,11 @@ object NetUtils { Await.result(pg.initialize().runAsync, 10 seconds) pg } - def randomTLSPeerGroup[M](implicit scheduler: Scheduler, codec: Codec[M],bufferInstantiator: BufferInstantiator[ByteBuffer]): TLSPeerGroup[M] = { + def randomTLSPeerGroup[M]( + implicit scheduler: Scheduler, + codec: Codec[M], + bufferInstantiator: BufferInstantiator[ByteBuffer] + ): TLSPeerGroup[M] = { val sc1 = new SelfSignedCertificate() val pg = new TLSPeerGroup(TLSPeerGroup.Config(aRandomAddress(), sc1.key(), List(sc1.cert()), Nil)) Await.result(pg.initialize().runAsync, 10 seconds) @@ -146,8 +150,8 @@ object NetUtils { def withTwoRandomTLSPeerGroups[M](clientAuth: Boolean = false)( testCode: (TLSPeerGroup[M], TLSPeerGroup[M]) => Any - )(implicit scheduler: Scheduler, codec: Codec[M],bufferInstantiator: BufferInstantiator[ByteBuffer]): Unit = { - val (pg1, pg2) = random2TLSPPeerGroup(clientAuth)(scheduler, codec,bufferInstantiator) + )(implicit scheduler: Scheduler, codec: Codec[M], bufferInstantiator: BufferInstantiator[ByteBuffer]): Unit = { + val (pg1, pg2) = random2TLSPPeerGroup(clientAuth)(scheduler, codec, bufferInstantiator) try { testCode(pg1, pg2) } finally { @@ -158,7 +162,11 @@ object NetUtils { def random2TLSPPeerGroup[M]( clientAuth: Boolean - )(implicit scheduler: Scheduler, codec: Codec[M],bufferInstantiator: BufferInstantiator[ByteBuffer]): (TLSPeerGroup[M], TLSPeerGroup[M]) = { + )( + implicit scheduler: Scheduler, + codec: Codec[M], + bufferInstantiator: BufferInstantiator[ByteBuffer] + ): (TLSPeerGroup[M], TLSPeerGroup[M]) = { val address1 = aRandomAddress() val address2 = aRandomAddress() val sc1 = new SelfSignedCertificate() diff --git a/src/io/iohk/scalanet/test/peergroup/DTLSPeerGroupSpec.scala b/src/io/iohk/scalanet/test/peergroup/DTLSPeerGroupSpec.scala index 430c50b3..18890f3d 100644 --- a/src/io/iohk/scalanet/test/peergroup/DTLSPeerGroupSpec.scala +++ b/src/io/iohk/scalanet/test/peergroup/DTLSPeerGroupSpec.scala @@ -107,8 +107,6 @@ object DTLSPeerGroupSpec { } } - - def dtlsPeerGroup[M]( config: Config )(implicit codec: Codec[M], bufferInstantiator: BufferInstantiator[ByteBuffer]): DTLSPeerGroup[M] = { diff --git a/src/io/iohk/scalanet/test/peergroup/TLSPeerGroupSpec.scala b/src/io/iohk/scalanet/test/peergroup/TLSPeerGroupSpec.scala index 8f43cb11..60777832 100644 --- a/src/io/iohk/scalanet/test/peergroup/TLSPeerGroupSpec.scala +++ b/src/io/iohk/scalanet/test/peergroup/TLSPeerGroupSpec.scala @@ -88,10 +88,9 @@ class TLSPeerGroupSpec extends FlatSpec with BeforeAndAfterAll { secondInbound.futureValue.to shouldBe alice.processAddress } - } -object TLSPeerGroupSpec{ +object TLSPeerGroupSpec { def signedCertConfig(alias: String): Config = { import scala.collection.JavaConverters._ @@ -101,21 +100,20 @@ object TLSPeerGroupSpec{ .asScala .toList - Config(aRandomAddress(),keyAt(alias),certChain, NetUtils.trustedCerts.toList) + Config(aRandomAddress(), keyAt(alias), certChain, NetUtils.trustedCerts.toList) } def selfSignedCertConfig(alias: String): Config = { - val key = keyStore.getKey(alias,"password".toCharArray).asInstanceOf[PrivateKey] + val key = keyStore.getKey(alias, "password".toCharArray).asInstanceOf[PrivateKey] val certChain = keyStore.getCertificateChain(alias).toList - val trustStore = List(keyStore.getCertificate("bob")) - Config(aRandomAddress(),key ,certChain, trustStore) + val trustStore = List(keyStore.getCertificate("bob")) + Config(aRandomAddress(), key, certChain, trustStore) } - def withTwoTLSPeerGroups[M](cgens: (String => Config)*)( - testCode: (TLSPeerGroup[M], TLSPeerGroup[M]) => Any + testCode: (TLSPeerGroup[M], TLSPeerGroup[M]) => Any )(implicit codec: Codec[M], bufferInstantiator: BufferInstantiator[ByteBuffer]): Unit = cgens.foreach { cgen => val pg1 = tlsPeerGroup[M](cgen("alice")) val pg2 = tlsPeerGroup[M](cgen("bob")) @@ -129,7 +127,9 @@ object TLSPeerGroupSpec{ } } - def tlsPeerGroup[M](config: Config)(implicit codec: Codec[M], bufferInstantiator: BufferInstantiator[ByteBuffer]): TLSPeerGroup[M] = { + def tlsPeerGroup[M]( + config: Config + )(implicit codec: Codec[M], bufferInstantiator: BufferInstantiator[ByteBuffer]): TLSPeerGroup[M] = { val pg = new TLSPeerGroup[M](config) Await.result(pg.initialize().runAsync, Duration.Inf) pg @@ -142,15 +142,14 @@ object TLSPeerGroupSpec{ val bobSc = new SelfSignedCertificate() keyStore.setCertificateEntry("alice", bobSc.cert()) - keyStore.setKeyEntry("alice",aliceSc.key(),"password".toCharArray,Array(aliceSc.cert())) + keyStore.setKeyEntry("alice", aliceSc.key(), "password".toCharArray, Array(aliceSc.cert())) keyStore.setCertificateEntry("bob", aliceSc.cert()) - keyStore.setKeyEntry("bob",bobSc.key(),"password".toCharArray,Array(bobSc.cert())) + keyStore.setKeyEntry("bob", bobSc.key(), "password".toCharArray, Array(bobSc.cert())) keyStore } - def keyAt(alias: String): PrivateKey = { NetUtils.keyStore.getKey(alias, "password".toCharArray).asInstanceOf[PrivateKey] }