cryptomgmtlibs/securitytestfw/test/autotesting/checklocationofcertificates.pl
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 #
       
     2 # Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 # All rights reserved.
       
     4 # This component and the accompanying materials are made available
       
     5 # under the terms of the License "Eclipse Public License v1.0"
       
     6 # which accompanies this distribution, and is available
       
     7 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 #
       
     9 # Initial Contributors:
       
    10 # Nokia Corporation - initial contribution.
       
    11 #
       
    12 # Contributors:
       
    13 #
       
    14 # Description: 
       
    15 #
       
    16 # This script was written as part the solution for DEF116697: Remove Security Test Certificates from CBR 
       
    17 # The purpose of the defect was to stop the export of all test certificates that may not be Symbian owned.
       
    18 # To accomplish this the certificates were all moved to a new location which does not get put in the CBR.
       
    19 # This script is run in the ONB so that no new certificates are added to any directory that appears in the CBR.
       
    20 # (Note that the certificates in rootcerts are Symbian owned and so can be exported.)
       
    21 
       
    22 
       
    23 # This script takes 2 arguments
       
    24 # - directory to search for certificates (defaults to \common\generic\security)
       
    25 # - output file for result of test (defaults to $ENV{EPOCROOT}epoc32\\winscw\\c\\CheckLocationOfCertificatesLog.txt)
       
    26 # The script searches through the specified directory for any certificate files (files ending in .cer, .der and .crt).
       
    27 # It will print out the names of any files found. 
       
    28  
       
    29 
       
    30 use File::Find;
       
    31 
       
    32 # array holding the list of full path names to all the certificates found.
       
    33 @Certificates;
       
    34  
       
    35  
       
    36 sub FindCerts
       
    37 {
       
    38 	# Check for certificates which are not in valid locations 
       
    39 	if (($File::Find::dir !~ m/\/testframework\/testcertificates/) && ($File::Find::dir !~ m/\/os\/security\/cryptoservices\/rootcertificates/))
       
    40 	{	
       
    41 		if ($File::Find::name =~ m/\.cer$/i)
       
    42 		{
       
    43 			push @Certificates, $File::Find::name;	 
       
    44 		}
       
    45 		if ($File::Find::name =~ m/\.crt$/i)
       
    46 		{
       
    47 			push @Certificates, $File::Find::name;	 
       
    48 		}
       
    49 		if ($File::Find::name =~ m/\.der$/i)
       
    50 		{
       
    51 			push @Certificates, $File::Find::name;
       
    52 		}
       
    53 		if ($File::Find::name =~ m/\.pem$/i)
       
    54 		{
       
    55 			push @Certificates, $File::Find::name;
       
    56 		}	
       
    57 	}
       
    58 	
       
    59 }
       
    60 
       
    61  
       
    62 
       
    63 # Determine directory to search  
       
    64 my $dirToSearch;
       
    65 if (@ARGV[0])
       
    66 	{
       
    67 	$dirToSearch = $ARGV[0];
       
    68 	}
       
    69 else
       
    70 	{
       
    71 	$dirToSearch = "$ENV{'SECURITYSOURCEDIR'}";
       
    72 	}
       
    73 
       
    74 # Determine where to put the logs. This file will be parsed by the overnight build system.
       
    75 my $outputFile;
       
    76 if (@ARGV[1])
       
    77 	{
       
    78 	$outputFile = $ARGV[1];
       
    79 	}
       
    80 else
       
    81 	{
       
    82 	die "EPOCROOT not defined, must specify directory" if !defined ($ENV{EPOCROOT});
       
    83 	my $emulatorLogDirectory = "$ENV{EPOCROOT}logs\\winscw\\c";
       
    84 
       
    85 	if ( ! -d $emulatorLogDirectory )
       
    86 		{
       
    87 		system("md $ENV{EPOCROOT}logs\\winscw\\c");
       
    88 		}
       
    89 		$outputFile = "$ENV{EPOCROOT}epoc32\\winscw\\c\\checklocationofcertificateslog.txt";
       
    90 	}
       
    91 
       
    92 unlink $outputFile;
       
    93 die "\nUnable to open log $outputFile\n" if( not open( SCANLOG, ">$outputFile" ) );
       
    94 
       
    95 
       
    96 print SCANLOG "\nScanning $dirToSearch for incorrectly located certificate files.\n\n";
       
    97 
       
    98 
       
    99 # Search for certificate files
       
   100 find { wanted => \&FindCerts, no_chdir => 1 }, $dirToSearch;
       
   101 
       
   102 my $count = scalar(@Certificates);
       
   103  
       
   104 if ($count eq 0)
       
   105 {
       
   106  	print (SCANLOG "No certificates found in $dirToSearch. Test PASSED.\n\n");
       
   107  	print (SCANLOG "\nTests completed OK");
       
   108  	print (SCANLOG "\nRun: 1");
       
   109  	print (SCANLOG "\nPassed: 1");	
       
   110 	print (SCANLOG "\n0 tests failed out of 1"); 
       
   111 } 
       
   112 else 
       
   113 	{	
       
   114 	foreach $certificatefile (@Certificates)
       
   115 		{
       
   116 		$certificatefile =~ s/\//\\/g;
       
   117 		print (SCANLOG "Certificate: $certificatefile is in an invalid location. Should be moved to ......\\security\\testframework\\testcertificates\\...\n");
       
   118 		print (SCANLOG "Test for $certificatefile FAILED.\n\n");
       
   119 		}
       
   120 		print (SCANLOG "\nTests completed OK");
       
   121  		print (SCANLOG "\nRun: 1");
       
   122  		print (SCANLOG "\nPassed: 0");	
       
   123 		print (SCANLOG "\n1 tests failed out of 1"); 
       
   124 	}
       
   125  
       
   126 close(SCANLOG);
       
   127  
       
   128  
       
   129