KtorTlsConnector
Opens TLS connections for coaps+tcp (RFC 8323 §8.2, §9.1) on ktor-network-tls, on the JVM and Android. The server is authenticated by certificate (the Certificate mode of RFC 8323 §9.1): its chain must be valid under TlsClientConfig.trust, the platform trust store by default, and name the host of the URI (RFC 9525 §6), and then pass TlsClientConfig.pinner if one is set; otherwise the handshake fails and nothing is sent. The connection reports that chain as its Connection.peerIdentity, a PeerIdentity.Certificate.
val client = CoapClient(listOf(KtorTcpConnector(), KtorTlsConnector()), scope)
client.get("coaps+tcp://coap.example.org/sensors/temp")What ktor-network-tls 3.6.1 offers, and so what this connector does, is narrower than RFC 8323 §9.1 allows:
TLS 1.2 only, in ktor's own implementation of it, not the JDK's; no TLS 1.3, no session resumption.
Only the ECDHE suites with AES-GCM (
TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256and..._256_GCM_SHA384, the same with RSA), as RFC 9325 §4.2 recommends; ktor's RSA key transport and CBC suites are left out. RFC 7925'sTLS_ECDHE_ECDSA_WITH_AES_128_CCM_8is not among ktor's suites.Without the extended master secret (RFC 7627) and the renegotiation indication (RFC 5746: neither the
renegotiation_infoextension norTLS_EMPTY_RENEGOTIATION_INFO_SCSV), which RFC 9325 §3.5 requires of TLS 1.2 implementations: ktor-network-tls sends neither. The attacks they prevent (triple handshake, renegotiation injection) need a renegotiation, a resumed session or a client certificate, and this connector uses none of them, so the risk is low; the JSSE client that ADR 0010 plans would close the gap.No ALPN: RFC 8323 §8.2 has the client offer
coapon every port but 5684, so a port other than 5684 is refused unless TlsClientConfig.allowsAnyPortWithoutAlpn is set.Certificates only: no PreSharedKey or RawPublicKey mode, and no client certificate.
On the JVM only. ktor-network-tls has no TLS on Linux native or Apple platforms, where its handshake throws "TLS sessions are not supported on Native platform" (docs/platforms.md).
Server Name Indication carries the host when it is a name, never an IP literal (RFC 6066 §3).
Parameters
the ktor selector to use; when null, the connector creates one on Dispatchers.IO and closes it in close.
Constructors
Properties
Functions
Connects to peer, runs the TLS handshake and returns the secure connection.