Skip to content
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

SslHandshakeTimeoutException with SslHandler #85

Open
ttsatsanis opened this issue Apr 13, 2020 · 0 comments
Open

SslHandshakeTimeoutException with SslHandler #85

ttsatsanis opened this issue Apr 13, 2020 · 0 comments

Comments

@ttsatsanis
Copy link

I am trying to make a new implementation of an ISO8583 (currently is builded on jpos) with a client requesting from a server. All this is based on an Spring Boot application with WebFlux and Netty server.

Until know, I have figured how to create an SslHandler but, although I use the same SSLContext as in the previous implementation (in jpos), I keep getting an SslHandshakeTimeoutException.

Additionally, in jpos implementation, I'm using the PADChannel as the server responds with a header.

Any help would be very appreciated:

        val c = ClientConfiguration.newBuilder()
                .addEchoMessageListener(true)
                .addLoggingHandler(true)
                .describeFieldsInLog()
                .workerThreadsCount(4)
                .replyOnError(true)
                .build()

        val s = Iso8583Client(InetSocketAddress(host, port), c, factory).apply {
            setConfigurer(object : ConnectorConfigurer<ClientConfiguration, Bootstrap> {
                override fun configurePipeline(pipeline: ChannelPipeline?, configuration: ClientConfiguration?) {
                    super.configurePipeline(pipeline, configuration)

                    val ks = KeyStore.getInstance("JKS").apply {
                        load(ClassPathResource("keystore.jks").inputStream, password.toCharArray())
                    }
                    val km = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()).apply {
                        init(ks, password.toCharArray())
                    }
                    val tm = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()).apply {
                        init(ks)
                    }
                    val ctx = SSLContext.getInstance("SSL").apply {
                        init(km.keyManagers, tm.trustManagers, SecureRandom.getInstance("SHA1PRNG"))
                    }

                    val handler = SslHandler(ctx.createSSLEngine().apply { useClientMode = true }).apply {
                        this.handshakeFuture().addListener { f ->
                            if(!f.isSuccess) println("SSL handsake failed" + f.cause().message)
                        }
                    }

                    pipeline?.addLast(handler, Iso8583Decoder(isoMessageFactory), Iso8583Encoder(0))
                }
            })

            addMessageListener(object : IsoMessageListener<IsoMessage> {
                override fun onMessage(p0: ChannelHandlerContext?, p1: IsoMessage?): Boolean {
                    println(p1?.debugString())
                    return true
                }

                override fun applies(p0: IsoMessage?): Boolean {
                    println(p0?.debugString())
                    return true
                }
            })
        }

        try {
            s.init()
            s.connect()

            if(s.isConnected) {
                println("connected...")
                s.send(factory.newMessage(0x9800))
            }
        } finally {
            s.disconnect()
        }
    }

The error message is obvious and there is no need to post it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant