os/security/cryptomgmtlibs/securitytestfw/test/autotesting/checklocationofcertificates.pl
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptomgmtlibs/securitytestfw/test/autotesting/checklocationofcertificates.pl Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,127 @@
1.4 +#
1.5 +# Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +# All rights reserved.
1.7 +# This component and the accompanying materials are made available
1.8 +# under the terms of the License "Eclipse Public License v1.0"
1.9 +# which accompanies this distribution, and is available
1.10 +# at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +#
1.12 +# Initial Contributors:
1.13 +# Nokia Corporation - initial contribution.
1.14 +#
1.15 +# Contributors:
1.16 +#
1.17 +# Description:
1.18 +# This script was written as part the solution for DEF116697: Remove Security Test Certificates from CBR
1.19 +# The purpose of the defect was to stop the export of all test certificates that may not be Symbian owned.
1.20 +# To accomplish this the certificates were all moved to a new location which does not get put in the CBR.
1.21 +# This script is run in the ONB so that no new certificates are added to any directory that appears in the CBR.
1.22 +# (Note that the certificates in rootcerts are Symbian owned and so can be exported.)
1.23 +# This script takes 2 arguments
1.24 +# - directory to search for certificates (defaults to \common\generic\security)
1.25 +# - output file for result of test (defaults to $ENV{EPOCROOT}epoc32\\winscw\\c\\CheckLocationOfCertificatesLog.txt)
1.26 +# The script searches through the specified directory for any certificate files (files ending in .cer, .der and .crt).
1.27 +# It will print out the names of any files found.
1.28 +#
1.29 +
1.30 +
1.31 +use File::Find;
1.32 +
1.33 +# array holding the list of full path names to all the certificates found.
1.34 +@Certificates;
1.35 +
1.36 +
1.37 +sub FindCerts
1.38 +{
1.39 + # Check for certificates which are not in valid locations
1.40 + if (($File::Find::dir !~ m/\/testframework\/testcertificates/) && ($File::Find::dir !~ m/\/os\/security\/cryptoservices\/rootcertificates/) && ($File::Find::dir !~ m/\/os\/security\/cryptomgmtlibs\/securitytestfw\/testcertificates/))
1.41 + {
1.42 + if ($File::Find::name =~ m/\.cer$/i)
1.43 + {
1.44 + push @Certificates, $File::Find::name;
1.45 + }
1.46 + if ($File::Find::name =~ m/\.crt$/i)
1.47 + {
1.48 + push @Certificates, $File::Find::name;
1.49 + }
1.50 + if ($File::Find::name =~ m/\.der$/i)
1.51 + {
1.52 + push @Certificates, $File::Find::name;
1.53 + }
1.54 + if ($File::Find::name =~ m/\.pem$/i)
1.55 + {
1.56 + push @Certificates, $File::Find::name;
1.57 + }
1.58 + }
1.59 +
1.60 +}
1.61 +
1.62 +
1.63 +
1.64 +# Determine directory to search
1.65 +my $dirToSearch;
1.66 +if (@ARGV[0])
1.67 + {
1.68 + $dirToSearch = $ARGV[0];
1.69 + }
1.70 +else
1.71 + {
1.72 + $dirToSearch = "$ENV{'SECURITYSOURCEDIR'}";
1.73 + }
1.74 +
1.75 +# Determine where to put the logs. This file will be parsed by the overnight build system.
1.76 +my $outputFile;
1.77 +if (@ARGV[1])
1.78 + {
1.79 + $outputFile = $ARGV[1];
1.80 + }
1.81 +else
1.82 + {
1.83 + die "EPOCROOT not defined, must specify directory" if !defined ($ENV{EPOCROOT});
1.84 + my $emulatorLogDirectory = "$ENV{EPOCROOT}logs\\winscw\\c";
1.85 +
1.86 + if ( ! -d $emulatorLogDirectory )
1.87 + {
1.88 + system("md $ENV{EPOCROOT}logs\\winscw\\c");
1.89 + }
1.90 + $outputFile = "$ENV{EPOCROOT}epoc32\\winscw\\c\\checklocationofcertificateslog.txt";
1.91 + }
1.92 +
1.93 +unlink $outputFile;
1.94 +die "\nUnable to open log $outputFile\n" if( not open( SCANLOG, ">$outputFile" ) );
1.95 +
1.96 +
1.97 +print SCANLOG "\nScanning $dirToSearch for incorrectly located certificate files.\n\n";
1.98 +
1.99 +
1.100 +# Search for certificate files
1.101 +find { wanted => \&FindCerts, no_chdir => 1 }, $dirToSearch;
1.102 +
1.103 +my $count = scalar(@Certificates);
1.104 +
1.105 +if ($count eq 0)
1.106 +{
1.107 + print (SCANLOG "No certificates found in $dirToSearch. Test PASSED.\n\n");
1.108 + print (SCANLOG "\nTests completed OK");
1.109 + print (SCANLOG "\nRun: 1");
1.110 + print (SCANLOG "\nPassed: 1");
1.111 + print (SCANLOG "\n0 tests failed out of 1");
1.112 +}
1.113 +else
1.114 + {
1.115 + foreach $certificatefile (@Certificates)
1.116 + {
1.117 + $certificatefile =~ s/\//\\/g;
1.118 + print (SCANLOG "Certificate: $certificatefile is in an invalid location. Should be moved to ......\\security\\testframework\\testcertificates\\...\n");
1.119 + print (SCANLOG "Test for $certificatefile FAILED.\n\n");
1.120 + }
1.121 + print (SCANLOG "\nTests completed OK");
1.122 + print (SCANLOG "\nRun: 1");
1.123 + print (SCANLOG "\nPassed: 0");
1.124 + print (SCANLOG "\n1 tests failed out of 1");
1.125 + }
1.126 +
1.127 +close(SCANLOG);
1.128 +
1.129 +
1.130 +