How to use verify_signature method in Kiwi

Best Python code snippet using Kiwi_python

test_espsecure.py

Source:test_espsecure.py Github

copy

Full Screen

...118 self._open('bootloader_unsigned_v2.bin'))119 espsecure.sign_data(args)120 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key.pem'),121 output_file)122 espsecure.verify_signature(args)123 def test_sign_v2_multiple_keys(self):124 # 3 keys + Verify with 3rd key125 with tempfile.NamedTemporaryFile() as output_file:126 args = self.SignArgs('2', [self._open('rsa_secure_boot_signing_key.pem'),127 self._open('rsa_secure_boot_signing_key2.pem'),128 self._open('rsa_secure_boot_signing_key3.pem')],129 output_file.name, False,130 self._open('bootloader_unsigned_v2.bin'))131 espsecure.sign_data(args)132 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key3.pem'),133 output_file)134 espsecure.verify_signature(args)135 output_file.seek(0)136 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key2.pem'),137 output_file)138 espsecure.verify_signature(args)139 output_file.seek(0)140 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key.pem'),141 output_file)142 espsecure.verify_signature(args)143 def test_sign_v2_append_signatures(self):144 # Append signatures + Verify with an appended key (bootloader_signed_v2.bin already signed with rsa_secure_boot_signing_key.pem)145 with tempfile.NamedTemporaryFile() as output_file:146 args = self.SignArgs('2', [self._open('rsa_secure_boot_signing_key2.pem'),147 self._open('rsa_secure_boot_signing_key3.pem')],148 output_file.name, True,149 self._open('bootloader_signed_v2.bin'))150 espsecure.sign_data(args)151 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key.pem'),152 output_file)153 espsecure.verify_signature(args)154 output_file.seek(0)155 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key2.pem'),156 output_file)157 espsecure.verify_signature(args)158 output_file.seek(0)159 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key3.pem'),160 output_file)161 espsecure.verify_signature(args)162 def test_sign_v2_append_signatures_multiple_steps(self):163 # similar to previous test, but sign in two invocations164 with tempfile.NamedTemporaryFile() as output_file1, tempfile.NamedTemporaryFile() as output_file2:165 args = self.SignArgs('2', [self._open('rsa_secure_boot_signing_key2.pem')],166 output_file1.name, True,167 self._open('bootloader_signed_v2.bin'))168 espsecure.sign_data(args)169 args = self.SignArgs('2', [self._open('rsa_secure_boot_signing_key3.pem')],170 output_file2.name, True,171 output_file1)172 espsecure.sign_data(args)173 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key.pem'),174 output_file2)175 espsecure.verify_signature(args)176 output_file2.seek(0)177 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key2.pem'),178 output_file2)179 espsecure.verify_signature(args)180 output_file2.seek(0)181 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key3.pem'),182 output_file2)183 espsecure.verify_signature(args)184 def test_verify_signature_signing_key(self):185 # correct key v1186 args = self.VerifyArgs('1', self._open('ecdsa_secure_boot_signing_key.pem'),187 self._open('bootloader_signed.bin'))188 espsecure.verify_signature(args)189 # correct key v2190 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key.pem'),191 self._open('bootloader_signed_v2.bin'))192 espsecure.verify_signature(args)193 # wrong key v1194 args = self.VerifyArgs('1', self._open('ecdsa_secure_boot_signing_key2.pem'),195 self._open('bootloader_signed.bin'))196 with self.assertRaises(esptool.FatalError) as cm:197 espsecure.verify_signature(args)198 self.assertIn("Signature is not valid", str(cm.exception))199 # wrong key v2200 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key2.pem'),201 self._open('bootloader_signed_v2.bin'))202 with self.assertRaises(esptool.FatalError) as cm:203 espsecure.verify_signature(args)204 self.assertIn("Signature could not be verified with the provided key.", str(cm.exception))205 # multi-signed wrong key v2206 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_key4.pem'),207 self._open('bootloader_multi_signed_v2.bin'))208 with self.assertRaises(esptool.FatalError) as cm:209 espsecure.verify_signature(args)210 self.assertIn("Signature could not be verified with the provided key.", str(cm.exception))211 def test_verify_signature_public_key(self):212 # correct key v1213 args = self.VerifyArgs('1', self._open('ecdsa_secure_boot_signing_pubkey.pem'),214 self._open('bootloader_signed.bin'))215 espsecure.verify_signature(args)216 # correct key v2217 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_pubkey.pem'),218 self._open('bootloader_signed_v2.bin'))219 espsecure.verify_signature(args)220 # wrong key v1221 args = self.VerifyArgs('1', self._open('ecdsa_secure_boot_signing_pubkey2.pem'),222 self._open('bootloader_signed.bin'))223 with self.assertRaises(esptool.FatalError) as cm:224 espsecure.verify_signature(args)225 self.assertIn("Signature is not valid", str(cm.exception))226 # wrong key v2227 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_pubkey2.pem'),228 self._open('bootloader_signed_v2.bin'))229 with self.assertRaises(esptool.FatalError) as cm:230 espsecure.verify_signature(args)231 self.assertIn("Signature could not be verified with the provided key.", str(cm.exception))232 # multi-signed wrong key v2233 args = self.VerifyArgs('2', self._open('rsa_secure_boot_signing_pubkey4.pem'),234 self._open('bootloader_multi_signed_v2.bin'))235 with self.assertRaises(esptool.FatalError) as cm:236 espsecure.verify_signature(args)237 self.assertIn("Signature could not be verified with the provided key.", str(cm.exception))238 def test_extract_binary_public_key(self):239 ExtractKeyArgs = namedtuple('extract_public_key_args',240 ['version', 'keyfile', 'public_keyfile'])241 with tempfile.NamedTemporaryFile() as pub_keyfile, tempfile.NamedTemporaryFile() as pub_keyfile2:242 args = ExtractKeyArgs('1', self._open('ecdsa_secure_boot_signing_key.pem'),243 pub_keyfile)244 espsecure.extract_public_key(args)245 args = ExtractKeyArgs('1', self._open('ecdsa_secure_boot_signing_key2.pem'),246 pub_keyfile2)247 espsecure.extract_public_key(args)248 pub_keyfile.seek(0)249 pub_keyfile2.seek(0)250 # use correct extracted public key to verify251 args = self.VerifyArgs('1', pub_keyfile, self._open('bootloader_signed.bin'))252 espsecure.verify_signature(args)253 # use wrong extracted public key to try and verify254 args = self.VerifyArgs('1', pub_keyfile2, self._open('bootloader_signed.bin'))255 with self.assertRaises(esptool.FatalError) as cm:256 espsecure.verify_signature(args)257 self.assertIn("Signature is not valid", str(cm.exception))258class ESP32FlashEncryptionTests(EspSecureTestCase):259 def test_encrypt_decrypt_bootloader(self):260 self._test_encrypt_decrypt('bootloader.bin',261 'bootloader-encrypted.bin',262 '256bit_key.bin',263 0x1000,264 0xf)265 def test_encrypt_decrypt_app(self):266 self._test_encrypt_decrypt('hello-world-signed.bin',267 'hello-world-signed-encrypted.bin',268 'ef-flashencryption-key.bin',269 0x20000,270 0xf)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Kiwi automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful