1 #!/bin/bash 2 3 # 4 # Copyright (C) 2016 The Android Open Source Project 5 # 6 # Permission is hereby granted, free of charge, to any person 7 # obtaining a copy of this software and associated documentation 8 # files (the "Software"), to deal in the Software without 9 # restriction, including without limitation the rights to use, copy, 10 # modify, merge, publish, distribute, sublicense, and/or sell copies 11 # of the Software, and to permit persons to whom the Software is 12 # furnished to do so, subject to the following conditions: 13 # 14 # The above copyright notice and this permission notice shall be 15 # included in all copies or substantial portions of the Software. 16 # 17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 21 # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 22 # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 23 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 # SOFTWARE. 25 # 26 27 # This shell-script generates ATX test data in the working directory. 28 # An avbtool executable is assumed to reside in the parent directory 29 # of this script. 30 # 31 # The *atx* test data in the test/data/ directory was generated with 32 # this script. It is consistent with the expectations of avbtool unit 33 # tests and ATX unit tests. This script exists as a record of how the 34 # data was generated and as a convenience if it ever needs to be 35 # generated again. 36 # 37 # Typical usage: 38 # 39 # $ cd test/data; ../avb_atx_generate_test_data 40 41 set -e 42 43 TMP_FILE=$(mktemp /tmp/atx_generator.XXXXXXXXXX) 44 trap "rm -f '${TMP_FILE}'" EXIT 45 46 AVBTOOL=$(dirname "$0")/../avbtool 47 48 echo AVBTOOL = ${AVBTOOL} 49 50 # Get a random product ID. 51 head -c 16 /dev/urandom > atx_product_id.bin 52 53 # Generate key pairs. 54 openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -outform PEM \ 55 -out testkey_atx_prk.pem 56 openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -outform PEM \ 57 -out testkey_atx_pik.pem 58 openssl genpkey -algorithm RSA -pkeyopt rsa_keygen_bits:4096 -outform PEM \ 59 -out testkey_atx_psk.pem 60 61 # Construct permanent attributes. 62 ${AVBTOOL} make_atx_permanent_attributes --output=atx_permanent_attributes.bin \ 63 --product_id=atx_product_id.bin --root_authority_key=testkey_atx_prk.pem 64 65 # Construct a PIK certificate. 66 echo -n "fake PIK subject" > ${TMP_FILE} 67 ${AVBTOOL} make_atx_certificate --output=atx_pik_certificate.bin \ 68 --subject=${TMP_FILE} --subject_key=testkey_atx_pik.pem \ 69 --subject_is_intermediate_authority --subject_key_version 42 \ 70 --authority_key=testkey_atx_prk.pem 71 72 # Construct a PSK certificate. 73 ${AVBTOOL} make_atx_certificate --output=atx_psk_certificate.bin \ 74 --subject=atx_product_id.bin --subject_key=testkey_atx_psk.pem \ 75 --subject_key_version 42 --authority_key=testkey_atx_pik.pem 76 77 # Construct metadata. 78 ${AVBTOOL} make_atx_metadata --output=atx_metadata.bin \ 79 --intermediate_key_certificate=atx_pik_certificate.bin \ 80 --product_key_certificate=atx_psk_certificate.bin 81 82