コード例 #1
0
def test_sign_resign(
    image_config: ImageConfig,
    image_config_signed: ImageConfig,
    config_digest_canonical: str,
    config_digest_signed_canonical: str,
    signature: str,
):
    """Test configuration resigning for signed and unsigned configurations."""

    signer = FakeSigner()
    assert image_config.sign(signer,
                             SignatureTypes.RESIGN) == signer.signature_value
    assert (image_config_signed.sign(
        signer, SignatureTypes.RESIGN) == signer.signature_value)

    # Previously unsigned configurations should now contain the new signature.
    assert b"BEGIN FAKE SIGNATURE" in image_config.get_config()
    signatures = image_config.get_signature_list()
    assert len(signatures) == 1
    assert signatures[0]["digest"] == config_digest_canonical
    assert signatures[0]["signature"] == signer.signature_value

    # Previously signed configurations should now contain (only) the new signature.
    assert b"BEGIN FAKE SIGNATURE" in image_config_signed.get_config()
    assert b"BEGIN PGP SIGNATURE" not in image_config_signed.get_config()
    signatures_signed = image_config_signed.get_signature_list()
    assert len(signatures_signed) == 1
    assert signatures[0]["digest"] == config_digest_canonical
    assert signatures[0]["signature"] == signer.signature_value
コード例 #2
0
def test_sign_endorse(
    image_config: ImageConfig,
    image_config_signed: ImageConfig,
    config_digest_canonical: str,
    config_digest_signed_canonical: str,
    signature: str,
):
    """Test configuration endorsement for signed and unsigned configurations."""

    signer = FakeSigner()
    assert image_config.sign(signer,
                             SignatureTypes.ENDORSE) == signer.signature_value
    assert (image_config_signed.sign(
        signer, SignatureTypes.ENDORSE) == signer.signature_value)

    # Previously unsigned configurations should now contain the new signature.
    assert b"BEGIN FAKE SIGNATURE" in image_config.get_config()
    signatures = image_config.get_signature_list()
    assert len(signatures) == 1
    assert signatures[0]["digest"] == config_digest_canonical
    assert signatures[0]["signature"] == signer.signature_value

    # Previously signed configurations should now contain the original signature(s) and the new signature.
    assert b"BEGIN FAKE SIGNATURE" in image_config_signed.get_config()
    assert b"BEGIN PGP SIGNATURE" in image_config_signed.get_config()
    signatures_signed = image_config_signed.get_signature_list()
    assert len(signatures_signed) == 2
    assert signatures_signed[0]["digest"] == config_digest_canonical
    assert signatures_signed[0]["signature"] == signature
    assert signatures_signed[1]["digest"] == config_digest_signed_canonical
    assert signatures_signed[1]["signature"] == signer.signature_value
コード例 #3
0
def test_get_config(
    image_config: ImageConfig,
    image_config_signed: ImageConfig,
    json_bytes: bytes,
    json_bytes_signed: bytes,
):
    """Test get_config() pass-through for signed and unsigned configurations."""
    assert image_config.get_config() == json_bytes
    assert image_config_signed.get_config() == json_bytes_signed
コード例 #4
0
def test_unsign(image_config: ImageConfig, image_config_signed: ImageConfig):
    """Test configuration unsigning for signed and unsigned configurations."""

    image_config.unsign()
    image_config_signed.unsign()

    # Previously unsigned configurations should still contain no signature.
    assert b"BEGIN FAKE SIGNATURE" not in image_config.get_config()

    # Previously signed configurations should now contain no signature(s).
    assert b"BEGIN FAKE SIGNATURE" not in image_config_signed.get_config()
    assert b"BEGIN PGP SIGNATURE" not in image_config_signed.get_config()
コード例 #5
0
def test_sign(image_config: ImageConfig, image_config_signed: ImageConfig):
    """Test configuration signing for signed and unsigned configurations."""

    signer = FakeSigner()
    assert image_config.sign(signer) == signer.signature_value
    assert image_config_signed.sign(signer) == signer.signature_value

    # Previously unsigned configurations should now contain the new signature.
    assert b"BEGIN FAKE SIGNATURE" in image_config.get_config()

    # Previously signed configurations should now contain the original signature(s) and the new signature.
    assert b"BEGIN FAKE SIGNATURE" in image_config_signed.get_config()
    assert b"BEGIN PGP SIGNATURE" in image_config_signed.get_config()
コード例 #6
0
def test_acceptance_sign_unsign_symmetry(image_config: ImageConfig,
                                         image_config_signed: ImageConfig):
    """Tests that sign and unsign are (mostly) symmetric operations."""

    config_digest = image_config.get_config_digest()

    # 1. Sign
    signer = FakeSigner()
    assert image_config.sign(signer) == signer.signature_value
    assert image_config_signed.sign(signer) == signer.signature_value

    # Previously unsigned configurations should now contain the new signature.
    assert b"BEGIN FAKE SIGNATURE" in image_config.get_config()

    # Previously signed configurations should now contain the original signature(s) and the new signature.
    assert b"BEGIN FAKE SIGNATURE" in image_config_signed.get_config()
    assert b"BEGIN PGP SIGNATURE" in image_config_signed.get_config()

    # 2. Unsign
    image_config.unsign()
    image_config_signed.unsign()

    # Configurations where we added the first signature should be reverted.
    assert b"BEGIN FAKE SIGNATURE" not in image_config.get_config()

    # Configurations where we appended a signature should now contain no signature(s).
    assert b"BEGIN FAKE SIGNATURE" not in image_config_signed.get_config()
    assert b"BEGIN PGP SIGNATURE" not in image_config_signed.get_config()

    assert image_config.get_config_digest() == config_digest
コード例 #7
0
def test_minimal():
    """Test minimal image configuration (for non-conformant labels)k."""

    # Note: At a minimum, [Cc]onfig key must exist with non-null value
    image_config = ImageConfig(b'{"Config":{}}')
    config_digest_canonical = image_config.get_config_digest_canonical()
    signer = FakeSigner()
    assert image_config.sign(signer) == signer.signature_value

    # A signature should always be able to be added ...
    assert b"BEGIN FAKE SIGNATURE" in image_config.get_config()
    signatures = image_config.get_signature_list()
    assert len(signatures) == 1
    assert signatures[0]["digest"] == config_digest_canonical
    assert signatures[0]["signature"] == signer.signature_value