3 # Copyright (c) 2008, 2009 Nicira Networks.
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:
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
21 $CGI::POST_MAX = 65536; # Limit POSTs to 64 kB.
26 my $pkidir = '@PKIDIR@';
29 die unless $q->request_method() eq 'POST';
31 my $type = $q->param('type');
32 die unless defined $type;
33 die unless $type eq 'switch' or $type eq 'controller';
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;
40 my $digest = Digest::SHA1::sha1_hex($req);
41 my $incoming = "$pkidir/${type}ca/incoming";
42 my $dst = "$incoming/$digest-req.pem";
44 sysopen(REQUEST, "$dst.tmp", O_RDWR | O_CREAT | O_EXCL, 0600)
45 or die "sysopen $dst.tmp: $!";
47 close(REQUEST) or die "close $dst.tmp: $!";
49 rename("$dst.tmp", $dst) or die "rename $dst.tmp to $dst: $!";
51 print $q->header('text/html', '204 No response');