7 $CGI::POST_MAX = 65536; # Limit POSTs to 64 kB.
12 my $pkidir = '@pkidir@';
15 die unless $q->request_method() eq 'POST';
17 my $type = $q->param('type');
18 die unless defined $type;
19 die unless $type eq 'switch' or $type eq 'controller';
21 my $req = $q->param('req');
22 die unless defined $req;
23 die unless $req =~ /^-----BEGIN CERTIFICATE REQUEST-----$/m;
24 die unless $req =~ /^-----END CERTIFICATE REQUEST-----$/m;
26 my $digest = Digest::SHA1::sha1_hex($req);
27 my $incoming = "$pkidir/${type}ca/incoming";
28 my $dst = "$incoming/$digest-req.pem";
30 sysopen(REQUEST, "$dst.tmp", O_RDWR | O_CREAT | O_EXCL, 0600)
31 or die "sysopen $dst.tmp: $!";
33 close(REQUEST) or die "close $dst.tmp: $!";
35 rename("$dst.tmp", $dst) or die "rename $dst.tmp to $dst: $!";
37 print $q->header('text/html', '204 No response');