mirror of https://github.com/wolfSSL/wolfTPM.git
fix keyload ecc 159 in CI: writeKeyBlob silent write failure
parent
4df63f1e88
commit
3f7db58943
|
|
@ -62,6 +62,11 @@ jobs:
|
|||
ip link set lo up
|
||||
make check
|
||||
'
|
||||
# make check runs as root via sudo -E unshare; restore ownership of
|
||||
# any files left in the workspace so later steps (running as the
|
||||
# unprivileged runner) can rewrite them — otherwise stale root-owned
|
||||
# blobs (e.g. eccblob.bin) silently break run_examples.sh later.
|
||||
sudo chown -R "$(id -u):$(id -g)" .
|
||||
|
||||
# ----- Tier 2: per-example standalone runs -----
|
||||
# Each example gets its own GitHub Actions check so a regression
|
||||
|
|
|
|||
|
|
@ -65,6 +65,8 @@ wait_for_port() {
|
|||
# Clean stale key blobs and certs from prior runs.
|
||||
# These depend on TPM NV state (SRK seed), so they're invalid after NV wipe.
|
||||
rm -f keyblob.bin rsa_test_blob.raw ecc_test_blob.raw
|
||||
rm -f eccblob.bin ecckeyblob.bin ecckeyblobeh.bin
|
||||
rm -f rsakeyblob.bin rsakeyblobeh.bin
|
||||
rm -f ./certs/tpm-rsa-cert.pem ./certs/tpm-ecc-cert.pem
|
||||
rm -f ./certs/tpm-rsa-cert.csr ./certs/tpm-ecc-cert.csr
|
||||
rm -f ./certs/server-rsa-cert.pem ./certs/server-ecc-cert.pem
|
||||
|
|
@ -273,7 +275,7 @@ if [ $WOLFCRYPT_ENABLE -eq 1 ]; then
|
|||
fi
|
||||
fi
|
||||
fi
|
||||
rm -f ececcblob.bin
|
||||
rm -f eccblob.bin
|
||||
|
||||
if [ $ENABLE_V185 -eq 1 ]; then
|
||||
echo -e "PQC Key Generation Tests (v1.85)"
|
||||
|
|
|
|||
|
|
@ -136,40 +136,54 @@ int readBin(const char* filename, byte *buf, word32* bufSz)
|
|||
int writeKeyBlob(const char* filename,
|
||||
WOLFTPM2_KEYBLOB* key)
|
||||
{
|
||||
int rc = 0;
|
||||
int rc = TPM_RC_FAILURE;
|
||||
#if !defined(NO_FILESYSTEM) && !defined(NO_WRITE_TEMP_FILES)
|
||||
XFILE fp = NULL;
|
||||
size_t fileSz = 0;
|
||||
size_t expectedSz;
|
||||
byte pubAreaBuffer[sizeof(TPM2B_PUBLIC)];
|
||||
int pubAreaSize;
|
||||
|
||||
fp = XFOPEN(filename, "wb");
|
||||
if (fp != XBADFILE) {
|
||||
/* Make publicArea in encoded format to eliminate empty fields,
|
||||
* save space */
|
||||
rc = TPM2_AppendPublic(pubAreaBuffer, (word32)sizeof(pubAreaBuffer),
|
||||
&pubAreaSize, &key->pub);
|
||||
if (rc != TPM_RC_SUCCESS) {
|
||||
XFCLOSE(fp);
|
||||
return rc;
|
||||
}
|
||||
if (pubAreaSize != (key->pub.size + (int)sizeof(key->pub.size))) {
|
||||
printf("writeKeyBlob: Sanity check for publicArea size failed\n");
|
||||
XFCLOSE(fp);
|
||||
return BUFFER_E;
|
||||
}
|
||||
#ifdef WOLFTPM_DEBUG_VERBOSE
|
||||
TPM2_PrintBin(pubAreaBuffer, pubAreaSize);
|
||||
#endif
|
||||
/* Write size marker for the public part */
|
||||
fileSz += XFWRITE(&key->pub.size, 1, sizeof(key->pub.size), fp);
|
||||
/* Write the public part with bytes aligned */
|
||||
fileSz += XFWRITE(pubAreaBuffer, 1, sizeof(UINT16) + key->pub.size, fp);
|
||||
/* Write the private part, size marker is included */
|
||||
fileSz += XFWRITE(&key->priv, 1, sizeof(UINT16) + key->priv.size, fp);
|
||||
XFCLOSE(fp);
|
||||
if (fp == XBADFILE) {
|
||||
printf("writeKeyBlob: cannot open %s for writing\n", filename);
|
||||
return TPM_RC_FAILURE;
|
||||
}
|
||||
|
||||
/* Make publicArea in encoded format to eliminate empty fields,
|
||||
* save space */
|
||||
rc = TPM2_AppendPublic(pubAreaBuffer, (word32)sizeof(pubAreaBuffer),
|
||||
&pubAreaSize, &key->pub);
|
||||
if (rc != TPM_RC_SUCCESS) {
|
||||
XFCLOSE(fp);
|
||||
return rc;
|
||||
}
|
||||
if (pubAreaSize != (key->pub.size + (int)sizeof(key->pub.size))) {
|
||||
printf("writeKeyBlob: Sanity check for publicArea size failed\n");
|
||||
XFCLOSE(fp);
|
||||
return BUFFER_E;
|
||||
}
|
||||
#ifdef WOLFTPM_DEBUG_VERBOSE
|
||||
TPM2_PrintBin(pubAreaBuffer, pubAreaSize);
|
||||
#endif
|
||||
/* Write size marker for the public part */
|
||||
fileSz += XFWRITE(&key->pub.size, 1, sizeof(key->pub.size), fp);
|
||||
/* Write the public part with bytes aligned */
|
||||
fileSz += XFWRITE(pubAreaBuffer, 1, sizeof(UINT16) + key->pub.size, fp);
|
||||
/* Write the private part, size marker is included */
|
||||
fileSz += XFWRITE(&key->priv, 1, sizeof(UINT16) + key->priv.size, fp);
|
||||
XFCLOSE(fp);
|
||||
|
||||
expectedSz = sizeof(key->pub.size)
|
||||
+ sizeof(UINT16) + key->pub.size
|
||||
+ sizeof(UINT16) + key->priv.size;
|
||||
printf("Wrote %d bytes to %s\n", (int)fileSz, filename);
|
||||
if (fileSz != expectedSz) {
|
||||
printf("writeKeyBlob: short write %d/%d to %s\n",
|
||||
(int)fileSz, (int)expectedSz, filename);
|
||||
return TPM_RC_FAILURE;
|
||||
}
|
||||
rc = TPM_RC_SUCCESS;
|
||||
#else
|
||||
(void)filename;
|
||||
(void)key;
|
||||
|
|
|
|||
Loading…
Reference in New Issue