Skip to content

Commit

Permalink
Merge pull request #636 from openziti/fix-ssl-socket-wrapper
Browse files Browse the repository at this point in the history
implement handshake listeners, fix erroneous EOF return
  • Loading branch information
ekoby authored Sep 16, 2024
2 parents 965cbcc + f908c45 commit 85803af
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions ziti/src/main/kotlin/org/openziti/net/internal/ZitiSSLSocket.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class ZitiSSLSocket(val transport: Socket, val engine: SSLEngine) :
constructor(s: Socket, host: String, port: Int): this(s, tls.createSSLEngine(host, port))

private val sslBuffer: ByteBuffer = ByteBuffer.allocate(32 * 1024)
private val hsListeners = mutableListOf<HandshakeCompletedListener>()

init {
engine.useClientMode = true
Expand Down Expand Up @@ -114,7 +115,6 @@ class ZitiSSLSocket(val transport: Socket, val engine: SSLEngine) :
with(engine.unwrap(sslBuffer, plainBuffer)) {
sslBuffer.compact()
if (bytesProduced() > 0) {
plainBuffer.flip()
return copyPlainText(out, off, len)
}
}
Expand Down Expand Up @@ -194,6 +194,12 @@ class ZitiSSLSocket(val transport: Socket, val engine: SSLEngine) :
}
}

val ev = HandshakeCompletedEvent(this, engine.session)
synchronized(hsListeners) {
hsListeners.forEach {
it.handshakeCompleted(ev)
}
}
}

override fun getSession(): SSLSession {
Expand Down Expand Up @@ -243,11 +249,21 @@ class ZitiSSLSocket(val transport: Socket, val engine: SSLEngine) :
override fun getSupportedProtocols(): Array<String> = engine.supportedProtocols

override fun addHandshakeCompletedListener(listener: HandshakeCompletedListener?) {
error("not implemented")
listener?.let {
synchronized(hsListeners) {
hsListeners.add(it)
}
if (engine.handshakeStatus == SSLEngineResult.HandshakeStatus.NOT_HANDSHAKING)
listener.handshakeCompleted(HandshakeCompletedEvent(this, engine.session))
}
}

override fun removeHandshakeCompletedListener(listener: HandshakeCompletedListener?) {
error("not implemented")
listener?.let {
synchronized(hsListeners) {
hsListeners.remove(it)
}
}
}

override fun setEnableSessionCreation(flag: Boolean) {
Expand Down

0 comments on commit 85803af

Please sign in to comment.