sl@0: # sl@0: # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: # All rights reserved. sl@0: # This component and the accompanying materials are made available sl@0: # under the terms of the License "Eclipse Public License v1.0" sl@0: # which accompanies this distribution, and is available sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: # sl@0: # Initial Contributors: sl@0: # Nokia Corporation - initial contribution. sl@0: # sl@0: # Contributors: sl@0: # sl@0: # Description: sl@0: # This script was written as part the solution for DEF116697: Remove Security Test Certificates from CBR sl@0: # The purpose of the defect was to stop the export of all test certificates that may not be Symbian owned. sl@0: # To accomplish this the certificates were all moved to a new location which does not get put in the CBR. sl@0: # This script is run in the ONB so that no new certificates are added to any directory that appears in the CBR. sl@0: # (Note that the certificates in rootcerts are Symbian owned and so can be exported.) sl@0: # This script takes 2 arguments sl@0: # - directory to search for certificates (defaults to \common\generic\security) sl@0: # - output file for result of test (defaults to $ENV{EPOCROOT}epoc32\\winscw\\c\\CheckLocationOfCertificatesLog.txt) sl@0: # The script searches through the specified directory for any certificate files (files ending in .cer, .der and .crt). sl@0: # It will print out the names of any files found. sl@0: # sl@0: sl@0: sl@0: use File::Find; sl@0: sl@0: # array holding the list of full path names to all the certificates found. sl@0: @Certificates; sl@0: sl@0: sl@0: sub FindCerts sl@0: { sl@0: # Check for certificates which are not in valid locations sl@0: if (($File::Find::dir !~ m/\/testframework\/testcertificates/) && ($File::Find::dir !~ m/\/os\/security\/cryptoservices\/rootcertificates/) && ($File::Find::dir !~ m/\/os\/security\/cryptomgmtlibs\/securitytestfw\/testcertificates/)) sl@0: { sl@0: if ($File::Find::name =~ m/\.cer$/i) sl@0: { sl@0: push @Certificates, $File::Find::name; sl@0: } sl@0: if ($File::Find::name =~ m/\.crt$/i) sl@0: { sl@0: push @Certificates, $File::Find::name; sl@0: } sl@0: if ($File::Find::name =~ m/\.der$/i) sl@0: { sl@0: push @Certificates, $File::Find::name; sl@0: } sl@0: if ($File::Find::name =~ m/\.pem$/i) sl@0: { sl@0: push @Certificates, $File::Find::name; sl@0: } sl@0: } sl@0: sl@0: } sl@0: sl@0: sl@0: sl@0: # Determine directory to search sl@0: my $dirToSearch; sl@0: if (@ARGV[0]) sl@0: { sl@0: $dirToSearch = $ARGV[0]; sl@0: } sl@0: else sl@0: { sl@0: $dirToSearch = "$ENV{'SECURITYSOURCEDIR'}"; sl@0: } sl@0: sl@0: # Determine where to put the logs. This file will be parsed by the overnight build system. sl@0: my $outputFile; sl@0: if (@ARGV[1]) sl@0: { sl@0: $outputFile = $ARGV[1]; sl@0: } sl@0: else sl@0: { sl@0: die "EPOCROOT not defined, must specify directory" if !defined ($ENV{EPOCROOT}); sl@0: my $emulatorLogDirectory = "$ENV{EPOCROOT}logs\\winscw\\c"; sl@0: sl@0: if ( ! -d $emulatorLogDirectory ) sl@0: { sl@0: system("md $ENV{EPOCROOT}logs\\winscw\\c"); sl@0: } sl@0: $outputFile = "$ENV{EPOCROOT}epoc32\\winscw\\c\\checklocationofcertificateslog.txt"; sl@0: } sl@0: sl@0: unlink $outputFile; sl@0: die "\nUnable to open log $outputFile\n" if( not open( SCANLOG, ">$outputFile" ) ); sl@0: sl@0: sl@0: print SCANLOG "\nScanning $dirToSearch for incorrectly located certificate files.\n\n"; sl@0: sl@0: sl@0: # Search for certificate files sl@0: find { wanted => \&FindCerts, no_chdir => 1 }, $dirToSearch; sl@0: sl@0: my $count = scalar(@Certificates); sl@0: sl@0: if ($count eq 0) sl@0: { sl@0: print (SCANLOG "No certificates found in $dirToSearch. Test PASSED.\n\n"); sl@0: print (SCANLOG "\nTests completed OK"); sl@0: print (SCANLOG "\nRun: 1"); sl@0: print (SCANLOG "\nPassed: 1"); sl@0: print (SCANLOG "\n0 tests failed out of 1"); sl@0: } sl@0: else sl@0: { sl@0: foreach $certificatefile (@Certificates) sl@0: { sl@0: $certificatefile =~ s/\//\\/g; sl@0: print (SCANLOG "Certificate: $certificatefile is in an invalid location. Should be moved to ......\\security\\testframework\\testcertificates\\...\n"); sl@0: print (SCANLOG "Test for $certificatefile FAILED.\n\n"); sl@0: } sl@0: print (SCANLOG "\nTests completed OK"); sl@0: print (SCANLOG "\nRun: 1"); sl@0: print (SCANLOG "\nPassed: 0"); sl@0: print (SCANLOG "\n1 tests failed out of 1"); sl@0: } sl@0: sl@0: close(SCANLOG); sl@0: sl@0: sl@0: