OSDN Git Service

2013.10.24
[uclinux-h8/uClinux-dist.git] / freeswan / utils / _secretcensor
1 #! /bin/sh
2 # implements secret censoring for barf
3 # Copyright (C) 1999  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: _secretcensor,v 1.9 2002/04/01 23:36:50 mcr Exp $
16
17 usage="Usage: $0 [file ...]"
18 me="ipsec _secretcensor"
19
20 for dummy
21 do
22         case "$1" in
23         --help)         echo "$usage" ; exit 0  ;;
24         --version)      echo "$me $IPSEC_VERSION" ; exit 0              ;;
25         --)             shift ; break           ;;
26         -*)             echo "$0: unknown option \`$1'" >&2 ; exit 2    ;;
27         *)              break                   ;;
28         esac
29         shift
30 done
31
32 awk '   function cool(hot,   q, cooled, run) {
33                 # warning:  may destroy input line!
34                 q = "'"'"'"     # single quote
35                 if (hot ~ q)
36                         return "[cannot be summed]"
37                 if (hot ~ /^0s/)
38                         return "[keyid " substr(hot, 3, 9) "]"
39                 run = "echo " q hot q " | md5sum"
40                 run | getline
41                 close(run)
42                 return "[sums to " substr($1, 1, 4) "...]"
43         }
44         /"/ {
45                 i = match($0, /"[^"]+"/)
46                 cold1 = substr($0, 1, i)
47                 cold2 = substr($0, i+RLENGTH-1)
48                 hot = substr($0, i+1, RLENGTH-2)
49                 print cold1 cool(hot) cold2
50                 next
51         }
52         /#pubkey=/ {
53                 i = match($0, /^.*#pubkey=/)
54                 i += RLENGTH-1
55                 cold = substr($0, 1, i)
56                 hot = substr($0, i+1)
57                 print cold cool(hot)
58                 next
59         }
60         /#IN KEY / {
61                 i = match($0, /^.*[ \t][^ \t]/)
62                 i += RLENGTH-2
63                 cold = substr($0, 1, i)
64                 hot = substr($0, i+1)
65                 print cold cool("0s" hot)
66                 next
67         }
68         /^[ \t]+(Modulus|P[a-z]+Exponent|Prime[12]|Exponent[12]|Coefficient):/ {
69                 i = match($0, /^[^:]*:[ \t]*/)
70                 i += RLENGTH-1
71                 cold = substr($0, 1, i)
72                 print cold "[...]"
73                 next
74         }
75         { print }' $*