Contenidos
Git https://github.com/jesusninoc/ServidorSSL
Crear un certificado auto-firmado
1 |
keytool -genkeypair -alias mycert -keyalg RSA -keysize 2048 -validity 3650 -keystore keystore.jks |
Servidor en Kotlin (es necesario instalar dependencias KTOR)
1 2 3 4 |
dependencies { implementation("io.ktor:ktor-server-netty:1.6.5") implementation("io.ktor:ktor-server-core:1.6.5") } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import io.ktor.application.* import io.ktor.features.* import io.ktor.http.* import io.ktor.response.* import io.ktor.routing.* import io.ktor.server.engine.* import io.ktor.server.netty.* import java.io.File import java.security.KeyStore fun main() { val keystoreFile = File("keystore.jks") val keystorePassword = "123456789" val privateKeyPassword = "123456789" // Load the keystore val keyStore = KeyStore.getInstance("JKS").apply { load(keystoreFile.inputStream(), keystorePassword.toCharArray()) } // Define the SSL connector configuration val environment = applicationEngineEnvironment { sslConnector( keyStore = keyStore, keyAlias = "mycert", keyStorePassword = { keystorePassword.toCharArray() }, privateKeyPassword = { privateKeyPassword.toCharArray() } ) { port = 8443 keyStorePath = keystoreFile.absoluteFile } module(Application::module) } embeddedServer(Netty, environment).start(wait = true) } fun Application.module() { install(CallLogging) routing { get("/") { call.respondText("<html><body><h1>Hello, world!</h1></body></html>", ContentType.Text.Html) } } } |

Petición desde Chrome al puerto configurado como seguro
