plgd-dev / go-coap

Implementation of CoAP Server & Client in Go

Home Page:https://coap.technology

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get IdentityHint for request

nulopes opened this issue · comments

Hello, I've implemented a server using DTLS and PSK. Everything is working great but I would like to make sure about the identity of the client while processing the request. Is there any way of accessing the IdentityHint in the Handler? I've seen that in pion it is available in the ConnectionState() of the Conn struct, but didn't find a way to get to that. Am I missing something?

Thanks for your great work.

@nulopes You need to call func (cc *Conn) NetConn() net.Conn to get underlined connection:

       conn := c.NetConn()
       if tlsCon, ok := conn.(*tls.Conn); ok {
		peerCertificates := tlsCon.ConnectionState().PeerCertificates
		if len(peerCertificates) > 0 {
			...
                }
	}
	if tlsCon, ok := conn.(*dtls.Conn); ok {
		peerCertificates := tlsCon.ConnectionState().PeerCertificates
		if len(peerCertificates) > 0 {
                       ...
                }
        }

For example in our code: https://github.com/plgd-dev/hub/blob/72a50f0d1384ab77deb12432a9df8603b431f261/coap-gateway/service/service.go#L449

Closing for no response.