|
1 /* |
|
2 * Copyright (c) 2002-2005 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 // INCLUDE FILES |
|
26 #include <SenIdentityProvider.h> |
|
27 #include <xmlengbinarycontainer.h> |
|
28 |
|
29 #include "SenWsSecurityHeader2.h" |
|
30 #include "sendebug.h" |
|
31 |
|
32 namespace |
|
33 { |
|
34 _LIT8(KUsernameTokenStartTagFmt, "<%S:UsernameToken>"); |
|
35 _LIT8(KUsernameFmt, "<%S:Username>%S</%S:Username>"); |
|
36 _LIT8(KPasswordStartTagDefaultFmt, "<%S:Password>%S"); |
|
37 _LIT8(KPasswordStartTagTypeFmt, "<%S:Password Type=\"%S:%S\">%S"); |
|
38 _LIT8(KPasswordEndTagFmt, "</%S:Password>"); |
|
39 _LIT8(KUsernameTokenEndTag, "</%S:UsernameToken>"); |
|
40 _LIT8(KTimestampExpiresFormatString8, |
|
41 "<%S:Timestamp xmlns:%S=\"%S\"><%S:Created>%S</%S:Created><%S:Expires>%S</%S:Expires></%S:Timestamp>"); |
|
42 _LIT8(KTimestampFormatString8, |
|
43 "<%S:Timestamp xmlns:%S=\"%S\"><%S:Created>%S</%S:Created></%S:Timestamp>"); |
|
44 /* |
|
45 TInt TokenL(const TDesC8& aSecurityNsPrefix, const TDesC8& aUsername, HBufC8*& aToken) |
|
46 { |
|
47 aToken = HBufC8::NewLC( KUsernameTokenStartTagFmt().Length() + |
|
48 KUsernameFmt().Length() + |
|
49 KUsernameTokenEndTag().Length() + |
|
50 aUsername.Length() + |
|
51 aSecurityNsPrefix.Length() * 4 ); |
|
52 |
|
53 TPtr8 ptr = aToken->Des(); |
|
54 ptr.Format(KUsernameTokenStartTagFmt, &aSecurityNsPrefix); |
|
55 ptr.AppendFormat(KUsernameFmt, &aSecurityNsPrefix, &aUsername, &aSecurityNsPrefix); |
|
56 ptr.AppendFormat(KUsernameTokenEndTag, &aSecurityNsPrefix); |
|
57 CleanupStack::Pop(); // aToken |
|
58 return KErrNone; |
|
59 } |
|
60 */ |
|
61 |
|
62 } |
|
63 |
|
64 EXPORT_C CSenWsSecurityHeader2* CSenWsSecurityHeader2::NewL( |
|
65 RSenDocument aDocument, |
|
66 TXmlEngElement aElement) |
|
67 { |
|
68 CSenWsSecurityHeader2* pNew = CSenWsSecurityHeader2::NewLC(aDocument, |
|
69 aElement); |
|
70 CleanupStack::Pop(pNew); |
|
71 return pNew; |
|
72 } |
|
73 |
|
74 EXPORT_C CSenWsSecurityHeader2* CSenWsSecurityHeader2::NewLC( |
|
75 RSenDocument aDocument, |
|
76 TXmlEngElement aElement) |
|
77 { |
|
78 CSenWsSecurityHeader2* pNew = new (ELeave) CSenWsSecurityHeader2; |
|
79 CleanupStack::PushL(pNew); |
|
80 pNew->BaseConstructL(aDocument, aElement); |
|
81 return pNew; |
|
82 } |
|
83 |
|
84 EXPORT_C CSenWsSecurityHeader2* CSenWsSecurityHeader2::NewL( |
|
85 const TDesC8& aData, |
|
86 RSenDocument aDocument, |
|
87 TXmlEngElement aElement) |
|
88 { |
|
89 CSenWsSecurityHeader2* pNew = CSenWsSecurityHeader2::NewLC(aData, |
|
90 aDocument, |
|
91 aElement); |
|
92 CleanupStack::Pop(pNew); |
|
93 return pNew; |
|
94 } |
|
95 |
|
96 EXPORT_C CSenWsSecurityHeader2* CSenWsSecurityHeader2::NewLC( |
|
97 const TDesC8& aData, |
|
98 RSenDocument aDocument, |
|
99 TXmlEngElement aElement) |
|
100 { |
|
101 CSenWsSecurityHeader2* pNew = new (ELeave) CSenWsSecurityHeader2; |
|
102 CleanupStack::PushL(pNew); |
|
103 pNew->BaseConstructL(aData, aDocument, aElement); |
|
104 return pNew; |
|
105 } |
|
106 |
|
107 EXPORT_C CSenWsSecurityHeader2* CSenWsSecurityHeader2::NewL( |
|
108 const TDesC8& aData, |
|
109 const TDesC8& aSecurityNs, |
|
110 RSenDocument aDocument, |
|
111 TXmlEngElement aElement) |
|
112 { |
|
113 CSenWsSecurityHeader2* pNew = CSenWsSecurityHeader2::NewLC(aData, |
|
114 aSecurityNs, |
|
115 aDocument, |
|
116 aElement); |
|
117 CleanupStack::Pop(pNew); |
|
118 return pNew; |
|
119 } |
|
120 |
|
121 EXPORT_C CSenWsSecurityHeader2* CSenWsSecurityHeader2::NewLC( |
|
122 const TDesC8& aData, |
|
123 const TDesC8& aSecurityNs, |
|
124 RSenDocument aDocument, |
|
125 TXmlEngElement aElement) |
|
126 { |
|
127 CSenWsSecurityHeader2* pNew = new (ELeave) CSenWsSecurityHeader2; |
|
128 CleanupStack::PushL(pNew); |
|
129 pNew->BaseConstructL(aData, aSecurityNs, aDocument, aElement); |
|
130 return pNew; |
|
131 } |
|
132 |
|
133 EXPORT_C CSenWsSecurityHeader2::CSenWsSecurityHeader2() |
|
134 { |
|
135 } |
|
136 |
|
137 EXPORT_C void CSenWsSecurityHeader2::BaseConstructL(RSenDocument aDocument, |
|
138 TXmlEngElement aElement) |
|
139 { |
|
140 RAttributeArray attrArray; |
|
141 CSenFragmentBase::BaseConstructL(XmlNs(), KSecurityName, XmlNsPrefix(), |
|
142 attrArray, aElement, aDocument); |
|
143 } |
|
144 |
|
145 EXPORT_C void CSenWsSecurityHeader2::BaseConstructL(const TDesC8& aData, |
|
146 RSenDocument aDocument, |
|
147 TXmlEngElement aElement) |
|
148 { |
|
149 BaseConstructL(aDocument, aElement); |
|
150 if ( aData.Length() ) |
|
151 { |
|
152 TXmlEngElement element = AsElementL(); |
|
153 TPtrC8 content = element.Text(); |
|
154 if ( content.Length() > 0 ) |
|
155 { |
|
156 HBufC8* pContent = HBufC8::NewLC( content.Length() + aData.Length() ); |
|
157 TXmlEngElement element = AsElementL(); |
|
158 TPtr8 ptrContent = pContent->Des(); |
|
159 ptrContent.Append(content); |
|
160 ptrContent.Append(aData); |
|
161 element.SetTextNoEncL(*pContent); |
|
162 CleanupStack::PopAndDestroy(pContent); |
|
163 } |
|
164 else |
|
165 { |
|
166 element.SetTextNoEncL(aData); |
|
167 } |
|
168 } |
|
169 } |
|
170 |
|
171 EXPORT_C void CSenWsSecurityHeader2::BaseConstructL(const TDesC8& aData, |
|
172 const TDesC8& aSecurityNs, |
|
173 RSenDocument aDocument, |
|
174 TXmlEngElement aElement) |
|
175 { |
|
176 RAttributeArray attrArray; |
|
177 CSenFragmentBase::BaseConstructL(aSecurityNs, KSecurityName, XmlNsPrefix(), |
|
178 attrArray, aElement, aDocument); |
|
179 if ( aData.Length() ) |
|
180 { |
|
181 TXmlEngElement element = AsElementL(); |
|
182 TPtrC8 content = element.Text(); |
|
183 if ( content.Length() > 0 ) |
|
184 { |
|
185 HBufC8* pContent = HBufC8::NewLC( content.Length() + aData.Length() ); |
|
186 TXmlEngElement element = AsElementL(); |
|
187 TPtr8 ptrContent = pContent->Des(); |
|
188 ptrContent.Append(content); |
|
189 ptrContent.Append(aData); |
|
190 element.SetTextNoEncL(*pContent); |
|
191 CleanupStack::PopAndDestroy(pContent); |
|
192 } |
|
193 else |
|
194 { |
|
195 element.SetTextNoEncL(aData); |
|
196 } |
|
197 } |
|
198 } |
|
199 |
|
200 EXPORT_C CSenWsSecurityHeader2::~CSenWsSecurityHeader2() |
|
201 { |
|
202 } |
|
203 |
|
204 EXPORT_C HBufC8* CSenWsSecurityHeader2::UsernameTokenL(CSenIdentityProvider &aIdentityProvider) |
|
205 { |
|
206 TPtrC8 username = aIdentityProvider.AuthzID(); |
|
207 HBufC8* pToken = NULL; |
|
208 User::LeaveIfError(UsernameTokenL(username, pToken)); |
|
209 return pToken; |
|
210 } |
|
211 |
|
212 |
|
213 EXPORT_C TPtrC8 CSenWsSecurityHeader2::XmlNs() |
|
214 { |
|
215 if ( iElement.NotNull() ) |
|
216 { |
|
217 if ( iElement.NamespaceUri() != KNullDesC8 ) |
|
218 { |
|
219 return iElement.NamespaceUri(); |
|
220 } |
|
221 } |
|
222 |
|
223 return KSecurityXmlNs(); |
|
224 } |
|
225 |
|
226 EXPORT_C TPtrC8 CSenWsSecurityHeader2::XmlNsPrefix() |
|
227 { |
|
228 if ( iElement.NotNull() ) |
|
229 { |
|
230 if ( iElement.Prefix() != KNullDesC8 ) |
|
231 { |
|
232 return iElement.Prefix(); |
|
233 } |
|
234 } |
|
235 |
|
236 return KSecurityXmlNsPrefix(); |
|
237 } |
|
238 |
|
239 EXPORT_C TInt CSenWsSecurityHeader2::UsernameTokenL(const TDesC8& aUsername, HBufC8*& aToken) |
|
240 { |
|
241 TPtrC8 nsPrefix = KSecurityXmlNsPrefix(); |
|
242 aToken = HBufC8::NewLC( KUsernameTokenStartTagFmt().Length() + |
|
243 KUsernameFmt().Length() + |
|
244 KUsernameTokenEndTag().Length() + |
|
245 aUsername.Length() + |
|
246 nsPrefix.Length() * 4 ); |
|
247 |
|
248 TPtr8 ptr = aToken->Des(); |
|
249 ptr.Format(KUsernameTokenStartTagFmt, &nsPrefix); |
|
250 ptr.AppendFormat(KUsernameFmt, &nsPrefix, &aUsername, &nsPrefix); |
|
251 ptr.AppendFormat(KUsernameTokenEndTag, &nsPrefix); |
|
252 CleanupStack::Pop(); // aToken |
|
253 return KErrNone; |
|
254 } |
|
255 |
|
256 |
|
257 EXPORT_C HBufC8* CSenWsSecurityHeader2::UsernameTokenL(CSenIdentityProvider &aIdentityProvider, |
|
258 CSenWsSecurityHeader2::TPasswordType aType) |
|
259 { |
|
260 TPtrC8 username = aIdentityProvider.AuthzID(); |
|
261 TPtrC8 password = aIdentityProvider.Password(); |
|
262 HBufC8* pToken = NULL; |
|
263 User::LeaveIfError(UsernameTokenL(username, password, aType, pToken)); |
|
264 return pToken; |
|
265 } |
|
266 |
|
267 EXPORT_C TInt CSenWsSecurityHeader2::UsernameTokenL(const TDesC8& aUsername, |
|
268 const TDesC8& aPassword, |
|
269 HBufC8*& aToken) |
|
270 { |
|
271 TPtrC8 nsPrefix = KSecurityXmlNsPrefix(); |
|
272 aToken = HBufC8::NewLC( KUsernameTokenStartTagFmt().Length() + |
|
273 KUsernameFmt().Length() + |
|
274 KUsernameTokenEndTag().Length() + |
|
275 KPasswordStartTagDefaultFmt().Length() + |
|
276 KPasswordEndTagFmt().Length() + |
|
277 aPassword.Length() + |
|
278 aUsername.Length() + |
|
279 nsPrefix.Length() * 6 ); |
|
280 |
|
281 TPtr8 ptr = aToken->Des(); |
|
282 ptr.Format(KUsernameTokenStartTagFmt, &nsPrefix); |
|
283 ptr.AppendFormat(KUsernameFmt, &nsPrefix, &aUsername, &nsPrefix); |
|
284 ptr.AppendFormat(KPasswordStartTagDefaultFmt, |
|
285 &nsPrefix, &aPassword); // no Type -attribute used |
|
286 ptr.AppendFormat(KPasswordEndTagFmt, &nsPrefix); |
|
287 ptr.AppendFormat(KUsernameTokenEndTag, &nsPrefix); |
|
288 CleanupStack::Pop(); // aToken |
|
289 return KErrNone; |
|
290 } |
|
291 |
|
292 EXPORT_C TInt CSenWsSecurityHeader2::UsernameTokenL(const TDesC8& aUsername, |
|
293 const TDesC8& aPassword, |
|
294 CSenWsSecurityHeader2::TPasswordType aType, |
|
295 HBufC8*& aToken) |
|
296 { |
|
297 switch(aType) |
|
298 { |
|
299 case EText: |
|
300 { |
|
301 return UsernameTokenL(aUsername, aPassword, aToken); |
|
302 } |
|
303 case EDigest: |
|
304 { |
|
305 TPtrC8 nsPrefix = KSecurityXmlNsPrefix(); |
|
306 TPtrC8 typeAttr(KSecurityAttrTypeDigest); |
|
307 |
|
308 aToken = HBufC8::NewLC( KUsernameTokenStartTagFmt().Length() + |
|
309 KUsernameFmt().Length() + |
|
310 KUsernameTokenEndTag().Length() + |
|
311 KPasswordStartTagTypeFmt().Length() + |
|
312 KPasswordEndTagFmt().Length() + |
|
313 aUsername.Length() + |
|
314 aPassword.Length() + |
|
315 typeAttr.Length() + |
|
316 nsPrefix.Length() * 7 ); |
|
317 TPtr8 ptr = aToken->Des(); |
|
318 ptr.Format(KUsernameTokenStartTagFmt, &nsPrefix); |
|
319 ptr.AppendFormat(KUsernameFmt, &nsPrefix, &aUsername, &nsPrefix); |
|
320 ptr.AppendFormat(KPasswordStartTagTypeFmt, &nsPrefix, &nsPrefix, |
|
321 &typeAttr, &aPassword); // Type = wsse:PasswordDigest |
|
322 ptr.AppendFormat(KPasswordEndTagFmt, &nsPrefix); |
|
323 ptr.AppendFormat(KUsernameTokenEndTag, &nsPrefix); |
|
324 CleanupStack::Pop(); // aToken |
|
325 return KErrNone; |
|
326 } |
|
327 default: |
|
328 { |
|
329 return KErrNotSupported; |
|
330 } |
|
331 } |
|
332 } |
|
333 |
|
334 EXPORT_C TInt CSenWsSecurityHeader2::TimestampL(const TDesC8& aCreated, const TDesC8& aExpires, HBufC8*& aToken) |
|
335 { |
|
336 TPtrC8 nsPrefix = KSecurityUtilityXmlNsPrefix(); |
|
337 aToken = HBufC8::NewLC(KTimestampExpiresFormatString8().Length() |
|
338 + aCreated.Length() |
|
339 + aExpires.Length() |
|
340 + nsPrefix.Length()*7 |
|
341 + KSecurityUtilityXmlNs().Length()); |
|
342 |
|
343 TPtr8 ptr = aToken->Des(); |
|
344 ptr.Format(KTimestampExpiresFormatString8, |
|
345 &nsPrefix, |
|
346 &nsPrefix, |
|
347 &KSecurityUtilityXmlNs(), |
|
348 &nsPrefix, |
|
349 &aCreated, |
|
350 &nsPrefix, |
|
351 &nsPrefix, |
|
352 &aExpires, |
|
353 &nsPrefix, |
|
354 &nsPrefix); |
|
355 CleanupStack::Pop(aToken); |
|
356 return KErrNone; |
|
357 } |
|
358 |
|
359 EXPORT_C TInt CSenWsSecurityHeader2::TimestampL(const TDesC8& aCreated, HBufC8*& aToken) |
|
360 { |
|
361 TPtrC8 nsPrefix = KSecurityUtilityXmlNsPrefix(); |
|
362 aToken = HBufC8::NewLC(KTimestampFormatString8().Length() |
|
363 + aCreated.Length() |
|
364 + nsPrefix.Length()*5 |
|
365 + KSecurityUtilityXmlNs().Length()); |
|
366 |
|
367 TPtr8 ptr = aToken->Des(); |
|
368 ptr.Format(KTimestampFormatString8, |
|
369 &nsPrefix, |
|
370 &nsPrefix, |
|
371 &KSecurityUtilityXmlNs(), |
|
372 &nsPrefix, |
|
373 &aCreated, |
|
374 &nsPrefix, |
|
375 &nsPrefix); |
|
376 CleanupStack::Pop(aToken); |
|
377 return KErrNone; |
|
378 } |
|
379 |
|
380 //EXPORT_C TInt CSenWsSecurityHeader2::SecurityTokenReferenceL(const TDesC8& aURI, HBufC8*& aToken) |
|
381 // { |
|
382 // //to do |
|
383 // } |
|
384 |
|
385 |
|
386 // End of File |