|
1 /* |
|
2 * Copyright (c) 1998-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 "pkixvalidationresult.h" |
|
20 |
|
21 //validationresult |
|
22 EXPORT_C CPKIXValidationResultBase* CPKIXValidationResultBase::NewL() |
|
23 { |
|
24 CPKIXValidationResultBase* s = CPKIXValidationResultBase::NewLC(); |
|
25 CleanupStack::Pop();//s |
|
26 return s; |
|
27 } |
|
28 |
|
29 EXPORT_C CPKIXValidationResultBase* CPKIXValidationResultBase::NewLC() |
|
30 { |
|
31 CPKIXValidationResultBase* s = new(ELeave) CPKIXValidationResultBase; |
|
32 CleanupStack::PushL(s); |
|
33 s->ConstructL(); |
|
34 return s; |
|
35 } |
|
36 |
|
37 EXPORT_C CPKIXValidationResultBase::~CPKIXValidationResultBase() |
|
38 { |
|
39 delete iWarnings; |
|
40 if (iPolicies != NULL) |
|
41 { |
|
42 iPolicies->ResetAndDestroy(); |
|
43 } |
|
44 delete iPolicies; |
|
45 iCertWarnings.ResetAndDestroy(); |
|
46 } |
|
47 |
|
48 EXPORT_C CPKIXValidationResultBase::CPKIXValidationResultBase() |
|
49 :iError(EChainHasNoRoot, 0) |
|
50 { |
|
51 } |
|
52 |
|
53 EXPORT_C void CPKIXValidationResultBase::ConstructL() |
|
54 { |
|
55 #ifdef _DEBUG |
|
56 // In OOM we don't want the size of the arrays to change because this will |
|
57 // cause a change in the numbers of allocated cells |
|
58 iWarnings = new(ELeave) CArrayFixFlat<TValidationStatus> (100); |
|
59 iPolicies = new(ELeave) CArrayPtrFlat<CX509CertPolicyInfo> (100); |
|
60 iPolicies->AppendL(0); |
|
61 iPolicies->ResetAndDestroy(); |
|
62 #else |
|
63 iWarnings = new(ELeave) CArrayFixFlat<TValidationStatus> (1); |
|
64 iPolicies = new(ELeave) CArrayPtrFlat<CX509CertPolicyInfo> (1); |
|
65 #endif |
|
66 } |
|
67 |
|
68 EXPORT_C const TValidationStatus CPKIXValidationResultBase::Error() const |
|
69 { |
|
70 return iError; |
|
71 } |
|
72 |
|
73 EXPORT_C const CArrayFixFlat<TValidationStatus>& CPKIXValidationResultBase::Warnings() const |
|
74 { |
|
75 return *iWarnings; |
|
76 } |
|
77 |
|
78 EXPORT_C const CArrayPtrFlat<CX509CertPolicyInfo>& CPKIXValidationResultBase::Policies() const |
|
79 { |
|
80 return *iPolicies; |
|
81 } |
|
82 |
|
83 void CPKIXValidationResultBase::Reset() |
|
84 { |
|
85 iError = TValidationStatus(EChainHasNoRoot, 0); |
|
86 iWarnings->Reset(); |
|
87 RemovePolicies(); |
|
88 } |
|
89 |
|
90 void CPKIXValidationResultBase::SetErrorAndLeaveL(const TValidationError aError, const TInt aCert) |
|
91 { |
|
92 SetError(aError, aCert); |
|
93 User::Leave(KErrGeneral); |
|
94 } |
|
95 |
|
96 void CPKIXValidationResultBase::SetError(const TValidationError aError, const TInt aCert) |
|
97 { |
|
98 iError.iReason = aError; |
|
99 iError.iCert = aCert; |
|
100 } |
|
101 |
|
102 void CPKIXValidationResultBase::AppendWarningL(TValidationStatus aWarning) |
|
103 { |
|
104 iWarnings->AppendL(aWarning); |
|
105 |
|
106 if (aWarning.iReason != ECriticalExtendedKeyUsage && aWarning.iReason != ECriticalPolicyMapping && |
|
107 aWarning.iReason != ECriticalDeviceId && aWarning.iReason != ECriticalSid && |
|
108 aWarning.iReason != ECriticalVid && aWarning.iReason != ECriticalCapabilities) |
|
109 { |
|
110 (*iCertWarnings[iCertWarnings.Count()-1]).AppendWarningL(aWarning); |
|
111 } |
|
112 } |
|
113 |
|
114 void CPKIXValidationResultBase::AppendPolicyL(CX509CertPolicyInfo& aPolicy) |
|
115 { |
|
116 iPolicies->AppendL(&aPolicy); |
|
117 } |
|
118 |
|
119 void CPKIXValidationResultBase::RemovePolicies() |
|
120 { |
|
121 iPolicies->ResetAndDestroy(); |
|
122 } |
|
123 |
|
124 EXPORT_C void CPKIXValidationResultBase::ExternalizeL(RWriteStream& aStream) const |
|
125 { |
|
126 // iError |
|
127 aStream.WriteL(TPckgC<TValidationStatus>(iError)); |
|
128 |
|
129 // iWarnings |
|
130 aStream.WriteInt32L(iWarnings->Count()); |
|
131 TInt32 i; |
|
132 for (i = 0;i < iWarnings->Count(); ++i) |
|
133 { |
|
134 aStream.WriteL(TPckgC<TValidationStatus>((*iWarnings)[i])); |
|
135 } |
|
136 |
|
137 // iPolicies |
|
138 aStream.WriteInt32L(iPolicies->Count()); |
|
139 for (i = 0;i < iPolicies->Count(); ++i) |
|
140 { |
|
141 (*iPolicies)[i]->ExternalizeL(aStream); |
|
142 } |
|
143 |
|
144 // iCertWarnings |
|
145 aStream.WriteInt32L(iCertWarnings.Count()); |
|
146 for (i = 0;i< iCertWarnings.Count(); ++i) |
|
147 { |
|
148 (*iCertWarnings[i]).ExternalizeL(aStream); |
|
149 } |
|
150 } |
|
151 |
|
152 EXPORT_C void CPKIXValidationResultBase::InternalizeL(RReadStream& aStream) |
|
153 { |
|
154 // iError |
|
155 TPckg<TValidationStatus> pckg(iError); |
|
156 aStream.ReadL(pckg); |
|
157 |
|
158 // iWarnings |
|
159 iWarnings->Reset(); |
|
160 |
|
161 TInt32 count=aStream.ReadInt32L(); |
|
162 TInt32 i; |
|
163 for (i = 0;i < count; ++i) |
|
164 { |
|
165 TValidationStatus warning(EValidatedOK,0); |
|
166 TPckg<TValidationStatus> pckg(warning); |
|
167 aStream.ReadL(pckg); |
|
168 iWarnings->AppendL(warning); |
|
169 } |
|
170 |
|
171 // iPolicies |
|
172 iPolicies->ResetAndDestroy(); |
|
173 |
|
174 count=aStream.ReadInt32L(); |
|
175 for (i = 0;i < count; ++i) |
|
176 { |
|
177 CX509CertPolicyInfo* certPolicyInfo=CX509CertPolicyInfo::NewLC(aStream); |
|
178 iPolicies->AppendL(certPolicyInfo); |
|
179 CleanupStack::Pop(certPolicyInfo); |
|
180 } |
|
181 |
|
182 // iCertWarnings |
|
183 iCertWarnings.Reset(); |
|
184 |
|
185 count=aStream.ReadInt32L(); |
|
186 for (i = 0;i < count; ++i) |
|
187 { |
|
188 CCertificateValidationWarnings* certWarning=CCertificateValidationWarnings::InternalizeL(aStream); |
|
189 CleanupStack::PushL(certWarning); |
|
190 iCertWarnings.AppendL(certWarning); |
|
191 CleanupStack::Pop(certWarning); |
|
192 } |
|
193 } |
|
194 |
|
195 EXPORT_C const RPointerArray<CCertificateValidationWarnings>& CPKIXValidationResultBase::ValidationWarnings() const |
|
196 { |
|
197 return iCertWarnings; |
|
198 } |
|
199 |
|
200 EXPORT_C void CPKIXValidationResultBase::AppendCertificateValidationObjectL(const CCertificateValidationWarnings& aCertWarning) |
|
201 { |
|
202 iCertWarnings.AppendL(&aCertWarning); |
|
203 } |
|
204 |
|
205 EXPORT_C void CPKIXValidationResultBase::AppendCriticalExtensionWarningL(TDesC& aCriticalExt) |
|
206 { |
|
207 (*iCertWarnings[iCertWarnings.Count()-1]).AppendCriticalExtensionWarningL(aCriticalExt); |
|
208 } |