long.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/sh
  2. #
  3. # Copyright The Mbed TLS Contributors
  4. # SPDX-License-Identifier: Apache-2.0
  5. #
  6. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  7. # not use this file except in compliance with the License.
  8. # You may obtain a copy of the License at
  9. #
  10. # http://www.apache.org/licenses/LICENSE-2.0
  11. #
  12. # Unless required by applicable law or agreed to in writing, software
  13. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  14. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. # See the License for the specific language governing permissions and
  16. # limitations under the License.
  17. set -eu
  18. : ${OPENSSL:=openssl}
  19. NB=20
  20. OPT="-days 3653 -sha256"
  21. # generate self-signed root
  22. $OPENSSL ecparam -name prime256v1 -genkey -out 00.key
  23. $OPENSSL req -new -x509 -subj "/C=UK/O=mbed TLS/CN=CA00" $OPT \
  24. -key 00.key -out 00.crt
  25. # cXX.pem is the chain starting at XX
  26. cp 00.crt c00.pem
  27. # generate long chain
  28. i=1
  29. while [ $i -le $NB ]; do
  30. UP=$( printf "%02d" $((i-1)) )
  31. ME=$( printf "%02d" $i )
  32. $OPENSSL ecparam -name prime256v1 -genkey -out ${ME}.key
  33. $OPENSSL req -new -subj "/C=UK/O=mbed TLS/CN=CA${ME}" \
  34. -key ${ME}.key -out ${ME}.csr
  35. $OPENSSL x509 -req -CA ${UP}.crt -CAkey ${UP}.key -set_serial 1 $OPT \
  36. -extfile int.opensslconf -extensions int \
  37. -in ${ME}.csr -out ${ME}.crt
  38. cat ${ME}.crt c${UP}.pem > c${ME}.pem
  39. rm ${ME}.csr
  40. i=$((i+1))
  41. done