Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
|
|
# Copyright 2020, New York University and the TUF contributors
|
|
|
|
|
# SPDX-License-Identifier: MIT OR Apache-2.0
|
2020-08-20 10:19:55 +00:00
|
|
|
""" Unit tests for api/metadata.py
|
2020-08-18 13:55:43 +00:00
|
|
|
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
"""
|
2020-08-18 13:55:43 +00:00
|
|
|
|
2020-08-18 15:04:55 +00:00
|
|
|
import json
|
2020-08-18 13:55:43 +00:00
|
|
|
import sys
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
import logging
|
|
|
|
|
import os
|
|
|
|
|
import shutil
|
|
|
|
|
import tempfile
|
|
|
|
|
import unittest
|
2020-10-28 14:31:03 +00:00
|
|
|
import copy
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
2020-09-03 13:28:36 +00:00
|
|
|
from datetime import datetime, timedelta
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
from dateutil.relativedelta import relativedelta
|
|
|
|
|
|
2020-11-19 12:45:09 +00:00
|
|
|
from tests import utils
|
2020-09-15 15:05:51 +00:00
|
|
|
|
2021-03-02 21:13:12 +00:00
|
|
|
import tuf.exceptions
|
|
|
|
|
from tuf.api.metadata import (
|
|
|
|
|
Metadata,
|
2020-11-24 10:49:58 +00:00
|
|
|
Root,
|
2021-03-02 21:13:12 +00:00
|
|
|
Snapshot,
|
|
|
|
|
Timestamp,
|
2021-04-26 11:29:43 +00:00
|
|
|
Targets,
|
|
|
|
|
Key,
|
2021-04-29 13:43:03 +00:00
|
|
|
Role,
|
2021-03-30 14:39:10 +00:00
|
|
|
MetaFile,
|
2021-03-30 15:13:16 +00:00
|
|
|
TargetFile,
|
2021-04-29 13:43:03 +00:00
|
|
|
Delegations,
|
|
|
|
|
DelegatedRole,
|
2021-03-02 21:13:12 +00:00
|
|
|
)
|
|
|
|
|
|
2021-02-09 14:36:49 +00:00
|
|
|
from tuf.api.serialization import (
|
|
|
|
|
DeserializationError
|
|
|
|
|
)
|
|
|
|
|
|
2021-03-04 09:51:45 +00:00
|
|
|
from tuf.api.serialization.json import (
|
|
|
|
|
JSONSerializer,
|
|
|
|
|
JSONDeserializer,
|
|
|
|
|
CanonicalJSONSerializer
|
|
|
|
|
)
|
|
|
|
|
|
2021-03-02 21:13:12 +00:00
|
|
|
from securesystemslib.interface import (
|
|
|
|
|
import_ed25519_publickey_from_file,
|
|
|
|
|
import_ed25519_privatekey_from_file
|
|
|
|
|
)
|
|
|
|
|
|
2021-02-03 16:46:02 +00:00
|
|
|
from securesystemslib.signer import (
|
|
|
|
|
SSlibSigner
|
|
|
|
|
)
|
|
|
|
|
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestMetadata(unittest.TestCase):
|
2020-08-31 14:13:59 +00:00
|
|
|
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
@classmethod
|
|
|
|
|
def setUpClass(cls):
|
2020-08-31 14:13:59 +00:00
|
|
|
# Create a temporary directory to store the repository, metadata, and
|
|
|
|
|
# target files. 'temporary_directory' must be deleted in
|
|
|
|
|
# TearDownClass() so that temporary files are always removed, even when
|
|
|
|
|
# exceptions occur.
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
cls.temporary_directory = tempfile.mkdtemp(dir=os.getcwd())
|
|
|
|
|
|
|
|
|
|
test_repo_data = os.path.join(
|
|
|
|
|
os.path.dirname(os.path.realpath(__file__)), 'repository_data')
|
|
|
|
|
|
|
|
|
|
cls.repo_dir = os.path.join(cls.temporary_directory, 'repository')
|
|
|
|
|
shutil.copytree(
|
|
|
|
|
os.path.join(test_repo_data, 'repository'), cls.repo_dir)
|
|
|
|
|
|
|
|
|
|
cls.keystore_dir = os.path.join(cls.temporary_directory, 'keystore')
|
|
|
|
|
shutil.copytree(
|
|
|
|
|
os.path.join(test_repo_data, 'keystore'), cls.keystore_dir)
|
|
|
|
|
|
2020-08-31 14:10:19 +00:00
|
|
|
# Load keys into memory
|
|
|
|
|
cls.keystore = {}
|
|
|
|
|
for role in ['delegation', 'snapshot', 'targets', 'timestamp']:
|
|
|
|
|
cls.keystore[role] = {
|
|
|
|
|
'private': import_ed25519_privatekey_from_file(
|
|
|
|
|
os.path.join(cls.keystore_dir, role + '_key'),
|
|
|
|
|
password="password"),
|
|
|
|
|
'public': import_ed25519_publickey_from_file(
|
|
|
|
|
os.path.join(cls.keystore_dir, role + '_key.pub'))
|
|
|
|
|
}
|
|
|
|
|
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def tearDownClass(cls):
|
2020-08-31 14:13:59 +00:00
|
|
|
# Remove the temporary repository directory, which should contain all
|
|
|
|
|
# the metadata, targets, and key files generated for the test cases.
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
shutil.rmtree(cls.temporary_directory)
|
|
|
|
|
|
|
|
|
|
|
2020-08-18 15:04:55 +00:00
|
|
|
def test_generic_read(self):
|
|
|
|
|
for metadata, inner_metadata_cls in [
|
2020-11-24 10:49:58 +00:00
|
|
|
('root', Root),
|
2020-08-31 14:13:59 +00:00
|
|
|
('snapshot', Snapshot),
|
|
|
|
|
('timestamp', Timestamp),
|
|
|
|
|
('targets', Targets)]:
|
2020-08-18 15:04:55 +00:00
|
|
|
|
2020-09-03 13:35:05 +00:00
|
|
|
# Load JSON-formatted metdata of each supported type from file
|
|
|
|
|
# and from out-of-band read JSON string
|
2020-08-18 15:04:55 +00:00
|
|
|
path = os.path.join(self.repo_dir, 'metadata', metadata + '.json')
|
2021-03-04 09:51:45 +00:00
|
|
|
metadata_obj = Metadata.from_file(path)
|
2020-09-03 13:35:05 +00:00
|
|
|
with open(path, 'rb') as f:
|
2021-04-16 13:12:15 +00:00
|
|
|
metadata_obj2 = Metadata.from_bytes(f.read())
|
2020-08-18 15:04:55 +00:00
|
|
|
|
2020-09-03 13:35:05 +00:00
|
|
|
# Assert that both methods instantiate the right inner class for
|
|
|
|
|
# each metadata type and ...
|
2020-08-18 15:04:55 +00:00
|
|
|
self.assertTrue(
|
|
|
|
|
isinstance(metadata_obj.signed, inner_metadata_cls))
|
2020-09-03 13:35:05 +00:00
|
|
|
self.assertTrue(
|
|
|
|
|
isinstance(metadata_obj2.signed, inner_metadata_cls))
|
|
|
|
|
|
2021-03-04 11:46:16 +00:00
|
|
|
# ... and return the same object (compared by dict representation)
|
|
|
|
|
self.assertDictEqual(
|
|
|
|
|
metadata_obj.to_dict(), metadata_obj2.to_dict())
|
2020-09-03 13:35:05 +00:00
|
|
|
|
2020-08-18 15:04:55 +00:00
|
|
|
# Assert that it chokes correctly on an unknown metadata type
|
|
|
|
|
bad_metadata_path = 'bad-metadata.json'
|
|
|
|
|
bad_metadata = {'signed': {'_type': 'bad-metadata'}}
|
2021-04-16 13:12:15 +00:00
|
|
|
bad_string = json.dumps(bad_metadata).encode('utf-8')
|
2020-08-18 15:04:55 +00:00
|
|
|
with open(bad_metadata_path, 'wb') as f:
|
2021-04-16 13:12:15 +00:00
|
|
|
f.write(bad_string)
|
2020-08-18 15:04:55 +00:00
|
|
|
|
2021-02-09 14:36:49 +00:00
|
|
|
with self.assertRaises(DeserializationError):
|
2021-03-04 09:51:45 +00:00
|
|
|
Metadata.from_file(bad_metadata_path)
|
2021-04-16 13:12:15 +00:00
|
|
|
with self.assertRaises(DeserializationError):
|
|
|
|
|
Metadata.from_bytes(bad_string)
|
2020-08-18 15:04:55 +00:00
|
|
|
|
|
|
|
|
os.remove(bad_metadata_path)
|
|
|
|
|
|
2020-08-31 14:13:59 +00:00
|
|
|
|
2020-08-19 08:40:58 +00:00
|
|
|
def test_compact_json(self):
|
|
|
|
|
path = os.path.join(self.repo_dir, 'metadata', 'targets.json')
|
2021-03-04 09:51:45 +00:00
|
|
|
metadata_obj = Metadata.from_file(path)
|
2020-08-19 08:40:58 +00:00
|
|
|
self.assertTrue(
|
2021-03-04 09:51:45 +00:00
|
|
|
len(JSONSerializer(compact=True).serialize(metadata_obj)) <
|
|
|
|
|
len(JSONSerializer().serialize(metadata_obj)))
|
2020-08-19 08:40:58 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_read_write_read_compare(self):
|
2020-11-24 10:49:58 +00:00
|
|
|
for metadata in ['root', 'snapshot', 'timestamp', 'targets']:
|
2020-08-19 08:40:58 +00:00
|
|
|
path = os.path.join(self.repo_dir, 'metadata', metadata + '.json')
|
2021-03-04 09:51:45 +00:00
|
|
|
metadata_obj = Metadata.from_file(path)
|
2020-08-19 08:40:58 +00:00
|
|
|
|
|
|
|
|
path_2 = path + '.tmp'
|
2021-03-04 09:51:45 +00:00
|
|
|
metadata_obj.to_file(path_2)
|
|
|
|
|
metadata_obj_2 = Metadata.from_file(path_2)
|
2020-08-19 08:40:58 +00:00
|
|
|
|
2021-03-04 11:46:16 +00:00
|
|
|
self.assertDictEqual(
|
|
|
|
|
metadata_obj.to_dict(),
|
|
|
|
|
metadata_obj_2.to_dict())
|
2020-08-19 08:40:58 +00:00
|
|
|
|
|
|
|
|
os.remove(path_2)
|
|
|
|
|
|
2020-08-18 15:04:55 +00:00
|
|
|
|
2020-08-31 14:10:19 +00:00
|
|
|
def test_sign_verify(self):
|
|
|
|
|
# Load sample metadata (targets) and assert ...
|
|
|
|
|
path = os.path.join(self.repo_dir, 'metadata', 'targets.json')
|
2021-03-04 09:51:45 +00:00
|
|
|
metadata_obj = Metadata.from_file(path)
|
2020-08-31 14:10:19 +00:00
|
|
|
|
|
|
|
|
# ... it has a single existing signature,
|
|
|
|
|
self.assertTrue(len(metadata_obj.signatures) == 1)
|
2020-09-08 15:28:50 +00:00
|
|
|
# ... which is valid for the correct key.
|
2020-08-31 14:10:19 +00:00
|
|
|
self.assertTrue(metadata_obj.verify(
|
|
|
|
|
self.keystore['targets']['public']))
|
|
|
|
|
|
2021-02-03 16:46:02 +00:00
|
|
|
sslib_signer = SSlibSigner(self.keystore['snapshot']['private'])
|
2020-08-31 14:10:19 +00:00
|
|
|
# Append a new signature with the unrelated key and assert that ...
|
2021-02-03 16:46:02 +00:00
|
|
|
metadata_obj.sign(sslib_signer, append=True)
|
2020-08-31 14:10:19 +00:00
|
|
|
# ... there are now two signatures, and
|
|
|
|
|
self.assertTrue(len(metadata_obj.signatures) == 2)
|
|
|
|
|
# ... both are valid for the corresponding keys.
|
|
|
|
|
self.assertTrue(metadata_obj.verify(
|
|
|
|
|
self.keystore['targets']['public']))
|
|
|
|
|
self.assertTrue(metadata_obj.verify(
|
|
|
|
|
self.keystore['snapshot']['public']))
|
|
|
|
|
|
2021-02-03 16:46:02 +00:00
|
|
|
sslib_signer.key_dict = self.keystore['timestamp']['private']
|
2020-08-31 14:10:19 +00:00
|
|
|
# Create and assign (don't append) a new signature and assert that ...
|
2021-02-03 16:46:02 +00:00
|
|
|
metadata_obj.sign(sslib_signer, append=False)
|
2020-08-31 14:10:19 +00:00
|
|
|
# ... there now is only one signature,
|
|
|
|
|
self.assertTrue(len(metadata_obj.signatures) == 1)
|
|
|
|
|
# ... valid for that key.
|
|
|
|
|
self.assertTrue(metadata_obj.verify(
|
|
|
|
|
self.keystore['timestamp']['public']))
|
|
|
|
|
|
2020-09-08 15:28:50 +00:00
|
|
|
# Assert exception if there are more than one signatures for a key
|
2021-02-03 16:46:02 +00:00
|
|
|
metadata_obj.sign(sslib_signer, append=True)
|
2020-09-08 15:28:50 +00:00
|
|
|
with self.assertRaises(tuf.exceptions.Error) as ctx:
|
|
|
|
|
metadata_obj.verify(self.keystore['timestamp']['public'])
|
|
|
|
|
self.assertTrue(
|
|
|
|
|
'2 signatures for key' in str(ctx.exception),
|
|
|
|
|
str(ctx.exception))
|
|
|
|
|
|
|
|
|
|
# Assert exception if there is no signature for a key
|
|
|
|
|
with self.assertRaises(tuf.exceptions.Error) as ctx:
|
|
|
|
|
metadata_obj.verify(self.keystore['targets']['public'])
|
|
|
|
|
self.assertTrue(
|
|
|
|
|
'no signature for' in str(ctx.exception),
|
|
|
|
|
str(ctx.exception))
|
2020-08-31 14:10:19 +00:00
|
|
|
|
|
|
|
|
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
def test_metadata_base(self):
|
|
|
|
|
# Use of Snapshot is arbitrary, we're just testing the base class features
|
|
|
|
|
# with real data
|
|
|
|
|
snapshot_path = os.path.join(
|
|
|
|
|
self.repo_dir, 'metadata', 'snapshot.json')
|
2021-03-04 09:51:45 +00:00
|
|
|
md = Metadata.from_file(snapshot_path)
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
|
|
|
|
self.assertEqual(md.signed.version, 1)
|
|
|
|
|
md.signed.bump_version()
|
|
|
|
|
self.assertEqual(md.signed.version, 2)
|
2020-09-03 13:28:36 +00:00
|
|
|
self.assertEqual(md.signed.expires, datetime(2030, 1, 1, 0, 0))
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
md.signed.bump_expiration()
|
2020-09-03 13:28:36 +00:00
|
|
|
self.assertEqual(md.signed.expires, datetime(2030, 1, 2, 0, 0))
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
md.signed.bump_expiration(timedelta(days=365))
|
2020-09-03 13:28:36 +00:00
|
|
|
self.assertEqual(md.signed.expires, datetime(2031, 1, 2, 0, 0))
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
2021-04-12 10:57:01 +00:00
|
|
|
# Test is_expired with reference_time provided
|
|
|
|
|
is_expired = md.signed.is_expired(md.signed.expires)
|
|
|
|
|
self.assertTrue(is_expired)
|
|
|
|
|
is_expired = md.signed.is_expired(md.signed.expires + timedelta(days=1))
|
|
|
|
|
self.assertTrue(is_expired)
|
|
|
|
|
is_expired = md.signed.is_expired(md.signed.expires - timedelta(days=1))
|
|
|
|
|
self.assertFalse(is_expired)
|
|
|
|
|
|
2021-05-12 11:35:32 +00:00
|
|
|
# Test is_expired without reference_time,
|
2021-04-12 10:57:01 +00:00
|
|
|
# manipulating md.signed.expires
|
|
|
|
|
expires = md.signed.expires
|
|
|
|
|
md.signed.expires = datetime.utcnow()
|
|
|
|
|
is_expired = md.signed.is_expired()
|
|
|
|
|
self.assertTrue(is_expired)
|
|
|
|
|
md.signed.expires = datetime.utcnow() + timedelta(days=1)
|
|
|
|
|
is_expired = md.signed.is_expired()
|
|
|
|
|
self.assertFalse(is_expired)
|
|
|
|
|
md.signed.expires = expires
|
2021-05-12 11:35:32 +00:00
|
|
|
|
2021-05-12 12:43:39 +00:00
|
|
|
|
|
|
|
|
def test_metafile_class(self):
|
|
|
|
|
# Test from_dict and to_dict with all attributes.
|
|
|
|
|
data = {
|
|
|
|
|
"hashes": {
|
|
|
|
|
"sha256": "8f88e2ba48b412c3843e9bb26e1b6f8fc9e98aceb0fbaa97ba37b4c98717d7ab"
|
|
|
|
|
},
|
|
|
|
|
"length": 515,
|
|
|
|
|
"version": 1
|
|
|
|
|
}
|
|
|
|
|
metafile_obj = MetaFile.from_dict(copy.copy(data))
|
|
|
|
|
self.assertEqual(metafile_obj.to_dict(), data)
|
|
|
|
|
|
|
|
|
|
# Test from_dict and to_dict without length.
|
|
|
|
|
del data["length"]
|
|
|
|
|
metafile_obj = MetaFile.from_dict(copy.copy(data))
|
|
|
|
|
self.assertEqual(metafile_obj.to_dict(), data)
|
|
|
|
|
|
|
|
|
|
# Test from_dict and to_dict without length and hashes.
|
|
|
|
|
del data["hashes"]
|
|
|
|
|
metafile_obj = MetaFile.from_dict(copy.copy(data))
|
|
|
|
|
self.assertEqual(metafile_obj.to_dict(), data)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_targetfile_class(self):
|
|
|
|
|
# Test from_dict and to_dict with all attributes.
|
|
|
|
|
data = {
|
|
|
|
|
"custom": {
|
|
|
|
|
"file_permissions": "0644"
|
|
|
|
|
},
|
|
|
|
|
"hashes": {
|
|
|
|
|
"sha256": "65b8c67f51c993d898250f40aa57a317d854900b3a04895464313e48785440da",
|
|
|
|
|
"sha512": "467430a68afae8e9f9c0771ea5d78bf0b3a0d79a2d3d3b40c69fde4dd42c461448aef76fcef4f5284931a1ffd0ac096d138ba3a0d6ca83fa8d7285a47a296f77"
|
|
|
|
|
},
|
|
|
|
|
"length": 31
|
|
|
|
|
}
|
|
|
|
|
targetfile_obj = TargetFile.from_dict(copy.copy(data))
|
|
|
|
|
self.assertEqual(targetfile_obj.to_dict(), data)
|
|
|
|
|
|
|
|
|
|
# Test from_dict and to_dict without custom.
|
|
|
|
|
del data["custom"]
|
|
|
|
|
targetfile_obj = TargetFile.from_dict(copy.copy(data))
|
|
|
|
|
self.assertEqual(targetfile_obj.to_dict(), data)
|
|
|
|
|
|
|
|
|
|
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
def test_metadata_snapshot(self):
|
|
|
|
|
snapshot_path = os.path.join(
|
|
|
|
|
self.repo_dir, 'metadata', 'snapshot.json')
|
2021-03-04 09:51:45 +00:00
|
|
|
snapshot = Metadata.from_file(snapshot_path)
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
2021-03-30 14:39:10 +00:00
|
|
|
# Create a MetaFile instance representing what we expect
|
|
|
|
|
# the updated data to be.
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
hashes = {'sha256': 'c2986576f5fdfd43944e2b19e775453b96748ec4fe2638a6d2f32f1310967095'}
|
2021-03-30 14:39:10 +00:00
|
|
|
fileinfo = MetaFile(2, 123, hashes)
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
2021-03-30 14:39:10 +00:00
|
|
|
self.assertNotEqual(
|
|
|
|
|
snapshot.signed.meta['role1.json'].to_dict(), fileinfo.to_dict()
|
|
|
|
|
)
|
2021-05-14 14:54:31 +00:00
|
|
|
snapshot.signed.update('role1', fileinfo)
|
2021-03-30 14:39:10 +00:00
|
|
|
self.assertEqual(
|
|
|
|
|
snapshot.signed.meta['role1.json'].to_dict(), fileinfo.to_dict()
|
|
|
|
|
)
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
2021-03-29 15:17:49 +00:00
|
|
|
# Test from_dict and to_dict without hashes and length.
|
|
|
|
|
snapshot_dict = snapshot.to_dict()
|
2021-03-30 14:39:10 +00:00
|
|
|
del snapshot_dict['signed']['meta']['role1.json']['length']
|
|
|
|
|
del snapshot_dict['signed']['meta']['role1.json']['hashes']
|
|
|
|
|
test_dict = copy.deepcopy(snapshot_dict['signed'])
|
2021-03-29 15:17:49 +00:00
|
|
|
snapshot = Snapshot.from_dict(test_dict)
|
|
|
|
|
self.assertEqual(snapshot_dict['signed'], snapshot.to_dict())
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
|
|
|
|
def test_metadata_timestamp(self):
|
|
|
|
|
timestamp_path = os.path.join(
|
|
|
|
|
self.repo_dir, 'metadata', 'timestamp.json')
|
2021-03-04 09:51:45 +00:00
|
|
|
timestamp = Metadata.from_file(timestamp_path)
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
|
|
|
|
self.assertEqual(timestamp.signed.version, 1)
|
|
|
|
|
timestamp.signed.bump_version()
|
|
|
|
|
self.assertEqual(timestamp.signed.version, 2)
|
|
|
|
|
|
2020-09-03 13:28:36 +00:00
|
|
|
self.assertEqual(timestamp.signed.expires, datetime(2030, 1, 1, 0, 0))
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
timestamp.signed.bump_expiration()
|
2020-09-03 13:28:36 +00:00
|
|
|
self.assertEqual(timestamp.signed.expires, datetime(2030, 1, 2, 0, 0))
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
timestamp.signed.bump_expiration(timedelta(days=365))
|
2020-09-03 13:28:36 +00:00
|
|
|
self.assertEqual(timestamp.signed.expires, datetime(2031, 1, 2, 0, 0))
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
|
|
|
|
# Test whether dateutil.relativedelta works, this provides a much
|
|
|
|
|
# easier to use interface for callers
|
|
|
|
|
delta = relativedelta(days=1)
|
|
|
|
|
timestamp.signed.bump_expiration(delta)
|
2020-09-03 13:28:36 +00:00
|
|
|
self.assertEqual(timestamp.signed.expires, datetime(2031, 1, 3, 0, 0))
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
delta = relativedelta(years=5)
|
|
|
|
|
timestamp.signed.bump_expiration(delta)
|
2020-09-03 13:28:36 +00:00
|
|
|
self.assertEqual(timestamp.signed.expires, datetime(2036, 1, 3, 0, 0))
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
2021-03-30 14:39:10 +00:00
|
|
|
# Create a MetaFile instance representing what we expect
|
|
|
|
|
# the updated data to be.
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
hashes = {'sha256': '0ae9664468150a9aa1e7f11feecb32341658eb84292851367fea2da88e8a58dc'}
|
2021-03-30 14:39:10 +00:00
|
|
|
fileinfo = MetaFile(2, 520, hashes)
|
2020-10-28 14:31:03 +00:00
|
|
|
|
2021-03-30 14:39:10 +00:00
|
|
|
self.assertNotEqual(
|
|
|
|
|
timestamp.signed.meta['snapshot.json'].to_dict(), fileinfo.to_dict()
|
|
|
|
|
)
|
2021-05-14 14:54:31 +00:00
|
|
|
timestamp.signed.update(fileinfo)
|
2021-03-30 14:39:10 +00:00
|
|
|
self.assertEqual(
|
|
|
|
|
timestamp.signed.meta['snapshot.json'].to_dict(), fileinfo.to_dict()
|
|
|
|
|
)
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
|
2021-03-29 15:17:49 +00:00
|
|
|
# Test from_dict and to_dict without hashes and length.
|
|
|
|
|
timestamp_dict = timestamp.to_dict()
|
2021-03-30 14:39:10 +00:00
|
|
|
del timestamp_dict['signed']['meta']['snapshot.json']['length']
|
|
|
|
|
del timestamp_dict['signed']['meta']['snapshot.json']['hashes']
|
|
|
|
|
test_dict = copy.deepcopy(timestamp_dict['signed'])
|
2021-03-29 15:17:49 +00:00
|
|
|
timestamp_test = Timestamp.from_dict(test_dict)
|
|
|
|
|
self.assertEqual(timestamp_dict['signed'], timestamp_test.to_dict())
|
|
|
|
|
|
2021-04-26 11:29:43 +00:00
|
|
|
def test_key_class(self):
|
|
|
|
|
keys = {
|
|
|
|
|
"59a4df8af818e9ed7abe0764c0b47b4240952aa0d179b5b78346c470ac30278d":{
|
|
|
|
|
"keytype": "ed25519",
|
|
|
|
|
"keyval": {
|
|
|
|
|
"public": "edcd0a32a07dce33f7c7873aaffbff36d20ea30787574ead335eefd337e4dacd"
|
|
|
|
|
},
|
|
|
|
|
"scheme": "ed25519"
|
2021-04-29 13:43:03 +00:00
|
|
|
},
|
2021-04-26 11:29:43 +00:00
|
|
|
}
|
|
|
|
|
for key_dict in keys.values():
|
|
|
|
|
# Testing that the workflow of deserializing and serializing
|
|
|
|
|
# a key dictionary doesn't change the content.
|
|
|
|
|
test_key_dict = key_dict.copy()
|
|
|
|
|
key_obj = Key.from_dict(test_key_dict)
|
|
|
|
|
self.assertEqual(key_dict, key_obj.to_dict())
|
|
|
|
|
# Test creating an instance without a required attribute.
|
|
|
|
|
for key in key_dict.keys():
|
|
|
|
|
test_key_dict = key_dict.copy()
|
|
|
|
|
del test_key_dict[key]
|
|
|
|
|
with self.assertRaises(KeyError):
|
|
|
|
|
Key.from_dict(test_key_dict)
|
|
|
|
|
# Test creating a Key instance with wrong keyval format.
|
|
|
|
|
key_dict["keyval"] = {}
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
Key.from_dict(key_dict)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_role_class(self):
|
|
|
|
|
roles = {
|
|
|
|
|
"root": {
|
|
|
|
|
"keyids": [
|
|
|
|
|
"4e777de0d275f9d28588dd9a1606cc748e548f9e22b6795b7cb3f63f98035fcb"
|
|
|
|
|
],
|
|
|
|
|
"threshold": 1
|
|
|
|
|
},
|
|
|
|
|
"snapshot": {
|
|
|
|
|
"keyids": [
|
|
|
|
|
"59a4df8af818e9ed7abe0764c0b47b4240952aa0d179b5b78346c470ac30278d"
|
|
|
|
|
],
|
|
|
|
|
"threshold": 1
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
for role_dict in roles.values():
|
|
|
|
|
# Testing that the workflow of deserializing and serializing
|
|
|
|
|
# a role dictionary doesn't change the content.
|
|
|
|
|
test_role_dict = role_dict.copy()
|
|
|
|
|
role_obj = Role.from_dict(test_role_dict)
|
|
|
|
|
self.assertEqual(role_dict, role_obj.to_dict())
|
|
|
|
|
# Test creating an instance without a required attribute.
|
|
|
|
|
for role_attr in role_dict.keys():
|
|
|
|
|
test_role_dict = role_dict.copy()
|
|
|
|
|
del test_role_dict[role_attr]
|
|
|
|
|
with self.assertRaises(KeyError):
|
|
|
|
|
Key.from_dict(test_role_dict)
|
|
|
|
|
# Test creating a Role instance with keyid dublicates.
|
|
|
|
|
# for keyid in role_dict["keyids"]:
|
|
|
|
|
role_dict["keyids"].append(role_dict["keyids"][0])
|
|
|
|
|
test_role_dict = role_dict.copy()
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
Role.from_dict(test_role_dict)
|
|
|
|
|
|
|
|
|
|
|
2020-10-28 14:37:01 +00:00
|
|
|
def test_metadata_root(self):
|
|
|
|
|
root_path = os.path.join(
|
|
|
|
|
self.repo_dir, 'metadata', 'root.json')
|
2021-03-04 09:51:45 +00:00
|
|
|
root = Metadata.from_file(root_path)
|
2020-10-28 14:37:01 +00:00
|
|
|
|
|
|
|
|
# Add a second key to root role
|
|
|
|
|
root_key2 = import_ed25519_publickey_from_file(
|
|
|
|
|
os.path.join(self.keystore_dir, 'root_key2.pub'))
|
|
|
|
|
|
2021-05-12 11:35:32 +00:00
|
|
|
|
2020-10-28 14:37:01 +00:00
|
|
|
keyid = root_key2['keyid']
|
2021-05-12 11:35:32 +00:00
|
|
|
key_metadata = Key(root_key2['keytype'], root_key2['scheme'],
|
|
|
|
|
root_key2['keyval'])
|
2020-10-28 14:37:01 +00:00
|
|
|
|
|
|
|
|
# Assert that root does not contain the new key
|
2021-04-20 11:16:19 +00:00
|
|
|
self.assertNotIn(keyid, root.signed.roles['root'].keyids)
|
2020-10-28 14:37:01 +00:00
|
|
|
self.assertNotIn(keyid, root.signed.keys)
|
|
|
|
|
|
|
|
|
|
# Add new root key
|
|
|
|
|
root.signed.add_key('root', keyid, key_metadata)
|
|
|
|
|
|
|
|
|
|
# Assert that key is added
|
2021-04-20 11:16:19 +00:00
|
|
|
self.assertIn(keyid, root.signed.roles['root'].keyids)
|
2020-10-28 14:37:01 +00:00
|
|
|
self.assertIn(keyid, root.signed.keys)
|
|
|
|
|
|
2021-05-12 11:35:32 +00:00
|
|
|
# Confirm that the newly added key does not break
|
|
|
|
|
# the object serialization
|
|
|
|
|
root.to_dict()
|
|
|
|
|
|
2021-04-28 10:01:41 +00:00
|
|
|
# Try adding the same key again and assert its ignored.
|
|
|
|
|
pre_add_keyid = root.signed.roles['root'].keyids.copy()
|
|
|
|
|
root.signed.add_key('root', keyid, key_metadata)
|
|
|
|
|
self.assertEqual(pre_add_keyid, root.signed.roles['root'].keyids)
|
|
|
|
|
|
2020-10-28 14:37:01 +00:00
|
|
|
# Remove the key
|
|
|
|
|
root.signed.remove_key('root', keyid)
|
|
|
|
|
|
|
|
|
|
# Assert that root does not contain the new key anymore
|
2021-04-20 11:16:19 +00:00
|
|
|
self.assertNotIn(keyid, root.signed.roles['root'].keyids)
|
2020-10-28 14:37:01 +00:00
|
|
|
self.assertNotIn(keyid, root.signed.keys)
|
|
|
|
|
|
2021-05-07 13:34:26 +00:00
|
|
|
with self.assertRaises(KeyError):
|
|
|
|
|
root.signed.remove_key('root', 'nosuchkey')
|
2020-10-28 14:37:01 +00:00
|
|
|
|
2021-05-14 16:33:53 +00:00
|
|
|
# Test serializing and deserializing without consistent_snapshot.
|
|
|
|
|
root_dict = root.to_dict()
|
|
|
|
|
del root_dict["signed"]["consistent_snapshot"]
|
|
|
|
|
root = Root.from_dict(copy.deepcopy(root_dict["signed"]))
|
|
|
|
|
self.assertEqual(root_dict["signed"], root.to_dict())
|
|
|
|
|
|
2021-04-29 13:43:03 +00:00
|
|
|
def test_delegated_role_class(self):
|
|
|
|
|
roles = [
|
|
|
|
|
{
|
|
|
|
|
"keyids": [
|
|
|
|
|
"c8022fa1e9b9cb239a6b362bbdffa9649e61ad2cb699d2e4bc4fdf7930a0e64a"
|
|
|
|
|
],
|
|
|
|
|
"name": "role1",
|
|
|
|
|
"paths": [
|
|
|
|
|
"file3.txt"
|
|
|
|
|
],
|
|
|
|
|
"terminating": False,
|
|
|
|
|
"threshold": 1
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
for role in roles:
|
|
|
|
|
# Testing that the workflow of deserializing and serializing
|
|
|
|
|
# a delegation role dictionary doesn't change the content.
|
|
|
|
|
key_obj = DelegatedRole.from_dict(role.copy())
|
|
|
|
|
self.assertEqual(role, key_obj.to_dict())
|
|
|
|
|
|
|
|
|
|
# Test creating a DelegatedRole object with both "paths" and
|
|
|
|
|
# "path_hash_prefixes" set.
|
|
|
|
|
role["path_hash_prefixes"] = "foo"
|
|
|
|
|
with self.assertRaises(ValueError):
|
|
|
|
|
DelegatedRole.from_dict(role.copy())
|
|
|
|
|
|
2021-05-14 11:02:29 +00:00
|
|
|
# Test creating DelegatedRole only with "path_hash_prefixes" (an empty one)
|
2021-04-29 13:43:03 +00:00
|
|
|
del role["paths"]
|
2021-05-14 11:02:29 +00:00
|
|
|
role["path_hash_prefixes"] = []
|
|
|
|
|
role_obj = DelegatedRole.from_dict(role.copy())
|
|
|
|
|
self.assertEqual(role_obj.to_dict(), role)
|
2021-04-29 13:43:03 +00:00
|
|
|
|
2021-05-14 11:02:29 +00:00
|
|
|
# Test creating DelegatedRole only with "paths" (now an empty one)
|
2021-04-29 13:43:03 +00:00
|
|
|
del role["path_hash_prefixes"]
|
2021-05-14 11:02:29 +00:00
|
|
|
role["paths"] = []
|
|
|
|
|
role_obj = DelegatedRole.from_dict(role.copy())
|
|
|
|
|
self.assertEqual(role_obj.to_dict(), role)
|
2021-04-29 13:43:03 +00:00
|
|
|
|
|
|
|
|
# Test creating DelegatedRole without "paths" and
|
|
|
|
|
# "path_hash_prefixes" set
|
|
|
|
|
del role["paths"]
|
2021-05-14 11:02:29 +00:00
|
|
|
role_obj = DelegatedRole.from_dict(role.copy())
|
|
|
|
|
self.assertEqual(role_obj.to_dict(), role)
|
2021-04-29 13:43:03 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_delegation_class(self):
|
|
|
|
|
roles = [
|
|
|
|
|
{
|
|
|
|
|
"keyids": [
|
|
|
|
|
"c8022fa1e9b9cb239a6b362bbdffa9649e61ad2cb699d2e4bc4fdf7930a0e64a"
|
|
|
|
|
],
|
|
|
|
|
"name": "role1",
|
|
|
|
|
"paths": [
|
|
|
|
|
"file3.txt"
|
|
|
|
|
],
|
|
|
|
|
"terminating": False,
|
|
|
|
|
"threshold": 1
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
keys = {
|
|
|
|
|
"59a4df8af818e9ed7abe0764c0b47b4240952aa0d179b5b78346c470ac30278d":{
|
|
|
|
|
"keytype": "ed25519",
|
|
|
|
|
"keyval": {
|
|
|
|
|
"public": "edcd0a32a07dce33f7c7873aaffbff36d20ea30787574ead335eefd337e4dacd"
|
|
|
|
|
},
|
|
|
|
|
"scheme": "ed25519"
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
delegations_dict = {"keys": keys, "roles": roles}
|
|
|
|
|
delegations = Delegations.from_dict(copy.deepcopy(delegations_dict))
|
|
|
|
|
self.assertEqual(delegations_dict, delegations.to_dict())
|
|
|
|
|
|
2021-05-14 11:26:26 +00:00
|
|
|
# empty keys and roles
|
|
|
|
|
delegations_dict = {"keys":{}, "roles":[]}
|
|
|
|
|
delegations = Delegations.from_dict(delegations_dict.copy())
|
|
|
|
|
self.assertEqual(delegations_dict, delegations.to_dict())
|
|
|
|
|
|
|
|
|
|
# Test some basic missing or broken input
|
|
|
|
|
invalid_delegations_dicts = [
|
|
|
|
|
{},
|
|
|
|
|
{"keys":None, "roles":None},
|
|
|
|
|
{"keys":{"foo":0}, "roles":[]},
|
|
|
|
|
{"keys":{}, "roles":["foo"]},
|
|
|
|
|
]
|
|
|
|
|
for d in invalid_delegations_dicts:
|
|
|
|
|
with self.assertRaises((KeyError, AttributeError)):
|
|
|
|
|
Delegations.from_dict(d)
|
2020-10-28 14:37:01 +00:00
|
|
|
|
|
|
|
|
def test_metadata_targets(self):
|
|
|
|
|
targets_path = os.path.join(
|
|
|
|
|
self.repo_dir, 'metadata', 'targets.json')
|
2021-03-04 09:51:45 +00:00
|
|
|
targets = Metadata.from_file(targets_path)
|
2020-10-28 14:37:01 +00:00
|
|
|
|
|
|
|
|
# Create a fileinfo dict representing what we expect the updated data to be
|
|
|
|
|
filename = 'file2.txt'
|
|
|
|
|
hashes = {
|
|
|
|
|
"sha256": "141f740f53781d1ca54b8a50af22cbf74e44c21a998fa2a8a05aaac2c002886b",
|
|
|
|
|
"sha512": "ef5beafa16041bcdd2937140afebd485296cd54f7348ecd5a4d035c09759608de467a7ac0eb58753d0242df873c305e8bffad2454aa48f44480f15efae1cacd0"
|
|
|
|
|
},
|
|
|
|
|
|
2021-03-30 15:13:16 +00:00
|
|
|
fileinfo = TargetFile(length=28, hashes=hashes)
|
2020-10-28 14:37:01 +00:00
|
|
|
|
|
|
|
|
# Assert that data is not aleady equal
|
2021-03-30 15:13:16 +00:00
|
|
|
self.assertNotEqual(
|
|
|
|
|
targets.signed.targets[filename].to_dict(), fileinfo.to_dict()
|
|
|
|
|
)
|
2020-10-28 14:37:01 +00:00
|
|
|
# Update an already existing fileinfo
|
2021-05-14 14:54:31 +00:00
|
|
|
targets.signed.update(filename, fileinfo)
|
2020-10-28 14:37:01 +00:00
|
|
|
# Verify that data is updated
|
2021-03-30 15:13:16 +00:00
|
|
|
self.assertEqual(
|
|
|
|
|
targets.signed.targets[filename].to_dict(), fileinfo.to_dict()
|
|
|
|
|
)
|
2020-10-28 14:37:01 +00:00
|
|
|
|
2021-04-28 15:52:42 +00:00
|
|
|
# Test from_dict/to_dict Targets without delegations
|
|
|
|
|
targets_dict = targets.to_dict()
|
|
|
|
|
del targets_dict["signed"]["delegations"]
|
2021-03-30 15:13:16 +00:00
|
|
|
tmp_dict = copy.deepcopy(targets_dict["signed"])
|
2021-04-28 15:52:42 +00:00
|
|
|
targets_obj = Targets.from_dict(tmp_dict)
|
|
|
|
|
self.assertEqual(targets_dict["signed"], targets_obj.to_dict())
|
|
|
|
|
|
2021-04-09 13:20:24 +00:00
|
|
|
def setup_dict_with_unrecognized_field(self, file_path, field, value):
|
|
|
|
|
json_dict = {}
|
|
|
|
|
with open(file_path) as f:
|
|
|
|
|
json_dict = json.loads(f.read())
|
|
|
|
|
# We are changing the json dict without changing the signature.
|
|
|
|
|
# This could be a problem if we want to do verification on this dict.
|
|
|
|
|
json_dict["signed"][field] = value
|
|
|
|
|
return json_dict
|
|
|
|
|
|
|
|
|
|
def test_support_for_unrecognized_fields(self):
|
|
|
|
|
for metadata in ["root", "timestamp", "snapshot", "targets"]:
|
|
|
|
|
path = os.path.join(self.repo_dir, "metadata", metadata + ".json")
|
|
|
|
|
dict1 = self.setup_dict_with_unrecognized_field(path, "f", "b")
|
|
|
|
|
# Test that the metadata classes store unrecognized fields when
|
|
|
|
|
# initializing and passes them when casting the instance to a dict.
|
|
|
|
|
|
2021-04-20 09:35:52 +00:00
|
|
|
# Add unrecognized fields to all metadata sub (helper) classes.
|
|
|
|
|
if metadata == "root":
|
|
|
|
|
for keyid in dict1["signed"]["keys"].keys():
|
|
|
|
|
dict1["signed"]["keys"][keyid]["d"] = "c"
|
2021-04-20 11:16:19 +00:00
|
|
|
for role_str in dict1["signed"]["roles"].keys():
|
|
|
|
|
dict1["signed"]["roles"][role_str]["e"] = "g"
|
2021-04-21 14:54:48 +00:00
|
|
|
elif metadata == "targets" and dict1["signed"].get("delegations"):
|
|
|
|
|
for keyid in dict1["signed"]["delegations"]["keys"].keys():
|
|
|
|
|
dict1["signed"]["delegations"]["keys"][keyid]["d"] = "c"
|
|
|
|
|
new_roles = []
|
|
|
|
|
for role in dict1["signed"]["delegations"]["roles"]:
|
|
|
|
|
role["e"] = "g"
|
|
|
|
|
new_roles.append(role)
|
|
|
|
|
dict1["signed"]["delegations"]["roles"] = new_roles
|
|
|
|
|
dict1["signed"]["delegations"]["foo"] = "bar"
|
2021-04-20 11:16:19 +00:00
|
|
|
|
2021-04-09 13:20:24 +00:00
|
|
|
temp_copy = copy.deepcopy(dict1)
|
|
|
|
|
metadata_obj = Metadata.from_dict(temp_copy)
|
|
|
|
|
|
|
|
|
|
self.assertEqual(dict1["signed"], metadata_obj.signed.to_dict())
|
|
|
|
|
|
|
|
|
|
# Test that two instances of the same class could have different
|
|
|
|
|
# unrecognized fields.
|
|
|
|
|
dict2 = self.setup_dict_with_unrecognized_field(path, "f2", "b2")
|
|
|
|
|
temp_copy2 = copy.deepcopy(dict2)
|
|
|
|
|
metadata_obj2 = Metadata.from_dict(temp_copy2)
|
|
|
|
|
self.assertNotEqual(
|
|
|
|
|
metadata_obj.signed.to_dict(), metadata_obj2.signed.to_dict()
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
# Run unit test.
|
|
|
|
|
if __name__ == '__main__':
|
2020-09-15 15:05:51 +00:00
|
|
|
utils.configure_test_logging(sys.argv)
|
Add simple TUF role metadata model (WIP)
Add metadata module with container classes for TUF role metadata, including
methods to read/serialize/write from and to JSON, perform TUF-compliant
metadata updates, and create and verify signatures.
The 'Metadata' class provides a container for inner TUF metadata objects (Root,
Timestamp, Snapshot, Targets) (i.e. OOP composition)
The 'Signed' class provides a base class to aggregate common attributes (i.e.
version, expires, spec_version) of the inner metadata classes. (i.e. OOP
inheritance). The name of the class also aligns with the 'signed' field of
the outer metadata container.
Based on prior observations in TUF's sister project in-toto, this architecture
seems to well represent the metadata model as it is defined in the
specification (see in-toto/in-toto#98 and in-toto/in-toto#142 for related
discussions).
This commits also adds tests.
**TODO: See doc header TODO list**
**Additional design considerations**
(also in regards to prior sketches of this module)
- Aims at simplicity, brevity and recognizability of the wireline metadata
format.
- All attributes that correspond to fields in TUF JSON metadata are public.
There doesn't seem to be a good reason to protect them with leading
underscores and use setters/getters instead, it just adds more code, and
impedes recognizability of the wireline metadata format.
- Although, it might be convenient to have short-cuts on the Metadata class
that point to methods and attributes that are common to all subclasses of
the contained Signed class (e.g. Metadata.version instead of
Metadata.signed.version, etc.), this also conflicts with goal of
recognizability of the wireline metadata. Thus we won't add such short-cuts
for now. See:
https://github.com/theupdateframework/tuf/pull/1060#discussion_r452906629
- Signing keys and a 'consistent_snapshot' boolean are not on the targets
metadata class. They are a better fit for management code. See:
https://github.com/theupdateframework/tuf/pull/1060#issuecomment-660056376,
and #660.
- Does not use sslib schema checks (see TODO notes about validation in
doc header)
- Does not use existing tuf utils, such as make_metadata_fileinfo,
build_dict_conforming_to_schema, if it is easy and more explicit to
just re-implement the desired behavior on the metadata classes.
- All datetime's are treated as UTC. Since timezone info is not captured in
the wireline metadata format it should not be captured in the internal
representation either.
- Does not use 3rd-party dateutil package, in order to minimize dependency
footprint, which is especially important for update clients which often have
to vendor their dependencies.
However, compatibility between the more advanced dateutil.relativedelta (e.g
handles leap years automatically) and timedelta is tested.
- Uses PEP8 indentation (4 space) and Google-style doc string instead of
sslab-style. See
https://github.com/secure-systems-lab/code-style-guidelines/issues/20
- Does not support Python =< 3.5
Co-authored-by: Trishank Karthik Kuppusamy <trishank.kuppusamy@datadoghq.com>
Co-authored-by: Joshua Lock <jlock@vmware.com>
Co-authored-by: Teodora Sechkova <tsechkova@vmware.com>
Signed-off-by: Lukas Puehringer <lukas.puehringer@nyu.edu>
2020-08-18 09:15:49 +00:00
|
|
|
unittest.main()
|