|
1 /* |
|
2 * Copyright (c) 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: Interface to BbB encryption. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CDRMMESSAGEPARSER_H |
|
21 #define CDRMMESSAGEPARSER_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <s32strm.h> |
|
26 |
|
27 // CONSTANTS |
|
28 |
|
29 // MACROS |
|
30 |
|
31 // DATA TYPES |
|
32 |
|
33 // FUNCTION PROTOTYPES |
|
34 // FORWARD DECLARATIONS |
|
35 class COma1DcfCreator; |
|
36 class CDRMRights; |
|
37 class RDRMRightsClient; |
|
38 |
|
39 // CLASS DECLARATION |
|
40 |
|
41 /** |
|
42 * This class handles all DRM Message parsing and B64 decoding, |
|
43 * and feeds the resulting data either to |
|
44 * DRMAuthenticated::Encrypt[Initialize|Update|Finalize]L or writes the |
|
45 * data directly to given output stream (DCF in DRM Message). |
|
46 * The internal state iState is modified in quite many places in the |
|
47 * class methods. |
|
48 * |
|
49 * @lib DRMAuthenticated.dll |
|
50 * @since S60Rel2.5 |
|
51 */ |
|
52 NONSHARABLE_CLASS(CDRMMessageParser): public CBase |
|
53 { |
|
54 public: // Constructors and destructor |
|
55 enum TDRMMessageParserState |
|
56 { |
|
57 ESearchingBoundary = 0x00, // The first operation to do. |
|
58 EGotBoundary = 0x01, |
|
59 EReadingHeaderPart = 0x02, |
|
60 EReadingRightsPart = 0x04, |
|
61 EGotRightsPart = 0x08, |
|
62 EReadingContentPart = 0x10, |
|
63 EGotContentPart = 0x20, |
|
64 EGotContentEncoding = 0x40, |
|
65 EBase64 = 0x80, |
|
66 EGotContentType = 0x100, |
|
67 EDCFFile = 0x200, |
|
68 EDCFURIModified = 0x400, |
|
69 EDCFHeadersModified = 0x800, |
|
70 EEncryptStreamOk = 0x1000, |
|
71 EFLContent = 0x2000, |
|
72 EAllDone = 0x4000, |
|
73 EBroken = 0x8000 |
|
74 }; |
|
75 /** |
|
76 * Two-phased constructor. |
|
77 */ |
|
78 IMPORT_C static CDRMMessageParser* NewL( void ); |
|
79 |
|
80 /** |
|
81 * Destructor. |
|
82 */ |
|
83 IMPORT_C virtual ~CDRMMessageParser( void ); |
|
84 |
|
85 |
|
86 public: // New functions |
|
87 |
|
88 /** |
|
89 * InitializeMessageParserL |
|
90 * |
|
91 * @since 2.0 |
|
92 * DRM message Block-by-Block parser initialization method must be called |
|
93 * once before ProcessMessageDataL can be called. All processed data is |
|
94 * written to given write stream when calling ProcessMessageDataL and |
|
95 * FinalizeMessageParserL methods. |
|
96 * |
|
97 * InitializeMessageParserL, ProcessMessageDataL and FinalizeMessageParserL |
|
98 * use EncryptInitializeL, EncryptUpdateL and EncryptFinalizeL internally, |
|
99 * so one instance of DRMAuthenticated can only process one encryption |
|
100 * session at a time. |
|
101 * @param aOutput Write stream where the processed data is written. |
|
102 */ |
|
103 IMPORT_C void InitializeMessageParserL( |
|
104 RWriteStream& aOutput ); |
|
105 |
|
106 /** |
|
107 * ProcessMessageDataL |
|
108 * |
|
109 * @since 2.0 |
|
110 * This method processes the given part of DRM message data. If |
|
111 * there is some data to be returned (there might not always be), |
|
112 * the processed data is written to the output stream. |
|
113 * @param aMessageData Part of DRM message data to be processed. |
|
114 */ |
|
115 IMPORT_C void ProcessMessageDataL( |
|
116 const TDesC8& aMessageData ); |
|
117 |
|
118 /** |
|
119 * FinalizeMessageParserL |
|
120 * |
|
121 * @since 2.0 |
|
122 * This method finalizes the BbB parsing of DRM message. The method |
|
123 * flushes the internal buffers returns any remaining processed data |
|
124 * to output stream depending on the initialization. After calling this |
|
125 * method the parser needs to |
|
126 * be re-initialized in order to process more data. |
|
127 */ |
|
128 IMPORT_C void FinalizeMessageParserL(); |
|
129 |
|
130 /** |
|
131 * ProcessMessage |
|
132 * |
|
133 * Takes a memory buffer containing a DRM message, splits the message |
|
134 * into the contained parts and processes the parts. After completion |
|
135 * of the function, the input buffer contains the DCF from the message, |
|
136 * the Rights Object is saved to the rights database.. |
|
137 * |
|
138 * @since 2.0 |
|
139 * @param aDRMMessage: In/out parameter containing the DRM message |
|
140 * before the function call and the DCF after the function call |
|
141 * @return EOk if the message has been processed successfully |
|
142 */ |
|
143 IMPORT_C TInt ProcessMessage( |
|
144 HBufC8*& aDRMMessage); |
|
145 |
|
146 /** |
|
147 * ProcessRightsObject |
|
148 * |
|
149 * Takes a memory buffer containing a Rights Object and saves it to the |
|
150 * rights database. Returns the detailed rights specification of the |
|
151 * Rights Object. |
|
152 * |
|
153 * @since 2.0 |
|
154 * @param aRightsObject: Buffer containing the rights object |
|
155 * @param aRightsDetail: Out parameter for the details of the rights |
|
156 * in the rights object |
|
157 * @return EOk if the rights object could be stored successfully |
|
158 */ |
|
159 IMPORT_C TInt ProcessRightsObject( |
|
160 const TDesC8& aRightsObject, |
|
161 RPointerArray<CDRMRights>& aRightsDetail); |
|
162 |
|
163 /** |
|
164 * Cleans up the internal storages in case of |
|
165 * CleanupStack::PopAndDestroy() |
|
166 */ |
|
167 void Release( void ); |
|
168 |
|
169 public: // Functions from base classes |
|
170 |
|
171 protected: // New functions |
|
172 |
|
173 /** |
|
174 * C++ default constructor. |
|
175 */ |
|
176 CDRMMessageParser( void ); |
|
177 |
|
178 protected: // Functions from base classes |
|
179 |
|
180 private: |
|
181 |
|
182 /** |
|
183 * By default Symbian 2nd phase constructor is private. |
|
184 */ |
|
185 void ConstructL( void ); |
|
186 |
|
187 /** |
|
188 * Processes the data from DRM Message body. |
|
189 */ |
|
190 void HandleContentDataL( void ); |
|
191 |
|
192 /** |
|
193 * Processes the rights object data part from DRM Message. |
|
194 */ |
|
195 void HandleRightsDataL( void ); |
|
196 |
|
197 /** |
|
198 * Tries to locate the boundary separator from the beginning of the |
|
199 * message, and if a boundary is found, it is stored. |
|
200 */ |
|
201 void FindBoundaryL( void ); |
|
202 |
|
203 /** |
|
204 * Parses the DRM Message header part. |
|
205 */ |
|
206 void ReadHeaderL( void ); |
|
207 |
|
208 /** |
|
209 * Returns a single line from the message, ending to \n. |
|
210 * @return Reference to a single line in the message. |
|
211 */ |
|
212 TPtrC8 GetLineL( void ); |
|
213 |
|
214 /** |
|
215 * Extracts a MIME header value from the given line. Ignores |
|
216 * possible parameters. |
|
217 * @param aLine Line to be searched for the header value. |
|
218 * @return Reference to the header value found. |
|
219 */ |
|
220 TPtrC8 HeaderValueL( const TDesC8& aLine ); |
|
221 |
|
222 /** |
|
223 * Compresses the internal buffers discarding all already used |
|
224 * data. |
|
225 */ |
|
226 void CompressInputBuffer( void ); |
|
227 |
|
228 /** |
|
229 * Prepares the content data to be encrypted/processed, i.e. |
|
230 * constructs a descriptor to iInputBuffer which can then be |
|
231 * processed. |
|
232 */ |
|
233 void PrepareContentDataL( void ); |
|
234 |
|
235 /** |
|
236 * Do base64 decoding to the given descriptor. |
|
237 * @param aData in/out descriptor: after successful call, the |
|
238 * descriptor contains base64 decoded data. |
|
239 * @return How many base64 encoded bytes from aData was consumed. |
|
240 */ |
|
241 TInt HandleBase64DataL( TPtrC8& aData ); |
|
242 |
|
243 /** |
|
244 * Extracts the endline characters from the given descriptor. |
|
245 * @param aBuf A single line to be stripped from endline characters. |
|
246 * The descriptor length is changed to corresponding value. |
|
247 */ |
|
248 void StripEndLineL( TPtrC8& aBuf ); |
|
249 |
|
250 /** |
|
251 * Tells whether the given line is a boundary line, and if so, is it |
|
252 * the final boundary marking the end of the message. |
|
253 * @param aLine Line. |
|
254 * @param aLast Out-parameter: if the line is a boundary line and this |
|
255 * is the last boundary, aLast == ETrue after the call. |
|
256 * @return Truth value. |
|
257 */ |
|
258 TBool IsBoundary( const TDesC8& aLine, |
|
259 TBool& aLast ) const; |
|
260 |
|
261 /** |
|
262 * This method generates a FL rights object if the message being |
|
263 * processed is a FL message. If the message is a CD message, |
|
264 * no rights object. Saves the rights object into rights database. |
|
265 */ |
|
266 void HandleFlContentL( void ); |
|
267 |
|
268 /** |
|
269 * Helper method for HandleFlContentL: saves the RO to the database. |
|
270 * @param aCID Content-ID. |
|
271 * @param aData rights data. |
|
272 */ |
|
273 void ProcessRightsDataL( const TDesC8& aCID, |
|
274 const TDesC8& aData ); |
|
275 |
|
276 /** |
|
277 * Writes the (base64 decoded) data to EncryptUpdateL or directly to |
|
278 * the output stream. Modifies the content-type of DCF file in case |
|
279 * "DCF inside DRM Message" case. |
|
280 * @param aData Data to be encrypted / written to the stream. |
|
281 */ |
|
282 void ProcessContentDataL( TPtrC8& aData ); |
|
283 |
|
284 void EnsureFLRightsExistL( RDRMRightsClient& aClient, CDRMRights** aOutput ); |
|
285 /** |
|
286 * Checks whether the given character is valid base64 encoded character. |
|
287 * @param aChar Character to be checked. |
|
288 * @return Truth value. |
|
289 */ |
|
290 TBool ValidB64CharL( const TUint8 aChar ); |
|
291 |
|
292 /** |
|
293 * Sets an internal state bit. |
|
294 * @param aBit New state bit to be enabled. |
|
295 */ |
|
296 void SetBit( TUint32 aBit ); |
|
297 |
|
298 /** |
|
299 * Clears an internal state bit. |
|
300 * @param aBit The state bit to be cleared. |
|
301 */ |
|
302 void ClearBit( TUint32 aBit ); |
|
303 |
|
304 /** |
|
305 * Do cleanup operations & update internal state to indicate an |
|
306 * error occured. |
|
307 * @param aError Error code which is thrown. KErrNone does not leave. |
|
308 */ |
|
309 void SetBrokenStateL( const TInt aError ); |
|
310 |
|
311 void Reset(); |
|
312 |
|
313 void DoProcessMessageL( HBufC8*& aDRMMessage ); |
|
314 void DoProcessRightsObjectL( const TDesC8& aRightsObject, |
|
315 RPointerArray<CDRMRights>& aRightsDetail ); |
|
316 void DeletePermission(); |
|
317 void InitDCFBufferL(); |
|
318 |
|
319 void CreateCDCIDL( HBufC8*& aCID ); |
|
320 TInt RetrieveFlRights(); |
|
321 void ProcessDCFDataL( TPtrC8& aData ); |
|
322 |
|
323 void FillDCFBufferL( TPtrC8& aData ); |
|
324 void CompressDCFBuffer( const TInt aHowMuch ); |
|
325 TBool FindDCFHeader( const TDesC8& aString, |
|
326 TUint& aOffset, |
|
327 TUint& aLength ); |
|
328 |
|
329 HBufC8* EncryptDCFFieldLC( const TDesC8& aOldHeader ); |
|
330 |
|
331 // Prohibit copy constructor if not deriving from CBase. |
|
332 CDRMMessageParser( const CDRMMessageParser& ); |
|
333 // Prohibit assigment operator if not deriving from CBase. |
|
334 CDRMMessageParser& operator=( const CDRMMessageParser& ); |
|
335 |
|
336 public: // Data |
|
337 TBool iDoPop; |
|
338 |
|
339 protected: // Data |
|
340 |
|
341 private: // Data |
|
342 // Given stream |
|
343 RWriteStream iOutputStream; |
|
344 |
|
345 COma1DcfCreator* iDcfCreator; |
|
346 |
|
347 // CD rights object. |
|
348 HBufC8* iRightsData; |
|
349 CDRMRights* iRightsObject; |
|
350 |
|
351 // Boundary obtained from the given data. |
|
352 HBufC8* iBoundary; |
|
353 |
|
354 // Content type from the given data. |
|
355 HBufC8* iContentType; |
|
356 |
|
357 // Temporary store for DCF data. |
|
358 HBufC8* iDCFBuffer; |
|
359 |
|
360 // Current internal state. |
|
361 TUint32 iState; |
|
362 |
|
363 // DCF header sizes. |
|
364 TUint32 iDCFHeaderSize[ 2 ]; |
|
365 |
|
366 // Input cache & counter. |
|
367 TPtr8 iInputBuffer; |
|
368 TInt iUsedFromInput; |
|
369 |
|
370 // Temporary storage & counter |
|
371 TPtrC8 iInputData; |
|
372 |
|
373 public: // Friend classes |
|
374 protected: // Friend classes |
|
375 private: // Friend classes |
|
376 }; |
|
377 |
|
378 #endif // CDRMMESSAGEPARSER_H |
|
379 |
|
380 // End of File |