Skip to content

Commit

Permalink
testcase mit https server
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon committed Nov 6, 2017
1 parent 6d2a912 commit 5552998
Show file tree
Hide file tree
Showing 18 changed files with 63 additions and 19 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.gradle
build
out
.idea
Expand Down
Binary file removed .gradle/4.3/fileChanges/last-build.bin
Binary file not shown.
Binary file removed .gradle/4.3/fileContent/annotation-processors.bin
Binary file not shown.
Binary file removed .gradle/4.3/fileContent/fileContent.lock
Binary file not shown.
Binary file removed .gradle/4.3/fileHashes/fileHashes.bin
Binary file not shown.
Binary file removed .gradle/4.3/fileHashes/fileHashes.lock
Binary file not shown.
Binary file removed .gradle/4.3/fileHashes/resourceHashesCache.bin
Binary file not shown.
Binary file removed .gradle/4.3/taskHistory/taskHistory.bin
Binary file not shown.
Binary file removed .gradle/4.3/taskHistory/taskHistory.lock
Binary file not shown.
Binary file removed .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 0 additions & 2 deletions .gradle/buildOutputCleanup/cache.properties

This file was deleted.

Binary file removed .gradle/buildOutputCleanup/outputFiles.bin
Binary file not shown.
6 changes: 3 additions & 3 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ In the following you can see some basic examples of using the Kotlin DSL for set
----
val fac = createSocketFactory {
keyManager {
open("certsandstores/clientkeystore") withPass "123456" beingA "jks"
open("certsandstores/clientkeystore") withPass "123456" ofType "jks"
}
trustManager {
open("certsandstores/myTruststore") withPass "123456" beingA "jks"
open("certsandstores/myTruststore") withPass "123456" ofType "jks"
}
sockets {
cipherSuites = listOf("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
Expand All @@ -52,7 +52,7 @@ In the following you can see some basic examples of using the Kotlin DSL for set
----
val fac = createServerSocketFactory {
keyManager {
open("certsandstores/clientkeystore") withPass "123456" beingA "jks"
open("certsandstores/clientkeystore") withPass "123456" ofType "jks"
}
}
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {

testCompile(kotlin("test-junit", kotlinVersion))
testCompile("junit:junit:4.11")
testCompile("org.eclipse.jetty:jetty-server:9.4.7.v20170914")
}

repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TLSSocketFactoryProvider(init: ProviderConfiguration.() -> Unit) {
return SSLContext.getInstance(protocols[0]).apply {
val kmConfig = config.kmConfig
val tmConfig = config.tmConfig
LOG.debug("Creating Factory with \n$kmConfig \n$tmConfig")
LOG.debug("Creating Factory with \nKeyManager: $kmConfig \nTrustManager: $tmConfig")

val keyManagerFactory = kmConfig?.let { conf ->
val defaultAlgorithm = KeyManagerFactory.getDefaultAlgorithm()
Expand Down Expand Up @@ -79,7 +79,7 @@ class Store(val name: String) {
password = pass.toCharArray()
}

infix fun beingA(type: String) = apply {
infix fun ofType(type: String) = apply {
fileType = type
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import de.swirtz.sekurity.api.socketFactory
fun main(args: Array<String>) {
val fac = socketFactory {
keyManager {
open("certsandstores/clientkeystore") withPass "123456" beingA "jks"
open("certsandstores/clientkeystore") withPass "123456" ofType "jks"
}
trustManager {
open("certsandstores/myTruststore") withPass "123456" beingA "jks"
open("certsandstores/myTruststore") withPass "123456" ofType "jks"
}
sockets {
cipherSuites = listOf("TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256", "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384",
Expand Down
60 changes: 52 additions & 8 deletions src/test/kotlin/de/swirtz/tslib/HttpsClientConnectionTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,70 @@ package de.swirtz.tslib

import de.swirtz.sekurity.api.socketFactory
import de.swirtz.sekurity.samples.HttpsClientConnection
import org.junit.Ignore
import org.eclipse.jetty.server.*
import org.eclipse.jetty.server.handler.AbstractHandler
import org.eclipse.jetty.util.ssl.SslContextFactory
import org.junit.After
import org.junit.Before
import org.junit.Test
import java.util.*
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import kotlin.test.assertEquals


class HttpsClientConnectionTest {
private val port = 9911

private val content = "<h1>Hello World</h1>"
private lateinit var server: Server

@Before
fun startJetty() {
server = Server(port).apply {
handler = object : AbstractHandler() {
override fun handle(target: String, baseRequest: Request, request: HttpServletRequest, response: HttpServletResponse) {
response.contentType = "text/html;charset=utf-8"
response.status = HttpServletResponse.SC_OK
baseRequest.isHandled = true
response.writer.println(content)
}
}

val factory = SslContextFactory().apply {
keyStorePath = "certsandstores/clientkeystore"
setKeyStorePassword("123456")
}
val sslConnector = ServerConnector(this, SslConnectionFactory(factory, "http/1.1"),
HttpConnectionFactory(HttpConfiguration().apply {
addCustomizer(SecureRequestCustomizer())
}))
sslConnector.port = port
connectors = arrayOf(sslConnector)

}
server.start()
}

@After
fun stopJetty() = server.stop()

@Ignore("Mock Server!")
@Test
fun testCreateConnection() {
val sf = socketFactory {
trustManager {
open("src/test/resources/truststore.jks") withPass "123456" beingA "jks"
open("certsandstores/myTruststore") withPass "123456" ofType "jks"
}
sockets {
timeout = 10_000
}
}
val inputStream = HttpsClientConnection(sf, 5000).createHttpsUrlConnection("https://192.168.3.214/connector.sds").inputStream
inputStream.use {
val s = java.util.Scanner(it).useDelimiter("\\A")
if (s.hasNext()) println(s.next())
}

HttpsClientConnection(sf, 5000).
createHttpsUrlConnection("https://localhost:$port/").inputStream.
use {
val s = Scanner(it).useDelimiter("\\A")
if (s.hasNext()) assertEquals(content, s.next().trim())
}
}
}
4 changes: 2 additions & 2 deletions src/test/kotlin/de/swirtz/tslib/TlsLibraryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TlsLibraryTest {
private fun createClientSocketFactory(): SSLSocketFactory {
val fac = socketFactory {
trustManager {
open("certsandstores/myTruststore") withPass "123456" beingA "jks"
open("certsandstores/myTruststore") withPass "123456" ofType "jks"
}
sockets {
timeout = 10_000
Expand All @@ -48,7 +48,7 @@ class TlsLibraryTest {
private fun startServer() {
val fac = serverSocketFactory {
keyManager {
open("certsandstores/clientkeystore") withPass "123456" beingA "jks"
open("certsandstores/clientkeystore") withPass "123456" ofType "jks"
}
sockets {
clientAuth = true
Expand Down

0 comments on commit 5552998

Please sign in to comment.