%args> $identifier => undef $content_type => "PLAIN" $format => "PEM" %args> <%init> ## first we have to determine the content-type my $attachment = 1; switch ($content_type) { case "X509_CA_CERT" {$content_type = "application/x-x509-ca-cert"; $attachment = 0; } case "X509_USER_CERT" {$content_type = "application/x-x509-user-cert"; $attachment = 0; } case "X509_EMAIL_CERT" {$content_type = "application/x-x509-email-cert"; $attachment = 0; } case "IE_CA" {$content_type = "application/x-x509-ca-cert"} case "IE_USER" {$content_type = "application/x-x509-user-cert"} case "PLAIN" {$content_type = "text/plain"; $attachment = 0;} case "DOWNLOAD" {$content_type = "application/octet-string"} else { print "
\n"; print i18nGettext('I18N_OPENXPKI_CLIENT_HTML_MASON_GET_CERT_WRONG_CONTENT_TYPE_DESC', '__CONTENT_TYPE__' => $content_type)."\n"; print "
\n"; return 1; } } ## second we have to check the format my $native = ""; my $extension = ""; switch ($format) { case "PKCS7" {$native = "PKCS7"; $extension = 'p7'; } case "TXT" {$native = "TXT"; $extension = 'txt'; } case "DER" {$native = "DER"; $extension = 'der'; } case "PEM" {$native = "PEM"; $extension = 'pem'; $attachment = 1; } case "IE_ENROLL" {$native = "PEM"; $extension = 'pem'; } # ??? else { print "\n"; print i18nGettext('I18N_OPENXPKI_CLIENT_HTML_MASON_GET_CERT_WRONG_FORMAT_DESC', '__FORMAT__' => $format)."\n"; print "
\n"; return 1; } } if ($format eq 'PEM' && $content_type ne 'DOWNLOAD') { # Mozilla certificate installation has to be sent inline $attachment = 0; } my $filename = $m->comp('/lib/filename_for_cert.mhtml', 'identifier' => $identifier, 'extension' => $extension, ); ## now request the certificate from the server my $msg = $context->{client}->send_receive_command_msg ( "get_cert", {'IDENTIFIER' => $identifier, 'FORMAT' => $native}); my $item = $msg->{PARAMS}; ## now send the stuff if ($attachment) { eval { $r->header_out('Content-Disposition' => ("attachment; filename=$filename")); }; if ($EVAL_ERROR) { # mod_perl 2 $r->headers_out->add('Content-Disposition' => ("attachment; filename=$filename")); } } $r->content_type ($content_type); print $item; return 1; %init> <%once> use Switch; use English; %once>