Re: [PATCH] selftests/sgx: fix EINIT failure dueto SGX_INVALID_SIGNATURE

From: Tianjia Zhang
Date: Wed Mar 03 2021 - 11:42:32 EST




On 3/2/21 8:51 PM, Jarkko Sakkinen wrote:
Nit: "due to"

Start with capital letter "Fix"


Will do in the next patch.

On Tue, Mar 02, 2021 at 01:06:52PM +0800, Tianjia Zhang wrote:


On 3/1/21 5:54 PM, Jarkko Sakkinen wrote:
On Mon, Mar 01, 2021 at 01:18:36PM +0800, Tianjia Zhang wrote:
q2 is not always 384-byte length. Sometimes it only has 383-byte.

What does determine this?

In this case, the valid portion of q2 is reordered reversely for
little endian order, and the remaining portion is filled with zero.

I'm presuming that you want to say "In this case, q2 needs to be reversed because...".

I'm lacking these details:

1. Why the length of Q2 can vary?
2. Why reversing the bytes is the correct measure to counter-measure
this variation?

/Jarkko


When use openssl to generate a key instead of using the built-in
sign_key.pem, there is a probability that will encounter this problem.

Here is a problematic key I encountered. The calculated q1 and q2 of this
key are both 383 bytes, If the length is not processed, the hardware
signature will fail.

Why is reversing bytes the correct way to fix the issue?


This is caused by the incorrect length of the reversed data. If the length of q2 is 383 bytes, the inversion will cause the first byte to be zero. For this, please refer to the signature tool in sgx sdk:

https://github.com/intel/linux-sgx/blob/master/sdk/sign_tool/SignTool/sign_tool.cpp#L381

If it can be repaired, it may be possible to use to generate sign_key.pem key on fly instead of using the static key.

Best regards,
Tianjia