os/security/cryptoservices/certificateandkeymgmt/tpkixcert/tpkixcertval.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
/**
sl@0
    20
 @file
sl@0
    21
*/
sl@0
    22
sl@0
    23
#include "tpkixcertval.h"
sl@0
    24
#include "tcertutils.h"
sl@0
    25
#include "t_input.h"
sl@0
    26
sl@0
    27
//tags for elements in specification file
sl@0
    28
_LIT(KRootStart, "<root>");
sl@0
    29
_LIT(KRootEnd, "</root>");
sl@0
    30
_LIT(KCertificateStart, "<certificate>");
sl@0
    31
_LIT(KCertificateEnd, "</certificate>");
sl@0
    32
_LIT(KLabelStart, "<label>");
sl@0
    33
_LIT(KLabelEnd, "</label>");
sl@0
    34
_LIT(KEEStart, "<ee>");
sl@0
    35
_LIT(KEEEnd, "</ee>");
sl@0
    36
_LIT(KInterStart, "<inter>");
sl@0
    37
_LIT(KInterEnd, "</inter>");
sl@0
    38
_LIT(KIPoliciesStart, "<ipolicies>");
sl@0
    39
_LIT(KIPoliciesEnd, "</ipolicies>");
sl@0
    40
_LIT(KIPolicyStart, "<ipolicy>");
sl@0
    41
_LIT(KIPolicyEnd, "</ipolicy>");
sl@0
    42
_LIT(KOResultStart, "<oresult>");
sl@0
    43
_LIT(KOResultEnd, "</oresult>");
sl@0
    44
_LIT(KOPoliciesStart, "<opolicies>");
sl@0
    45
_LIT(KOPoliciesEnd, "</opolicies>");
sl@0
    46
_LIT(KOPolicyStart, "<opolicy>");
sl@0
    47
_LIT(KOPolicyEnd, "</opolicy>");
sl@0
    48
sl@0
    49
//const TUint KUnicodeMarker = 0xfeff;
sl@0
    50
sl@0
    51
//**Cert Chain**//
sl@0
    52
CTestChain* CTestChain::NewL(const TDesC& aBuf)
sl@0
    53
	{
sl@0
    54
	CTestChain* self = CTestChain::NewLC(aBuf);
sl@0
    55
	CleanupStack::Pop();
sl@0
    56
	return self;
sl@0
    57
	}
sl@0
    58
sl@0
    59
CTestChain* CTestChain::NewLC(const TDesC& aBuf)
sl@0
    60
	{
sl@0
    61
	CTestChain* self = new(ELeave) CTestChain;
sl@0
    62
	CleanupStack::PushL(self);
sl@0
    63
	self->ConstructL(aBuf);
sl@0
    64
	return self;
sl@0
    65
	}
sl@0
    66
sl@0
    67
CTestChain::~CTestChain()
sl@0
    68
	{
sl@0
    69
	delete iIntermediateCertsFileName;
sl@0
    70
	delete iIntermediateCertsLabel;
sl@0
    71
	}
sl@0
    72
sl@0
    73
CTestChain::CTestChain()
sl@0
    74
	{
sl@0
    75
	}
sl@0
    76
sl@0
    77
void CTestChain::ConstructL(const TDesC& aBuf)
sl@0
    78
	{
sl@0
    79
	TInt pos = 0;
sl@0
    80
	TInt err = KErrNone;
sl@0
    81
	TPtrC rootCert(Input::ParseElement(aBuf, KRootStart, KRootEnd, pos, err));
sl@0
    82
	TInt dummyPos = 0;
sl@0
    83
	iRootCertFileName = Input::ParseElement(rootCert, KCertificateStart, 
sl@0
    84
		KCertificateEnd, dummyPos, err);
sl@0
    85
	iRootCertLabel = Input::ParseElement(rootCert, KLabelStart,
sl@0
    86
		KLabelEnd, dummyPos, err);
sl@0
    87
	if (iRootCertLabel == KNullDesC)
sl@0
    88
		{
sl@0
    89
		User::Leave(KErrNotFound);
sl@0
    90
		}
sl@0
    91
sl@0
    92
	TPtrC EECert(Input::ParseElement(aBuf, KEEStart, KEEEnd, pos));
sl@0
    93
	dummyPos = 0;
sl@0
    94
	iEECertFileName = Input::ParseElement(EECert, KCertificateStart,
sl@0
    95
		KCertificateEnd, dummyPos);
sl@0
    96
	iEECertLabel = Input::ParseElement(EECert, KLabelStart,
sl@0
    97
		KLabelEnd, dummyPos);
sl@0
    98
sl@0
    99
	iIntermediateCertsFileName = new(ELeave) CDesCArrayFlat(1);
sl@0
   100
	iIntermediateCertsLabel = new(ELeave) CDesCArrayFlat(1);
sl@0
   101
	while(AddInter(aBuf, pos))
sl@0
   102
		{
sl@0
   103
		}
sl@0
   104
	}
sl@0
   105
sl@0
   106
TBool CTestChain::AddInter(const TDesC& aBuf, TInt& aPos)
sl@0
   107
	{
sl@0
   108
	TPtrC interBuf = Input::ParseElement(aBuf, KInterStart, KInterEnd, aPos);
sl@0
   109
	TInt dummyPos = 0;
sl@0
   110
	if (interBuf != KNullDesC)
sl@0
   111
		{
sl@0
   112
		iIntermediateCertsFileName->AppendL(Input::ParseElement(interBuf, 
sl@0
   113
			KCertificateStart, KCertificateEnd, dummyPos));
sl@0
   114
		iIntermediateCertsLabel->AppendL(Input::ParseElement(interBuf,
sl@0
   115
			KLabelStart, KLabelEnd, dummyPos));
sl@0
   116
		return ETrue;
sl@0
   117
		}
sl@0
   118
	return EFalse;
sl@0
   119
	}
sl@0
   120
sl@0
   121
//**Policy Input/Output**//
sl@0
   122
CTestParameters* CTestParameters::NewL(const TDesC& aBuf)
sl@0
   123
	{
sl@0
   124
	CTestParameters* self = CTestParameters::NewLC(aBuf);
sl@0
   125
	CleanupStack::Pop();
sl@0
   126
	return self;
sl@0
   127
	}
sl@0
   128
sl@0
   129
CTestParameters* CTestParameters::NewLC(const TDesC& aBuf)
sl@0
   130
	{
sl@0
   131
	CTestParameters* self = new(ELeave) CTestParameters;
sl@0
   132
	CleanupStack::PushL(self);
sl@0
   133
	self->ConstructL(aBuf);
sl@0
   134
	return self;
sl@0
   135
	}
sl@0
   136
sl@0
   137
CTestParameters::~CTestParameters()
sl@0
   138
	{
sl@0
   139
	delete iWarnings;
sl@0
   140
	delete iPolicyInput;
sl@0
   141
	delete iExpectedPolicyOutput;
sl@0
   142
	}
sl@0
   143
sl@0
   144
CTestParameters::CTestParameters()
sl@0
   145
	:iIPoliciesSet(ETrue), iOPoliciesSet(ETrue), iOWarningsSet(ETrue)
sl@0
   146
	{
sl@0
   147
	}
sl@0
   148
sl@0
   149
void CTestParameters::ConstructL(const TDesC& aBuf)
sl@0
   150
	{
sl@0
   151
	iWarnings = new(ELeave)CArrayFixFlat<TValidationStatus> (1);
sl@0
   152
	iPolicyInput = new(ELeave) CDesCArrayFlat (1);
sl@0
   153
	iExpectedPolicyOutput = new(ELeave) CDesCArrayFlat (1);
sl@0
   154
sl@0
   155
	TInt pos = 0;
sl@0
   156
	TInt err = KErrNone;
sl@0
   157
	TPtrC iIPolicyBuf = Input::ParseElement(aBuf, KIPoliciesStart, KIPoliciesEnd, pos, err);
sl@0
   158
	if (err != KErrNone)
sl@0
   159
		{
sl@0
   160
		iIPoliciesSet = EFalse;//input policies are optional
sl@0
   161
		}
sl@0
   162
	pos = 0;
sl@0
   163
	while(AddPolicy(iIPolicyBuf, KIPolicyStart, KIPolicyEnd,pos, *iPolicyInput))
sl@0
   164
		{
sl@0
   165
		}	
sl@0
   166
	iError = Input::ParseElement(aBuf, KOResultStart, KOResultEnd, pos);
sl@0
   167
	TPtrC iOPolicyBuf = Input::ParseElement(aBuf, KOPoliciesStart, KOPoliciesEnd, pos, err);
sl@0
   168
	if (err != KErrNone)
sl@0
   169
		{
sl@0
   170
		iOPoliciesSet = EFalse;//output policies are optional
sl@0
   171
		}
sl@0
   172
	pos = 0;
sl@0
   173
	while(AddPolicy(iOPolicyBuf, KOPolicyStart, KOPolicyEnd, pos, *iExpectedPolicyOutput))
sl@0
   174
		{
sl@0
   175
		}	
sl@0
   176
	}
sl@0
   177
sl@0
   178
TBool CTestParameters::AddPolicy(const TDesC& aBuf, const TDesC& aStart, const TDesC& aEnd, TInt& aPos, CDesCArray& aPolicySet)
sl@0
   179
	{
sl@0
   180
	TPtrC policyBuf = Input::ParseElement(aBuf, aStart, aEnd, aPos);
sl@0
   181
	if (policyBuf != KNullDesC)
sl@0
   182
		{
sl@0
   183
		aPolicySet.AppendL(policyBuf);
sl@0
   184
		return ETrue;
sl@0
   185
		}
sl@0
   186
	return EFalse;
sl@0
   187
	}