Search code examples
firebasenest-api

Firebase websocket protocol, am I missing something?


I am working on an experimental c# nest client using websockets on an embeded hardware. My problem is that nest doesn't seem to want to communicate with me after the initial handshake.

wss://developer-api.nest.com/.es?v=5 HTTP1.1

wssClient | Handshake header: Upgrade: websocket
wssClient | Handshake header: Connection: Upgrade
wssClient | Handshake header: Sec-WebSocket-Accept: 2TSbkk9Kv0soMbpA0fGrtQUWoyI=
wssClient | Handshake header:
wssClient | Expected sec key: 2TSbkk9Kv0soMbpA0fGrtQUWoyI=
wssClient | Response sec key: 2TSbkk9Kv0soMbpA0fGrtQUWoyI=
wssClient | Connected
nest-cli | connection state changed: Connected
wssClient | Text frame received: 81 7E 00 95 ..
nest-cli | < {"t":"c","d":{"t":"h","d":{"ts":1422883899173,"v":"5","h":"firebase-apiserver03-tah01-iad01.dapi.production.nest.com:9553","s":"session-425920698"}}}
nest-cli | > {"t":"d","d":{"r":1,"a":"auth","b":{"cred":"c.R...MK0"}}}
wssClient | Sending data frame: 81 7E 00 C2 ...

after the client sends the credential frame (just like the Firebase.js client) I get no reply from nest .. no redirection nor confirmation of authentication

is this behavior deliberate (somehow detects that its peer is not firebase) or I am doing something wrong ?

Thank you


Solution

  • I discovered my mistake the next day. The frames that are sent need to be masked.

    https://www.rfc-editor.org/rfc/rfc6455#section-5.3

    also.., a couple of headers are needed but I don't know exactly which ones (yet)
    I'll update my answer when I do.