dtls

package module
v2.0.0-...-960f3f3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2020 License: MPL-2.0 Imports: 19 Imported by: 0

README

dtls

Build Status Coverage GoDoc License ReportCard

https://github.com/tartabit/dtls

This package implements a RFC-4347 compliant DTLS client and server. NOTE: This library is under active development and is not yet stable enough to be used in production.

Key Features

  • Pure go, no CGo
  • Supports both client and server via UDP
  • Supports TLS_PSK_WITH_AES_128_CCM_8 cipher RFC-6655
  • Supports pre-shared key authentication, does not support certificate based authentication
  • Supports DTLS session resumption
  • Designed for OMA LWM2M comliance LWM2M

TODO

  • Implement session renegotiation
  • Implement packet retransmission for handshake
  • Implement out of order handshake processing
  • Implement replay detection
  • Implement client hello stateless cookie handling
  • Improve parallel processing of incoming packets
  • Add interface for custom DTLS session cache storage

Samples

Keystore

	mks := keystore.NewMemoryKeyStore()
	keystore.SetKeyStores([]keystore.KeyStore{mks})
	psk, _ := hex.DecodeString("00112233445566")
	mks.AddKey("myIdentity", psk)

Sample Client

	listener, _ = NewUdpListener(":6000", time.Second*5)
	peer, err := listener.AddPeer("127.0.0.1:5684", "myIdentity")

	err = peer.Write("hello world")
	data, rsp := listener.Read()

Documentation

http://godoc.org/github.com/bocajim/dtls

License

Mozilla Public License Version 2.0

NOTE: License was changed from MIT on 11/20/2020.

Documentation

Overview

Package ccm implements a CCM, Counter with CBC-MAC as per RFC 3610.

See https://tools.ietf.org/html/rfc3610

Package ccm implements a CCM, Counter with CBC-MAC as per RFC 3610.

See https://tools.ietf.org/html/rfc3610

Index

Constants

View Source
const (
	AlertType_Warning                uint8 = 1
	AlertType_Fatal                  uint8 = 2
	AlertDesc_CloseNotify            uint8 = 0
	AlertDesc_UnexpectedMessage      uint8 = 10
	AlertDesc_BadRecordMac           uint8 = 20
	AlertDesc_DecryptionFailed       uint8 = 21
	AlertDesc_RecordOverflow         uint8 = 22
	AlertDesc_DecompressionFailure   uint8 = 30
	AlertDesc_HandshakeFailure       uint8 = 40
	AlertDesc_NoCertificate          uint8 = 41
	AlertDesc_BadCertificate         uint8 = 42
	AlertDesc_UnsupportedCertificate uint8 = 43
	AlertDesc_CertificateRevoked     uint8 = 44
	AlertDesc_CertificateExpired     uint8 = 45
	AlertDesc_CertificateUnknown     uint8 = 46
	AlertDesc_IllegalParameter       uint8 = 47
	AlertDesc_UnknownCa              uint8 = 48
	AlertDesc_AccessDenied           uint8 = 49
	AlertDesc_DecodeError            uint8 = 50
	AlertDesc_DecryptError           uint8 = 51
	AlertDesc_ExportRestriction      uint8 = 60
	AlertDesc_ProtocolVersion        uint8 = 70
	AlertDesc_InsufficientSecurity   uint8 = 71
	AlertDesc_InternalError          uint8 = 80
	AlertDesc_UserCanceled           uint8 = 90
	AlertDesc_NoRenegotiation        uint8 = 100
	AlertDesc_UnsupportedExtension   uint8 = 110
	AlertDesc_Noop                   uint8 = 254
)
View Source
const (
	LogLevelError string = "error"
	LogLevelWarn  string = "warn"
	LogLevelInfo  string = "info"
	LogLevelDebug string = "debug"
)
View Source
const (
	ContentType_ChangeCipherSpec ContentType = 20
	ContentType_Alert                        = 21
	ContentType_Handshake                    = 22
	ContentType_Appdata                      = 23
)
View Source
const (
	SessionType_Server string = "server"
	SessionType_Client string = "client"
)
View Source
const (
	AadAuthLen int = 13
)
View Source
const (
	DtlsVersion12 uint16 = 0xFEFD
)

Variables

View Source
var DebugEncryption bool = false
View Source
var DebugHandshake bool = false
View Source
var DebugHandshakeHash bool = false
View Source
var HandshakeCompleteCallback func(*Peer, string, time.Duration, error)

This callback is invoked each time a handshake completes, if the handshake failed, the reason is stored in error

View Source
var PeerInactivityTimeout = time.Hour * 24
View Source
var SessionCacheSweepInterval = time.Minute * -5

set to the interval to look for expired sessions

View Source
var SessionCacheTtl = time.Hour * 24

set to whatever you want the cache time to live to be

Functions

func DebugAll

func DebugAll()

func GetPskFromKeystore

func GetPskFromKeystore(identity string, remoteAddr string) []byte

func SessionCacheSize

func SessionCacheSize() int

func SetKeyStores

func SetKeyStores(ks []Keystore)

func SetLogFunc

func SetLogFunc(lf LogFunc)

func SetLogLevel

func SetLogLevel(level string)

Types

type CCM

type CCM interface {
	cipher.AEAD
	// MaxLength returns the maxium length of plaintext in calls to Seal.
	// The maximum length of ciphertext in calls to Open is MaxLength()+Overhead().
	// The maximum length is related to CCM's `L` parameter (15-noncesize) and
	// is 1<<(8*L) - 1 (but also limited by the maxium size of an int).
	MaxLength() int
}

CCM is a block cipher in Counter with CBC-MAC mode. Providing authenticated encryption with associated data via the cipher.AEAD interface.

func NewCCM

func NewCCM(b cipher.Block, tagsize, noncesize int) (CCM, error)

NewCCM returns the given 128-bit block cipher wrapped in CCM. The tagsize must be an even integer between 4 and 16 inclusive and is used as CCM's `M` parameter. The noncesize must be an integer between 7 and 13 inclusive, 15-noncesize is used as CCM's `L` parameter.

type Cipher

type Cipher interface {
	GetPrfSize() int
	GenerateKeyBlock(masterSecret []byte, rawKeyBlock []byte) *keyBlock
	Encrypt(rec *record, key []byte, iv []byte, mac []byte) ([]byte, error)
	Decrypt(rec *record, key []byte, iv []byte, mac []byte) ([]byte, error)
}

type CipherCBC

type CipherCBC struct {
	// contains filtered or unexported fields
}

func (CipherCBC) Decrypt

func (c CipherCBC) Decrypt(rec *record, key []byte, iv []byte, mac []byte) ([]byte, error)

func (CipherCBC) Encrypt

func (c CipherCBC) Encrypt(rec *record, key []byte, iv []byte, mac []byte) ([]byte, error)

func (CipherCBC) GenerateKeyBlock

func (c CipherCBC) GenerateKeyBlock(masterSecret []byte, rawKeyBlock []byte) *keyBlock

func (CipherCBC) GetPrfSize

func (c CipherCBC) GetPrfSize() int

type CipherCcm

type CipherCcm struct {
	// contains filtered or unexported fields
}

func (CipherCcm) Decrypt

func (c CipherCcm) Decrypt(rec *record, key []byte, iv []byte, mac []byte) ([]byte, error)

func (CipherCcm) Encrypt

func (c CipherCcm) Encrypt(rec *record, key []byte, iv []byte, mac []byte) ([]byte, error)

func (CipherCcm) GenerateKeyBlock

func (c CipherCcm) GenerateKeyBlock(masterSecret []byte, rawKeyBlock []byte) *keyBlock

func (CipherCcm) GetPrfSize

func (c CipherCcm) GetPrfSize() int

type CipherSuite

type CipherSuite uint16
const (
	CipherSuite_TLS_PSK_WITH_AES_128_CCM_8      CipherSuite = 0xC0A8
	CipherSuite_TLS_PSK_WITH_AES_128_CBC_SHA256 CipherSuite = 0x00ae
)

type CompressionMethod

type CompressionMethod uint8
const (
	CompressionMethod_Null CompressionMethod = 0
)

type ContentType

type ContentType uint8

type Keystore

type Keystore interface {
	GetPsk(identity string, remoteAddr string) ([]byte, error)
}

type KeystoreInMemory

type KeystoreInMemory struct {
	// contains filtered or unexported fields
}

func NewKeystoreInMemory

func NewKeystoreInMemory() *KeystoreInMemory

func (*KeystoreInMemory) AddKey

func (ks *KeystoreInMemory) AddKey(identity string, psk []byte)

func (*KeystoreInMemory) GetPsk

func (ks *KeystoreInMemory) GetPsk(identity string, remoteAddr string) ([]byte, error)

type Listener

type Listener struct {
	// contains filtered or unexported fields
}

func NewUdpListener

func NewUdpListener(listener string, readTimeout time.Duration) (*Listener, error)

func (*Listener) AddCipherSuite

func (l *Listener) AddCipherSuite(cipherSuite CipherSuite)

func (*Listener) AddCompressionMethod

func (l *Listener) AddCompressionMethod(compressionMethod CompressionMethod)

func (*Listener) AddPeer

func (l *Listener) AddPeer(addr string, identity string) (*Peer, error)

func (*Listener) AddPeerWithParams

func (l *Listener) AddPeerWithParams(params *PeerParams) (*Peer, error)

func (*Listener) CountPeers

func (l *Listener) CountPeers() int

func (*Listener) FindPeer

func (l *Listener) FindPeer(addr string) (*Peer, error)

func (*Listener) Read

func (l *Listener) Read() ([]byte, *Peer)

func (*Listener) RemovePeer

func (l *Listener) RemovePeer(peer *Peer, alertDesc uint8) error

func (*Listener) RemovePeerByAddr

func (l *Listener) RemovePeerByAddr(addr string, alertDesc uint8) error

func (*Listener) Shutdown

func (l *Listener) Shutdown() error

type LogFunc

type LogFunc func(ts time.Time, level string, peer *Peer, err error, msg string)

type Peer

type Peer struct {
	// contains filtered or unexported fields
}

func (*Peer) Close

func (p *Peer) Close(alertDesc uint8)

func (*Peer) LastActivity

func (p *Peer) LastActivity() time.Time

func (*Peer) Lock

func (p *Peer) Lock()

func (*Peer) Read

func (p *Peer) Read(timeout time.Duration) ([]byte, error)

func (*Peer) RemoteAddr

func (p *Peer) RemoteAddr() string

func (*Peer) SessionIdentity

func (p *Peer) SessionIdentity() string

func (*Peer) SetName

func (p *Peer) SetName(name string)

func (*Peer) Unlock

func (p *Peer) Unlock()

func (*Peer) UseQueue

func (p *Peer) UseQueue(en bool)

func (*Peer) Write

func (p *Peer) Write(data []byte) error

type PeerParams

type PeerParams struct {
	Addr             string
	Identity         string
	HandshakeTimeout time.Duration
	SessionId        []byte
}

type Transport

type Transport interface {
	Type() string
	Local() string
	Shutdown() error
	NewEndpoint(address string) TransportEndpoint
	ReadPacket() ([]byte, TransportEndpoint, error)
}

type TransportEndpoint

type TransportEndpoint interface {
	String() string
	WritePacket(data []byte) error
}

func NewUdpPeerFromSocket

func NewUdpPeerFromSocket(socket *net.UDPConn, addr *net.UDPAddr) TransportEndpoint

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL