secureswitools/swianalysistoolkit/source/chainvalidityandinstallfilestatustools/common/siscertificatechain.cpp
changeset 0 ba25891c3a9e
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2005-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 */
       
    17 
       
    18 
       
    19 #include "siscertificatechain.h"
       
    20 #include "osinterface.h"
       
    21 #include <algorithm>
       
    22 using namespace std;
       
    23 
       
    24 SISCertificateChain::SISCertificateChain()
       
    25 	:iDevCertCapabilities(0) ,
       
    26 	iCertChain (0)
       
    27 	{
       
    28 	}
       
    29 
       
    30 
       
    31 int SISCertificateChain::Run(const Options& aOptions , const SWICertStore& aStore, const string& aDirectory)
       
    32 	{
       
    33 	const StringVector& chainDirectory = OSInterface::ExtractFilesFromDirectory(aDirectory , "pem");
       
    34 	int size = chainDirectory.size();
       
    35 	iCertChain = new CertificateChain[size];
       
    36 	int i = 0 ;
       
    37 	int valid = 0;
       
    38 	//implies sis file is signed.
       
    39 	if(size > 0)
       
    40 		{
       
    41 		for(vector<string>::const_iterator iterFile = chainDirectory.begin(); iterFile != chainDirectory.end(); iterFile++)
       
    42 			{
       
    43 			if(i < chainDirectory.size())
       
    44 				{
       
    45 				valid = iCertChain[i].ValidateChain(aOptions , *iterFile , aStore);
       
    46 				if(valid)
       
    47 					{
       
    48 					if(iCertChain[i].IsDevCertificate())
       
    49 						{
       
    50 						iDevCertCapabilities = iDevCertCapabilities |(iCertChain[i].GetDevCaps());
       
    51 						//only those rootcerts which validates the devcerts are pushed into this vector
       
    52 						//so that when unifying caps is called,even though root cert may validate the chain,if the chain is b broken or expired
       
    53 						//they wouldn't be considered.
       
    54 						if(iCertChain[i].GetValidationStatus() == 0)
       
    55 							{
       
    56 							
       
    57 							iDevCertValidatedRootSignature.push_back(iCertChain[i].GetValidatedRootSignatures());
       
    58 							}
       
    59 						}
       
    60 					else
       
    61 						{
       
    62 						//even though the cert chain may be validated by any certs in the certstore,but the chain is broken or any certificate in the chain is expired.
       
    63 						//they wouldn't be considered for unifying caps .
       
    64 						if(iCertChain[i].GetValidationStatus() == 0)
       
    65 							{
       
    66 							iValidatedRootSignature.push_back(iCertChain[i].GetValidatedRootSignatures());
       
    67 							}
       
    68 						}
       
    69 					}
       
    70 			else
       
    71 				{
       
    72 #ifdef DUMPCHAINVALIDITYTOOL
       
    73 				cout<<"Is Not Validated By Certstore:" << endl << endl;
       
    74 #endif
       
    75 				}
       
    76 			}
       
    77 		i++;
       
    78 		}
       
    79 	}
       
    80 
       
    81 	else
       
    82 		{
       
    83 		cout<<"SIS File is Unsigned." << endl << endl;
       
    84 		return 0;
       
    85 		}
       
    86 
       
    87 	return 1;
       
    88 	}
       
    89 
       
    90 
       
    91 void SISCertificateChain::VerifyMandatory(const SWICertStore& aStore)
       
    92 	{
       
    93 	string missingMandatoryCerts;
       
    94 	const SWICertStore::MandatoryCertInfo* mandatoryList = aStore.GetMandatoryCertInfoList();
       
    95 	while(mandatoryList)
       
    96 		{
       
    97 		if(iValidatedRootSignature.size())
       
    98 			{
       
    99 			StringVector::iterator start = iValidatedRootSignature.begin();
       
   100 			StringVector::iterator last = iValidatedRootSignature.end();
       
   101 			string signature((const char*)(mandatoryList->iSignature) , (mandatoryList->iSignatureLength));
       
   102 			StringVector::iterator mandatory = find(start , last , signature);
       
   103 			if(mandatory == last)
       
   104 				{
       
   105 				string missingMandatoryLabel = mandatoryList->iMandatoryCertName;
       
   106 				missingMandatoryCerts.append(missingMandatoryLabel);
       
   107 				missingMandatoryCerts.append("\n");
       
   108 				}
       
   109 			}
       
   110 		mandatoryList = mandatoryList->iNext;
       
   111 		}
       
   112 
       
   113 	if(missingMandatoryCerts.length())
       
   114 		{
       
   115 #ifdef DUMPCHAINVALIDITYTOOL
       
   116 		cout << "SIS File is not signed with the following Mandatory Certificate " << endl << "in the CertStore :" << endl << endl;
       
   117 		cout << missingMandatoryCerts << endl;
       
   118 #endif
       
   119 		}
       
   120 	}
       
   121 
       
   122 SISCertificateChain::~SISCertificateChain()
       
   123 	{
       
   124 	delete [] iCertChain;
       
   125 	}