16f3961507e73f90cec665896dece884e86be560aBill Richardson#!/bin/bash -eux 26f3961507e73f90cec665896dece884e86be560aBill Richardson# Copyright 2014 The Chromium OS Authors. All rights reserved. 36f3961507e73f90cec665896dece884e86be560aBill Richardson# Use of this source code is governed by a BSD-style license that can be 46f3961507e73f90cec665896dece884e86be560aBill Richardson# found in the LICENSE file. 56f3961507e73f90cec665896dece884e86be560aBill Richardson 66f3961507e73f90cec665896dece884e86be560aBill Richardsonme=${0##*/} 76f3961507e73f90cec665896dece884e86be560aBill RichardsonTMP="$me.tmp" 86f3961507e73f90cec665896dece884e86be560aBill Richardson 96f3961507e73f90cec665896dece884e86be560aBill Richardson# Work in scratch directory 106f3961507e73f90cec665896dece884e86be560aBill Richardsoncd "$OUTDIR" 116f3961507e73f90cec665896dece884e86be560aBill Richardson 126f3961507e73f90cec665896dece884e86be560aBill Richardson# Helper utility to modify binary blobs 136f3961507e73f90cec665896dece884e86be560aBill RichardsonREPLACE="${BUILD_RUN}/tests/futility/binary_editor" 146f3961507e73f90cec665896dece884e86be560aBill Richardson 156f3961507e73f90cec665896dece884e86be560aBill Richardson# First, let's test the basic functionality 166f3961507e73f90cec665896dece884e86be560aBill Richardson 176f3961507e73f90cec665896dece884e86be560aBill Richardson# For simplicity, we'll use the same size for all properties. 186f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -c 16,0x10,16,0x10 ${TMP}.blob 196f3961507e73f90cec665896dece884e86be560aBill Richardson 206f3961507e73f90cec665896dece884e86be560aBill Richardson# Flags 216f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -s --flags=0xdeadbeef ${TMP}.blob 226f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g --flags ${TMP}.blob | grep -i 0xdeadbeef 236f3961507e73f90cec665896dece884e86be560aBill Richardson 246f3961507e73f90cec665896dece884e86be560aBill Richardson# HWID length should include the terminating null - this is too long 251eae873b6194db25781233d7a4aaee6a34160eecBill Richardsonif ${FUTILITY} gbb_utility -s --hwid="0123456789ABCDEF" ${TMP}.blob; then 261eae873b6194db25781233d7a4aaee6a34160eecBill Richardson false; 271eae873b6194db25781233d7a4aaee6a34160eecBill Richardsonfi 286f3961507e73f90cec665896dece884e86be560aBill Richardson# This works 291eae873b6194db25781233d7a4aaee6a34160eecBill Richardson${FUTILITY} gbb_utility -s --hwid="0123456789ABCDE" ${TMP}.blob 306f3961507e73f90cec665896dece884e86be560aBill Richardson# Read it back? 316f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g ${TMP}.blob | grep "0123456789ABCDE" 326f3961507e73f90cec665896dece884e86be560aBill Richardson 336f3961507e73f90cec665896dece884e86be560aBill Richardson# Same kind of tests for the other fields, but they need binary files. 346f3961507e73f90cec665896dece884e86be560aBill Richardson 356f3961507e73f90cec665896dece884e86be560aBill Richardson# too long 366f3961507e73f90cec665896dece884e86be560aBill Richardsondd if=/dev/urandom bs=17 count=1 of=${TMP}.data1.toolong 376f3961507e73f90cec665896dece884e86be560aBill Richardsondd if=/dev/urandom bs=17 count=1 of=${TMP}.data2.toolong 386f3961507e73f90cec665896dece884e86be560aBill Richardsondd if=/dev/urandom bs=17 count=1 of=${TMP}.data3.toolong 396f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility -s --rootkey ${TMP}.data1.toolong ${TMP}.blob; then false; fi 406f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility -s --recoverykey ${TMP}.data2.toolong ${TMP}.blob; then false; fi 416f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility -s --bmpfv ${TMP}.data3.toolong ${TMP}.blob; then false; fi 426f3961507e73f90cec665896dece884e86be560aBill Richardson 436f3961507e73f90cec665896dece884e86be560aBill Richardson# shorter than max should be okay, though 446f3961507e73f90cec665896dece884e86be560aBill Richardsondd if=/dev/urandom bs=10 count=1 of=${TMP}.data1.short 456f3961507e73f90cec665896dece884e86be560aBill Richardsondd if=/dev/urandom bs=10 count=1 of=${TMP}.data2.short 466f3961507e73f90cec665896dece884e86be560aBill Richardsondd if=/dev/urandom bs=10 count=1 of=${TMP}.data3.short 476f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -s \ 486f3961507e73f90cec665896dece884e86be560aBill Richardson --rootkey ${TMP}.data1.short \ 496f3961507e73f90cec665896dece884e86be560aBill Richardson --recoverykey ${TMP}.data2.short \ 506f3961507e73f90cec665896dece884e86be560aBill Richardson --bmpfv ${TMP}.data3.short ${TMP}.blob 516f3961507e73f90cec665896dece884e86be560aBill Richardson# read 'em back 526f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g \ 536f3961507e73f90cec665896dece884e86be560aBill Richardson --rootkey ${TMP}.read1 \ 546f3961507e73f90cec665896dece884e86be560aBill Richardson --recoverykey ${TMP}.read2 \ 556f3961507e73f90cec665896dece884e86be560aBill Richardson --bmpfv ${TMP}.read3 ${TMP}.blob 566f3961507e73f90cec665896dece884e86be560aBill Richardson# Verify (but remember, it's short) 576f3961507e73f90cec665896dece884e86be560aBill Richardsoncmp -n 10 ${TMP}.data1.short ${TMP}.read1 586f3961507e73f90cec665896dece884e86be560aBill Richardsoncmp -n 10 ${TMP}.data2.short ${TMP}.read2 596f3961507e73f90cec665896dece884e86be560aBill Richardsoncmp -n 10 ${TMP}.data3.short ${TMP}.read3 606f3961507e73f90cec665896dece884e86be560aBill Richardson 616f3961507e73f90cec665896dece884e86be560aBill Richardson# Okay 626f3961507e73f90cec665896dece884e86be560aBill Richardsondd if=/dev/urandom bs=16 count=1 of=${TMP}.data1 636f3961507e73f90cec665896dece884e86be560aBill Richardsondd if=/dev/urandom bs=16 count=1 of=${TMP}.data2 646f3961507e73f90cec665896dece884e86be560aBill Richardsondd if=/dev/urandom bs=16 count=1 of=${TMP}.data3 656f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -s --rootkey ${TMP}.data1 ${TMP}.blob 666f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -s --recoverykey ${TMP}.data2 ${TMP}.blob 676f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -s --bmpfv ${TMP}.data3 ${TMP}.blob 686f3961507e73f90cec665896dece884e86be560aBill Richardson 696f3961507e73f90cec665896dece884e86be560aBill Richardson# Read 'em back. 706f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g --rootkey ${TMP}.read1 ${TMP}.blob 716f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g --recoverykey ${TMP}.read2 ${TMP}.blob 726f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g --bmpfv ${TMP}.read3 ${TMP}.blob 736f3961507e73f90cec665896dece884e86be560aBill Richardson# Verify 746f3961507e73f90cec665896dece884e86be560aBill Richardsoncmp ${TMP}.data1 ${TMP}.read1 756f3961507e73f90cec665896dece884e86be560aBill Richardsoncmp ${TMP}.data2 ${TMP}.read2 766f3961507e73f90cec665896dece884e86be560aBill Richardsoncmp ${TMP}.data3 ${TMP}.read3 776f3961507e73f90cec665896dece884e86be560aBill Richardson 786f3961507e73f90cec665896dece884e86be560aBill Richardson 796f3961507e73f90cec665896dece884e86be560aBill Richardson# Okay, creating GBB blobs seems to work. Now let's make sure that corrupted 806f3961507e73f90cec665896dece884e86be560aBill Richardson# blobs are rejected. 816f3961507e73f90cec665896dece884e86be560aBill Richardson 826f3961507e73f90cec665896dece884e86be560aBill Richardson# Danger Will Robinson! We assume that ${TMP}.blob has this binary struct: 836f3961507e73f90cec665896dece884e86be560aBill Richardson# 846f3961507e73f90cec665896dece884e86be560aBill Richardson# Field Offset Value 856f3961507e73f90cec665896dece884e86be560aBill Richardson# 866f3961507e73f90cec665896dece884e86be560aBill Richardson# signature: 0x0000 $GBB 876f3961507e73f90cec665896dece884e86be560aBill Richardson# major_version: 0x0004 0x0001 886f3961507e73f90cec665896dece884e86be560aBill Richardson# minor_version: 0x0006 0x0001 896f3961507e73f90cec665896dece884e86be560aBill Richardson# header_size: 0x0008 0x00000080 906f3961507e73f90cec665896dece884e86be560aBill Richardson# flags: 0x000c 0xdeadbeef 916f3961507e73f90cec665896dece884e86be560aBill Richardson# hwid_offset: 0x0010 0x00000080 926f3961507e73f90cec665896dece884e86be560aBill Richardson# hwid_size: 0x0014 0x00000010 936f3961507e73f90cec665896dece884e86be560aBill Richardson# rootkey_offset: 0x0018 0x00000090 946f3961507e73f90cec665896dece884e86be560aBill Richardson# rootkey_size: 0x001c 0x00000010 956f3961507e73f90cec665896dece884e86be560aBill Richardson# bmpfv_offset: 0x0020 0x000000a0 966f3961507e73f90cec665896dece884e86be560aBill Richardson# bmpfv_size: 0x0024 0x00000010 976f3961507e73f90cec665896dece884e86be560aBill Richardson# recovery_key_offset: 0x0028 0x000000b0 986f3961507e73f90cec665896dece884e86be560aBill Richardson# recovery_key_size: 0x002c 0x00000010 996f3961507e73f90cec665896dece884e86be560aBill Richardson# pad: 0x0030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1006f3961507e73f90cec665896dece884e86be560aBill Richardson# 0x0040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1016f3961507e73f90cec665896dece884e86be560aBill Richardson# 0x0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1026f3961507e73f90cec665896dece884e86be560aBill Richardson# 0x0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1036f3961507e73f90cec665896dece884e86be560aBill Richardson# 0x0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 1046f3961507e73f90cec665896dece884e86be560aBill Richardson# (HWID) 0x0080 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45 00 1056f3961507e73f90cec665896dece884e86be560aBill Richardson# (rootkey) 0x0090 xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx 1066f3961507e73f90cec665896dece884e86be560aBill Richardson# (bmpfv) 0x00a0 xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx 1076f3961507e73f90cec665896dece884e86be560aBill Richardson# (recovery_key) 0x00b0 xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx 1086f3961507e73f90cec665896dece884e86be560aBill Richardson# 0x00c0 <EOF> 1096f3961507e73f90cec665896dece884e86be560aBill Richardson# 1106f3961507e73f90cec665896dece884e86be560aBill Richardson 1116f3961507e73f90cec665896dece884e86be560aBill Richardson# bad major_version 1126f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x4 2 > ${TMP}.blob.bad 1136f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1146f3961507e73f90cec665896dece884e86be560aBill Richardson 1156f3961507e73f90cec665896dece884e86be560aBill Richardson# header size too large 1166f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x8 0x81 > ${TMP}.blob.bad 1176f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1186f3961507e73f90cec665896dece884e86be560aBill Richardson 1196f3961507e73f90cec665896dece884e86be560aBill Richardson# header size too small 1206f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x8 0x7f > ${TMP}.blob.bad 1216f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1226f3961507e73f90cec665896dece884e86be560aBill Richardson 1236f3961507e73f90cec665896dece884e86be560aBill Richardson# HWID not null-terminated is invalid 1246f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x8f 0x41 > ${TMP}.blob.bad 1256f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1266f3961507e73f90cec665896dece884e86be560aBill Richardson 1276f3961507e73f90cec665896dece884e86be560aBill Richardson# HWID of length zero is okay 1286f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x14 0x00 > ${TMP}.blob.ok 1296f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility ${TMP}.blob.ok 1306f3961507e73f90cec665896dece884e86be560aBill Richardson# And HWID of length 1 consisting only of '\0' is okay, too. 1316f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x14 0x01 | ${REPLACE} 0x80 0x00 > ${TMP}.blob.ok 1326f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility ${TMP}.blob.ok 1336f3961507e73f90cec665896dece884e86be560aBill Richardson 1346f3961507e73f90cec665896dece884e86be560aBill Richardson# zero-length HWID not null-terminated is invalid 1356f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x8f 0x41 > ${TMP}.blob.bad 1366f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1376f3961507e73f90cec665896dece884e86be560aBill Richardson 1386f3961507e73f90cec665896dece884e86be560aBill Richardson# hwid_offset < GBB_HEADER_SIZE is invalid 1396f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x10 0x7f > ${TMP}.blob.bad 1406f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1416f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x10 0x00 > ${TMP}.blob.bad 1426f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1436f3961507e73f90cec665896dece884e86be560aBill Richardson 1446f3961507e73f90cec665896dece884e86be560aBill Richardson# rootkey_offset < GBB_HEADER_SIZE is invalid 1456f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x18 0x7f > ${TMP}.blob.bad 1466f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1476f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x18 0x00 > ${TMP}.blob.bad 1486f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1496f3961507e73f90cec665896dece884e86be560aBill Richardson 1506f3961507e73f90cec665896dece884e86be560aBill Richardson# bmpfv_offset < GBB_HEADER_SIZE is invalid 1516f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x20 0x7f > ${TMP}.blob.bad 1526f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1536f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x20 0x00 > ${TMP}.blob.bad 1546f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1556f3961507e73f90cec665896dece884e86be560aBill Richardson 1566f3961507e73f90cec665896dece884e86be560aBill Richardson# recovery_key_offset < GBB_HEADER_SIZE is invalid 1576f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x28 0x7f > ${TMP}.blob.bad 1586f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1596f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x28 0x00 > ${TMP}.blob.bad 1606f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility ${TMP}.blob.bad; then false; fi 1616f3961507e73f90cec665896dece884e86be560aBill Richardson 1626f3961507e73f90cec665896dece884e86be560aBill Richardson# hwid: offset + size == end of file is okay; beyond is invalid 1636f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x14 0x40 > ${TMP}.blob.bad 1646f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g ${TMP}.blob.bad 1656f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x14 0x41 > ${TMP}.blob.bad 1666f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility -g ${TMP}.blob.bad; then false; fi 1676f3961507e73f90cec665896dece884e86be560aBill Richardson 1686f3961507e73f90cec665896dece884e86be560aBill Richardson# rootkey: offset + size == end of file is okay; beyond is invalid 1696f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x1c 0x30 > ${TMP}.blob.bad 1706f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g ${TMP}.blob.bad 1716f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x1c 0x31 > ${TMP}.blob.bad 1726f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility -g ${TMP}.blob.bad; then false; fi 1736f3961507e73f90cec665896dece884e86be560aBill Richardson 1746f3961507e73f90cec665896dece884e86be560aBill Richardson# bmpfv: offset + size == end of file is okay; beyond is invalid 1756f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x24 0x20 > ${TMP}.blob.bad 1766f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g ${TMP}.blob.bad 1776f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x24 0x21 > ${TMP}.blob.bad 1786f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility -g ${TMP}.blob.bad; then false; fi 1796f3961507e73f90cec665896dece884e86be560aBill Richardson 1806f3961507e73f90cec665896dece884e86be560aBill Richardson# recovery_key: offset + size == end of file is okay; beyond is invalid 1816f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x2c 0x10 > ${TMP}.blob.bad 1826f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g ${TMP}.blob.bad 1836f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x2c 0x11 > ${TMP}.blob.bad 1846f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility -g ${TMP}.blob.bad; then false; fi 1856f3961507e73f90cec665896dece884e86be560aBill Richardson 1866f3961507e73f90cec665896dece884e86be560aBill Richardson# hwid_size == 0 doesn't complain, but can't be set 1876f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x14 0x00 > ${TMP}.blob.bad 1886f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g ${TMP}.blob.bad 1891eae873b6194db25781233d7a4aaee6a34160eecBill Richardsonif ${FUTILITY} gbb_utility -s --hwid="A" ${TMP}.blob.bad; then false; fi 1906f3961507e73f90cec665896dece884e86be560aBill Richardson 1916f3961507e73f90cec665896dece884e86be560aBill Richardson# rootkey_size == 0 gives warning, gets nothing, can't be set 1926f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x1c 0x00 > ${TMP}.blob.bad 1936f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g --rootkey ${TMP}.read1 ${TMP}.blob.bad 1946f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility -s --rootkey ${TMP}.data1 ${TMP}.blob.bad; then false; fi 1956f3961507e73f90cec665896dece884e86be560aBill Richardson 1966f3961507e73f90cec665896dece884e86be560aBill Richardson# bmpfv_size == 0 gives warning, gets nothing, can't be set 1976f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x24 0x00 > ${TMP}.blob.bad 1986f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g --bmpfv ${TMP}.read3 ${TMP}.blob.bad 1996f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility -s --bmpfv ${TMP}.data3 ${TMP}.blob.bad; then false; fi 2006f3961507e73f90cec665896dece884e86be560aBill Richardson 2016f3961507e73f90cec665896dece884e86be560aBill Richardson# recovery_key_size == 0 gives warning, gets nothing, can't be set 2026f3961507e73f90cec665896dece884e86be560aBill Richardsoncat ${TMP}.blob | ${REPLACE} 0x2c 0x00 > ${TMP}.blob.bad 2036f3961507e73f90cec665896dece884e86be560aBill Richardson${FUTILITY} gbb_utility -g --recoverykey ${TMP}.read2 ${TMP}.blob.bad 2046f3961507e73f90cec665896dece884e86be560aBill Richardsonif ${FUTILITY} gbb_utility -s --recoverykey ${TMP}.data2 ${TMP}.blob.bad; then false; fi 2056f3961507e73f90cec665896dece884e86be560aBill Richardson 2066df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson 2076df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# GBB v1.2 adds a sha256 digest field in what was previously padding: 2086df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# 2096df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# hwid_digest: 0x0030 xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx 2106df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# 0x0040 xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx xx 2116df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# pad: 0x0050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2126df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# 0x0060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2136df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# 0x0070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2146df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# (HWID) 0x0080 30 31 32 33 34 35 36 37 38 39 41 42 43 44 45 00 2156df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson 2166df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# See that the digest is updated properly. 2176df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardsonhwid="123456789ABCDEF" 2181eae873b6194db25781233d7a4aaee6a34160eecBill Richardson${FUTILITY} gbb_utility -s --hwid=${hwid} ${TMP}.blob 2196df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardsonexpect=$(echo -n "$hwid" | sha256sum | cut -d ' ' -f 1) 2206df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson[ $(echo -n ${expect} | wc -c) == "64" ] 2216df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson${FUTILITY} gbb_utility -g --digest ${TMP}.blob | grep ${expect} 2226df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson 2236df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# Garble the digest, see that it's noticed. 2246df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# (assuming these zeros aren't present) 2256df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardsoncat ${TMP}.blob | ${REPLACE} 0x33 0x00 0x00 0x00 0x00 0x00 > ${TMP}.blob.bad 2266df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson${FUTILITY} gbb_utility -g --digest ${TMP}.blob.bad | grep '0000000000' 2276df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson${FUTILITY} gbb_utility -g --digest ${TMP}.blob.bad | grep 'invalid' 2286df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson 2296df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson# Garble the HWID. The digest is unchanged, but now invalid. 2306df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardsoncat ${TMP}.blob | ${REPLACE} 0x84 0x70 0x71 0x72 > ${TMP}.blob.bad 2316df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson${FUTILITY} gbb_utility -g --digest ${TMP}.blob.bad | grep 'invalid' 2326df3e33912baf2633ed27fce6fe166d87e2f04a8Bill Richardson 2336f3961507e73f90cec665896dece884e86be560aBill Richardson# cleanup 2346f3961507e73f90cec665896dece884e86be560aBill Richardsonrm -f ${TMP}* 2356f3961507e73f90cec665896dece884e86be560aBill Richardsonexit 0 236