-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsp
More file actions
executable file
·345 lines (267 loc) · 7.02 KB
/
csp
File metadata and controls
executable file
·345 lines (267 loc) · 7.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
#!/usr/bin/perl
use lib './blib/lib';
use CSP;
use Getopt::Long;
sub list_csp
{
my $dir = shift;
opendir CSPD,"$dir/csp";
my @dirs = readdir CSPD;
closedir CSPD;
grep /^[^.]/,@dirs;
}
$usage=<<EOU;
Usage: $0 <ca name> create
$0 <ca name> delete
$0 <ca name> init
[--crtfile=<PEM certificate>]
$0 <ca name> init
[--keysize=<size>]
[--keypass=<ca private key password>]
[--keyfile=<private key file>]
[--csrfile=<output PKCS10 request>]
[--days=<ca certificate validity (days)>]
[--email=<subjectAltName email>]
[--url=<subjectAltName url>]
[--crldays=<days to first CRL update>]
[--crlhours=<hours to first CRL update>]
[--digest=<sha1*|md5|md2|mdc2>]
[--verbose]+
<CA Subject (X509 Name)>
$0 <ca name> request
[--keysize=<size>]
[--keypass=<subject private key password>]
[--keyfile=<private key file>]
[--type=<*user|server|objsign|ca>]
[--csrfile=<output pkcs10 request file>]
[--noconfirm]
[--verbose]+
[--digest=<sha1*|md5|md2|mdc2>]
{<X509 Name>|<RFC822 address>|<DNS name>}
$0 <ca name> issue
[--keysize=<size> ]
[--keypass=<subject private key password>]
[--keyfile=<private key file>]
[--noconfirm]
[--verbose]+
[--type=<*user|server|objsign|ca>]
[--days=<certificate validity (days)>]
[--capass=<CA private key password>]
[--email=<subjectAltName email>]
[--url=<subjectAltName url>]
[--ip=<subjectAltName ip address>]
[--dns=<subjectAltName dns name>]
[--digest=<sha1*|md5|md2|mdc2>]
{<X509 Name>|<RFC822 address>|<DNS name>}
$0 <ca name> sign
[--type=<*user|server|objsign|ca>]
[--capass=<CA private key password>]
[--csrfile=<input PKCS10 request>]
[--email=<subjectAltName email>]
[--url=<subjectAltName url>]
[--ip=<subjectAltName ip address>]
[--dns=<subjectAltName dns name>]
[--digest=<sha1*|md5|md2|mdc2>]
[--verbose]+
$0 <ca name> p12
[--p12pass=<pkcs12 export password>]
[--keypass=<private key password>]
[--verbose]+
<serial>
$0 <ca name> revoke <serial>
[--noconfirm] [--quiet[=<level>]]
$0 <ca name> gencrl
[--crldays=<days to next CRL update>]
[--crlhours=<hours to next CRL update>]
[--digest=<sha1*|md5|md2|mdc2>]
[--verbose]+
$0 <ca name> genpublic
[--export=<export directory>]
[--verbose]+
$0 <ca name> list
[--serial=<serial>]
[--all]
[--xinfo]
[--contents]
[--verbose]+
$0 --list
$0 --bundle
EOU
die $usage unless @ARGV > 0;
my $name = shift @ARGV;
warn "Warning: \$CSPHOME unset. This may prevent CSP from working properly.\n"
unless $ENV{CSPHOME};
die "Panic: \$OPENSSL does not point to a executable.\n"
unless -x $ENV{OPENSSL};
my $home = $ENV{CSPHOME} || 'ca';
mkdir "$home/csp",00755 unless -d "$home/csp";
$name eq '--list' and
do
{
map { print "$_\n"; } &list_csp($home);
},exit;
$name eq '--bundle' and
do
{
my @certs = map { "$home/csp/$_/ca.crt" } list_csp($home);
CSP->caBundle({bundle=>"$home/ca-bundle.crt"},@certs);
},exit;
die $usage unless @ARGV > 0;
my $cmd = shift @ARGV;
my $csp = CSP->new($home,$name);
my %args = (keysize => 1024,
days => 365,
crldays => 30,
crlhours=> 0,
type => 'user',
verbose => 0,
confirm => 1,
xinfo => 0,
contents=> 0,
digest => 'sha1',
all => 0,
capass => '');
my @args = ("type=s",
"all!",
"verbose+",
"confirm!",
"keysize=i",
"days=i",
"xinfo!",
"contents!",
"serial=i",
"keypass=s",
"keyfile=s",
"csrfile=s",
"crtfile=s",
"email=s",
"ip=s",
"dns=s",
"export:s",
"digest=s",
"url=s",
"capass=s");
SWITCH:
{
##
## Dump (text form) the CA certificate
##
$cmd eq 'dump' and
do
{
GetOptions(\%args,@args) or die $usage;
$csp->dump(\%args);
},last SWITCH;
##
## Drop the CA
##
$cmd eq 'delete' and
do
{
GetOptions(\%args,@args) or die $usage;
$csp->delete(\%args);
},last SWITCH;
##
## Initialize a ca using a self-signed certificate.
##
$cmd eq 'create' and
do
{
GetOptions(\%args,@args) or die $usage;
$csp->create(\%args);
},last SWITCH;
##
## Initialize a ca using a self-signed certificate.
##
$cmd eq 'init' and
do
{
$args{keysize} = 2048;
$args{type} = 'root';
GetOptions(\%args,@args) or die $usage;
die $usage unless @ARGV == 1 or $args{crtfile};
$args{dn} = $csp->getDN(shift @ARGV,\%args) if @ARGV;
$csp->init(\%args);
},last SWITCH;
##
## Request a certificate of a specific type
##
$cmd eq 'request' and
do
{
GetOptions(\%args,@args) or die $usage;
die $usage unless @ARGV == 1;
$args{dn} = $csp->getDN(shift @ARGV,\%args);
$csp->request(\%args);
},last SWITCH;
##
## Create a pkcs12 object for a given serial
##
$cmd eq 'p12' and
do
{
GetOptions(\%args,@args) or die $usage;
die $usage unless @ARGV == 1;
$args{serial} = $ARGV[0];
$csp->export_pkcs12(\%args);
},last SWITCH;
##
## Issue a certificate of a specific type
##
$cmd eq 'issue' and
do
{
GetOptions(\%args,@args) or die $usage;
die $usage unless @ARGV == 1;
$args{dn} = $csp->getDN(shift @ARGV,\%args);
$csp->issue(\%args);
},last SWITCH;
##
## Sign a certificate request (PKCS10 file)
##
$cmd eq 'sign' and
do
{
GetOptions(\%args,@args) or die $usage;
$csp->issue(\%args);
},last SWITCH;
##
## Revoke a certificate given by serial
##
$cmd eq 'revoke' and
do
{
GetOptions(\%args,@args) or die $usage;
die $usage unless @ARGV == 1 || $args{serial};
$args{serial} = shift unless $args{serial};
$csp->revoke(\%args);
},last SWITCH;
##
## Generate a new crl
##
$cmd eq 'gencrl' and
do
{
GetOptions(\%args,@args) or die $usage;
$csp->gencrl(\%args);
},last SWITCH;
##
## Generate public sites (www & ldap)
##
($cmd eq 'genpublic') and
do
{
GetOptions(\%args,@args) or die $usage;
$csp->genPublic(\%args);
},last SWITCH;
##
## List certificates
##
($cmd eq 'list' or $cmd eq 'show') and
do
{
GetOptions(\%args,@args) or die $usage;
map { $_->dump(); } $csp->list(\%args,'CSP::Entity');
},last SWITCH;
die $usage;
}