MCPcopy Index your code
hub / github.com/pion/dtls

github.com/pion/dtls @v3.1.5

Chat with this repo
repository ↗ · DeepWiki ↗ · release v3.1.5 ↗ · + Follow
1,296 symbols 5,521 edges 229 files 673 documented · 52% 56 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Pion DTLS

A Go implementation of DTLS

Pion DTLS Sourcegraph Widget join us on Discord Follow us on Bluesky

GitHub Workflow Status Go Reference Coverage Status Go Report Card License: MIT

Native DTLS 1.2 implementation in the Go programming language.

A long term goal is a professional security review, and maybe an inclusion in stdlib.

[!WARNING] This branch is currently frozen from tagging while DTLS 1.3 work is underway.

DTLS 1.3 and breaking changes should target the main branch. Bug fixes and DTLS 1.2 improvments should target the v3 branch, which can be used for tags until DTLS 1.3 is ready.

RFCs

Implemented

Goals/Progress

This will only be targeting DTLS 1.2, and the most modern/common cipher suites. We would love contributions that fall under the 'Planned Features' and any bug fixes!

Current features

  • DTLS 1.2 Client/Server
  • Key Exchange via ECDHE(curve25519, nistp256, nistp384) and PSK
  • Packet loss and re-ordering is handled during handshaking
  • Key export (RFC 5705)
  • Serialization and Resumption of sessions
  • Extended Master Secret extension (RFC 7627)
  • ALPN extension (RFC 7301)

Supported ciphers

ECDHE
  • TLS_ECDHE_ECDSA_WITH_AES_128_CCM (RFC 6655)
  • TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8 (RFC 6655)
  • TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 (RFC 5289)
  • TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (RFC 5289)
  • TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 (RFC 5289)
  • TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (RFC 5289)
  • TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA (RFC 8422)
  • TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA (RFC 8422)
  • TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 (RFC 7905)
  • TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 (RFC 7905)
PSK
  • TLS_PSK_WITH_AES_128_CCM (RFC 6655)
  • TLS_PSK_WITH_AES_128_CCM_8 (RFC 6655)
  • TLS_PSK_WITH_AES_256_CCM_8 (RFC 6655)
  • TLS_PSK_WITH_AES_128_GCM_SHA256 (RFC 5487)
  • TLS_PSK_WITH_AES_128_CBC_SHA256 (RFC 5487)
  • TLS_PSK_WITH_CHACHA20_POLY1305_SHA256 (RFC 7905)
ECDHE & PSK
  • TLS_ECDHE_PSK_WITH_AES_128_CBC_SHA256 (RFC 5489)

Planned Features

Excluded Features

  • DTLS 1.0
  • Renegotiation
  • Compression

Using

This library needs at least Go 1.21, and you should have Go modules enabled.

Pion DTLS

For a DTLS 1.2 Server that listens on 127.0.0.1:4444

go run examples/listen/selfsign/main.go

For a DTLS 1.2 Client that connects to 127.0.0.1:4444

go run examples/dial/selfsign/main.go

OpenSSL

Pion DTLS can connect to itself and OpenSSL.

  // Generate a certificate
  openssl ecparam -out key.pem -name prime256v1 -genkey
  openssl req -new -sha256 -key key.pem -out server.csr
  openssl x509 -req -sha256 -days 365 -in server.csr -signkey key.pem -out cert.pem

  // Use with examples/dial/selfsign/main.go
  openssl s_server -dtls1_2 -cert cert.pem -key key.pem -accept 4444

  // Use with examples/listen/selfsign/main.go
  openssl s_client -dtls1_2 -connect 127.0.0.1:4444 -debug -cert cert.pem -key key.pem

Using with PSK

Pion DTLS also comes with examples that do key exchange via PSK

Pion DTLS

go run examples/listen/psk/main.go
go run examples/dial/psk/main.go

OpenSSL

  // Use with examples/dial/psk/main.go
  openssl s_server -dtls1_2 -accept 4444 -nocert -psk abc123 -cipher PSK-AES128-CCM8

  // Use with examples/listen/psk/main.go
  openssl s_client -dtls1_2 -connect 127.0.0.1:4444 -psk abc123 -cipher PSK-AES128-CCM8

Community

Pion has an active community on the Discord.

Follow the Pion Bluesky or Pion Twitter for project updates and important WebRTC news.

We are always looking to support your projects. Please reach out if you have something to build! If you need commercial support or don't want to use public methods you can contact us at team@pion.ly

Contributing

Check out the contributing wiki to join the group of amazing people making this project possible

Funding

NLnet foundation logo NLnet foundation logo

The DTLS 1.3 implementation in this project is funded through the NGI0 Commons Fund, a fund established by NLnet with financial support from the European Commission's Next Generation Internet programme, under the aegis of DG Communications Networks, Content and Technology under grant agreement No 101135429. Additional funding is made available by the Swiss State Secretariat for Education, Research and Innovation (SERI). Learn more on the NLnet project page.

License

MIT License - see LICENSE for full text

Extension points exported contracts — how you extend this code

CipherSuite (Interface)
CipherSuite is an interface that all DTLS CipherSuites must satisfy. [6 implementers]
cipher_suite.go
Message (Interface)
Message is the body of a Handshake datagram. [12 implementers]
pkg/protocol/handshake/handshake.go
PacketListener (Interface)
A PacketListener is the same as net.Listener but returns a net.PacketConn on Accept() rather than a net.Conn. Multiple [3 …
pkg/net/net.go
SessionStore (Interface)
SessionStore defines methods needed for session resumption. [1 implementers]
session.go
CCM (Interface)
CCM is a block cipher in Counter with CBC-MAC mode. Providing authenticated encryption with associated data via the ciph [1 …
pkg/crypto/ccm/ccm.go
ServerOption (Interface)
ServerOption configures a DTLS server.
options.go
PSKCallback (FuncType)
nolint:gochecknoglobals PSKCallback is called once we have the remote's PSKIdentityHint. If the remote provided none it
config.go
Extension (Interface)
Extension represents a single TLS extension. [19 implementers]
pkg/protocol/extension/extension.go

Core symbols most depended-on inside this repo

Equal
called by 362
pkg/protocol/version.go
Run
called by 180
handshaker.go
Close
called by 156
pkg/net/net.go
RemoteAddr
called by 91
conn.go
String
called by 70
cipher_suite.go
Check
called by 43
examples/util/util.go
Read
called by 38
conn.go
GenerateSelfSigned
called by 37
pkg/crypto/selfsign/selfsign.go

Shape

Function 644
Method 481
Struct 128
TypeAlias 23
Interface 13
FuncType 7

Languages

Go100%

Modules by API surface

options.go57 symbols
e2e/e2e_test.go54 symbols
conn_test.go54 symbols
conn.go53 symbols
pkg/protocol/errors.go25 symbols
internal/net/buffer_test.go22 symbols
cipher_suite.go22 symbols
pkg/protocol/handshake/message_certificate_13_test.go21 symbols
handshaker.go20 symbols
pkg/net/net.go18 symbols
internal/net/udp/packet_conn.go18 symbols
state.go16 symbols

For agents

$ claude mcp add dtls \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact