My understanding of the authentication process. The host creates a secret
and a public api key
. The client is crypting the payload with the help of the secret, this is the signature. Then sends its public key, payload, signature to the host.
The host checks if the public key is allowed to do an operation and gets the secret according to the clients public key. With the help of the secret the host decrypts the signature and compares it to the payload.
Question
- Is the above process described correctly?
- How to decrypt the signature and compare it to the payload?
- Or am I supposed to crypt it in the same way as the client dos and compare it then?
- What exactly do the two steps
update
&digest
Node Docs
Client:
authenticate: (self)->
payload = 'AUTH' + moment()
signature = crypto.createHmac('sha384', WEBSOCKET_SECRET)
.update(payload)
.digest('hex')
data = {
event: 'auth',
apiKey: WEBSOCKET_KEY,
authSig: signature,
authPayload: payload
}
self.send self, data
Server:
hmac = crypto.createHmac('sha384', WEBSOCKET_SECRET)
hmac.on 'readable', () ->
data = hmac.read()
if (data)
console.log data, data.toString('utf-8')
# hmac.write(authPayload)
hmac.write(signature)
hmac.end()
Current Server Side Solution
authenticate: (authPublicKey, authSignature, authPayload)->
signature = crypto.createHmac('sha384', WEBSOCKET_SECRET)
.update(authPayload)
.digest('hex')
return authSignature == signature