Errors because of removing trailing 0A and 0D bytes from HTTP responses
Dear ETSI ITS Team,
We are using the STF525 branch of the project to test our (Microsec's) V2X PKI infrastructure software. This is a great help and many thanks for building such a useful testing tool!
During our tests sometimes we get a message from the test suite as follows:
fx__decrypt__aes__128__ccm__test: Failed to decrypt message
As we investigated further, we saw that the error was that the last byte of the authTag was changed to 00. When the HTTP response was read, it contained either 0A (LF) or 0D (CR) as the last byte:
MTC@aa2a65190077: http_codec::decode_body: Aligned body='...0EB347CDCF7EEDE541E20E517455770D'O
MTC@aa2a65190077: http_codec::decode_body: counter=1
MTC@aa2a65190077: http_codec::decode_body: body length=331
MTC@aa2a65190077: http_codec::decode_body: Finalised body='...0EB347CDCF7EEDE541E20E51745577'O
As you can see, here we have already lost the last byte (0D). The authTag is incorrect too:
MTC@aa2a65190077: fx__decrypt__aes__128__ccm__test: tag: '0EB347CDCF7EEDE541E20E5174557700'O
The following code snippet removes trailing CR/LF bytes from HTTP responses, which may be incorrect and causes the above phenomenon:
// Remove CRLF if any
int counter = 0;
if ((body[body.lengthof() - 1].get_octet() == 0x0d) || (body[body.lengthof() - 1].get_octet() == 0x0a)) {
counter += 1;
if ((body[body.lengthof() - 2].get_octet() == 0x0d) || (body[body.lengthof() - 2].get_octet() == 0x0a)) {
counter += 1;
}
}
loggers::get_instance().log("http_codec::decode_body: counter=%d", counter);
How can we correctly transfer an HTTP response which contains trailing 0A or 0D bytes to the test system? Now the only solution is re-running the test to see the error message (probably) disappear.
Thanks in advance for your response,
BR,
Szilveszter Tóth
Microsec