Kinetic / kinetic-protocol

34 stars 21 forks source link

HMAC did not compare #35

Closed koolfunky closed 9 years ago

koolfunky commented 9 years ago

Hi,

I'm using the kinetic simulator to test my nodejs code. For computing me HMAC I'm doing this :

hmac =  crypto.createHmac('sha1', 'asdfasdf').update(Command.toBuffer()).digest('binary');

I tried with many digest : 'binary' 'hex' 'utf8'

where Command is the protobuf Command like :

           Message({
            "authType": 1,
            "hmacAuth": {
                "identity": 1,
                "hmac": hmac,
            },
            "commandBytes": Command.toBuffer(),
        });

but the kinetic simulator respond me :

status: { 
     code: 2,
     statusMessage: 'com.seagate.kinetic.simulator.lib.HeaderException:HMAC did not compare',
     detailedMessage: null 
}

I really don't understand because kinetic say in the doc :

Within a Kinetic PDU, the protobuf message encodes the specifics of the requested operation (or response). At a high level, each protobuf message contains:

Someone can help me to see why it's not working ?

garyballance commented 9 years ago

The HMAC is generated by performing a SHA1 over the size of the command (as a 4-byte big endian value) followed by the command. So, the problem I see is that you are not including the size of the command in the HMAC generation.

koolfunky commented 9 years ago

Thank you, Sorry I didn't see it in the documentation.