blob: 6ae71812a67bec89a24460eeac7ae12f2b06a18f [file] [log] [blame]
Sandrine Bailleuxd9d3c5b2023-10-20 13:43:28 +02001#!/usr/bin/env bash
2#
3# Copyright (c) 2023, Arm Limited. All rights reserved.
4#
5# SPDX-License-Identifier: BSD-3-Clause
6#
7
8# This run fragment is used to generate boot certificates and key files.
9
10post_tf_build() {
11 local bl31_key_file="${workspace}/bl31-key.pem"
12 local bl32_key_file="${workspace}/bl32-key.pem"
13 local bl33_key_file="${workspace}/bl33-key.pem"
14 local trusted_key_file="${workspace}/trusted-private-key.pem"
15 local non_trusted_key_file="${workspace}/non-trusted-private-key.pem"
16
17 local key_files=(
18 "$bl31_key_file"
19 "$bl33_key_file"
20 "$trusted_key_file"
21 "$non_trusted_key_file"
22 )
23
24 # BL32 key only gets generated if building TF-A with an SPD.
25 if upon "$(get_tf_opt SPD)"; then
26 key_files+=("$bl32_key_file")
27 fi
28
29 # Generate the boot certificates and key files.
30 #
31 # Note that even if we do not generate a FIP, TF-A build system still
32 # demands a BL33 image so provide a dummy one.
33 tf_extra_rules="certificates" build_tf_extra \
34 BL33="$(mktempfile)" \
35 GENERATE_COT=1 \
36 CREATE_KEYS=1 \
37 SAVE_KEYS=1 \
38 BL31_KEY="$bl31_key_file" \
39 BL32_KEY="$bl32_key_file" \
40 BL33_KEY="$bl33_key_file" \
41 TRUSTED_WORLD_KEY="$trusted_key_file" \
42 NON_TRUSTED_WORLD_KEY="$non_trusted_key_file" \
43
44
45 echo "Checking that the keys got correctly generated and saved..."
46
47 for i in "${!key_files[@]}"; do
48 # A valid private key file in PEM format starts with:
49 # -----BEGIN PRIVATE KEY-----
50 grep -q 'BEGIN PRIVATE KEY' "${key_files[$i]}" || \
51 (echo "Key file \"${key_files[$i]}\" is incorrect." && exit 1)
52 done
53
54 echo "All keys verified."
55}