-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for DTLS 1.2 Connection IDs
Updates pion/dtls dependency to bring in support for DTLS 1.2 Connection IDs. Signed-off-by: Daniel Mangum <[email protected]>
- Loading branch information
Showing
6 changed files
with
118 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"time" | ||
|
||
piondtls "github.com/pion/dtls/v2" | ||
"github.com/plgd-dev/go-coap/v3/dtls" | ||
) | ||
|
||
func main() { | ||
co, err := dtls.Dial("localhost:5684", &piondtls.Config{ | ||
PSK: func(hint []byte) ([]byte, error) { | ||
fmt.Printf("Server's hint: %s \n", hint) | ||
return []byte("test"), nil | ||
}, | ||
PSKIdentityHint: []byte("test@pilot-project-0df546"), | ||
CipherSuites: []piondtls.CipherSuiteID{piondtls.TLS_PSK_WITH_AES_128_CCM_8}, | ||
ConnectionIDGenerator: piondtls.OnlySendCIDGenerator(), | ||
}) | ||
if err != nil { | ||
log.Fatalf("Error dialing: %v", err) | ||
} | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second) | ||
defer cancel() | ||
resp, err := co.Get(ctx, "/hello") | ||
if err != nil { | ||
log.Fatalf("Error sending request: %v", err) | ||
} | ||
log.Printf("Response payload: %+v", resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"log" | ||
|
||
piondtls "github.com/pion/dtls/v2" | ||
coap "github.com/plgd-dev/go-coap/v3" | ||
"github.com/plgd-dev/go-coap/v3/message" | ||
"github.com/plgd-dev/go-coap/v3/message/codes" | ||
"github.com/plgd-dev/go-coap/v3/mux" | ||
) | ||
|
||
func handleA(w mux.ResponseWriter, r *mux.Message) { | ||
log.Printf("got message in handleA: %+v from %v\n", r, w.Conn().RemoteAddr()) | ||
err := w.SetResponse(codes.GET, message.TextPlain, bytes.NewReader([]byte("A hello world"))) | ||
if err != nil { | ||
log.Printf("cannot set response: %v", err) | ||
} | ||
} | ||
|
||
func handleB(w mux.ResponseWriter, r *mux.Message) { | ||
log.Printf("got message in handleB: %+v from %v\n", r, w.Conn().RemoteAddr()) | ||
customResp := w.Conn().AcquireMessage(r.Context()) | ||
defer w.Conn().ReleaseMessage(customResp) | ||
customResp.SetCode(codes.Content) | ||
customResp.SetToken(r.Token()) | ||
customResp.SetContentFormat(message.TextPlain) | ||
customResp.SetBody(bytes.NewReader([]byte("B hello world"))) | ||
err := w.Conn().WriteMessage(customResp) | ||
if err != nil { | ||
log.Printf("cannot set response: %v", err) | ||
} | ||
} | ||
|
||
func main() { | ||
m := mux.NewRouter() | ||
m.Handle("/a", mux.HandlerFunc(handleA)) | ||
m.Handle("/b", mux.HandlerFunc(handleB)) | ||
|
||
log.Fatal(coap.ListenAndServeDTLS("udp", ":5688", &piondtls.Config{ | ||
PSK: func(hint []byte) ([]byte, error) { | ||
fmt.Printf("Client's hint: %s \n", hint) | ||
return []byte{0xAB, 0xC1, 0x23}, nil | ||
}, | ||
PSKIdentityHint: []byte("Pion DTLS Client"), | ||
CipherSuites: []piondtls.CipherSuiteID{piondtls.TLS_PSK_WITH_AES_128_CCM_8}, | ||
ConnectionIDGenerator: piondtls.RandomCIDGenerator(8), | ||
}, m)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters