File: test_encrypt.py

package info (click to toggle)
rauc 1.15-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 6,336 kB
  • sloc: ansic: 36,989; python: 3,354; sh: 1,391; xml: 53; makefile: 41
file content (89 lines) | stat: -rw-r--r-- 2,610 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import os

from helper import run


def test_encrypt_multi_single_cert_pem(tmp_path):
    out, err, exitcode = run(
        "rauc encrypt "
        "--to openssl-enc/keys/rsa-4096/cert-000.pem "
        "--to openssl-enc/keys/rsa-4096/cert-001.pem "
        "--keyring openssl-ca/dev-ca.pem "
        f"good-crypt-bundle-unencrypted.raucb {tmp_path}/encrypted.raucb"
    )

    assert exitcode == 0

    assert os.path.exists(f"{tmp_path}/encrypted.raucb")


def test_encrypt_single_multi_cert_pem(tmp_path):
    out, err, exitcode = run(
        "rauc encrypt "
        "--to openssl-enc/keys/rsa-4096/certs.pem "
        "--keyring openssl-ca/dev-ca.pem "
        f"good-crypt-bundle-unencrypted.raucb {tmp_path}/encrypted.raucb"
    )

    assert exitcode == 0

    assert os.path.exists(f"{tmp_path}/encrypted.raucb")


def test_encrypt_single_multi_cert_pem_rsa_ecc_mixed(tmp_path):
    out, err, exitcode = run(
        "rauc encrypt "
        "--to openssl-enc/keys/rsa-4096/certs.pem "
        "--to openssl-enc/keys/ecc/certs.pem "
        "--keyring openssl-ca/dev-ca.pem "
        f"good-crypt-bundle-unencrypted.raucb {tmp_path}/encrypted.raucb"
    )

    assert exitcode == 0

    assert os.path.exists(f"{tmp_path}/encrypted.raucb")


def test_encrypt_broken_multi_cert_pem(tmp_path):
    with open("openssl-enc/keys/rsa-4096/certs.pem") as infile:
        with open(f"{tmp_path}/certs.pem", "a") as outfile:
            outfile.writelines(infile.readlines()[:-5])

    out, err, exitcode = run(
        "rauc encrypt "
        f"--to {tmp_path}/certs.pem "
        "--keyring openssl-ca/dev-ca.pem "
        f"good-crypt-bundle-unencrypted.raucb {tmp_path}/encrypted.raucb"
    )

    assert exitcode == 1

    assert not os.path.exists(f"{tmp_path}/encrypted.raucb")


def test_encrypt_missing_cert_in_file(tmp_path):
    out, err, exitcode = run(
        "rauc encrypt "
        "--to openssl-enc/keys/rsa-4096/private-key-001.pem "
        "--keyring openssl-ca/dev-ca.pem "
        f"good-crypt-bundle-unencrypted.raucb {tmp_path}/encrypted.raucb"
    )

    assert exitcode == 1
    assert "Expecting: CERTIFICATE" in err

    assert not os.path.exists(f"{tmp_path}/encrypted.raucb")


def test_encrypt_verity_bundle(tmp_path):
    out, err, exitcode = run(
        "rauc encrypt "
        "--to openssl-enc/keys/rsa-4096/cert-000.pem "
        "--keyring openssl-ca/dev-ca.pem "
        f"good-verity-bundle.raucb {tmp_path}/encrypted.raucb"
    )

    assert exitcode == 1
    assert "Refused to encrypt input bundle" in err

    assert not os.path.exists(f"{tmp_path}/encrypted.raucb")