| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | |
| 3 | # Copyright (C) 2021 Free Software Foundation, Inc. |
| 4 | # |
| 5 | # Author: Daniel Kahn Gillmor |
| 6 | # |
| 7 | # This file is part of GnuTLS. |
| 8 | # |
| 9 | # GnuTLS is free software; you can redistribute it and/or modify it |
| 10 | # under the terms of the GNU General Public License as published by the |
| 11 | # Free Software Foundation; either version 3 of the License, or (at |
| 12 | # your option) any later version. |
| 13 | # |
| 14 | # GnuTLS is distributed in the hope that it will be useful, but |
| 15 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | # General Public License for more details. |
| 18 | # |
| 19 | # You should have received a copy of the GNU General Public License |
| 20 | # along with GnuTLS. If not, see <https://www.gnu.org/licenses/>. |
| 21 | |
| 22 | #set -e |
| 23 | |
| 24 | : ${srcdir=.} |
| 25 | : ${CERTTOOL=../../src/certtool${EXEEXT}} |
| 26 | TMPFILE=crfg-kx.$$.tmp |
| 27 | TMPCA=eddsa-ca.$$.tmp |
| 28 | TMPCAKEY=eddsa-ca-key.$$.tmp |
| 29 | TMPSUBCA=eddsa-subca.$$.tmp |
| 30 | TMPSUBCAKEY=eddsa-subca-key.$$.tmp |
| 31 | TMPKEY=kx-key.$$.tmp |
| 32 | TMPTEMPL=template.$$.tmp |
| 33 | TMPUSER=user.$$.tmp |
| 34 | VERIFYOUT=verify.$$.tmp |
| 35 | |
| 36 | if ! testscip-shell system . . test. -x "${CERTTOOL}"; then |
| 37 | exit 77 |
| 38 | fi |
| 39 | |
| 40 | for curve in 25519 448; do |
| 41 | echoscip-shell system . . echo. ca > $TMPTEMPL |
| 42 | echoscip-shell system . . echo. "cn = Ed$curve CA" >> $TMPTEMPL |
| 43 | |
| 44 | "${CERTTOOL}" --generate-privkey --key-type=ed$curve > $TMPCAKEY 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 45 | |
| 46 | "${CERTTOOL}" -d 2 --generate-self-signed --template $TMPTEMPL \ |
| 47 | --load-privkey $TMPCAKEY \ |
| 48 | --outfile $TMPCA >$TMPFILE 2>&1 |
| 49 | |
| 50 | if [scip-shell system . . `[`. $? != 0 ]; then |
| 51 | catscip-shell system . . cat. $TMPFILE |
| 52 | exit 1 |
| 53 | fi |
| 54 | |
| 55 | echoscip-shell system . . echo. ca > $TMPTEMPL |
| 56 | echoscip-shell system . . echo. "cn = Ed$curve Mid CA" >> $TMPTEMPL |
| 57 | |
| 58 | "${CERTTOOL}" --generate-privkey --key-type=ed$curve > $TMPSUBCAKEY 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 59 | |
| 60 | "${CERTTOOL}" -d 2 --generate-certificate --template $TMPTEMPL \ |
| 61 | --load-ca-privkey $TMPCAKEY \ |
| 62 | --load-ca-certificate $TMPCA \ |
| 63 | --load-privkey $TMPSUBCAKEY \ |
| 64 | --outfile $TMPSUBCA >$TMPFILE 2>&1 |
| 65 | |
| 66 | if [scip-shell system . . `[`. $? != 0 ]; then |
| 67 | catscip-shell system . . cat. $TMPFILE |
| 68 | exit 1 |
| 69 | fi |
| 70 | |
| 71 | echoscip-shell system . . echo. "cn = End-user" > $TMPTEMPL |
| 72 | echoscip-shell system . . echo. email_protection_key >> $TMPTEMPL |
| 73 | echoscip-shell system . . echo. encryption_key >> $TMPTEMPL |
| 74 | |
| 75 | "${CERTTOOL}" --generate-privkey --key-type=x$curve > $TMPKEY 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 76 | |
| 77 | "${CERTTOOL}" -d 2 --generate-certificate --template $TMPTEMPL \ |
| 78 | --load-ca-privkey $TMPSUBCAKEY \ |
| 79 | --load-ca-certificate $TMPSUBCA \ |
| 80 | --load-privkey $TMPKEY \ |
| 81 | --outfile $TMPUSER >$TMPFILE 2>&1 |
| 82 | |
| 83 | if [scip-shell system . . `[`. $? != 0 ]; then |
| 84 | catscip-shell system . . cat. $TMPFILE |
| 85 | exit 1 |
| 86 | fi |
| 87 | |
| 88 | catscip-shell system . . cat. $TMPUSER $TMPSUBCA $TMPCA > $TMPFILE |
| 89 | "${CERTTOOL}" --verify-chain <$TMPFILE > $VERIFYOUT |
| 90 | |
| 91 | if [scip-shell system . . `[`. $? != 0 ]; then |
| 92 | catscip-shell system . . cat. $VERIFYOUT |
| 93 | exit 1 |
| 94 | fi |
| 95 | |
| 96 | rmscip-shell system . . rm. -f $VERIFYOUT $TMPUSER $TMPCA $TMPSUBCA $TMPTEMPL $TMPFILE |
| 97 | rmscip-shell system . . rm. -f $TMPSUBCAKEY $TMPCAKEY $TMPKEY |
| 98 | done |
| 99 | |
| 100 | exit 0 |