Skip to content

Fix keyids in the 1.0 spec - #43

Merged
lukpueh merged 1 commit into
theupdateframework:masterfrom
erickt:keyid
Oct 17, 2019
Merged

lukpueh merged 1 commit into
theupdateframework:masterfrom
erickt:keyid

Conversation

@erickt

@erickt erickt commented Apr 22, 2019 •

Copy link
Copy Markdown
Contributor

It looks like the sample Key IDs in the 1.0 spec were not updated to the TUF 1.0 algorithm. For example:

>>> key_meta = { "keytype": "ed25519", "keyval": { "public": "72378e5bc588793e58f81c8533da64a2e8f1565c1fcc7f253496394ffc52542c" } }
>>> key_update_data = securesystemslib.formats.encode_canonical(key_meta)
>>> digest_object = securesystemslib.hash.digest("sha256")
>>> digest_object.update(key_update_data.encode('utf-8'))
>>> digest_object.hexdigest()
'1a2b4110927d4cba257262f614896179ff85ca1f1353a41b5224ac474ca71cb4'
>>>
>>> key_meta = { "keytype": "ed25519", "scheme": "ed25519", "keyval": { "public": "72378e5bc588793e58f81c8533da64a2e8f1565c1fcc7f253496394ffc52542c" } }
>>> key_update_data = securesystemslib.formats.encode_canonical(key_meta)
>>> digest_object = securesystemslib.hash.digest("sha256")
>>> digest_object.update(key_update_data.encode('utf-8'))
>>> digest_object.hexdigest()
'1bf1c6e3cdd3d3a8420b19199e27511999850f4b376c4547b2f32fba7e80fca3'

This updates the keys to be calculated with the new algorithm, which includes the "method" in the key metadata.

edit: I was wrong, all the key ids were using the old algorithm. I updated this PR to also rewrite those key ids.

@erickt erickt changed the title Fix timestamp keyid Fix keyids in the 1.0 spec Apr 22, 2019
@lukpueh

lukpueh commented Oct 16, 2019

Copy link
Copy Markdown
Member

Thanks for the PR @erickt! I just extracted all the keys from the spec and generated new keyids.

I confirm that your patch correctly updates all occurrences of keyids of keys defined in the spec's exemplary root.json.

It does, however, not update the keyids for a key defined in targets.json, i.e.:

s/ce3e02e72980b09ca6f5efa68197130b381921e5d0675e2e0c8f3c47e0626bba/f761033eb880143c52358d941d987ca5577675090e2215e856ba0099bc0ce4f6/g

Do you want to make the change here, or should I submit a follow-up PR?

@lukpueh

lukpueh commented Oct 16, 2019

Copy link
Copy Markdown
Member

Btw. here's the script I used to re-gerneate the keys:

from securesystemslib.formats import encode_canonical
from securesystemslib.hash import digest

spec_keys = {
  '1a2b4110927d4cba257262f614896179ff85ca1f1353a41b5224ac474ca71cb4': {'keytype': 'ed25519', 'scheme': 'ed25519', 'keyval': {'public': '72378e5bc588793e58f81c8533da64a2e8f1565c1fcc7f253496394ffc52542c'}},
  '93ec2c3dec7cc08922179320ccd8c346234bf7f21705268b93e990d5273a2a3b': {'keytype': 'ed25519', 'scheme': 'ed25519', 'keyval': {'public': '68ead6e54a43f8f36f9717b10669d1ef0ebb38cee6b05317669341309f1069cb'}},
  'f2d5020d08aea06a0a9192eb6a4f549e17032ebefa1aa9ac167c1e3e727930d6': {'keytype': 'ed25519', 'scheme': 'ed25519', 'keyval': {'public': '66dd78c5c2a78abc6fc6b267ff1a8017ba0e8bfc853dd97af351949bba021275'}},
  'fce9cf1cc86b0945d6a042f334026f31ed8e4ee1510218f198e8d3f191d15309': {'keytype': 'ed25519', 'scheme': 'ed25519', 'keyval': {'public': '01c61f8dc7d77fcef973f4267927541e355e8ceda757e2c402818dad850f856e'}},
  'ce3e02e72980b09ca6f5efa68197130b381921e5d0675e2e0c8f3c47e0626bba': {'keytype': 'ed25519', 'scheme': 'ed25519', 'keyval': {'public': 'b6e40fb71a6041212a3d84331336ecaa1f48a0c523f80ccc762a034c727606fa'}}
  }


for old_keyid, key in spec_keys.items():
  canonical_key_bytes = encode_canonical(key).encode("utf-8")
  hasher = digest("sha256")
  hasher.update(canonical_key_bytes)
  new_keyid = hasher.hexdigest()

  print(old_keyid, " --> ", new_keyid)

It looks like the sample Key IDs in the 1.0 spec were not updated
to the TUF 1.0 algorithm. For example:

```
>>> key_meta = { "keytype": "ed25519", "keyval": { "public": "72378e5bc588793e58f81c8533da64a2e8f1565c1fcc7f253496394ffc52542c" } }
>>> key_update_data = securesystemslib.formats.encode_canonical(key_meta)
>>> digest_object = securesystemslib.hash.digest("sha256")
>>> digest_object.update(key_update_data.encode('utf-8'))
>>> digest_object.hexdigest()
'1a2b4110927d4cba257262f614896179ff85ca1f1353a41b5224ac474ca71cb4'
>>>
>>> key_meta = { "keytype": "ed25519", "scheme": "ed25519", "keyval": { "public": "72378e5bc588793e58f81c8533da64a2e8f1565c1fcc7f253496394ffc52542c" } }
>>> key_update_data = securesystemslib.formats.encode_canonical(key_meta)
>>> digest_object = securesystemslib.hash.digest("sha256")
>>> digest_object.update(key_update_data.encode('utf-8'))
>>> digest_object.hexdigest()
'1bf1c6e3cdd3d3a8420b19199e27511999850f4b376c4547b2f32fba7e80fca3'
```

This updates the keys to be calculated with the new algorithm,
which includes the `"method"` in the key metadata.
@lukpueh
lukpueh merged commit 1da6ead into theupdateframework:master Oct 17, 2019
@lukpueh

lukpueh commented Oct 17, 2019 •

Copy link
Copy Markdown
Member

@erickt, I just realized that I have push access to your branch. :) So I added the missing keyid update myself and amended your last commit. Thanks again for the contribution.

@erickt

erickt commented Oct 17, 2019

Copy link
Copy Markdown
Contributor Author

@lukpueh no problem! thanks for merging this in!

@erickt
erickt deleted the keyid branch October 17, 2019 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants