## OpenCA - Public Web-Gateway Command
## (c) 1998-2001 by Massimiliano Pala and OpenCA Group
##
##   File Name: test_cert
##       Brief: test a certificate
## Description: test and verify an existing certificate which was used 
##              for loading this page
##  Parameters: 
 
sub cmdTest_cert {

my $basedoc    = getRequired ('testcertform');

## Get the base Page ( got in $page variable )
my $page = $tools->getFile( "$basedoc" );

## Create Base Table
$table = $query->startTable ( COLS=> [ gettext("Variable"), gettext("Value") ],
                              WIDTH => "100%",
                              TITLE_BGCOLOR=>"#DDCCFF" );

my $dn =  $ENV{SSL_SERVER_S_DN};
my $dn2 = $ENV{SSL_CLIENT_S_DN};

$dn =~ s/^\///;
$dn =~ s/\//<BR>/g;

$dn2 =~ s/^\///;
$dn2 =~ s/\//<BR>/g;

# Add relevant Variables...
$table .= $query->addTableLine ( DATA=>[ gettext("Session Protocol:"),
                                      $ENV{SSL_PROTOCOL} ] );
$table .= $query->addTableLine ( DATA=>[ gettext("Session Chiper:"),
                                      $ENV{SSL_CIPHER} ] );
$table .= $query->addTableLine ( DATA=>[ gettext("Session Key Size:"),
                                      $ENV{SSL_CIPHER_USEKEYSIZE} ] );
$table .= $query->addTableLine ( DATA=>[ gettext("Server Distinguished Name:"),
                                      $dn ] );
$table .= $query->addTableLine ( DATA=>[ gettext("Client Authentication:"), 
                                      $ENV{SSL_CLIENT_VERIFY} ] );
$table .= $query->addTableLine ( DATA=>[ gettext("Client Distinguished Name:"),
                                      $dn2 ] );
## Close the Table
$table .= $query->endTable ();
$table .= getCopyRight ();

# Text to sign
$text = gettext ("You are going to sign this simple text. Be sure\n Javascript is enabled and your certificate gets\n correctly verified in your browser.\n");
  
## Substitute the Variables in the $page
$page = $query->subVar( $page, '@TABLE@', $table );
$page = $query->subVar( $page, '@TEXT@', $text );

print "$page";

}

1;
