1a8e1175bSopenharmony_ci#!/bin/sh
2a8e1175bSopenharmony_ci#
3a8e1175bSopenharmony_ci# Copyright The Mbed TLS Contributors
4a8e1175bSopenharmony_ci# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
5a8e1175bSopenharmony_ci
6a8e1175bSopenharmony_ciset -eu
7a8e1175bSopenharmony_ci
8a8e1175bSopenharmony_ci: ${OPENSSL:=openssl}
9a8e1175bSopenharmony_ciNB=20
10a8e1175bSopenharmony_ci
11a8e1175bSopenharmony_ciOPT="-days 3653 -sha256"
12a8e1175bSopenharmony_ci
13a8e1175bSopenharmony_ci# generate self-signed root
14a8e1175bSopenharmony_ci$OPENSSL ecparam -name prime256v1 -genkey -out 00.key
15a8e1175bSopenharmony_ci$OPENSSL req -new -x509 -subj "/C=UK/O=mbed TLS/CN=CA00" $OPT \
16a8e1175bSopenharmony_ci             -key 00.key -out 00.crt
17a8e1175bSopenharmony_ci
18a8e1175bSopenharmony_ci# cXX.pem is the chain starting at XX
19a8e1175bSopenharmony_cicp 00.crt c00.pem
20a8e1175bSopenharmony_ci
21a8e1175bSopenharmony_ci# generate long chain
22a8e1175bSopenharmony_cii=1
23a8e1175bSopenharmony_ciwhile [ $i -le $NB ]; do
24a8e1175bSopenharmony_ci    UP=$( printf "%02d" $((i-1)) )
25a8e1175bSopenharmony_ci    ME=$( printf "%02d" $i )
26a8e1175bSopenharmony_ci
27a8e1175bSopenharmony_ci    $OPENSSL ecparam -name prime256v1 -genkey -out ${ME}.key
28a8e1175bSopenharmony_ci    $OPENSSL req -new -subj "/C=UK/O=mbed TLS/CN=CA${ME}" \
29a8e1175bSopenharmony_ci                 -key ${ME}.key -out ${ME}.csr
30a8e1175bSopenharmony_ci    $OPENSSL x509 -req -CA ${UP}.crt -CAkey ${UP}.key -set_serial 1 $OPT \
31a8e1175bSopenharmony_ci                  -extfile int.opensslconf -extensions int \
32a8e1175bSopenharmony_ci                  -in ${ME}.csr -out ${ME}.crt
33a8e1175bSopenharmony_ci
34a8e1175bSopenharmony_ci    cat ${ME}.crt c${UP}.pem > c${ME}.pem
35a8e1175bSopenharmony_ci
36a8e1175bSopenharmony_ci    rm ${ME}.csr
37a8e1175bSopenharmony_ci    i=$((i+1))
38a8e1175bSopenharmony_cidone
39