-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Native Sockets TLS Client/Server support for linux #2939
Changes from 4 commits
861fed4
fb91fd6
b6a2f3c
a6c32fe
b8266d7
ade156a
b7425fc
3772f17
433a829
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,23 @@ | ||
kotlin.sourceSets { | ||
jvmAndNixMain { | ||
dependencies { | ||
api(project(":ktor-network")) | ||
api(project(":ktor-utils")) | ||
kotlin { | ||
linuxX64 { | ||
val main by compilations.getting { | ||
val openssl by cinterops.creating { | ||
defFile(project.file("linuxX64/interop/openssl.def")) | ||
} | ||
} | ||
} | ||
jvmTest { | ||
dependencies { | ||
api(project(":ktor-network:ktor-network-tls:ktor-network-tls-certificates")) | ||
api(libs.netty.handler) | ||
sourceSets { | ||
jvmAndNixMain { | ||
dependencies { | ||
api(project(":ktor-network")) | ||
api(project(":ktor-utils")) | ||
} | ||
} | ||
jvmTest { | ||
dependencies { | ||
api(project(":ktor-network:ktor-network-tls:ktor-network-tls-certificates")) | ||
api(libs.netty.handler) | ||
} | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.network.tls | ||
|
||
public class PKCS12Certificate( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. kdocs are missing |
||
public val path: String, | ||
public val password: (() -> CharArray)? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. consider adding default if password really can be null |
||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.network.tls | ||
|
||
/** | ||
* [TLSConfig] builder. | ||
*/ | ||
public actual class TLSConfigBuilder actual constructor(private val isClient: Boolean) { | ||
private var authenticationBuilder: TLSAuthenticationConfigBuilder? = null | ||
private var verificationBuilder: TLSVerificationConfigBuilder? = null | ||
|
||
/** | ||
* Custom server name for TLS server name extension. | ||
* See also: https://en.wikipedia.org/wiki/Server_Name_Indication | ||
*/ | ||
public actual var serverName: String? = null | ||
|
||
public actual fun authentication( | ||
privateKeyPassword: () -> CharArray, | ||
block: TLSAuthenticationConfigBuilder.() -> Unit | ||
) { | ||
authenticationBuilder = TLSAuthenticationConfigBuilder(privateKeyPassword).apply(block) | ||
} | ||
|
||
public actual fun verification( | ||
block: TLSVerificationConfigBuilder.() -> Unit | ||
) { | ||
verificationBuilder = TLSVerificationConfigBuilder().apply(block) | ||
} | ||
|
||
public actual fun takeFrom(other: TLSConfigBuilder) { | ||
serverName = other.serverName | ||
authenticationBuilder = other.authenticationBuilder | ||
} | ||
|
||
/** | ||
* Create [TLSConfig]. | ||
*/ | ||
public actual fun build(): TLSConfig = TLSConfig( | ||
isClient = isClient, | ||
serverName = serverName, | ||
authentication = authenticationBuilder?.build(), | ||
verification = verificationBuilder?.build() | ||
) | ||
} | ||
|
||
public actual class TLSAuthenticationConfigBuilder actual constructor( | ||
private val privateKeyPassword: () -> CharArray | ||
) { | ||
private var certificate: PKCS12Certificate? = null | ||
|
||
public actual fun pkcs12Certificate(certificatePath: String, certificatePassword: (() -> CharArray)?) { | ||
certificate = PKCS12Certificate(certificatePath, certificatePassword) | ||
} | ||
|
||
public actual fun build(): TLSAuthenticationConfig = TLSAuthenticationConfig( | ||
certificate, | ||
privateKeyPassword | ||
) | ||
} | ||
|
||
public actual class TLSVerificationConfigBuilder { | ||
private var certificate: PKCS12Certificate? = null | ||
|
||
public actual fun pkcs12Certificate(certificatePath: String, certificatePassword: (() -> CharArray)?) { | ||
certificate = PKCS12Certificate(certificatePath, certificatePassword) | ||
} | ||
|
||
public actual fun build(): TLSVerificationConfig = TLSVerificationConfig( | ||
certificate | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// ktlint-disable filename | ||
/* | ||
* Copyright 2014-2019 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.network.tls | ||
|
||
import io.ktor.utils.io.core.* | ||
|
||
public actual class TLSConfig( | ||
public actual val isClient: Boolean, | ||
public actual val serverName: String?, | ||
public actual val authentication: TLSAuthenticationConfig?, | ||
public actual val verification: TLSVerificationConfig?, | ||
) : Closeable { | ||
override fun close() { | ||
//NOOP | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. obsolete |
||
} | ||
} | ||
|
||
public actual class TLSAuthenticationConfig( | ||
public val certificate: PKCS12Certificate?, | ||
public val privateKeyPassword: () -> CharArray | ||
) | ||
|
||
public actual class TLSVerificationConfig( | ||
public val certificate: PKCS12Certificate?, | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* Copyright 2014-2022 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license. | ||
*/ | ||
|
||
package io.ktor.network.tls | ||
|
||
import io.ktor.network.sockets.* | ||
import kotlin.coroutines.* | ||
|
||
public actual suspend fun Connection.tls( | ||
coroutineContext: CoroutineContext, | ||
config: TLSConfig | ||
): Socket { | ||
error("TLS is not supported on Darwin platform.") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could we try adding other platofrms?