How can I validate a X-HW-SIGNATURE in PHP?
The documentation for request parameters reads:
Message header signature, which is mandatory, indicating the
signature information sent to your server that receives uplink messages.
There's also example data:
timestamp=1563105451261; nonce=:; value=E4YeOsnMtHZ6592U8B9S37238E+Hwtjfrmpf8AQXF+c=
The keys are:
timestamp: standard Unix timestampnonce: colonvalue: character string to be encrypted
This here is the part which I don't understand:
timestamp + nonce + Uplink message content: obtained after the encryption using the set password in HMAC-SHA256 algorithm and encoding in Base64.
How can I validate the message payload against the header signature?
What I've tried so far basically is:
private function parse_request_body(): void {
$this->rawBody = stream_get_contents(STDIN);
if (isset($_SERVER['X-HW-SIGNATURE']) && !empty($_SERVER['X-HW-SIGNATURE'])) {
if (! $this->hmac_verify( $this->rawBody, $_SERVER['X-HW-SIGNATURE'] )) {
// spoof message
}
}
}
private function hmac_verify( string $payload, string $signature ): bool {
// the problem obviously lies here ...
return true;
}



This is how i would go about verifying the signature. From my understanding from the doc. However it isn't 100% clear as they do not provide an example, which is a shame...
You should have (or be able to create one) a secret key within your Huawei account somewhere.