]> git.proxmox.com Git - ovs.git/blame - utilities/ovs-pki-cgi.in
Global replace of Nicira Networks.
[ovs.git] / utilities / ovs-pki-cgi.in
CommitLineData
064af421
BP
1#! @PERL@
2
e0edde6f 3# Copyright (c) 2008, 2009 Nicira, Inc.
a14bc59f
BP
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
064af421
BP
17use CGI;
18use Digest::SHA1;
19use Fcntl;
20
21$CGI::POST_MAX = 65536; # Limit POSTs to 64 kB.
22
23use strict;
24use warnings;
25
26my $pkidir = '@PKIDIR@';
27my $q = new CGI;
28
29die unless $q->request_method() eq 'POST';
30
31my $type = $q->param('type');
32die unless defined $type;
33die unless $type eq 'switch' or $type eq 'controller';
34
35my $req = $q->param('req');
36die unless defined $req;
37die unless $req =~ /^-----BEGIN CERTIFICATE REQUEST-----$/m;
38die unless $req =~ /^-----END CERTIFICATE REQUEST-----$/m;
39
40my $digest = Digest::SHA1::sha1_hex($req);
41my $incoming = "$pkidir/${type}ca/incoming";
42my $dst = "$incoming/$digest-req.pem";
43
44sysopen(REQUEST, "$dst.tmp", O_RDWR | O_CREAT | O_EXCL, 0600)
45 or die "sysopen $dst.tmp: $!";
46print REQUEST $req;
47close(REQUEST) or die "close $dst.tmp: $!";
48
49rename("$dst.tmp", $dst) or die "rename $dst.tmp to $dst: $!";
50
51print $q->header('text/html', '204 No response');
52
53# Local Variables:
54# mode: perl
55# End: