summaryrefslogtreecommitdiff
path: root/tests/futility/test_show_contents.sh
blob: f24c434d00f9668d83a07f7913713a5d20ec226a (plain)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/bin/bash -eux
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

me=${0##*/}
TMP="$me.tmp"

# Work in scratch directory
cd "$OUTDIR"

# Test 'futility show' against expected output
SHOW_FILES="
  tests/devkeys/root_key.vbpubk
  tests/devkeys/root_key.vbprivk
  tests/devkeys/kernel.keyblock
  tests/futility/data/fw_vblock.bin
  tests/futility/data/fw_gbb.bin
  tests/futility/data/bios_zgb_mp.bin
  tests/futility/data/bios_mario_mp.bin
  tests/futility/data/kern_preamble.bin
  tests/futility/data/sample.vbpubk2
  tests/futility/data/sample.vbprik2
  tests/testkeys/key_rsa2048.pem
  tests/testkeys/key_rsa8192.pub.pem
"

for file in $SHOW_FILES; do
    outfile="show.${file//\//_}"
    gotfile="${OUTDIR}/${outfile}"
    wantfile="${SRCDIR}/tests/futility/expect_output/${outfile}"
    ${FUTILITY} show "${SRCDIR}/${file}" | tee "${gotfile}"

    # Uncomment this to update the expected output
    #cp ${gotfile} ${wantfile}

    diff ${wantfile} ${gotfile}
done


# Test 'futility vbutil_key' against expected output
VBUTIL_KEY_FILES="
  tests/devkeys/root_key.vbpubk
  tests/devkeys/root_key.vbprivk
"

for file in $VBUTIL_KEY_FILES; do
    outfile="vbutil_key.${file//\//_}"
    gotfile="${OUTDIR}/${outfile}"
    wantfile="${SRCDIR}/tests/futility/expect_output/${outfile}"
    ${FUTILITY} vbutil_key --unpack "${SRCDIR}/${file}" | tee "${gotfile}"

    # Uncomment this to update the expected output
    #cp ${gotfile} ${wantfile}

    diff ${wantfile} ${gotfile}
done


# Test 'futility vbutil_keyblock' against expected output
file="tests/devkeys/kernel.keyblock"
outfile="vbutil_keyblock.${file//\//_}"
gotfile="${OUTDIR}/${outfile}"
wantfile="${SRCDIR}/tests/futility/expect_output/${outfile}"
${FUTILITY} vbutil_keyblock --unpack "${SRCDIR}/${file}" \
    --signpubkey "${SRCDIR}/tests/devkeys/kernel_subkey.vbpubk" \
    | tee "${gotfile}"

# Uncomment this to update the expected output
#cp ${gotfile} ${wantfile}

diff ${wantfile} ${gotfile}


# Test 'futility vbutil_firmware' against expected output
KEYDIR=${SRCDIR}/tests/devkeys
outfile="vbutil_firmware.verify"
gotfile="${OUTDIR}/${outfile}"
wantfile="${SRCDIR}/tests/futility/expect_output/${outfile}"

# Create a firmware blob and vblock.  Version and flags are just
# arbitrary non-zero numbers so we can verify they're printed
# properly.
dd bs=1024 count=16 if=/dev/urandom of=${TMP}.fw_main
${FUTILITY} vbutil_firmware --vblock ${TMP}.vblock.old \
  --keyblock ${KEYDIR}/firmware.keyblock \
  --signprivate ${KEYDIR}/firmware_data_key.vbprivk \
  --version 12 \
  --fv ${TMP}.fw_main \
  --kernelkey ${KEYDIR}/kernel_subkey.vbpubk \
  --flags 42

# Verify
${FUTILITY} vbutil_firmware --verify ${TMP}.vblock.old \
  --signpubkey ${KEYDIR}/root_key.vbpubk \
  --fv ${TMP}.fw_main | tee "${gotfile}"

# Uncomment this to update the expected output
#cp ${gotfile} ${wantfile}

diff ${wantfile} ${gotfile}


# cleanup
rm -rf ${TMP}*
exit 0