Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start TLS_PSK_WITH_AES_128_CCM8 #76

Merged
merged 7 commits into from
Jul 2, 2019
Merged

Start TLS_PSK_WITH_AES_128_CCM8 #76

merged 7 commits into from
Jul 2, 2019

Conversation

Sean-Der
Copy link
Member

@Sean-Der Sean-Der commented Jun 30, 2019

@daenney This works 100% !OpenSSL <-> Pion and Pion <-> Pion

I am going on vacation on Tuesday, mind helping me catch corner cases etc...? Would love to get this merged and tagged :)

@Sean-Der Sean-Der requested a review from daenney June 30, 2019 10:04
@codecov-io
Copy link

codecov-io commented Jun 30, 2019

Codecov Report

Merging #76 into master will increase coverage by 0.74%.
The diff coverage is 78.67%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #76      +/-   ##
==========================================
+ Coverage   69.67%   70.42%   +0.74%     
==========================================
  Files          48       50       +2     
  Lines        2681     2847     +166     
==========================================
+ Hits         1868     2005     +137     
- Misses        579      600      +21     
- Partials      234      242       +8
Impacted Files Coverage Δ
handshake_message_server_hello.go 52.83% <0%> (ø) ⬆️
prf.go 62.83% <100%> (+2.08%) ⬆️
crypto_gcm.go 62.5% <100%> (-7.5%) ⬇️
crypto.go 61.11% <100%> (+5.55%) ⬆️
cipher_suite.go 97.01% <100%> (+0.09%) ⬆️
crypto_ccm.go 62.5% <62.5%> (ø)
client_handlers.go 81.25% <68%> (+1.39%) ⬆️
handshake_message_client_key_exchange.go 72.72% <71.42%> (+6.06%) ⬆️
conn.go 76.68% <72.72%> (+0.64%) ⬆️
cipher_suite_tls_psk_with_aes_128_ccm8.go 75% <75%> (ø)
... and 8 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b1c2af3...d3da74b. Read the comment docs.

We can decrypt what OpenSSL sends us, but OpenSSL
is unable to decrypt from us.

Relates to #45
Need to add tests still, but running dial/listen
against each other works!

Relates to #45
@Sean-Der Sean-Der force-pushed the issue-45 branch 2 times, most recently from 409f569 to b6ef63c Compare July 1, 2019 00:21
Expand e2e tests to cover PSK

Resolves #45
Include PSK support in README and add
two new examples

Resolves #45
Less edge cases to worry about

Resolves #45
@Sean-Der
Copy link
Member Author

Sean-Der commented Jul 1, 2019

@daenney @igolaizola

I am happy with this w/e I can get a review I would really appreciate it!

@daenney
Copy link
Member

daenney commented Jul 1, 2019

This is awesome, thank you so much! I'm currently also on vacay but I have access to the IoT equipment at home, so I'll try to test this today.

Copy link
Member

@igolaizola igolaizola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job!

conn.go Outdated Show resolved Hide resolved
@daenney
Copy link
Member

daenney commented Jul 1, 2019

I'm happy to say I've just managed to ping my IKEA Tradfri gateway with this! So this has been validated in protoduction 😄.

If anyone's looking on and would like to try it, here's the sample code:

package main

import (
	"fmt"
	"net"

	"github.com/dustin/go-coap"
	"github.com/pion/dtls"
)

func main() {
	addr := &net.UDPAddr{IP: net.ParseIP("gateway-ip"), Port: 5684}
	config := &dtls.Config{
		PSK: func(_ []byte) ([]byte, error) {
			return []byte("psk-on-bottom-of-gateway"), nil
		},
		PSKIdentityHint: []byte("Client_identity"), // For Tradfri Gateway the IdentityHint MUST be Client_identity
		CipherSuites:    []dtls.CipherSuiteID{dtls.TLS_PSK_WITH_AES_128_CCM8},
	}

	dtlsConn, err := dtls.Dial("udp", addr, config)
	if err != nil {
		panic(err)
	}
	defer dtlsConn.Close()

	req := coap.Message{
		Type:      coap.Confirmable,
		Code:      coap.GET,
		MessageID: 1,
		Token:     []byte{},
		Payload:   []byte{},
	} // This is a CoAP Ping, empty confirmable message

	data, err := req.MarshalBinary()
	if err != nil {
		panic(err)
	}

	_, err = dtlsConn.Write(data)
	if err != nil {
		panic(err)
	}

	resp := make([]byte, 2048)
	dtlsConn.Read(resp)
	msg, err := coap.ParseMessage(resp)
	if err != nil {
		panic(err)
	}
	fmt.Println(msg.MessageID)
	fmt.Println(msg.Type)
	fmt.Println(msg.Code)
	fmt.Println(msg.Token)
	fmt.Println(string(msg.Payload))

}

It'll output:

1
Acknowledgement
NotFound
[]
Not Found

@Sean-Der
Copy link
Member Author

Sean-Der commented Jul 1, 2019

@daenney that is awesome! So glad it works :)

Thanks for doing half the work, really glad we did this. I am hoping we can get pion/dtls good enough so it can get wide adoption/get the community around one Go implementation.

Print the hint to stdout, just so the user understands
the purpose of the passed value.

Resolves #45
ServerKeyExchange is optional for PSK, exclude
this message if PSKIdentityHint is nil

Resolves #45
@Sean-Der Sean-Der merged commit f5ceadd into master Jul 2, 2019
@daenney daenney deleted the issue-45 branch July 2, 2019 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants