Other Parts Discussed in Thread: UNIFLASH, AES-128
Tool/software:
Hi,
I want to verify a signature of an external file (OriginalFile, not in the filesystem).
I can get the signature via OTA, and the hash (SHA256) via UART or SPI.
Obs, the certificate is already in flash.
So, I have all the pieces needed, but I always get errors when closing the file (which is when the signature is verified).
Here is what I have so far:
- Perform OTA to get OriginalFileSignature.bin on the file system.
- Read the file into the variable signedHash[256].
- Get OriginalFileHash from other external source, put into unsignedHash[32].
Here is what I want to do:
- Create/Overwrite new secure file, called Data.bin.
- Write unsignedHash[32] to Data.bin.
- Close the file with signedHash[256] as the Signature, and CERTNAME pointing to the cert with the public key.
- If closed properly, then the signature has been verified.
So if it is successfully written/closed then the signature would be confirmed.
FileHandle = sl_FsOpen((unsigned char *)FileName,
SL_FS_CREATE | SL_FS_CREATE_SECURE | SL_FS_CREATE_MAX_SIZE( MaxSize ) | SL_FS_OVERWRITE ,
&MasterToken);
if(FileHandle >= 0)
{
RetValWriteToFile = sl_FsWrite(FileHandle, 0, &unsignedHash[0], sizeof(unsignedHash));
RetValCloseFile = sl_FsClose(FileHandle, CERTNAME, (const unsigned char *)&signedHash[0], sizeof(signedHash));
}
Display_printf(dispHandle, 0, 0, "The file [%s] opened: %s \t[%d] \n\rWrote To File: %s \t[%d] \n\rClosed/Verified: %s \t[%d]", FileName,
(FileHandle >= 0) ? "Successfully" : "Error", FileHandle,
(RetValWriteToFile > 0) ? "Successfully" : "Error", RetValWriteToFile,
(RetValCloseFile == 0) ? "OK" : "Not ok", RetValCloseFile);
I was not sure how the signature should be structured. In OpenSSL, I've tried the following.
(Note that <Data> is the <HashOfOriginalFile>)
- $ openssl dgst -sha256 -binary -sign <PrivateKey> -out <Signature> <Data>
- $ openssl dgst -sha1 -binary -sign <PrivateKey> -out <Signature> <Data>
- $ openssl dgst -sha256 -binary <Data> > <TempFile>
$ cat <Data> >> <TempFile>
$ openssl dgst -sha256 -binary -sign <PrivateKey> -out <Signature> <TempFile>
(this is the same way I verify the Image of the CC3235SF)
Then I turn the <Signature> into an array in c (like "uint8_t signedHash[256] = {0xF8, 0x2c, ...};" to test it).
So, basically, the <HashOfOriginalFile> is a normal secure file, but I have no Idea how to use them (except for the Image).
I have the "MasterToken=0" for now, since I do not know how to use/deal with it.
The error I get when closing the file is "-10289", meaning "SL_ERROR_FS_WRONG_SIGNATURE_SECURITY_ALERT",
but when I verify it directly with OpenSSL it works fine.
Would appreciate any help or suggestions on the issue!
Best Regards
David