## OpenCA - Command
## (c) 1998-2001 by Massimiliano Pala and OpenCA Group
## (c) Copyright 2002-2004 The OpenCA Project
##
## File Name: viewCert
## Brief: Display a certificate
## Version: $Revision: 1.6 $
## Description: Display certificate data
## Parameters: dataType, key
## this script supports the following configurable references
##
## INSTALL_CERT
## LDAP
## REVOCATION
## SENDCERT
## SEND_CERT_KEY
## VIEW_CSR
## TOKENHANDLING
## MAIL
## SET_PUBLIC_PASSWD
## DELETE_PUBLIC_PASSWD
use strict;
sub cmdViewCert {
our ( $query, $self );
my ($info_list, $cmd_list, $hidden_list, $cmd_panel) = (undef, undef, undef, undef);
my ($hidden_pos, $info_pos, $cmd_pos) = (0, 0, 0);
## Get the Serial Number
my $key = $query->param( 'key' );
my $dataType = $query->param( 'dataType' );
my $status;
my @certDataTypes = ( "VALID_CERTIFICATE", "EXPIRED_CERTIFICATE",
"SUSPENDED_CERTIFICATE", "REVOKED_CERTIFICATE" );
if( not $key and ($key != 0)) {
configError( gettext ("Error, missing key!") );
}
if ( not $dataType ) {
$dataType = "CERTIFICATE";
}
if ( $dataType =~ /^VALID_CERTIFICATE/ ) {
$status = gettext ("Valid");
} elsif ( $dataType =~ /^EXPIRED_CERTIFICATE/ ) {
$status = gettext("Expired");
} elsif ( $dataType =~ /^SUSPENDED_CERTIFICATE/ ) {
$status = gettext("Suspended");
} elsif ( $dataType =~ /^REVOKED_CERTIFICATE/ ) {
$status = gettext("Revoked");
} elsif ( $dataType =~ /^VALID_CA_CERTIFICATE/ ) {
$status = gettext("Valid");
} elsif ( $dataType =~ /^EXPIRED_CA_CERTIFICATE/ ) {
$status = gettext("Expired");
} elsif ( $dataType =~ /^CA_CERTIFICATE/ ) {
## try to determine the datatype
if ($db->getItem ( DATATYPE => "VALID_CA_CERTIFICATE", KEY => $key )) {
$dataType = "VALID_CA_CERTIFICATE";
$status = gettext("Valid");
} elsif ($db->getItem ( DATATYPE => "EXPIRED_CA_CERTIFICATE", KEY => $key )) {
$dataType = "EXPIRED_CA_CERTIFICATE";
$status = gettext("Expired");
} else {
configError ( gettext ("Cannot determine status of this CA-Certificate!"));
}
} elsif ( $dataType =~ /^CERTIFICATE/ ) {
## try to determine the datatype
if ($db->getItem ( DATATYPE => "VALID_CERTIFICATE", KEY => $key )) {
$dataType = "VALID_CERTIFICATE";
$status = gettext("Valid");
} elsif ($db->getItem ( DATATYPE => "EXPIRED_CERTIFICATE", KEY => $key )) {
$dataType = "EXPIRED_CERTIFICATE";
$status = gettext("Expired");
} elsif ($db->getItem ( DATATYPE => "SUSPENDED_CERTIFICATE", KEY => $key )) {
$dataType = "SUSPENDED_CERTIFICATE";
$status = gettext("Suspended");
} elsif ($db->getItem ( DATATYPE => "REVOKED_CERTIFICATE", KEY => $key )) {
$dataType = "REVOKED_CERTIFICATE";
$status = gettext("Revoked");
} else {
configError ( gettext ("Cannot determine status of this Certificate!"));
}
} else {
configError (i18nGettext ("DataType not supported (__DATATYPE__)!", "__DATATYPE__", $dataType));
}
my $cert = $db->getItem( DATATYPE=>$dataType, KEY=>$key );
configError( i18nGettext ("Error __ERRNO__, unable to get cert from dB! (__ERRVAL__)",
"__ERRNO__", $db->errno(),
"__ERRVAL__", $db->errval())) if( not $cert );
my $parsedCert = $cert->getParsed();
## build emailaddress string
my $emails = "";
foreach my $email (@{$parsedCert->{EMAILADDRESSES}})
{
$emails .= ", " if ($emails);
$emails .= $email;
}
$hidden_list->{"cmd"} = "";
$hidden_list->{"GET_PARAMS_CMD"} = "";
$hidden_list->{"passwd"} = "";
$hidden_list->{"key"} = $key;
$hidden_list->{"HIDDEN_key"} = $key;
$hidden_list->{"dataType"} = $dataType;
$hidden_list->{"dn"} = $parsedCert->{DN};
$hidden_list->{"new_dn"} = "";
$hidden_list->{"name"} = "PUBLIC";
$hidden_list->{"format"} = "";
$hidden_list->{"text"} = "";
$hidden_list->{"signature"} = "";
my $tmpIssuer = $parsedCert->{ISSUER};
my $tmpDN = $parsedCert->{DN};
my $tmpStatus = $status;
## old version - if it can be removed then simply remove it
$tmpIssuer =~ s/[\/,]\s*(?=[A-Za-z0-9\-]+=)/
\n/g;
$tmpDN =~ s/[\/,]\s*(?=[A-Za-z0-9\-]+=)/
\n/g;
my $now = timestamp();
if ( $tmpStatus =~ /^Valid/i ) {
if ($now >
$cryptoShell->getNumericDate ($parsedCert->{NOTAFTER})) {
$tmpStatus = gettext("Expired");
}
} elsif ( $tmpStatus =~ /revoked/gi ) {
$tmpStatus = i18nGettext ("Revoked on __DATE__", "__DATE__", $parsedCert->{HEADER}->{REVOKED});
} elsif ( $tmpStatus =~ /^Expired/i ) {
if ($now <=
$cryptoShell->getNumericDate ($parsedCert->{NOTAFTER})) {
$tmpStatus = gettext("Not Expired");
}
}
my $download = "";
my $revoke = "";
my $ctype = "";
if ( $dataType =~ /CA_CERTIFICATE/gi ) {
$download = '?cmd=send_email_cert;type=ca;dataType=$dataType;key='.
$key; # $cert->getSerial();
$ctype = "ca";
} else {
$download = '?cmd=send_email_cert;type=email;dataType=$dataType;key='.
$key; # $cert->getSerial();
$ctype = "email";
$revoke = '?cmd=revoke_req;key='.$cert->getSerial();
}
# $info_list->{HEAD}->[0] = gettext("Variable");
# $info_list->{HEAD}->[1] = gettext("Value");
my $html_download = "";
my $text = undef;
$text = "
" .
"getSerial() . "\" alt=\"" .
$key . "\" alt=\"" .
gettext ("Install this Certificate" ) . "\">" .
" | ";
$text .= "" ;
$text .= "
| ";
$text .= "||||||||||
" . " | |||||||||||
" . # " | " . # $html_download . " | ||||||||||
" . gettext ("Certificate Profile" ) .
# ": " . $parsedCert->{HEADER}->{ROLE} . " | |||||||||||
" . gettext ("Fingerprint" ) .
": " . $parsedCert->{FINGERPRINT} . " |