Global replace of Nicira Networks.
[sliver-openvswitch.git] / utilities / ovs-pki-cgi.in
1 #! @PERL@
2
3 # Copyright (c) 2008, 2009 Nicira, Inc.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at:
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 use CGI;
18 use Digest::SHA1;
19 use Fcntl;
20
21 $CGI::POST_MAX = 65536;    # Limit POSTs to 64 kB.
22
23 use strict;
24 use warnings;
25
26 my $pkidir = '@PKIDIR@';
27 my $q = new CGI;
28
29 die unless $q->request_method() eq 'POST';
30
31 my $type = $q->param('type');
32 die unless defined $type;
33 die unless $type eq 'switch' or $type eq 'controller';
34
35 my $req = $q->param('req');
36 die unless defined $req;
37 die unless $req =~ /^-----BEGIN CERTIFICATE REQUEST-----$/m;
38 die unless $req =~ /^-----END CERTIFICATE REQUEST-----$/m;
39
40 my $digest = Digest::SHA1::sha1_hex($req);
41 my $incoming = "$pkidir/${type}ca/incoming";
42 my $dst = "$incoming/$digest-req.pem";
43
44 sysopen(REQUEST, "$dst.tmp", O_RDWR | O_CREAT | O_EXCL, 0600)
45   or die "sysopen $dst.tmp: $!";
46 print REQUEST $req;
47 close(REQUEST) or die "close $dst.tmp: $!";
48
49 rename("$dst.tmp", $dst) or die "rename $dst.tmp to $dst: $!";
50
51 print $q->header('text/html', '204 No response');
52
53 # Local Variables:
54 # mode: perl
55 # End: