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