|
1 /* |
|
2 * Copyright (c) 2003 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 "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: Certificate trust settings information |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 |
|
22 #include "WimCertInfo.h" |
|
23 #include "WimDummyToken.h" |
|
24 #include <securitydefs.h> |
|
25 #include "WimTrace.h" |
|
26 |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CWimCertInfo::CWimCertInfo( CCTCertInfo* aCCTCertInfo, |
|
32 // const TBuf8<KSHA1HashLengthBytes> aHash, |
|
33 // RArray<HBufC*> aTrustedUsages, |
|
34 // TUint8 aCDFRefs ) |
|
35 // : iCCTCertInfo( aCCTCertInfo ), |
|
36 // iCertHash( aHash ), |
|
37 // iTrustedUsage( aTrustedUsages ), |
|
38 // iCDFRefs( aCDFRefs ) |
|
39 // Default constructor |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 CWimCertInfo::CWimCertInfo( CCTCertInfo* aCCTCertInfo, |
|
43 const TBuf8<KSHA1HashLengthBytes> aHash, |
|
44 RArray<HBufC*> aTrustedUsages, |
|
45 TUint8 aCDFRefs ) |
|
46 : iCCTCertInfo( aCCTCertInfo ), |
|
47 iCertHash( aHash ), |
|
48 iTrustedUsage( aTrustedUsages ), |
|
49 iCDFRefs( aCDFRefs ) |
|
50 { |
|
51 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::CWimCertInfo | Begin")); |
|
52 } |
|
53 |
|
54 // ----------------------------------------------------------------------------- |
|
55 // CWimCertInfo::ConstructL() |
|
56 // Second phase constructor |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 void CWimCertInfo::ConstructL() |
|
60 { |
|
61 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::ConstructL | Begin")); |
|
62 } |
|
63 |
|
64 // ----------------------------------------------------------------------------- |
|
65 // CWimCertInfo::NewLNewL( CCTCertInfo* aCCTCertInfo, |
|
66 // const TBuf8<KSHA1HashLengthBytes> aHash, |
|
67 // RArray<HBufC*> aTrustedUsages, |
|
68 // TUint8 aCDFRefs ) |
|
69 // Two-phased constructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 EXPORT_C CWimCertInfo* CWimCertInfo::NewL( CCTCertInfo* aCCTCertInfo, |
|
73 const TBuf8<KSHA1HashLengthBytes> aHash, |
|
74 RArray<HBufC*> aTrustedUsages, |
|
75 TUint8 aCDFRefs ) |
|
76 { |
|
77 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::NewL | Begin")); |
|
78 CWimCertInfo* self = new( ELeave ) CWimCertInfo( aCCTCertInfo, |
|
79 aHash, |
|
80 aTrustedUsages, |
|
81 aCDFRefs ); |
|
82 CleanupStack::PushL( self ); |
|
83 self->ConstructL( ); |
|
84 CleanupStack::Pop( self ); |
|
85 return self; |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CWimCertInfo::~CWimCertInfo() |
|
90 // Destructor |
|
91 // ----------------------------------------------------------------------------- |
|
92 // |
|
93 CWimCertInfo::~CWimCertInfo() |
|
94 { |
|
95 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::~CWimCertInfo | Begin")); |
|
96 if ( iCCTCertInfo ) |
|
97 { |
|
98 iCCTCertInfo->Release(); |
|
99 iCCTCertInfo = NULL; |
|
100 } |
|
101 |
|
102 //Delete arrays of trusted usaga and extendedkeyusage |
|
103 for ( TInt i = 0; i < iTrustedUsage.Count(); i++ ) |
|
104 { |
|
105 delete iTrustedUsage[i]; //Delete buffers |
|
106 } |
|
107 |
|
108 iTrustedUsage.Close(); |
|
109 |
|
110 for ( TInt j = 0; j < iExtendedKeyUsage.Count(); j++ ) |
|
111 { |
|
112 delete iExtendedKeyUsage[j]; //Delete buffers |
|
113 } |
|
114 |
|
115 iExtendedKeyUsage.Close(); |
|
116 } |
|
117 |
|
118 // ----------------------------------------------------------------------------- |
|
119 // CWimCertInfo::AddTrustedUsage( HBufC* aTrustedUsage ) |
|
120 // Add TrustedUsage OID |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 EXPORT_C TInt CWimCertInfo::AddTrustedUsage( HBufC* aTrustedUsage ) |
|
124 { |
|
125 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::AddTrustedUsage | Begin")); |
|
126 return ( iTrustedUsage.Append( aTrustedUsage ) ); |
|
127 } |
|
128 |
|
129 // ----------------------------------------------------------------------------- |
|
130 // CWimCertInfo::AddExtendedKeyUsage( HBufC* aExtendedKeyUsage ) |
|
131 // Add ExtendedKeyUsage OID |
|
132 // ----------------------------------------------------------------------------- |
|
133 // |
|
134 EXPORT_C TInt CWimCertInfo::AddExtendedKeyUsage( HBufC* aExtendedKeyUsage ) |
|
135 { |
|
136 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::AddExtendedKeyUsage | Begin")); |
|
137 return ( iExtendedKeyUsage.Append( aExtendedKeyUsage ) ); |
|
138 } |
|
139 |
|
140 // ----------------------------------------------------------------------------- |
|
141 // CWimCertInfo::GetCertHash( TBuf8<KSHA1HashLengthBytes>& aHash ) const |
|
142 // Get hash of certificate |
|
143 // ----------------------------------------------------------------------------- |
|
144 // |
|
145 EXPORT_C void CWimCertInfo::GetCertHash( |
|
146 TBuf8<KSHA1HashLengthBytes>& aHash ) const |
|
147 { |
|
148 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::GetCertHash | Begin")); |
|
149 aHash = iCertHash; |
|
150 } |
|
151 |
|
152 // ----------------------------------------------------------------------------- |
|
153 // CWimCertInfo::CctCert() const |
|
154 // Return pointer to CctCert (Symbian's certificate info ) |
|
155 // ----------------------------------------------------------------------------- |
|
156 // |
|
157 EXPORT_C const CCTCertInfo* CWimCertInfo::CctCert() const |
|
158 { |
|
159 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::CctCert | Begin")); |
|
160 return iCCTCertInfo; |
|
161 } |
|
162 |
|
163 // ----------------------------------------------------------------------------- |
|
164 // CWimCertInfo::TrustedUsage() const |
|
165 // Get pointer array of TrustedUsage OID's |
|
166 // ----------------------------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C RArray<HBufC*> CWimCertInfo::TrustedUsage() const |
|
169 { |
|
170 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::TrustedUsage | Begin")); |
|
171 return iTrustedUsage; |
|
172 } |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CWimCertInfo::ExtendedKeyUsage |
|
175 // Get pointer array of ExtendedKeyUsage OID's |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 EXPORT_C RArray<HBufC*> CWimCertInfo::ExtendedKeyUsage() const |
|
179 { |
|
180 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::ExtendedKeyUsage | Begin")); |
|
181 return iExtendedKeyUsage; |
|
182 } |
|
183 // ----------------------------------------------------------------------------- |
|
184 // CWimCertInfo::CDFRefs |
|
185 // Get location of certificate |
|
186 // ----------------------------------------------------------------------------- |
|
187 // |
|
188 EXPORT_C TUint8 CWimCertInfo::CDFRefs() const |
|
189 { |
|
190 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::CDFRefs | Begin")); |
|
191 return iCDFRefs; |
|
192 } |
|
193 // ----------------------------------------------------------------------------- |
|
194 // CWimCertInfo::SetCDFRefs |
|
195 // Set location of certificate |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 EXPORT_C void CWimCertInfo::SetCDFRefs( TUint8 aCDFRefs ) |
|
199 { |
|
200 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::SetCDFRefs | Begin")); |
|
201 iCDFRefs = aCDFRefs; |
|
202 } |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CWimCertInfo::Externalize |
|
206 // Externalize CWimCertInfo data to flat buffer |
|
207 // ----------------------------------------------------------------------------- |
|
208 // |
|
209 EXPORT_C TWimCertInfoPckg* CWimCertInfo::ExternalizeL() const |
|
210 { |
|
211 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::ExternalizeL | Begin")); |
|
212 TWimCertInfoPckg* certPckg = new( ELeave ) TWimCertInfoPckg(); |
|
213 |
|
214 GetCertHash( certPckg->iHash ); |
|
215 certPckg->iCertLabel.Copy( iCCTCertInfo->Label() ); |
|
216 certPckg->iCertificateOwnerType = iCCTCertInfo->CertificateOwnerType(); |
|
217 certPckg->iSize = iCCTCertInfo->Size(); |
|
218 certPckg->iFormat = iCCTCertInfo->CertificateFormat(); |
|
219 certPckg->iSubjectKeyId = iCCTCertInfo->SubjectKeyId(); |
|
220 certPckg->iIssuerKeyId = iCCTCertInfo->IssuerKeyId(); |
|
221 certPckg->iCDFRefs = iCDFRefs; |
|
222 certPckg->iTokenSerialNbr = iCCTCertInfo->Token().Label(); |
|
223 certPckg->iIndex = iCCTCertInfo->Handle().iObjectId; |
|
224 return certPckg; |
|
225 } |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // CWimCertInfo::InternalizeL |
|
229 // Instantiates CWimCertInfo of externalized data |
|
230 // ----------------------------------------------------------------------------- |
|
231 // |
|
232 EXPORT_C CWimCertInfo* CWimCertInfo::InternalizeL( |
|
233 TWimCertInfoPckg& aExternalizedInfo ) |
|
234 { |
|
235 _WIMTRACE(_L("WIM | WIMUtil | CWimCertInfo::InternalizeL | Begin")); |
|
236 RArray<HBufC*> trustedUsages; |
|
237 |
|
238 CWimDummyTokenType* tokenType = CWimDummyTokenType::NewL(); |
|
239 CleanupReleasePushL( *tokenType ); |
|
240 |
|
241 CWimDummyToken* token = CWimDummyToken::NewL( *tokenType ); |
|
242 CleanupStack::Pop( tokenType ); |
|
243 CleanupReleasePushL( *token ); |
|
244 |
|
245 token->SetSerialNumber( aExternalizedInfo.iTokenSerialNbr ); |
|
246 |
|
247 TInt certificateId = aExternalizedInfo.iIndex; |
|
248 TBool deletable = EFalse; |
|
249 |
|
250 |
|
251 CCTCertInfo* cctCertInfo = CCTCertInfo::NewL( |
|
252 aExternalizedInfo.iCertLabel, |
|
253 aExternalizedInfo.iFormat, |
|
254 aExternalizedInfo.iCertificateOwnerType, |
|
255 aExternalizedInfo.iSize, |
|
256 &(aExternalizedInfo.iSubjectKeyId), |
|
257 &(aExternalizedInfo.iIssuerKeyId), |
|
258 *token, |
|
259 certificateId, |
|
260 deletable ); |
|
261 CleanupStack::Pop( token ); |
|
262 CleanupReleasePushL( *cctCertInfo ); |
|
263 |
|
264 CWimCertInfo* certInfo = CWimCertInfo::NewL( cctCertInfo, |
|
265 aExternalizedInfo.iHash, |
|
266 trustedUsages, |
|
267 0 ); |
|
268 |
|
269 CleanupStack::Pop( cctCertInfo ); |
|
270 |
|
271 certInfo->SetCDFRefs( aExternalizedInfo.iCDFRefs ); |
|
272 |
|
273 return certInfo; |
|
274 } |
|
275 |
|
276 // End of File |