diff --git a/esptool/bin_image.py b/esptool/bin_image.py index 1fd5e3aa43..e5f5f11268 100644 --- a/esptool/bin_image.py +++ b/esptool/bin_image.py @@ -270,13 +270,24 @@ def maybe_patch_segment_data(self, f, segment_data): ) return segment_data - def save_segment(self, f, segment, checksum=None): + def save_segment(self, f, segment, checksum=None, segment_name=None): """ Save the next segment to the image file, return next checksum value if provided """ segment_data = self.maybe_patch_segment_data(f, segment.data) - f.write(struct.pack("= SIXTEEN_MB: + raise FatalError( + f"Invalid {segment_name} segment length {segment_len:#x}. The 16 MB limit has been exceeded." + ) + f.write(struct.pack(" tempfile.NamedTemporaryFile() # cannot be used for keyfile keyfile_name = os.path.join(keydir, "key.pem") - # We need to manually delete the keyfile as we are iterating over - # different schemes with the same keyfile so instead of using addCleanup, - # we remove it using os.remove at the end of each pass - for scheme in ["rsa3072", "ecdsa192", "ecdsa256", "ecdsa384"]: - args = self.GenerateKeyArgs("2", scheme, keyfile_name) - espsecure.generate_signing_key(args) + args = self.GenerateKeyArgs("2", scheme, keyfile_name) + espsecure.generate_signing_key(args) - with tempfile.NamedTemporaryFile() as pub_keyfile, open( - keyfile_name, "rb" - ) as keyfile: - args = self.ExtractKeyArgs("2", keyfile, pub_keyfile) - espsecure.extract_public_key(args) - os.remove(keyfile_name) + with tempfile.NamedTemporaryFile() as pub_keyfile, open( + keyfile_name, "rb" + ) as keyfile: + args = self.ExtractKeyArgs("2", keyfile, pub_keyfile) + espsecure.extract_public_key(args) class TestFlashEncryption(EspSecureTestCase): @@ -971,7 +844,7 @@ def test_digest_private_key(self): self.run_espsecure( "digest_private_key " - "--keyfile secure_images/ecdsa_secure_boot_signing_key.pem " + "--keyfile secure_images/ecdsa256_secure_boot_signing_key.pem " f"{outfile_name}" ) @@ -981,7 +854,7 @@ def test_digest_private_key(self): ) def test_digest_private_key_with_invalid_output(self, capsys): - fname = "secure_images/ecdsa_secure_boot_signing_key.pem" + fname = "secure_images/ecdsa256_secure_boot_signing_key.pem" with pytest.raises(subprocess.CalledProcessError): self.run_espsecure(f"digest_private_key --keyfile {fname} {fname}")