OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / utils / newhostkey
1 #! /bin/sh
2 # generate new key for this host
3 # Copyright (C) 2001, 2002  Henry Spencer.
4
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the
7 # Free Software Foundation; either version 2 of the License, or (at your
8 # option) any later version.  See <http://www.fsf.org/copyleft/gpl.txt>.
9
10 # This program is distributed in the hope that it will be useful, but
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 # or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13 # for more details.
14 #
15 # RCSID $Id: newhostkey,v 1.3.2.1 2002/04/09 21:34:56 mcr Exp $
16
17 me="ipsec newhostkey"
18 usage="Usage: $me --output filename [--bits n] [--quiet] [--hostname host]
19          or
20        $me --output - [--bits n] [--quiet] [--verbose] [--hostname host] >filename"
21
22 bits=2192
23 verbose=
24 host=
25 output=
26 for dummy
27 do
28         case "$1" in
29         --bits) bits="$2" ; shift       ;;
30         --quiet)        verbose=        ;;
31         --hostname)     host="--hostname $2" ; shift    ;;
32         --output)       output="$2" ; shift             ;;
33         --verbose)      verbose=--verbose       ;;
34         --version)      echo "$me $IPSEC_VERSION" ; exit 0      ;;
35         --help) echo "$usage" ; exit 0  ;;
36         --)     shift ; break           ;;
37         -*)     echo "$me: unknown option \`$1'" >&2 ; exit 2   ;;
38         *)      break                   ;;
39         esac
40         shift
41 done
42
43 if test " $output" = " " && test ! -f ${IPSEC_CONFS}/ipsec.secrets
44 then
45     output=${IPSEC_CONFS}/ipsec.secrets
46 fi
47
48 if test " $output" = " "
49 then
50         echo "$0: no --output specification included" >&2
51         exit 1
52 elif test " $verbose" != " " -a " $output" != " -" -a -s "$output"
53 then
54         echo "$0: WARNING: file \`$output' exists, appending to it" >&2
55 fi
56
57 (
58         echo ': RSA     {'
59         ipsec rsasigkey $verbose $host $bits
60         echo '  }'
61         echo '# do not change the indenting of that "}"'
62 ) |
63 if test " $output" = " -"
64 then
65         cat
66 else
67         umask 077
68         cat >>$output
69 fi