Merge branch 'master' of /afs/hcoop.net/user/h/hc/hcoop/.hcoop-git/domtool2
[hcoop/domtool2.git] / scripts / domtool-addcert
... / ...
CommitLineData
1#!/bin/sh -e
2
3USER="$1"
4if test -z "$USER"; then
5 echo Usage: domtool-addcert USERNAME
6 exit 1
7fi
8
9 KEYDIR=/afs/hcoop.net/common/etc/domtool/keys/$USER
10 KEYFILE=$KEYDIR/key.pem
11CERTFILE=/afs/hcoop.net/common/etc/domtool/certs/$USER.pem
12 NEWREQ=~/.newreq.pem
13 NEW=~/.new.pem
14 KEYIN=~/.keyin
15
16mkdir $KEYDIR || echo Key directory already exists.
17openssl genrsa -out $KEYFILE
18chown -R domtool.nogroup $KEYDIR
19fs sa $KEYDIR $USER read || echo This must be a server principal.
20echo "." >$KEYIN
21echo "." >>$KEYIN
22echo "." >>$KEYIN
23echo "." >>$KEYIN
24echo "." >>$KEYIN
25echo "$USER" >>$KEYIN
26echo "$USER@hcoop.net" >>$KEYIN
27echo "" >>$KEYIN
28echo "" >>$KEYIN
29openssl req -new -key $KEYFILE -out $NEWREQ -days 365 <$KEYIN
30rm $KEYIN
31cat $NEWREQ $KEYFILE >$NEW
32rm $NEWREQ
33openssl ca -batch -config /etc/domtool/openssl.cnf -policy policy_anything -out $CERTFILE -infiles $NEW
34rm $NEW
35chown domtool.nogroup $CERTFILE