|
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 "RightsReq.h" |
|
24 |
|
25 using namespace Roap; |
|
26 |
|
27 // LOCAL CONSTANTS AND MACROS |
|
28 _LIT8(KReqHeader, "<roap:roRequest xmlns:roap=\"urn:oma:bac:dldrm:roap-1.0\""); |
|
29 _LIT8(KReqNonceTrigger, " triggerNonce=\""); |
|
30 _LIT8(KReqNonceTriggerEnd, "\""); |
|
31 _LIT8(KReqHeaderEnd, ">"); |
|
32 _LIT8(KReqNonce, "<nonce>"); |
|
33 _LIT8(KReqNonceEnd, "</nonce>"); |
|
34 _LIT8(KReqTime, "<time>"); |
|
35 _LIT8(KReqTimeEnd, "</time>"); |
|
36 _LIT8(KReqDeviceId, "<deviceID><keyIdentifier xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\ |
|
37 algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>"); |
|
38 _LIT8(KReqDeviceIdEnd, "</hash></keyIdentifier></deviceID>"); |
|
39 _LIT8(KReqRiId, "<riID><keyIdentifier xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\ |
|
40 algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>"); |
|
41 _LIT8(KReqRiIdEnd, "</hash></keyIdentifier></riID>"); |
|
42 _LIT8(KReqRoInfo, "<roInfo>"); |
|
43 _LIT8(KReqRoInfoEnd, "</roInfo>"); |
|
44 _LIT8(KReqRoId, "<roID>"); |
|
45 _LIT8(KReqRoIdEnd, "</roID>"); |
|
46 _LIT8(KReqDomainId, "<domainID>"); |
|
47 _LIT8(KReqDomainIdEnd, "</domainID>"); |
|
48 _LIT8(KReqCertChain, "<certificateChain>"); |
|
49 _LIT8(KReqCert, "<certificate>"); |
|
50 _LIT8(KReqCertEnd, "</certificate>"); |
|
51 _LIT8(KReqCertChainEnd, "</certificateChain>"); |
|
52 _LIT8(KReqExtensions, "<extensions>"); |
|
53 _LIT8(KReqExtensionsEnd, "</extensions>"); |
|
54 _LIT8(KReqPeerKey, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\ |
|
55 xsi:type=\"roap:PeerKeyIdentifier\">\ |
|
56 <identifier algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>"); |
|
57 _LIT8(KReqPeerKeyEnd, "</hash></identifier></extension>"); |
|
58 _LIT8(KReqNoOcspResponse, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\ |
|
59 xsi:type=\"roap:NoOCSPResponse\"></extension>"); |
|
60 _LIT8(KReqOcspResponderKeyId, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\ |
|
61 xsi:type=\"roap:OCSPResponderKeyIdentifier\">\ |
|
62 <identifier algorithm=\"http://www.w3.org/2000/09/xmldsig#sha1\" xsi:type=\"roap:X509SPKIHash\"><hash>"); |
|
63 _LIT8(KReqOcspResponderKeyIdEnd, "</hash></identifier></extension>"); |
|
64 _LIT8(KReqTransactionContentId, "<extension xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\ |
|
65 xsi:type=\"roap:TransactionIdentifier\"><contentID>"); |
|
66 _LIT8(KReqTransactionContentIdEnd, "</contentID>"); |
|
67 _LIT8(KReqTransactionId, "<id>"); |
|
68 _LIT8(KReqTransactionIdEnd, "</id></extension>"); |
|
69 _LIT8(KReqSig, "<signature>"); |
|
70 _LIT8(KReqSigEnd, "</signature></roap:roRequest>"); |
|
71 |
|
72 // ============================ MEMBER FUNCTIONS =============================== |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CRightsReq::CRightsReq |
|
76 // C++ default constructor can NOT contain any code, that |
|
77 // might leave. |
|
78 // ----------------------------------------------------------------------------- |
|
79 // |
|
80 CRightsReq::CRightsReq(): |
|
81 iDomainId(NULL), |
|
82 iNonce(NULL), |
|
83 iSignature(NULL), |
|
84 iDcfHash(NULL), |
|
85 iOcspResponderKeyId(NULL), |
|
86 iTriggerNonce(NULL) |
|
87 { |
|
88 } |
|
89 |
|
90 // ----------------------------------------------------------------------------- |
|
91 // CRightsReq::ConstructL |
|
92 // Symbian 2nd phase constructor can leave. |
|
93 // ----------------------------------------------------------------------------- |
|
94 // |
|
95 void CRightsReq::ConstructL() |
|
96 { |
|
97 iDcfHash.SetLength(0); |
|
98 iTime.UniversalTime(); |
|
99 iPeerKeyIdentifier.SetLength(0); |
|
100 iOcspInfoStored = EFalse; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CRightsReq::NewL |
|
105 // Two-phased constructor. |
|
106 // ----------------------------------------------------------------------------- |
|
107 // |
|
108 CRightsReq* CRightsReq::NewL() |
|
109 { |
|
110 CRightsReq* self = new( ELeave ) CRightsReq; |
|
111 |
|
112 CleanupStack::PushL( self ); |
|
113 self->ConstructL(); |
|
114 CleanupStack::Pop(); |
|
115 |
|
116 return self; |
|
117 } |
|
118 |
|
119 |
|
120 // Destructor |
|
121 CRightsReq::~CRightsReq() |
|
122 { |
|
123 iRoIdList.ResetAndDestroy(); |
|
124 iCertificateChain.ResetAndDestroy(); |
|
125 iTransTrackIDs.ResetAndDestroy(); |
|
126 iContentIDs.ResetAndDestroy(); |
|
127 delete iDomainId; |
|
128 delete iSignature; |
|
129 delete iTriggerNonce; |
|
130 delete iOcspResponderKeyId; |
|
131 } |
|
132 |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CRightsReq::?member_function |
|
136 // ?implementation_description |
|
137 // (other items were commented in a header). |
|
138 // ----------------------------------------------------------------------------- |
|
139 // |
|
140 HBufC8* CRightsReq::MessageAsXmlL(void) |
|
141 { |
|
142 HBufC8* r = NULL; |
|
143 CBufFlat* b = NULL; |
|
144 TInt i; |
|
145 |
|
146 b = CBufFlat::NewL(128); |
|
147 CleanupStack::PushL(b); |
|
148 b->InsertL(0, KReqHeader); |
|
149 if (iTriggerNonce) |
|
150 { |
|
151 BufAppendL(b, KReqNonceTrigger); |
|
152 BufAppendL(b, *iTriggerNonce); |
|
153 BufAppendL(b, KReqNonceTriggerEnd); |
|
154 } |
|
155 BufAppendL(b, KReqHeaderEnd); |
|
156 |
|
157 BufAppendL(b, KReqDeviceId); |
|
158 BufAppendBase64L(b, iDeviceId); |
|
159 BufAppendL(b, KReqDeviceIdEnd); |
|
160 |
|
161 if (iDomainId) |
|
162 { |
|
163 BufAppendL(b, KReqDomainId); |
|
164 BufAppendL(b, *iDomainId); |
|
165 BufAppendL(b, KReqDomainIdEnd); |
|
166 } |
|
167 |
|
168 BufAppendL(b, KReqRiId); |
|
169 BufAppendBase64L(b, iRiId); |
|
170 BufAppendL(b, KReqRiIdEnd); |
|
171 |
|
172 BufAppendL(b, KReqNonce); |
|
173 BufAppendBase64L(b, iNonce); |
|
174 BufAppendL(b, KReqNonceEnd); |
|
175 |
|
176 BufAppendL(b, KReqTime); |
|
177 BufAppendTimeL(b, iTime); |
|
178 BufAppendL(b, KReqTimeEnd); |
|
179 |
|
180 BufAppendL(b, KReqRoInfo); |
|
181 for (i = 0; i < iRoIdList.Count(); i++) |
|
182 { |
|
183 BufAppendL(b, KReqRoId); |
|
184 BufAppendL(b, *iRoIdList[i]); |
|
185 BufAppendL(b, KReqRoIdEnd); |
|
186 } |
|
187 BufAppendL(b, KReqRoInfoEnd); |
|
188 |
|
189 if (iCertificateChain.Count() > 0) |
|
190 { |
|
191 BufAppendL(b, KReqCertChain); |
|
192 for (i = 0; i < iCertificateChain.Count(); i++) |
|
193 { |
|
194 BufAppendL(b, KReqCert); |
|
195 BufAppendBase64L(b, *iCertificateChain[i]); |
|
196 BufAppendL(b, KReqCertEnd); |
|
197 } |
|
198 BufAppendL(b, KReqCertChainEnd); |
|
199 } |
|
200 |
|
201 if (iTransTrackIDs.Count() || |
|
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 for ( TInt i = 0; i < iTransTrackIDs.Count() && i < iContentIDs.Count(); i++ ) |
|
229 { |
|
230 BufAppendL(b, KReqTransactionContentId); |
|
231 BufAppendL(b, *iContentIDs[i]); |
|
232 BufAppendL(b, KReqTransactionContentIdEnd); |
|
233 BufAppendL(b, KReqTransactionId); |
|
234 BufAppendL(b, *iTransTrackIDs[i]); |
|
235 BufAppendL(b, KReqTransactionIdEnd); |
|
236 } |
|
237 |
|
238 if (iTransTrackIDs.Count() || |
|
239 iPeerKeyIdentifier.Length() || |
|
240 iOcspResponderKeyId || |
|
241 iOcspInfoStored) |
|
242 { |
|
243 BufAppendL(b, KReqExtensionsEnd); |
|
244 } |
|
245 |
|
246 BufAppendL(b, KReqSig); |
|
247 BufAppendL(b, KReqSigEnd); |
|
248 |
|
249 r = b->Ptr(0).AllocL(); |
|
250 CleanupStack::PopAndDestroy(b); |
|
251 return r; |
|
252 } |
|
253 |
|
254 // End of File |