⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 revreq

📁 Perl写的CA认证程序
💻
字号:
#!/usr/bin/perl## Certificate Revocation Request## (c) 1999 by The OpenCA Team## All Rights Reserved#### Project Information:#### 	Current Version ..................... $ver: 0.020a##      Project Started on .................. 17/03/1999##      Last Modified on .................... 17/03/1999##      Project Closed on ................... n/a#### If you want to contact me (the author) please use the e-mail## addresses listed below. Do not esitate in reporting bugs, enhancement## or anything seems useful in developing this software:####	Miguel Armas <kuko@ulpgc.es>#### Thank you for using this software, and remember that Open Projects## are the future of mankind. Do not sleep, partecipate to world wide## efforts to make life easier for all!## Base requirementsrequire 5.001;push (@INC, "lib/" );## Modules to be installed to have this program to work properlyuse OpenCA::Configuration;use OpenCA::TRIStateCGI;## Generate a new reference to Configuration ( instance )my $config = new OpenCA::Configuration;## Let's load our default configuration$CONFIG = 'conf/public.conf'; if( $config->loadCfg( "$CONFIG" ) == -1 ) {	print "Content-type: text/html\n\n";	print "Error while Loading Configuration ($CONFIG)!";	die "Can not load config file ($CONFIG).";}## Now it's time to get the parameters passed over the webmy $query  = new OpenCA::TRIStateCGI;## Flush the output$|=1;## Print the Content Type for Browserprint "Content-type: text/html\n\n";## Main Section## ============my $doc = 'RevStartForm';my $dir = 'RevReqDir';my $basedoc = getRequired($doc);my $successPage = getRequired('RevSuccessPage');my $errorPage = getRequired('RevErrorPage');my $destDir  = getRequired($dir);my $verifypath = getRequired('VerifyPath');my $cacert = getRequired('VerifyCACert');# Read query parametersmy $OPERATION = $query->param('operation'); my $signature = $query->param('signature'); my $subject = $query->param('subject'); my $text  = $query->param('text'); if ( $OPERATION eq "sign" ) {     ## Get Destination FileName     $destFile = setFileName( "$subject" );     ## Open Destination File     open( FD, ">$destDir/$destFile" ) or             configError ("Error Writing Approved Request : $destFile");     print( FD "$text" );     close(FD);	          ## Write signature file     open( FD, ">$destDir/$destFile.sig" ) or             configError ("Error Writing Request Signature: $destFile.sig");     print( FD "-----BEGIN PKCS7-----\n");     print( FD "$signature\n" );     print( FD "-----END PKCS7-----\n");     close(FD);          # Let's test if the signature is correct...     $signaturefile = "$destDir/$destFile.sig";     $textfile = "$destDir/$destFile";     $command = "$verifypath $signaturefile -d $textfile -cf $cacert > /dev/null";     if (system("$command")) {        ## Couldn't verify signature, send error page		## There was an error, delete the erroneous request...	unlink $signaturefile;	unlink $textfile;		open ( FD, "$errorPage" ) || die ( "File not Found : $errorPage" );	while( $temp = <FD> ) {             $page .= $temp;	};	close ( FD );		print "$page";	exit 0;     }          # All went OK, send success page     open ( FD, "$successPage" ) || die ( "File not Found : $successPage" );     while( $temp = <FD> ) {        $page .= $temp;     };     close ( FD );          print "$page";     exit 0;}## Request Operation...## Get request form## Get the base Page ( got in $page variable )open ( FD, "$basedoc" ) || die ( "File not Found : $basedoc" );	while( $temp = <FD> ) {		$page .= $temp;	};close ( FD );$table = createTable();## Process all variables#while (($key,$val) = each %ENV) {#        $table .= addEntry ( $key, $val);#}# Add relevant Variables...$table .= addEntry ( "Subject:", $ENV{SSL_CLIENT_S_DN_CN});$table .= addEntry ( "E-Mail:", $ENV{SSL_CLIENT_S_DN_Email});$table .= addEntry ( "DN:", $ENV{SSL_CLIENT_S_DN});$table .= addEntry ( "Issued by:", $ENV{SSL_CLIENT_I_DN});$table .= addEntry ( "Not Before:", $ENV{SSL_CLIENT_V_START});$table .= addEntry ( "Not After:", $ENV{SSL_CLIENT_V_END});$table .= addEntry ( "Serial:", $ENV{SSL_CLIENT_M_SERIAL});# Text to sign$text  = "------- CERTIFICATE REVOCATION REQUEST -------\n";$text .= "Subject: $ENV{SSL_CLIENT_S_DN_CN} \n";$text .= "E-Mail: $ENV{SSL_CLIENT_S_DN_Email} \n";$text .= "DN: $ENV{SSL_CLIENT_S_DN} \n";$text .= "Issued by: $ENV{SSL_CLIENT_I_DN} \n";$text .= "Not Before: $ENV{SSL_CLIENT_V_START} \n";$text .= "Not After: $ENV{SSL_CLIENT_V_END} \n";$text .= "Serial: $ENV{SSL_CLIENT_M_SERIAL} \n";$text .= "----- END CERTIFICATE REVOCATION REQUEST -----\n";## Close the Table$table .= "</TABLE>\n\n";$table .= "<!--- End of the Cert Test CGI Generated Table ---!>";$table .= "<BR><CENTER>";$table .= "&copy; 1999 The OpenCA Team.";$table .= "</CENTER>\n";## Substitute the Variables in the $page$page = $query->subVar( $page, '$table', $table );$page = $query->subVar( $page, '$text', $text );$page = $query->subVar( $page, '$subject', $ENV{SSL_CLIENT_S_DN_CN});print "$page";exit 0;## Subroutines Section : main subroutines are the createTable wich ## creates the base Table with the main row ( with Descriptions ),## the addFile wich adds a Row with the File description and date of## creations and so on, and the subVars ehich substitutes the variables## name contained in the $page var with their correct values.sub createTable {	my @keys;        my $ret;        @keys = @_; 	## No parameters needed	$ret  = '<!--- Table Generated by Revocation Request CGI ---!>';	$ret .= '<TABLE BORDER=0 CELLSPACING=5 CELLPADDING=2 WIDTH="95%"';	$ret .= ' BGCOLOR="#FFFFFF">'."\n";	$ret .= '<TR BGCOLOR="#DDCCFF" NOSAVE>'."\n";	$ret .= '<TD NOSAVE><B>Variable</B></TD>'."\n";	$ret .= '<TD><B>Value</B></TD>'."\n";	$ret .= '</TR>'."\n";	return $ret;}sub addEntry {         my $key = shift @_;	 my $val = shift @_;         my $ret;	 $val =~ s/\///;	 $val =~ s/\//\<BR\>\n/gi;         $ret = '<TR VALIGN=TOP BGCOLOR="#FFFFFF">'."\n";	 $ret .= "<TD>$key</TD>";	 $ret .= '<TD>'. "$val" . '</TD>';         $ret .= "</TR>";}## Service Functions## =================## Returns the file Name in the format## Name_Surname~pid_DATE00-00-0000_req.p7sub setFileName {   ## local ($NAME_FILE) = @_ if @_;      ## Modified by Massimiliano Pala (10-12-1998)   my $NAME_FILE;   my @keys;      @keys = @_;      $NAME_FILE =  $keys[0];      ## Get Operator Certificate Serial Number   my $op = $ENV{'SSL_CLIENT_M_SERIAL'};      ## If no op serial, replace it with one random, but   ## it shouldn't happen. This modify is only for the   ## Demo version of the OpenCA.   $op=666 if ( not $op );		         $NAME_FILE =~ s/\s/_/go;   $NAME_FILE=~ s/[\(\)\+\?]/_/g;      ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);   $date = "$mday-".($mon+1)."-".(1900+$year);   $DATE="DATE"."$date";      $NM = "op" . $op . "_" . $NAME_FILE . "\~"   . $$ . "_" . $DATE . "_req";   return $NM;}sub configError {        my @keys = @_;	my $err = $keys[0];		print $query->start_html(-title=>"Administration Error",	        -BGCOLOR=>"#FFFFFF");	print "<CENTER><BR><HR WIDTH=80%><BR></CENTER>";	print "<OL><OL><H1><FONT COLOR=red>Error 690 </FONT></H1>";	print "<OL> <B>Configuration Error</B>. $err.</OL></OL></OL>";	closePage();}sub subVars {	my @keys;        my $ret;        @keys = @_; 	$pageVar = $keys[0];	$varName = $keys[1];	$var	 = $keys[2];	$match = "\\$varName";        $pageVar =~ s/$match/$var/g;	return $pageVar;};sub getRequired {        ## Returns required parameter SINGLE STRING VALUE        ## this function simplifies the parameter access        ## but returns only the first parameter        my $name = @_[0];        my $tmp;        if( ($tmp = $config->getParam($name)) == undef ) {                ## If there is an Error, just send the missing                ## parameter error to the browser                configError( "Missing Configuration Keyword : $dir" );        }        ## If all gone well we should have the value string in        ## $ret and return it to the calling funcion;        $ret = $tmp->{VALUES}->[0];        return $ret;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -