~lynxman/ubuntu/natty/openvswitch/lp_822142

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
#! @PERL@

# Copyright (c) 2008, 2009 Nicira Networks.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at:
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

use CGI;
use Digest::SHA1;
use Fcntl;

$CGI::POST_MAX = 65536;    # Limit POSTs to 64 kB.

use strict;
use warnings;

my $pkidir = '@PKIDIR@';
my $q = new CGI;

die unless $q->request_method() eq 'POST';

my $type = $q->param('type');
die unless defined $type;
die unless $type eq 'switch' or $type eq 'controller';

my $req = $q->param('req');
die unless defined $req;
die unless $req =~ /^-----BEGIN CERTIFICATE REQUEST-----$/m;
die unless $req =~ /^-----END CERTIFICATE REQUEST-----$/m;

my $digest = Digest::SHA1::sha1_hex($req);
my $incoming = "$pkidir/${type}ca/incoming";
my $dst = "$incoming/$digest-req.pem";

sysopen(REQUEST, "$dst.tmp", O_RDWR | O_CREAT | O_EXCL, 0600)
  or die "sysopen $dst.tmp: $!";
print REQUEST $req;
close(REQUEST) or die "close $dst.tmp: $!";

rename("$dst.tmp", $dst) or die "rename $dst.tmp to $dst: $!";

print $q->header('text/html', '204 No response');

# Local Variables:
# mode: perl
# End: