Skip to content

Commit

Permalink
add tests for migrate_key script
Browse files Browse the repository at this point in the history
Legacy key files created with modified
`securesystemslib.interface.generate_and_write*` methods
(needed modification to write plain and encrypted key)

TODO:
- proof-read
- maybe dry/de-duplicate/shorten tests
- where should this script live?
  purpose is to be able to drop legacy modules, but depends on legacy
modules. sslib dependency must be pinned. could be removed with
interface, but referenced in doc? ...

Signed-off-by: Lukas Puehringer <[email protected]>
  • Loading branch information
lukpueh committed Oct 13, 2023
1 parent 08d7ae2 commit b044ba2
Show file tree
Hide file tree
Showing 10 changed files with 259 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/data/legacy/ecdsa_private_encrypted
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8fbf611c59332aebc82bdcf026fe4119@@@@100000@@@@307a043b7e82a3bf4421f6971e3c5af13570d6824e52e096ab653b877fc52e9f@@@@835eccefffb6b5492c53027a5a92e445@@@@c6513cceb8cb00fd117787a4a8e0331b55b24f7467e7ed881910954deecd23611fd09238a425052ee0fe5647cedaf42ee31e04a9233d368616f8f0668ebd2cc63bf8aa466f438d2aa671ebab9dc4fdacdd5600672480161f43318dd76410145fea99eaa4eb4ef36a4d903007461ac1f123beb72fbb2793ea1d0f7bf9199894d8af43dc880968e882ff5cc342bdebfb827e4158e74aa93b70164324c510aef94389ee4bac90c39277da0ff6a56d41d28e2f019ac90d7008a58e792064ad8e8800925a10bdf161159cc8169bc6bde07bce5b57ffbdaae3f90c825b2f4af9f8a58617f4fcd020922d5b1f6d8b6fe273e59627698acc80ccac5574a5254b1d4e2faae67daeee9dc36c673724d1663ada890a9176d2754eb75c6245f429df773b19b80ef0e18c076f159572acff26a51b15f302473638e08230d137246ab6cada40b26717dda3bd295d9df675f5d025230f9d67d79e70f94cd766abae8afff13f11bb2137e28bb0ed2b4e3675b6a3df707fd89a780ebf6c3c93834eecf7d2ff80240abf7d04957feb613554afb1fd5517320b422ef228608b87740ac2801bd4f9907ac018a9aeb51f36317736c54cc593712219dcf00af3a009ac5a0c762c69cc4d579c425f642f0053668bec77d65bb3f046ed090ebdc502c09fe83e68cc94355be96ec22bd3019043dc6a9e0a3acbb245e710caebc5df7b9ed1c81ec983b6b828f84f8487ac1b068ee8c2cbd91c411041a7a48a4fe59d10e55a7ee0bb276ddde9a3bbfe21bedfd50c094dc161034e3100dfa0309cca8bbe8178a8d5504741e1953075cc25922bca7f19284c51e85669be52687c9c005892c3331057964733b4d5c5b85bfb7bc31bc4a75fcd1f9cd121b19dd48cf5dc
1 change: 1 addition & 0 deletions tests/data/legacy/ecdsa_private_unencrypted
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"keytype": "ecdsa", "scheme": "ecdsa-sha2-nistp256", "keyid": "57b7afab61dfd16b96619bb8af6c55483eeade3aa68cf20ff8f0aa69a8bcc8d8", "keyval": {"public": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEx+6/aDen+X60RXLETPYz/H4U4qAY\neD/faCdpHBBmyip7xRiyWIrWljDmqcwLfv5wswrqdLF8M6hAdgYjIQZU/A==\n-----END PUBLIC KEY-----", "private": "-----BEGIN EC PRIVATE KEY-----\nMHcCAQEEIEm0tgzxA8OHiudMGqscqR4QpaJfxwwREqAD3rlSfXGJoAoGCCqGSM49\nAwEHoUQDQgAEx+6/aDen+X60RXLETPYz/H4U4qAYeD/faCdpHBBmyip7xRiyWIrW\nljDmqcwLfv5wswrqdLF8M6hAdgYjIQZU/A==\n-----END EC PRIVATE KEY-----"}, "keyid_hash_algorithms": ["sha256", "sha512"]}
1 change: 1 addition & 0 deletions tests/data/legacy/ecdsa_public
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"keytype": "ecdsa", "scheme": "ecdsa-sha2-nistp256", "keyid_hash_algorithms": ["sha256", "sha512"], "keyval": {"public": "-----BEGIN PUBLIC KEY-----\nMFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEx+6/aDen+X60RXLETPYz/H4U4qAY\neD/faCdpHBBmyip7xRiyWIrWljDmqcwLfv5wswrqdLF8M6hAdgYjIQZU/A==\n-----END PUBLIC KEY-----"}}
1 change: 1 addition & 0 deletions tests/data/legacy/ed25519_private_encrypted
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9ad267c7c10c74fb754b2d0811cadb6a@@@@100000@@@@06e3a7f38f26fc7c08d28e112fb6b53ab56b84c6214ac040bfcfdafb2fd7d221@@@@52d11d61e2e4ce57f39b3db799e72d24@@@@a5dc0ef8f4c7b1a87ab91c71eac39453004b36fea1284526bc109ae97f179bed1efd5d2a39f69c4a9f246b5ca6cc2e53366f830c11e5d2032c792dfd7f64bc87562b791ca1c1af1cedd245d438033d81688414c1ceaf0883f5cd604311978a60a5239b96fe2ff64ca1cc96becb8aefafe8600dda3b268249bc265cdbd086edbaaf53fd016109125e1dec784390cb8eb1501ccfcdbc4a4608ed8ffbbffd56ec7c97badea762b4a37f00dc7998da8c22c13b0125ffa91465262004a6ed1747a22074a3b32aac64e773f104538fa5032b7667a76f6963bd86d1ec7d3e83e2d59a070d3f558e27e6c8228080f0cc81d07dff2907ef617571ba1b18836743327579285844b1cc6e8ce809a092af8f6e1f7c8d27621348cc35698dec7e1dd82d9d5f07e89bc6d3e192fb1f7822d057265a30f36f18fe376c3c729335605e7d0e0fdbc3f30352f3a2ed94cba2f01f4df015957d
1 change: 1 addition & 0 deletions tests/data/legacy/ed25519_private_unencrypted
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"keytype": "ed25519", "scheme": "ed25519", "keyid": "cb2eea1134dac06c1ca2e94b1ffbd15c0bf9f0f541458f0a1df6968a900392f9", "keyid_hash_algorithms": ["sha256", "sha512"], "keyval": {"public": "167ced64cc9908b0bebb92df124d8d7fbe4298d41407524e8d238d0bcdd76c79", "private": "71fe1138357bf15b08723fd01af86deb5b58e4f469eb0acc9892e3c4cf9f4504"}}
1 change: 1 addition & 0 deletions tests/data/legacy/ed25519_public
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"keytype": "ed25519", "scheme": "ed25519", "keyid_hash_algorithms": ["sha256", "sha512"], "keyval": {"public": "167ced64cc9908b0bebb92df124d8d7fbe4298d41407524e8d238d0bcdd76c79"}}
42 changes: 42 additions & 0 deletions tests/data/legacy/rsa_private_encrypted
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
-----BEGIN RSA PRIVATE KEY-----
Proc-Type: 4,ENCRYPTED
DEK-Info: AES-256-CBC,5196BEDDC2BA3ECB973C1B15CF8BA8F0

x0B78cwIeX7UjVqxUPaCdRhx+QhXduEVUL970GNYOQpLwnYAjBgDCXXVwyxIinnC
Ho0Qyd1bMAmlfAttlbPBN1Bf3lWUaLj3Rc51Sscj4pVWla9Q24LRN+87QCF6D9W+
TpfAtwByGFVZarhLE+g3Nuknd6zS73N3fzfxlluQcVN+NvAYmECZTqhb12F83mhY
0nsNmQrhC5zw3XKb+Fe4CD2Ds3VAfMaZR+r+D6CjpYfznmhKX73cHEtvzamoSCA+
qiTWwOhfOTPO78SZBVcEPPgNVIX/cUs2kDQAkgPSGNtyj5ELKcarXg6zyu5Y95q2
K3ZdurduJYM5S7y9JHjx2HZfRvF5p3o4biWzYUlaETnVzkCTts8TppJU3BiCaYXQ
CF5dYCrhF5CosANdOiL8Nq7hvJX+4YMkIO1GwbRMKhM1DaFXWzimP3cUENWPblll
T5FUF5Jg62BpFSXlp1a6ypJEZzAIQJIGzBwJIx5kWkeDYkNL2+9z6kByarS0Dsr+
n1xtq2Gbx4k+4GPanbh4FycjxAoXFZQQxYa4AACHl0A4j2MzGdIRQQapgtyQJ8Hj
7cZ4OKOooZ393NCZRQ8dc3kST0IvOptLzzk/COZCkt2gmcgL/6eblp4fqpWc3rt7
9V9iMi7HZnA2lZjLBqT39A/QQX9J9F3CZTpLsc0D9inlUogC6s3JCIi00x+5TYlL
uJZjk26CX39nqKFFMeNRYessGDDltSFMrNbiGsOWhZmAILT7oYsCCtlCeSIvBSll
bA5pzw7xn+b1fOW1MSVqc6wQ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qhJNcQ50X/Bc2RnM05CA67z3w8aBgalnzVKAq
b4HEJkGnmJn48zqcy5n1DZQ0Ov+xrO8vLm8ycDnb8f+miTlgPj9ehm0hUgKMJTH4
JY21dBNpmbn6+n8q1s9Odli0vnSwTo5ZrCLSz8XXAoy1QYcVl/a26/aBuNH877AR
aajmD563wBUpq8YuqdHeT/K7QjrSBqmtUgI5Twqc59MfTMUBHnWvw/wPFO1pw8bm
cb38NI4oC4eJhpq6w0pr06e55go6WZLrxhOB0TaqOcFQUQxaeFhvH9a4d0AEfh1y
AS/mrR2ydLyhTr7yH4DZyce+ql565rKbrbznn5Uy9YdLSEJSnh2vYcs6EoUHZ6yY
OMeqou0B6g3JlrMWrpefRwo6repcnzBK5axfwwMLHwC0zljY8VP3sMpMn7gTtyKO
FbiMcLYhD9L19ud3xbd4azaJ5zkjxjkIqIEQmDsbzppLuKqjWpmvgCVRKnV2WVbG
pzvH365UnfkZd0lElil5EGxHtId1g1RiDRZMZvz5DeEPlt/BzmA+X/OJt0J83td/
-----END RSA PRIVATE KEY-----
39 changes: 39 additions & 0 deletions tests/data/legacy/rsa_private_unencrypted
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
-----BEGIN RSA PRIVATE KEY-----
MIIG5AIBAAKCAYEAwYSU3rVOgJV1uXPdkBK+Wkx09xMMEQE/xTQG0wX4tLOSeHSK
+/MwXeYw83DGYAsHEtEb57j/iNrVSESMEJfB9CT6YBLh6DfnZQnG5GS5f997t8c3
zyGM1fYzoBWaVakMVO2DoM8vxst/c2MU1BJXaG7hW+Tu5Kuz856YGmX8fV6eGvet
WaQM9iN6jRmSS6Wmt/2WXcnvzjV5OyetpkH2s8kT60x1zElKiZtmGvz2lnxBZWK3
uMBiBL8I52KZF+s9G65+shPJScYFKJ/NLVcMEaVDCghPay5bZ9pv6vqhylisLIs+
alJoxWriz8a7Pc1tW0pBsWrk53adtBaxscFe3kjiJblQWE19xDwjEVCGA1MmslY0
LFi2+R6SVcDDnNK7m0wc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pUkR5
UXIiVZ1p1drnS9Q9DFoGwQgx3GQuS1B12B3N1u5fBallXC/10aC2saYPOvkYa46q
HHmarjL+zC5Yh1nRbWhDzUhDM/xqF4hmNZnXcPsCgcEAz9jA5T1MTJPGVs0Hdf28
XYQXkBcAJ/Fp1+4Nzr2h1LISuFvoUrQKLU+3K8XVemKqewChYiiAfDxofrCGisIR
zJ/iOnDsXZ4psoo1t1MYdB+giy9Fu5Hq6ecoSXlMCjf7rN7bi7mnfJg411mkIC02
oBXMHWyQJbx7QoNmDFUS2NvzJxXfr+efm5OiEOd2oz6JJsKc0u3EHbgTIlBtCFEa
5GSKOPQiFlVdwz26m4ashyNcyWWjwC3iPL2mijRqpv3rAoHAPd8QRLL7v4AtTERq
ZC/lalpi5hAX1ETcmn7jFrst91sSukaNOLDmZRO410Ong/izl8gH2DfVim3cMiqh
rtxFoRZJlj6TpAST6ClywEkQXNdCAoT3E2YneQWbAEzss0N4SwvdpJYOCMdOH59/
DUmmXv6ifLsVL7UJvfsHjRBIUi6SYiohbNf6WlceOI6X6yWBoauXVm82eyXfWHZ1
BXM/5ZZTZar3QLxV4tQXSV+V0AktEhhONyjVpcX4zVJzbDzTAoHBAI8dFlW/FCwS
Y06NZgU7NwpdTDKagjYh/CTnX3rEoIOv23B+ODzpqE5Jfm7kyBeYZM93ssZO2AQQ
lTFzudVi9KsnLcxh0Cx9FQV1K7UTLKlnUsxEtDn3noM9k3Z0rcMouqTtFRbJ59GP
ozrM4V0wa9Vja/cv7MYgz0wwAckuLyBA3X23Djq+qJ0+LwgyLMpMaHIx1LtNDTzO
z8f448/i3dJh6fgqv1J1GpOH5VT2n6qr/DIucjAeypPRFwKTEQADIg==
-----END RSA PRIVATE KEY-----
11 changes: 11 additions & 0 deletions tests/data/legacy/rsa_public
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-----BEGIN PUBLIC KEY-----
MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAwYSU3rVOgJV1uXPdkBK+
Wkx09xMMEQE/xTQG0wX4tLOSeHSK+/MwXeYw83DGYAsHEtEb57j/iNrVSESMEJfB
9CT6YBLh6DfnZQnG5GS5f997t8c3zyGM1fYzoBWaVakMVO2DoM8vxst/c2MU1BJX
aG7hW+Tu5Kuz856YGmX8fV6eGvetWaQM9iN6jRmSS6Wmt/2WXcnvzjV5OyetpkH2
s8kT60x1zElKiZtmGvz2lnxBZWK3uMBiBL8I52KZF+s9G65+shPJScYFKJ/NLVcM
EaVDCghPay5bZ9pv6vqhylisLIs+alJoxWriz8a7Pc1tW0pBsWrk53adtBaxscFe
3kjiJblQWE19xDwjEVCGA1MmslY0LFi2+R6SVcDDnNK7m0wcaqy1OG1bQXSpZLn/
bNKE0NvT1SzrlRUojkcneiH6sJSWucXmoo5tL2+uzjEFM/xppW/leo72Umtgahlq
jhvFboJB0slG7ppwcrkuWYg1SejTHBt51jdvzsq6tVtdAgMBAAE=
-----END PUBLIC KEY-----
161 changes: 161 additions & 0 deletions tests/test_migrate_key.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
"""Test key migration script"""

import shutil
import sys
import tempfile
import unittest
from pathlib import Path
from unittest.mock import patch

from securesystemslib.exceptions import UnverifiedSignatureError
from securesystemslib.interface import (
import_privatekey_from_file,
import_publickeys_from_file,
)
from securesystemslib.migrate_key import main as migrate_key_cli
from securesystemslib.signer import CryptoSigner, SSlibKey, SSlibSigner


class TestMigrateKey(unittest.TestCase):
"""Test key migration and backwards compatibility of signatures."""

@classmethod
def setUpClass(cls):
cls.old_keys = Path(__file__).parent / "data" / "legacy"
cls.new_keys = Path(tempfile.mkdtemp())

# Migrate keys
for algo in ["rsa", "ecdsa", "ed25519"]:
with patch.object(
sys,
"argv",
[
"migrate_key.py",
"--type",
"private",
"--algo",
algo,
"--in",
str(cls.old_keys / f"{algo}_private_unencrypted"),
"--out",
str(cls.new_keys / f"{algo}_private_unencrypted"),
],
):
migrate_key_cli()

with patch.object(
sys,
"argv",
[
"migrate_key.py",
"--type",
"private",
"--algo",
algo,
"--in",
str(cls.old_keys / f"{algo}_private_encrypted"),
"--out",
str(cls.new_keys / f"{algo}_private_encrypted"),
"--password",
"password",
],
):
migrate_key_cli()

with patch.object(
sys,
"argv",
[
"migrate_key.py",
"--type",
"public",
"--algo",
algo,
"--in",
str(cls.old_keys / f"{algo}_public"),
"--out",
str(cls.new_keys / f"{algo}_public"),
],
):
migrate_key_cli()

@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.new_keys)

def test_encrypted_and_unencrypted(self):
for algo in ["rsa", "ecdsa", "ed25519"]:
# Load migrated public key
with open(self.new_keys / f"{algo}_public", "rb") as f:
public_key = SSlibKey.from_pem(f.read())

# Load unencrypted signing key
path = self.new_keys / f"{algo}_private_unencrypted"
uri = f"file:{path}?encrypted=false"
signer = CryptoSigner.from_priv_key_uri(uri, public_key)
signature = signer.sign(b"data")

# Load encrypted signing key
path = self.new_keys / f"{algo}_private_encrypted"
uri = f"file:{path}?encrypted=true"
signer_enc = CryptoSigner.from_priv_key_uri(
uri, public_key, lambda sec: "password"
)
signature_enc = signer_enc.sign(b"data")

self.assertIsNone(public_key.verify_signature(signature, b"data"))
self.assertIsNone(
public_key.verify_signature(signature_enc, b"data")
)

with self.assertRaises(UnverifiedSignatureError):
public_key.verify_signature(signature, b"not data")
with self.assertRaises(UnverifiedSignatureError):
public_key.verify_signature(signature_enc, b"not data")

def test_new_signature_verifies_with_old_key(self):
for algo in ["rsa", "ecdsa", "ed25519"]:
# Load legacy public key
legacy_key_dicts = import_publickeys_from_file(
[str(self.old_keys / f"{algo}_public")], [algo]
)
legacy_key_dict = list(legacy_key_dicts.values())[0]
legacy_public_key = SSlibKey.from_securesystemslib_key(
legacy_key_dict
)

# Load unencrypted signing key
path = self.new_keys / f"{algo}_private_unencrypted"
uri = f"file:{path}?encrypted=false"
signer = CryptoSigner.from_priv_key_uri(uri, legacy_public_key)
signature = signer.sign(b"data")

self.assertIsNone(
legacy_public_key.verify_signature(signature, b"data")
)
with self.assertRaises(UnverifiedSignatureError):
legacy_public_key.verify_signature(signature, b"not data")

def test_old_signature_verifies_with_new_key(self):
for algo in ["rsa", "ecdsa", "ed25519"]:
# Load legacy private key and create a signature
legacy_private_key = import_privatekey_from_file(
str(self.old_keys / f"{algo}_private_unencrypted"), algo
)
legacy_signer = SSlibSigner(legacy_private_key)
signature = legacy_signer.sign(b"data")

with open(self.new_keys / f"{algo}_public", "rb") as f:
# NOTE: keyid is not migrated
public_key = SSlibKey.from_pem(
f.read(), keyid=legacy_private_key["keyid"]
)

self.assertIsNone(public_key.verify_signature(signature, b"data"))
with self.assertRaises(UnverifiedSignatureError):
public_key.verify_signature(signature, b"not data")


# Run the unit tests.
if __name__ == "__main__":
unittest.main()

0 comments on commit b044ba2

Please sign in to comment.