ext/openssl: add a dtls:// stream transport. Open as Draft.#22638
ext/openssl: add a dtls:// stream transport. Open as Draft.#22638GianfriAur wants to merge 18 commits into
Conversation
openssl: Add DTLS version floor and peer_fingerprint to dtls:// openssl: Validate peer_fingerprint openssl: Fix dtls:// non-blocking I/O, handshake timeout and tests
bukka
left a comment
There was a problem hiding this comment.
Hmm the amount of duplication is quite big. I think this is more a good PoC but it's very far from anything that we could merge. We might need to re-architecture the whole xp_ssl for this. I will need to do more research and thinking to see what would be the best way.
| return -1; | ||
| } | ||
|
|
||
| dtlssock->s.socket = php_network_connect_socket_to_host(host, (unsigned short)portno, |
There was a problem hiding this comment.
I don't think this is the right approach. We should re-use (and possibly extend if needed) the underlaying udp stream so it works in the same way as tls that is build on top tcp.
Thinking about it, we should really go with enable_crypto support from the beginning as it will mirror better the TLS code.
There was a problem hiding this comment.
Okay, great. I’ve already made an attempts. I’ll work on it over the next few days.
| return -1; | ||
| } | ||
| for (;;) { | ||
| int ret = DTLSv1_listen(ssl, client_addr); |
Okay, do you want me to try drafting an |
Yeah I think it would be actually better. |
|
Honestly I'm not a big fan of adding is_dgram to php_netstream_data_t, but I couldn't make dtls:// reuse the socket transport the clean way tls:// reuses it for tcp://. It comes down to an asymmetry in the generic socket transport. tls:// gets the reuse for free because TCP is the default socket type there — the comment in xp_socket.c even spells it out: That said, I'm not thrilled with it, if anyone has a cleaner idea, it's very welcome. |
058e4af to
afa54fe
Compare
Adds a
dtls://stream transport (with thedtlsv1.2://alias) toext/openssl:DTLS 1.2 over UDP from the stream API, both client and server. It is the datagram
counterpart of
tls://, with the samesslcontext options where they apply andthe same
Openssl\Sessionobject.Design. No core changes: it only registers the schemes in
ext/openssl,without touching
xp_ssl.cor the stream layer. It is a separate file(
xp_dtls.c) because DTLS is UDP whilexp_ssl.cis TCP, and to avoid risking aregression on the TLS path; it still follows
xp_ssl.c's patterns and style andreuses its shared primitives (
Openssl\Session). The server accept usesDTLSv1_listen(): a stateless cookie exchange (RFC 6347 §4.2.1) againstamplification and spoofing, with a constant-time compare. It is the stable API
present in every released OpenSSL and stays valid for 1.2 even when OpenSSL caps it
in favour of the new listener API for 1.3. The server is single-peer (one peer per
bind); multi-peer is future work.
Features (client and server): peer verification (
verify_peer,verify_peer_name,peer_name,cafile/capath,peer_fingerprint), mutualauthentication (
local_certwithpassphrase), session resumption(
session_dataon the client; an external cache viasession_new_cb/session_get_cb/session_remove_cbplussession_id_context/no_ticket/session_timeouton the server), keying material export (RFC 5705) and Path MTU(
dtls_link_mtu). The session,session_reused, protocol and cipher are exposedin
stream_get_meta_data()['crypto'].Tests. A
.phptsuite underext/openssl/tests/dtls_*(client againstopenssl s_server, PHP server and client against each other, server againstopenssl s_client): handshake and round-trip, verification by CA/name/fingerprint,mutual auth, robustness against bogus datagrams, keying material, MTU, and full
client- and server-side resumption.
Separate follow-ups (outside the scheme-only scope, they touch the core or
OpenSSL's listener API): a multi-peer server, factoring the code
shared between
xp_ssl.candxp_dtls.cinto anxp_common, andenable_cryptoon
udp://. There is also a small TODO:php_openssl_dtls_parse_ip_address()duplicates
parse_ip_address_ex()fromxp_socket.c.Discussed on internals: https://externals.io/message/131514.
TODO before removing Draft status
xp_commonwith shared methodsenable_crypto(overrideudp://, liketls://overtcp://)UPGRADINGandNEWSmaster, green suite, coding standards