|
1 /* |
|
2 * Copyright (c) 2002-2004 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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <e32std.h> |
|
22 #include "base64.h" |
|
23 #include "RegistrationReq.h" |
|
24 |
|
25 using namespace Roap; |
|
26 |
|
27 // LOCAL CONSTANTS AND MACROS |
|
28 _LIT8(KReqHeader, "<roap:registrationRequest xmlns:roap=\"urn:oma:bac:dldrm:roap-1.0\"\ |
|
29 sessionId=\""); |
|
30 _LIT8(KReqSessionIdEnd, "\""); |
|
31 _LIT8(KReqNonceTrigger, " triggerNonce=\""); |
|
32 _LIT8(KReqNonceTriggerEnd, "\""); |
|
33 _LIT8(KReqHeaderEnd, ">"); |
|
34 _LIT8(KReqNonce, "<nonce>"); |
|
35 _LIT8(KReqNonceEnd, "</nonce>"); |
|
36 _LIT8(KReqTime, "<time>"); |
|
37 _LIT8(KReqTimeEnd, "</time>"); |
|
38 _LIT8(KReqCertChain, "<certificateChain>"); |
|
39 _LIT8(KReqCert, "<certificate>"); |
|
40 _LIT8(KReqCertEnd, "</certificate>"); |
|
41 _LIT8(KReqCertChainEnd, "</certificateChain>"); |
|
42 _LIT8(KReqTrustedAuthorities,"<trustedAuthorities>"); |
|
43 _LIT8(KReqTrustedRoot, "<keyIdentifier xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\ |
|
44 algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>"); |
|
45 _LIT8(KReqTrustedRootEnd, "</hash></keyIdentifier>"); |
|
46 _LIT8(KReqTrustedAuthoritiesEnd, "</trustedAuthorities>"); |
|
47 _LIT8(KReqServerInfo, "<serverInfo>"); |
|
48 _LIT8(KReqServerInfoEnd, "</serverInfo>"); |
|
49 _LIT8(KReqExtensions, "<extensions>"); |
|
50 _LIT8(KReqExtensionsEnd, "</extensions>"); |
|
51 _LIT8(KReqPeerKey, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\ |
|
52 xsi:type=\"roap:PeerKeyIdentifier\">\ |
|
53 <identifier algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>"); |
|
54 _LIT8(KReqPeerKeyEnd, "</hash></identifier></extension>"); |
|
55 _LIT8(KReqNoOcspResponse, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\ |
|
56 xsi:type=\"roap:NoOCSPResponse\"></extension>"); |
|
57 _LIT8(KReqOcspResponderKeyId, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\ |
|
58 xsi:type=\"roap:OCSPResponderKeyIdentifier\">\ |
|
59 <identifier algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>"); |
|
60 _LIT8(KReqOcspResponderKeyIdEnd, "</hash></identifier></extension>"); |
|
61 _LIT8(KReqDevDetails, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\ |
|
62 xsi:type=\"roap:DeviceDetails\"><manufacturer>"); |
|
63 _LIT8(KReqDevDetailsModel, "</manufacturer><model>"); |
|
64 _LIT8(KReqDevDetailsVersion, "</model><version>"); |
|
65 _LIT8(KReqDevDetailsEnd, "</version></extension>"); |
|
66 _LIT8(KReqSig, "<signature>"); |
|
67 _LIT8(KReqSigEnd, "</signature></roap:registrationRequest>"); |
|
68 |
|
69 // ============================ MEMBER FUNCTIONS =============================== |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CRegistrationReq::CRegistrationReq |
|
73 // C++ default constructor can NOT contain any code, that |
|
74 // might leave. |
|
75 // ----------------------------------------------------------------------------- |
|
76 // |
|
77 CRegistrationReq::CRegistrationReq(): |
|
78 iSession(NULL), |
|
79 iNonce(NULL), |
|
80 iServerInfo(NULL), |
|
81 iSignature(NULL), |
|
82 iDeviceDetailsManufacturer(NULL), |
|
83 iDeviceDetailsModel(NULL), |
|
84 iDeviceDetailsVersion(NULL), |
|
85 iOcspResponderKeyId(NULL), |
|
86 iTriggerNonce(NULL) |
|
87 { |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CRegistrationReq::ConstructL |
|
92 // Symbian 2nd phase constructor can leave. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CRegistrationReq::ConstructL() |
|
96 { |
|
97 iTime.UniversalTime(); |
|
98 iPeerKeyIdentifier.SetLength(0); |
|
99 iOcspInfoStored = EFalse; |
|
100 } |
|
101 |
|
102 // ----------------------------------------------------------------------------- |
|
103 // CRegistrationReq::NewL |
|
104 // Two-phased constructor. |
|
105 // ----------------------------------------------------------------------------- |
|
106 // |
|
107 CRegistrationReq* CRegistrationReq::NewL() |
|
108 { |
|
109 CRegistrationReq* self = new( ELeave ) CRegistrationReq; |
|
110 |
|
111 CleanupStack::PushL( self ); |
|
112 self->ConstructL(); |
|
113 CleanupStack::Pop(); |
|
114 |
|
115 return self; |
|
116 } |
|
117 |
|
118 |
|
119 // Destructor |
|
120 CRegistrationReq::~CRegistrationReq() |
|
121 { |
|
122 iCertificateChain.ResetAndDestroy(); |
|
123 delete iSession; |
|
124 delete iSignature; |
|
125 delete iDeviceDetailsManufacturer; |
|
126 delete iDeviceDetailsModel; |
|
127 delete iDeviceDetailsVersion; |
|
128 delete iTriggerNonce; |
|
129 delete iServerInfo; |
|
130 delete iOcspResponderKeyId; |
|
131 iTrustedAuthorities.ResetAndDestroy(); |
|
132 } |
|
133 |
|
134 |
|
135 // ----------------------------------------------------------------------------- |
|
136 // CRegistrationReq::?member_function |
|
137 // ?implementation_description |
|
138 // (other items were commented in a header). |
|
139 // ----------------------------------------------------------------------------- |
|
140 // |
|
141 HBufC8* CRegistrationReq::MessageAsXmlL(void) |
|
142 { |
|
143 HBufC8* r = NULL; |
|
144 CBufFlat* b = NULL; |
|
145 TInt i; |
|
146 |
|
147 b = CBufFlat::NewL(128); |
|
148 CleanupStack::PushL(b); |
|
149 BufAppendL(b, KReqHeader); |
|
150 BufAppendL(b, *iSession); |
|
151 BufAppendL(b, KReqSessionIdEnd); |
|
152 if (iTriggerNonce) |
|
153 { |
|
154 BufAppendL(b, KReqNonceTrigger); |
|
155 BufAppendL(b, *iTriggerNonce); |
|
156 BufAppendL(b, KReqNonceTriggerEnd); |
|
157 } |
|
158 BufAppendL(b, KReqHeaderEnd); |
|
159 |
|
160 BufAppendL(b, KReqNonce); |
|
161 BufAppendBase64L(b, iNonce); |
|
162 BufAppendL(b, KReqNonceEnd); |
|
163 |
|
164 BufAppendL(b, KReqTime); |
|
165 BufAppendTimeL(b, iTime); |
|
166 BufAppendL(b, KReqTimeEnd); |
|
167 |
|
168 if (iCertificateChain.Count() > 0) |
|
169 { |
|
170 BufAppendL(b, KReqCertChain); |
|
171 for (i = 0; i < iCertificateChain.Count(); i++) |
|
172 { |
|
173 BufAppendL(b, KReqCert); |
|
174 BufAppendBase64L(b, *iCertificateChain[i]); |
|
175 BufAppendL(b, KReqCertEnd); |
|
176 } |
|
177 BufAppendL(b, KReqCertChainEnd); |
|
178 } |
|
179 |
|
180 if (iTrustedAuthorities.Count() > 0) |
|
181 { |
|
182 BufAppendL(b, KReqTrustedAuthorities); |
|
183 for (i = 0; i < iTrustedAuthorities.Count(); i++) |
|
184 { |
|
185 BufAppendL(b, KReqTrustedRoot); |
|
186 BufAppendBase64L(b, *iTrustedAuthorities[i]); |
|
187 BufAppendL(b, KReqTrustedRootEnd); |
|
188 } |
|
189 BufAppendL(b, KReqTrustedAuthoritiesEnd); |
|
190 } |
|
191 |
|
192 if (iServerInfo) |
|
193 { |
|
194 BufAppendL(b, KReqServerInfo); |
|
195 BufAppendL(b, *iServerInfo); |
|
196 BufAppendL(b, KReqServerInfoEnd); |
|
197 } |
|
198 |
|
199 if ((iDeviceDetailsManufacturer && |
|
200 iDeviceDetailsModel && |
|
201 iDeviceDetailsVersion) || |
|
202 iPeerKeyIdentifier.Length() || |
|
203 iOcspResponderKeyId || |
|
204 iOcspInfoStored ) |
|
205 { |
|
206 BufAppendL(b, KReqExtensions); |
|
207 } |
|
208 |
|
209 if (iPeerKeyIdentifier.Length()) |
|
210 { |
|
211 BufAppendL(b, KReqPeerKey); |
|
212 BufAppendBase64L(b, iPeerKeyIdentifier); |
|
213 BufAppendL(b, KReqPeerKeyEnd); |
|
214 } |
|
215 |
|
216 if (iOcspInfoStored) |
|
217 { |
|
218 BufAppendL(b, KReqNoOcspResponse); |
|
219 } |
|
220 |
|
221 if (iOcspResponderKeyId) |
|
222 { |
|
223 BufAppendL(b, KReqOcspResponderKeyId); |
|
224 BufAppendBase64L(b, *iOcspResponderKeyId); |
|
225 BufAppendL(b, KReqOcspResponderKeyIdEnd); |
|
226 } |
|
227 |
|
228 if (iDeviceDetailsManufacturer != NULL && |
|
229 iDeviceDetailsModel != NULL && |
|
230 iDeviceDetailsVersion != NULL) |
|
231 { |
|
232 BufAppendL(b, KReqDevDetails); |
|
233 BufAppendL(b, *iDeviceDetailsManufacturer); |
|
234 BufAppendL(b, KReqDevDetailsModel); |
|
235 BufAppendL(b, *iDeviceDetailsModel); |
|
236 BufAppendL(b, KReqDevDetailsVersion); |
|
237 BufAppendL(b, *iDeviceDetailsVersion); |
|
238 BufAppendL(b, KReqDevDetailsEnd); |
|
239 } |
|
240 |
|
241 if ((iDeviceDetailsManufacturer && |
|
242 iDeviceDetailsModel && |
|
243 iDeviceDetailsVersion) || |
|
244 iPeerKeyIdentifier.Length() || |
|
245 iOcspResponderKeyId || |
|
246 iOcspInfoStored ) |
|
247 { |
|
248 BufAppendL(b, KReqExtensionsEnd); |
|
249 } |
|
250 |
|
251 BufAppendL(b, KReqSig); |
|
252 BufAppendL(b, KReqSigEnd); |
|
253 |
|
254 r = b->Ptr(0).AllocL(); |
|
255 CleanupStack::PopAndDestroy(b); |
|
256 return r; |
|
257 } |
|
258 |
|
259 // End of File |