|
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: OMA DRM 2.0 Key Storage |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <e32std.h> |
|
21 #include <asymmetric.h> |
|
22 #include <symmetric.h> |
|
23 #include <hash.h> |
|
24 #include <asn1dec.h> |
|
25 #include <x509cert.h> |
|
26 #include <etelmm.h> |
|
27 #include <mmtsy_names.h> |
|
28 |
|
29 #ifdef RD_MULTIPLE_DRIVE |
|
30 #include <DriveInfo.h> |
|
31 #endif |
|
32 |
|
33 #include "DrmKeyStorage.h" |
|
34 #include "DrmStdKeyStorage.h" |
|
35 |
|
36 #ifdef _DEBUG |
|
37 #define LOGGING |
|
38 #endif |
|
39 |
|
40 #ifdef LOGGING |
|
41 _LIT(KLogDir, "DRM"); |
|
42 _LIT(KLogName, "KeyStorage.log"); |
|
43 #include "flogger.h" |
|
44 #define LOG(string) \ |
|
45 RFileLogger::Write(KLogDir, KLogName, \ |
|
46 EFileLoggingModeAppend, string); |
|
47 #define LOGHEX(buffer) \ |
|
48 RFileLogger::HexDump(KLogDir, KLogName, \ |
|
49 EFileLoggingModeAppend, _S(""), _S(""), \ |
|
50 buffer.Ptr(), buffer.Length()); |
|
51 #else |
|
52 #define LOG(string) |
|
53 #define LOGHEX(buffer) |
|
54 #endif |
|
55 |
|
56 #pragma message("Compiling DRM Std KeyStorage..") |
|
57 |
|
58 |
|
59 // LOCAL CONSTANTS AND MACROS |
|
60 |
|
61 const TInt KKeyLength = 128; |
|
62 const TInt KWaitingTime = 2000000; // 2 sec |
|
63 |
|
64 #ifdef RD_MULTIPLE_DRIVE |
|
65 _LIT(KKeyStoragePath, "%c:\\private\\101F51F2\\PKI\\"); |
|
66 _LIT(KRomKeyStoragePath, "%c:\\private\\101F51F2\\PKI\\"); |
|
67 |
|
68 #else |
|
69 _LIT(KKeyStoragePath, "c:\\private\\101F51F2\\PKI\\"); |
|
70 _LIT(KRomKeyStoragePath, "z:\\private\\101F51F2\\PKI\\"); |
|
71 #endif |
|
72 |
|
73 _LIT(KDeviceKeyFileName, "DevicePrivateKey.der"); |
|
74 _LIT(KDeviceCertFileName, "DeviceCert.der"); |
|
75 _LIT(KSingingCertFmt, "SigningCert%02d.der"); |
|
76 _LIT(KSingingCertPattern, "SigningCert*"); |
|
77 _LIT8(KDefaultKey, "0000000000000000"); |
|
78 |
|
79 #ifdef RD_MULTIPLE_DRIVE |
|
80 _LIT(KSerialNumberFile, "%c:\\private\\101F51F2\\rdbserial.dat"); |
|
81 _LIT(KUdtCertFileName, "%c:\\private\\101F51F2\\PKI\\UdtCertificate.der"); |
|
82 #else |
|
83 _LIT(KSerialNumberFile, "c:\\private\\101F51F2\\rdbserial.dat"); |
|
84 _LIT(KUdtCertFileName, "z:\\private\\101F51F2\\PKI\\UdtCertificate.der"); |
|
85 #endif |
|
86 |
|
87 _LIT(KCmla, "CMLA"); |
|
88 _LIT(KPadding, "\x0"); |
|
89 |
|
90 NONSHARABLE_STRUCT( TUnloadModule ) |
|
91 { |
|
92 RTelServer* iServer; |
|
93 const TDesC* iName; |
|
94 }; |
|
95 |
|
96 |
|
97 // ============================ LOCAL FUNCTIONS ================================ |
|
98 LOCAL_C void DoUnloadPhoneModule( TAny* aAny ); |
|
99 |
|
100 LOCAL_C void WriteFileL(RFs& aFs, const TDesC& aName, const TDesC8& aData) |
|
101 { |
|
102 RFile file; |
|
103 |
|
104 User::LeaveIfError(file.Replace(aFs, aName, EFileWrite)); |
|
105 User::LeaveIfError(file.Write(aData)); |
|
106 file.Close(); |
|
107 } |
|
108 |
|
109 LOCAL_C void ReadFileL(RFs& aFs, const TDesC& aName, HBufC8*& aContent) |
|
110 { |
|
111 RFile file; |
|
112 TInt size = 0; |
|
113 |
|
114 User::LeaveIfError(file.Open(aFs, aName, EFileRead)); |
|
115 CleanupClosePushL(file); |
|
116 User::LeaveIfError(file.Size(size)); |
|
117 aContent = HBufC8::NewLC(size); |
|
118 TPtr8 ptr(aContent->Des()); |
|
119 User::LeaveIfError(file.Read(ptr, size)); |
|
120 CleanupStack::Pop(); //aContent |
|
121 CleanupStack::PopAndDestroy(); // file |
|
122 } |
|
123 |
|
124 HBufC8* I2OSPL( |
|
125 RInteger& aInt, TInt& aKeySize ) |
|
126 { |
|
127 HBufC8* integer = aInt.BufferLC(); |
|
128 if (integer->Length() < aKeySize) |
|
129 { |
|
130 HBufC8* r = HBufC8::NewLC(aKeySize); |
|
131 TPtr8 ptr(r->Des()); |
|
132 for(TInt i = integer->Length(); i < aKeySize; i++) |
|
133 { |
|
134 ptr.Append(KPadding()); |
|
135 } |
|
136 ptr.Append(*integer); |
|
137 CleanupStack::Pop(r); |
|
138 CleanupStack::PopAndDestroy(integer); |
|
139 return r; |
|
140 } |
|
141 else |
|
142 { |
|
143 CleanupStack::Pop(integer); |
|
144 return integer; |
|
145 } |
|
146 } |
|
147 |
|
148 RInteger OS2IPL( |
|
149 const TDesC8& aOctetStream) |
|
150 { |
|
151 RInteger r; |
|
152 TInt i; |
|
153 |
|
154 r = RInteger::NewL(0); |
|
155 for (i = 0; i < aOctetStream.Length(); i++) |
|
156 { |
|
157 r *= 256; |
|
158 r += aOctetStream[i]; |
|
159 } |
|
160 return r; |
|
161 } |
|
162 |
|
163 void DoUnloadPhoneModule( TAny* aAny ) |
|
164 { |
|
165 __ASSERT_DEBUG( aAny, User::Invariant() ); |
|
166 TUnloadModule* module = ( TUnloadModule* ) aAny; |
|
167 module->iServer->UnloadPhoneModule( *( module->iName ) ); |
|
168 } |
|
169 |
|
170 |
|
171 // ============================ MEMBER FUNCTIONS =============================== |
|
172 |
|
173 // ----------------------------------------------------------------------------- |
|
174 // CDrmStdKeyStorage* CDrmStdKeyStorage::NewL |
|
175 // |
|
176 // ----------------------------------------------------------------------------- |
|
177 // |
|
178 EXPORT_C CDrmStdKeyStorage* CDrmStdKeyStorage::NewL(RLibrary aLibrary) |
|
179 { |
|
180 CDrmStdKeyStorage* self = new (ELeave) CDrmStdKeyStorage(aLibrary); |
|
181 CleanupStack::PushL(self); |
|
182 self->ConstructL(); |
|
183 CleanupStack::Pop(); |
|
184 return self; |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CDrmStdKeyStorage::CDrmStdKeyStorage |
|
189 // |
|
190 // ----------------------------------------------------------------------------- |
|
191 // |
|
192 CDrmStdKeyStorage::CDrmStdKeyStorage(RLibrary aLibrary): |
|
193 iFileMan(NULL), |
|
194 iRootSelected(EFalse), |
|
195 iKey(NULL), |
|
196 iImei(NULL), |
|
197 iLibrary(aLibrary) |
|
198 { |
|
199 } |
|
200 |
|
201 // ----------------------------------------------------------------------------- |
|
202 // CDrmStdKeyStorage::ConstructL |
|
203 // |
|
204 // ----------------------------------------------------------------------------- |
|
205 // |
|
206 void CDrmStdKeyStorage::ConstructL() |
|
207 { |
|
208 |
|
209 LOG(_L("CDrmStdKeyStorage::ConstructL ->")); |
|
210 User::LeaveIfError(iFs.Connect()); |
|
211 iFileMan = CFileMan::NewL(iFs); |
|
212 |
|
213 #ifdef __DRM_OMA2 |
|
214 SelectDefaultRootL(); |
|
215 #endif |
|
216 |
|
217 iDeviceSpecificKey.Copy(KDefaultKey); |
|
218 |
|
219 LOG(_L("CDrmStdKeyStorage::ConstructL <-")); |
|
220 } |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // MDrmKeyStorage::~MDrmKeyStorage |
|
224 // |
|
225 // ----------------------------------------------------------------------------- |
|
226 // |
|
227 |
|
228 MDrmKeyStorage::~MDrmKeyStorage() |
|
229 { |
|
230 } |
|
231 // ----------------------------------------------------------------------------- |
|
232 // DrmStdKeyStorage::~CDrmStdKeyStorage |
|
233 // |
|
234 // ----------------------------------------------------------------------------- |
|
235 // |
|
236 |
|
237 CDrmStdKeyStorage::~CDrmStdKeyStorage() |
|
238 { |
|
239 LOG(_L("CDrmStdKeyStorage::~CDrmStdKeyStorage ->")); |
|
240 delete iFileMan; |
|
241 delete iKey; |
|
242 delete iImei; iImei = NULL; |
|
243 iFs.Close(); |
|
244 //iLibrary.Close(); |
|
245 LOG(_L("CDrmStdKeyStorage::~CDrmStdKeyStorage <-")); |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // DrmStdKeyStorage::ModulusSize |
|
250 // |
|
251 // ----------------------------------------------------------------------------- |
|
252 // |
|
253 |
|
254 TInt CDrmStdKeyStorage::ModulusSize() |
|
255 { |
|
256 LOG(_L("CDrmStdKeyStorage::ModulusSize ->")); |
|
257 |
|
258 if(iKey == NULL) |
|
259 { |
|
260 return KErrGeneral; |
|
261 } |
|
262 LOG(_L("CDrmStdKeyStorage::ModulusSize <-")); |
|
263 return iKey->N().BitCount(); |
|
264 } |
|
265 |
|
266 // ----------------------------------------------------------------------------- |
|
267 // DrmStdKeyStorage::SelectTrustedRootL |
|
268 // |
|
269 // ----------------------------------------------------------------------------- |
|
270 // |
|
271 void CDrmStdKeyStorage::SelectTrustedRootL( |
|
272 const TDesC8& aRootKeyHash) |
|
273 { |
|
274 TFileName fileName; |
|
275 TEntry entry; |
|
276 TInt i; |
|
277 |
|
278 LOG(_L("CDrmStdKeyStorage::SelectTrustedRootL ->")); |
|
279 LOG(aRootKeyHash); |
|
280 if (aRootKeyHash.Length() != 0) |
|
281 { |
|
282 |
|
283 #ifndef RD_MULTIPLE_DRIVE |
|
284 |
|
285 fileName.Copy(KKeyStoragePath); |
|
286 |
|
287 #else //RD_MULTIPLE_DRIVE |
|
288 |
|
289 TFileName tempPath; |
|
290 TInt driveNumber( -1 ); |
|
291 TChar driveLetter; |
|
292 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
|
293 iFs.DriveToChar( driveNumber, driveLetter ); |
|
294 |
|
295 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
|
296 |
|
297 fileName.Copy(tempPath); |
|
298 |
|
299 #endif |
|
300 |
|
301 for (i = 0; i < SHA1_HASH; i++) |
|
302 { |
|
303 fileName.AppendNumFixedWidth(aRootKeyHash[i], EHex, 2); |
|
304 } |
|
305 fileName.Append('\\'); |
|
306 if (iFs.Entry(fileName, entry) != KErrNone) |
|
307 { |
|
308 |
|
309 #ifndef RD_MULTIPLE_DRIVE |
|
310 |
|
311 fileName.Copy(KRomKeyStoragePath); |
|
312 |
|
313 #else //RD_MULTIPLE_DRIVE |
|
314 |
|
315 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
|
316 iFs.DriveToChar( driveNumber, driveLetter ); |
|
317 |
|
318 tempPath.Format( KRomKeyStoragePath, (TUint)driveLetter ); |
|
319 |
|
320 fileName.Copy(tempPath); |
|
321 |
|
322 #endif |
|
323 |
|
324 for (i = 0; i < SHA1_HASH; i++) |
|
325 { |
|
326 fileName.AppendNumFixedWidth(aRootKeyHash[i], EHex, 2); |
|
327 } |
|
328 fileName.Append('\\'); |
|
329 // check that the path exists |
|
330 User::LeaveIfError(iFs.Entry(fileName, entry)); |
|
331 } |
|
332 User::LeaveIfError(iFs.SetSessionPath(fileName)); |
|
333 InitializeKeyL(); |
|
334 CheckRootForCmlaL(); |
|
335 iRootSelected = ETrue; |
|
336 } |
|
337 else |
|
338 { |
|
339 SelectDefaultRootL(); |
|
340 } |
|
341 LOG(_L("CDrmStdKeyStorage::SelectTrustedRootL <-")); |
|
342 } |
|
343 |
|
344 // ----------------------------------------------------------------------------- |
|
345 // DrmStdKeyStorage::SelectDefaultRootL |
|
346 // |
|
347 // ----------------------------------------------------------------------------- |
|
348 // |
|
349 void CDrmStdKeyStorage::SelectDefaultRootL() |
|
350 { |
|
351 CDir* dir = NULL; |
|
352 TFileName dirName; |
|
353 TBool found = EFalse; |
|
354 |
|
355 LOG(_L("CDrmStdKeyStorage::SelectDefaultRootL ->")); |
|
356 |
|
357 #ifndef RD_MULTIPLE_DRIVE |
|
358 |
|
359 if (iFs.GetDir(KKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
360 |
|
361 #else //RD_MULTIPLE_DRIVE |
|
362 |
|
363 TFileName tempPath; |
|
364 TInt driveNumber( -1 ); |
|
365 TChar driveLetter; |
|
366 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
|
367 iFs.DriveToChar( driveNumber, driveLetter ); |
|
368 |
|
369 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
|
370 |
|
371 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
372 |
|
373 #endif |
|
374 |
|
375 { |
|
376 __UHEAP_MARK; |
|
377 LOG(_L(" Checking keys on C:")); |
|
378 CleanupStack::PushL(dir); |
|
379 if (dir->Count() >= 1) |
|
380 { |
|
381 |
|
382 #ifndef RD_MULTIPLE_DRIVE |
|
383 |
|
384 dirName.Copy(KKeyStoragePath); |
|
385 |
|
386 #else //RD_MULTIPLE_DRIVE |
|
387 |
|
388 dirName.Copy(tempPath); |
|
389 |
|
390 #endif |
|
391 |
|
392 dirName.Append((*dir)[0].iName); |
|
393 dirName.Append('\\'); |
|
394 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
|
395 found = ETrue; |
|
396 } |
|
397 CleanupStack::PopAndDestroy(dir); |
|
398 __UHEAP_MARKEND; |
|
399 } |
|
400 |
|
401 #ifndef RD_MULTIPLE_DRIVE |
|
402 |
|
403 if (!found && iFs.GetDir(KRomKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
404 |
|
405 #else //RD_MULTIPLE_DRIVE |
|
406 |
|
407 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
|
408 iFs.DriveToChar( driveNumber, driveLetter ); |
|
409 |
|
410 tempPath.Format( KRomKeyStoragePath, (TUint)driveLetter ); |
|
411 |
|
412 if (!found && iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
413 |
|
414 #endif |
|
415 { |
|
416 LOG(_L(" Checking keys on Z:")); |
|
417 CleanupStack::PushL(dir); |
|
418 if (dir->Count() < 1) |
|
419 { |
|
420 User::Leave(KErrGeneral); |
|
421 } |
|
422 |
|
423 #ifndef RD_MULTIPLE_DRIVE |
|
424 |
|
425 dirName.Copy(KRomKeyStoragePath); |
|
426 |
|
427 #else //RD_MULTIPLE_DRIVE |
|
428 |
|
429 dirName.Copy(tempPath); |
|
430 |
|
431 #endif |
|
432 |
|
433 dirName.Append((*dir)[0].iName); |
|
434 dirName.Append('\\'); |
|
435 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
|
436 CleanupStack::PopAndDestroy(dir); |
|
437 found = ETrue; |
|
438 } |
|
439 if (!found) |
|
440 { |
|
441 User::Leave(KErrGeneral); |
|
442 } |
|
443 InitializeKeyL(); |
|
444 CheckRootForCmlaL(); |
|
445 iRootSelected = ETrue; |
|
446 LOG(_L("CDrmStdKeyStorage::SelectDefaultRootL <-")); |
|
447 } |
|
448 |
|
449 TBool CDrmStdKeyStorage::SelectedRootIsCmla() |
|
450 { |
|
451 return iRootIsCmla; |
|
452 } |
|
453 |
|
454 // ----------------------------------------------------------------------------- |
|
455 // DrmStdKeyStorage::GetTrustedRootsL |
|
456 // |
|
457 // ----------------------------------------------------------------------------- |
|
458 // |
|
459 |
|
460 void CDrmStdKeyStorage::GetTrustedRootsL( |
|
461 RPointerArray<HBufC8>& aRootList) |
|
462 { |
|
463 CDir* dir = NULL; |
|
464 TInt i; |
|
465 TInt j; |
|
466 TBuf8<SHA1_HASH> hash; |
|
467 TEntry entry; |
|
468 TUint8 c; |
|
469 TInt r = KErrNone; |
|
470 |
|
471 LOG(_L("CDrmStdKeyStorage::GetTrustedRootsL ->")); |
|
472 aRootList.ResetAndDestroy(); |
|
473 |
|
474 #ifndef RD_MULTIPLE_DRIVE |
|
475 |
|
476 if (iFs.GetDir(KKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
477 |
|
478 #else //RD_MULTIPLE_DRIVE |
|
479 |
|
480 TFileName tempPath; |
|
481 TInt driveNumber( -1 ); |
|
482 TChar driveLetter; |
|
483 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
|
484 iFs.DriveToChar( driveNumber, driveLetter ); |
|
485 |
|
486 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
|
487 |
|
488 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
489 |
|
490 #endif |
|
491 { |
|
492 LOG(_L(" Getting roots on C:")); |
|
493 CleanupStack::PushL(dir); |
|
494 for (i = 0; i < dir->Count(); i++) |
|
495 { |
|
496 entry = (*dir)[i]; |
|
497 hash.SetLength(0); |
|
498 LOG(entry.iName); |
|
499 r = KErrNone; |
|
500 for (j = 0; r == KErrNone && j < SHA1_HASH; j++) |
|
501 { |
|
502 TLex lex(entry.iName.Mid(j * 2, 2)); |
|
503 r = lex.Val(c, EHex); |
|
504 hash.Append(c); |
|
505 } |
|
506 if (r == KErrNone) |
|
507 { |
|
508 aRootList.Append(hash.AllocL()); |
|
509 } |
|
510 } |
|
511 CleanupStack::PopAndDestroy(dir); |
|
512 } |
|
513 |
|
514 #ifndef RD_MULTIPLE_DRIVE |
|
515 |
|
516 if (iFs.GetDir(KRomKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
517 |
|
518 #else //RD_MULTIPLE_DRIVE |
|
519 |
|
520 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
|
521 iFs.DriveToChar( driveNumber, driveLetter ); |
|
522 |
|
523 tempPath.Format( KRomKeyStoragePath, (TUint)driveLetter ); |
|
524 |
|
525 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
526 |
|
527 #endif |
|
528 { |
|
529 LOG(_L(" Getting roots on Z:")); |
|
530 CleanupStack::PushL(dir); |
|
531 for (i = 0; i < dir->Count(); i++) |
|
532 { |
|
533 LOG(entry.iName); |
|
534 entry = (*dir)[i]; |
|
535 hash.SetLength(0); |
|
536 r = KErrNone; |
|
537 for (j = 0; r == KErrNone && j < SHA1_HASH; j++) |
|
538 { |
|
539 TLex lex(entry.iName.Mid(j * 2, 2)); |
|
540 r = lex.Val(c, EHex); |
|
541 hash.Append(c); |
|
542 } |
|
543 if (r == KErrNone) |
|
544 { |
|
545 aRootList.Append(hash.AllocL()); |
|
546 } |
|
547 } |
|
548 CleanupStack::PopAndDestroy(dir); |
|
549 } |
|
550 LOG(_L("CDrmStdKeyStorage::GetTrustedRootsL <-")); |
|
551 } |
|
552 |
|
553 // ----------------------------------------------------------------------------- |
|
554 // DrmStdKeyStorage::GetCertificateChainL |
|
555 // |
|
556 // ----------------------------------------------------------------------------- |
|
557 // |
|
558 void CDrmStdKeyStorage::GetCertificateChainL( |
|
559 RPointerArray<HBufC8>& aCertChain) |
|
560 { |
|
561 TFileName fileName; |
|
562 TInt i; |
|
563 CDir* dir = NULL; |
|
564 HBufC8* cert = NULL; |
|
565 |
|
566 LOG(_L("CDrmStdKeyStorage::GetCertificateChainL ->")); |
|
567 if (!iRootSelected) |
|
568 { |
|
569 User::Leave(KErrGeneral); |
|
570 } |
|
571 aCertChain.ResetAndDestroy(); |
|
572 ReadFileL(iFs, KDeviceCertFileName, cert); |
|
573 aCertChain.Append(cert); |
|
574 iFs.GetDir(KSingingCertPattern, KEntryAttNormal, ESortByName, dir); |
|
575 CleanupStack::PushL(dir); |
|
576 for (i = 0; i < dir->Count(); i++) |
|
577 { |
|
578 ReadFileL(iFs, (*dir)[i].iName, cert); |
|
579 aCertChain.AppendL(cert); |
|
580 } |
|
581 CleanupStack::PopAndDestroy(); // dir |
|
582 LOG(_L("CDrmStdKeyStorage::GetCertificateChainL <-")); |
|
583 } |
|
584 |
|
585 // ----------------------------------------------------------------------------- |
|
586 // CDrmStdKeyStorage::RsaSignL |
|
587 // ----------------------------------------------------------------------------- |
|
588 // |
|
589 HBufC8* CDrmStdKeyStorage::RsaSignL( |
|
590 const TDesC8& aInput) |
|
591 { |
|
592 return ModularExponentiateWithKeyL(aInput); |
|
593 } |
|
594 |
|
595 // ----------------------------------------------------------------------------- |
|
596 // CDrmStdKeyStorage::RsaDecryptL |
|
597 // ----------------------------------------------------------------------------- |
|
598 // |
|
599 HBufC8* CDrmStdKeyStorage::RsaDecryptL( |
|
600 const TDesC8& aInput) |
|
601 { |
|
602 return ModularExponentiateWithKeyL(aInput); |
|
603 } |
|
604 |
|
605 // ----------------------------------------------------------------------------- |
|
606 // CDrmStdKeyStorage::ImportDataL |
|
607 // ----------------------------------------------------------------------------- |
|
608 // |
|
609 void CDrmStdKeyStorage::ImportDataL( |
|
610 const TDesC8& aPrivateKey, |
|
611 const RArray<TPtrC8>& aCertificateChain) |
|
612 { |
|
613 TInt i; |
|
614 TInt n; |
|
615 HBufC8* publicKey = NULL; |
|
616 CX509Certificate* cert = NULL; |
|
617 CSHA1* hasher = NULL; |
|
618 TBuf8<SHA1_HASH> publicKeyHash; |
|
619 TFileName fileName; |
|
620 |
|
621 LOG(_L("CDrmStdKeyStorage::ImportDataL ->")); |
|
622 n = aCertificateChain.Count(); |
|
623 cert = CX509Certificate::NewLC(aCertificateChain[n - 1]); |
|
624 publicKey = cert->DataElementEncoding( |
|
625 CX509Certificate::ESubjectPublicKeyInfo)->AllocL(); |
|
626 CleanupStack::PushL(publicKey); |
|
627 hasher = CSHA1::NewL(); |
|
628 CleanupStack::PushL(hasher); |
|
629 hasher->Update(*publicKey); |
|
630 publicKeyHash.Copy(hasher->Final()); |
|
631 |
|
632 #ifndef RD_MULTIPLE_DRIVE |
|
633 |
|
634 fileName.Copy(KKeyStoragePath); |
|
635 |
|
636 #else //RD_MULTIPLE_DRIVE |
|
637 |
|
638 TInt driveNumber( -1 ); |
|
639 TChar driveLetter; |
|
640 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
|
641 iFs.DriveToChar( driveNumber, driveLetter ); |
|
642 |
|
643 TFileName keyStorageDir; |
|
644 keyStorageDir.Format( KKeyStoragePath, (TUint)driveLetter ); |
|
645 |
|
646 fileName.Copy(keyStorageDir); |
|
647 |
|
648 #endif |
|
649 |
|
650 for (i = 0; i < SHA1_HASH; i++) |
|
651 { |
|
652 fileName.AppendNumFixedWidth(publicKeyHash[i], EHex, 2); |
|
653 } |
|
654 fileName.Append('\\'); |
|
655 iFileMan->Delete(fileName, CFileMan::ERecurse); |
|
656 iFs.MkDirAll(fileName); |
|
657 iFs.SetSessionPath(fileName); |
|
658 WriteFileL(iFs, KDeviceKeyFileName, aPrivateKey); |
|
659 fileName.Copy(fileName); |
|
660 WriteFileL(iFs, KDeviceCertFileName, aCertificateChain[0]); |
|
661 for (i = 1; i < n; i++) |
|
662 { |
|
663 fileName.SetLength(0); |
|
664 fileName.AppendFormat(KSingingCertFmt, i - 1); |
|
665 WriteFileL(iFs, fileName, aCertificateChain[i]); |
|
666 } |
|
667 CleanupStack::PopAndDestroy(3); // hasher, publicKey, cert |
|
668 LOG(_L("CDrmStdKeyStorage::ImportDataL <-")); |
|
669 } |
|
670 |
|
671 // ----------------------------------------------------------------------------- |
|
672 // CDrmStdKeyStorage::GetDeviceSpecificKeyL |
|
673 // ----------------------------------------------------------------------------- |
|
674 // |
|
675 void CDrmStdKeyStorage::GetDeviceSpecificKeyL( |
|
676 TBuf8<KDeviceSpecificKeyLength>& aKey) |
|
677 { |
|
678 |
|
679 HBufC8* key = NULL; |
|
680 TInt n; |
|
681 CSHA1* hasher = NULL; |
|
682 TBuf8<SHA1_HASH> hash; |
|
683 |
|
684 if (iDeviceSpecificKey.Compare(KDefaultKey) == 0) |
|
685 { |
|
686 |
|
687 GetImeiL(); |
|
688 |
|
689 HBufC8* buf = HBufC8::NewLC( iImei->Size() + sizeof(VID_DEFAULT) ); |
|
690 TPtr8 ptr( buf->Des() ); |
|
691 ptr.Copy( *iImei ); |
|
692 ptr.Append(VID_DEFAULT); |
|
693 |
|
694 hasher = CSHA1::NewL(); |
|
695 CleanupStack::PushL(hasher); |
|
696 hasher->Update(ptr); |
|
697 hash.Copy(hasher->Final()); |
|
698 key=hash.AllocL(); |
|
699 CleanupStack::PopAndDestroy(2,buf); // hasher,buf; |
|
700 |
|
701 n = Min(key->Length(), KDeviceSpecificKeyLength); |
|
702 iDeviceSpecificKey.Copy(key->Right(n)); |
|
703 delete key; |
|
704 n = KDeviceSpecificKeyLength - n; |
|
705 while (n > 0) |
|
706 { |
|
707 iDeviceSpecificKey.Append(0); |
|
708 n--; |
|
709 } |
|
710 } |
|
711 |
|
712 aKey.Copy(iDeviceSpecificKey); |
|
713 } |
|
714 |
|
715 // ----------------------------------------------------------------------------- |
|
716 // CDrmStdKeyStorage::InitializeKeyL |
|
717 // ----------------------------------------------------------------------------- |
|
718 // |
|
719 void CDrmStdKeyStorage::InitializeKeyL() |
|
720 { |
|
721 HBufC8* key = NULL; |
|
722 TASN1DecInteger encInt; |
|
723 TInt pos = 0; |
|
724 |
|
725 LOG(_L("CDrmStdKeyStorage::InitializeKeyL ->")); |
|
726 delete iKey; |
|
727 iKey = NULL; |
|
728 ReadFileL(iFs, KDeviceKeyFileName, key); |
|
729 CleanupStack::PushL(key); |
|
730 TASN1DecGeneric gen(*key); |
|
731 gen.InitL(); |
|
732 pos += gen.LengthDERHeader(); |
|
733 if (gen.Tag() != EASN1Sequence) |
|
734 { |
|
735 User::Leave(KErrArgument); |
|
736 } |
|
737 encInt.DecodeDERShortL(*key, pos); // version |
|
738 RInteger modulus = encInt.DecodeDERLongL(*key, pos); |
|
739 CleanupStack::PushL(modulus); |
|
740 RInteger publicExponent = encInt.DecodeDERLongL(*key, pos); |
|
741 CleanupStack::PushL(publicExponent); |
|
742 RInteger privateExponent = encInt.DecodeDERLongL(*key, pos); |
|
743 CleanupStack::PushL(privateExponent); |
|
744 iKey = CRSAPrivateKeyStandard::NewL(modulus, privateExponent); |
|
745 CleanupStack::Pop(); // privateExponent |
|
746 CleanupStack::PopAndDestroy();// publicExponent |
|
747 CleanupStack::Pop(); // modulus |
|
748 CleanupStack::PopAndDestroy(); // key |
|
749 LOG(_L("CDrmStdKeyStorage::InitializeKeyL <-")); |
|
750 } |
|
751 |
|
752 // ----------------------------------------------------------------------------- |
|
753 // CDrmStdKeyStorage::ModularExponentiateWithKeyL |
|
754 // ----------------------------------------------------------------------------- |
|
755 // |
|
756 HBufC8* CDrmStdKeyStorage::ModularExponentiateWithKeyL( |
|
757 const TDesC8& aInput) |
|
758 { |
|
759 RInteger result; |
|
760 RInteger input; |
|
761 HBufC8* output; |
|
762 TInt keyLength = KKeyLength; |
|
763 |
|
764 LOG(_L("CDrmStdKeyStorage::ModularExponentiateWithKeyL ->")); |
|
765 input = OS2IPL(aInput); |
|
766 CleanupClosePushL(input); |
|
767 result = TInteger::ModularExponentiateL(input,iKey->D(), iKey->N()); |
|
768 CleanupClosePushL(result); |
|
769 output = I2OSPL(result, keyLength); |
|
770 CleanupStack::PopAndDestroy(2); // result, input |
|
771 LOG(_L("CDrmStdKeyStorage::ModularExponentiateWithKeyL <-")); |
|
772 return output; |
|
773 } |
|
774 |
|
775 // ----------------------------------------------------------------------------- |
|
776 // CDrmStdKeyStorage::CheckRootForCmlaL |
|
777 // ----------------------------------------------------------------------------- |
|
778 // |
|
779 void CDrmStdKeyStorage::CheckRootForCmlaL() |
|
780 { |
|
781 CDir* dir = NULL; |
|
782 HBufC8* buffer = NULL; |
|
783 HBufC* name = NULL; |
|
784 CX509Certificate* cert = NULL; |
|
785 |
|
786 LOG(_L("CDrmStdKeyStorage::CheckRootForCmlaL ->")); |
|
787 __UHEAP_MARK; |
|
788 iFs.GetDir(KSingingCertPattern, KEntryAttNormal, ESortByName, dir); |
|
789 CleanupStack::PushL(dir); |
|
790 ReadFileL(iFs, (*dir)[dir->Count() - 1].iName, buffer); |
|
791 CleanupStack::PushL(buffer); |
|
792 cert = CX509Certificate::NewL(*buffer); |
|
793 CleanupStack::PushL(cert); |
|
794 name = cert->SubjectName().DisplayNameL(); |
|
795 CleanupStack::PushL(name); |
|
796 if (name->Find(KCmla) != KErrNotFound) |
|
797 { |
|
798 iRootIsCmla = ETrue; |
|
799 } |
|
800 else |
|
801 { |
|
802 iRootIsCmla = EFalse; |
|
803 } |
|
804 CleanupStack::PopAndDestroy(4); // name, cert, buffer, dir |
|
805 LOG(_L("CDrmStdKeyStorage::CheckRootForCmlaL <-")); |
|
806 __UHEAP_MARKEND; |
|
807 } |
|
808 |
|
809 // ----------------------------------------------------------------------------- |
|
810 // CDrmStdKeyStorage::GetRdbSerialNumberL |
|
811 // ----------------------------------------------------------------------------- |
|
812 // |
|
813 void CDrmStdKeyStorage::GetRdbSerialNumberL( |
|
814 TBuf8<KRdbSerialNumberLength>& aSerialNumber) |
|
815 { |
|
816 HBufC8* buffer = NULL; |
|
817 TUint att; |
|
818 |
|
819 #ifndef RD_MULTIPLE_DRIVE |
|
820 |
|
821 if (iFs.Att(KSerialNumberFile, att) != KErrNone) |
|
822 |
|
823 #else //RD_MULTIPLE_DRIVE |
|
824 |
|
825 TInt driveNumber( -1 ); |
|
826 TChar driveLetter; |
|
827 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
|
828 iFs.DriveToChar( driveNumber, driveLetter ); |
|
829 |
|
830 TFileName serialNoFile; |
|
831 serialNoFile.Format( KSerialNumberFile, (TUint)driveLetter ); |
|
832 |
|
833 if (iFs.Att(serialNoFile, att) != KErrNone) |
|
834 |
|
835 #endif |
|
836 { |
|
837 GenerateNewRdbSerialNumberL(); |
|
838 } |
|
839 |
|
840 #ifndef RD_MULTIPLE_DRIVE |
|
841 |
|
842 ReadFileL(iFs, KSerialNumberFile, buffer); |
|
843 |
|
844 #else //RD_MULTIPLE_DRIVE |
|
845 |
|
846 ReadFileL(iFs, serialNoFile, buffer); |
|
847 |
|
848 #endif |
|
849 |
|
850 aSerialNumber.Copy(*buffer); |
|
851 delete buffer; |
|
852 } |
|
853 |
|
854 // ----------------------------------------------------------------------------- |
|
855 // CDrmStdKeyStorage::GenerateNewRdbSerialNumberL |
|
856 // ----------------------------------------------------------------------------- |
|
857 // |
|
858 void CDrmStdKeyStorage::GenerateNewRdbSerialNumberL() |
|
859 { |
|
860 TBuf8<KRdbSerialNumberLength> serialNumber; |
|
861 TPtr8 random( const_cast<TUint8*>(serialNumber.Ptr()), |
|
862 KRdbSerialNumberLength, |
|
863 KRdbSerialNumberLength ); |
|
864 |
|
865 RandomDataGetL(random,KRdbSerialNumberLength); |
|
866 |
|
867 #ifndef RD_MULTIPLE_DRIVE |
|
868 |
|
869 WriteFileL(iFs, KSerialNumberFile, random); |
|
870 |
|
871 #else //RD_MULTIPLE_DRIVE |
|
872 |
|
873 TInt driveNumber( -1 ); |
|
874 TChar driveLetter; |
|
875 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
|
876 iFs.DriveToChar( driveNumber, driveLetter ); |
|
877 |
|
878 TFileName serialNoFile; |
|
879 serialNoFile.Format( KSerialNumberFile, (TUint)driveLetter ); |
|
880 |
|
881 WriteFileL(iFs, serialNoFile, random); |
|
882 |
|
883 #endif |
|
884 |
|
885 } |
|
886 |
|
887 // ----------------------------------------------------------------------------- |
|
888 // CDrmStdKeyStorage::UdtEncryptL |
|
889 // ----------------------------------------------------------------------------- |
|
890 // |
|
891 HBufC8* CDrmStdKeyStorage::UdtEncryptL( |
|
892 const TDesC8& aInput) |
|
893 { |
|
894 HBufC8* buffer = NULL; |
|
895 HBufC8* output = HBufC8::NewMaxLC( 256 ); |
|
896 CX509Certificate* cert = NULL; |
|
897 CRSAPublicKey* key = NULL; |
|
898 TX509KeyFactory factory; |
|
899 CRSAPKCS1v15Encryptor* encryptor = NULL; |
|
900 TPtr8 result(const_cast<TUint8*>(output->Ptr()), 0, 256); |
|
901 |
|
902 #ifndef RD_MULTIPLE_DRIVE |
|
903 |
|
904 ReadFileL(iFs, KUdtCertFileName, buffer); |
|
905 |
|
906 #else //RD_MULTIPLE_DRIVE |
|
907 |
|
908 TInt driveNumber( -1 ); |
|
909 TChar driveLetter; |
|
910 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
|
911 iFs.DriveToChar( driveNumber, driveLetter ); |
|
912 |
|
913 TFileName udtCertFile; |
|
914 udtCertFile.Format( KUdtCertFileName, (TUint)driveLetter ); |
|
915 |
|
916 ReadFileL(iFs, udtCertFile, buffer); |
|
917 |
|
918 #endif |
|
919 |
|
920 CleanupStack::PushL(buffer); |
|
921 cert = CX509Certificate::NewL(*buffer); |
|
922 CleanupStack::PushL(cert); |
|
923 key = factory.RSAPublicKeyL(cert->PublicKey().KeyData()); |
|
924 CleanupStack::PushL(key); |
|
925 |
|
926 encryptor = CRSAPKCS1v15Encryptor::NewLC(*key); |
|
927 encryptor->EncryptL(aInput, result); |
|
928 |
|
929 CleanupStack::PopAndDestroy(4); // encryptor, key, cert, buffer |
|
930 CleanupStack::Pop();// output |
|
931 return output; |
|
932 }; |
|
933 |
|
934 // ----------------------------------------------------------------------------- |
|
935 // CDrmStdKeyStorage::GetRootCertificatesL |
|
936 // ----------------------------------------------------------------------------- |
|
937 // |
|
938 void CDrmStdKeyStorage::GetRootCertificatesL( |
|
939 RPointerArray<HBufC8>& aRootCerts) |
|
940 { |
|
941 CDir* dir = NULL; |
|
942 CDir* rootCerts = NULL; |
|
943 TFileName dirName; |
|
944 HBufC8* cert = NULL; |
|
945 TInt i = 0; |
|
946 TBuf<256> path; |
|
947 |
|
948 iFs.SessionPath( path ); |
|
949 |
|
950 #ifndef RD_MULTIPLE_DRIVE |
|
951 |
|
952 if (iFs.GetDir(KKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
953 |
|
954 #else //RD_MULTIPLE_DRIVE |
|
955 |
|
956 TFileName tempPath; |
|
957 TInt driveNumber( -1 ); |
|
958 TChar driveLetter; |
|
959 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber ); |
|
960 iFs.DriveToChar( driveNumber, driveLetter ); |
|
961 |
|
962 tempPath.Format( KKeyStoragePath, (TUint)driveLetter ); |
|
963 |
|
964 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
965 |
|
966 #endif |
|
967 { |
|
968 CleanupStack::PushL(dir); |
|
969 for(i = 0; i < dir->Count(); i++) |
|
970 { |
|
971 if ((*dir)[i].IsDir()) |
|
972 { |
|
973 |
|
974 #ifndef RD_MULTIPLE_DRIVE |
|
975 |
|
976 dirName.Copy(KKeyStoragePath); |
|
977 |
|
978 #else //RD_MULTIPLE_DRIVE |
|
979 |
|
980 dirName.Copy(tempPath); |
|
981 |
|
982 #endif |
|
983 |
|
984 dirName.Append((*dir)[i].iName); |
|
985 dirName.Append('\\'); |
|
986 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
|
987 User::LeaveIfError(iFs.GetDir(KSingingCertPattern, KEntryAttNormal, ESortByName, rootCerts)); |
|
988 CleanupStack::PushL(rootCerts); |
|
989 ReadFileL(iFs, (*rootCerts)[rootCerts->Count() - 1].iName, cert); |
|
990 CleanupStack::PushL(cert); |
|
991 aRootCerts.AppendL(cert); |
|
992 CleanupStack::Pop(cert); |
|
993 CleanupStack::PopAndDestroy(); // rootCerts |
|
994 } |
|
995 } |
|
996 CleanupStack::PopAndDestroy(dir); |
|
997 } |
|
998 |
|
999 #ifndef RD_MULTIPLE_DRIVE |
|
1000 |
|
1001 if (iFs.GetDir(KRomKeyStoragePath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
1002 |
|
1003 #else //RD_MULTIPLE_DRIVE |
|
1004 |
|
1005 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber ); |
|
1006 iFs.DriveToChar( driveNumber, driveLetter ); |
|
1007 |
|
1008 tempPath.Format( KRomKeyStoragePath, (TUint)driveLetter ); |
|
1009 |
|
1010 if (iFs.GetDir(tempPath, KEntryAttDir, ESortByName, dir) == KErrNone) |
|
1011 |
|
1012 #endif |
|
1013 { |
|
1014 CleanupStack::PushL(dir); |
|
1015 for(i = 0; i < dir->Count(); i++) |
|
1016 { |
|
1017 if ((*dir)[i].IsDir()) |
|
1018 { |
|
1019 |
|
1020 #ifndef RD_MULTIPLE_DRIVE |
|
1021 |
|
1022 dirName.Copy(KRomKeyStoragePath); |
|
1023 |
|
1024 #else //RD_MULTIPLE_DRIVE |
|
1025 |
|
1026 dirName.Copy(tempPath); |
|
1027 |
|
1028 #endif |
|
1029 |
|
1030 dirName.Append((*dir)[i].iName); |
|
1031 dirName.Append('\\'); |
|
1032 User::LeaveIfError(iFs.SetSessionPath(dirName)); |
|
1033 User::LeaveIfError(iFs.GetDir(KSingingCertPattern, KEntryAttNormal, ESortByName, rootCerts)); |
|
1034 CleanupStack::PushL(rootCerts); |
|
1035 ReadFileL(iFs, (*rootCerts)[rootCerts->Count() - 1].iName, cert); |
|
1036 CleanupStack::PushL(cert); |
|
1037 aRootCerts.AppendL(cert); |
|
1038 CleanupStack::Pop(cert); |
|
1039 CleanupStack::PopAndDestroy(); // rootCerts |
|
1040 } |
|
1041 } |
|
1042 CleanupStack::PopAndDestroy(dir); |
|
1043 } |
|
1044 iFs.SetSessionPath( path ); |
|
1045 } |
|
1046 |
|
1047 // ----------------------------------------------------------------------------- |
|
1048 // CDrmStdKeyStorage::GetIMEIL |
|
1049 // ----------------------------------------------------------------------------- |
|
1050 // |
|
1051 const TDesC& CDrmStdKeyStorage::GetImeiL() |
|
1052 { |
|
1053 if ( iImei ) |
|
1054 { |
|
1055 return *iImei; |
|
1056 } |
|
1057 |
|
1058 #if (defined __WINS__ || defined WINSCW) |
|
1059 // Default IMEI used for emulator |
|
1060 _LIT( KDefaultSerialNumber, "123456789123456789" ); |
|
1061 iImei = KDefaultSerialNumber().AllocL(); |
|
1062 |
|
1063 return *iImei; |
|
1064 #else |
|
1065 |
|
1066 TInt error( KErrNone ); |
|
1067 TInt count( 0 ); |
|
1068 TInt count2( 0 ); |
|
1069 TUint32 caps( 0 ); |
|
1070 TBool found (EFalse); |
|
1071 |
|
1072 RTelServer etelServer; |
|
1073 RMobilePhone phone; |
|
1074 |
|
1075 TUint KMaxImeiTries = 5; |
|
1076 |
|
1077 for ( TUint8 i = 0; i < KMaxImeiTries; ++i ) |
|
1078 { |
|
1079 error = etelServer.Connect(); |
|
1080 if ( error ) |
|
1081 { |
|
1082 User::After( TTimeIntervalMicroSeconds32( KWaitingTime ) ); |
|
1083 } |
|
1084 else |
|
1085 { |
|
1086 break; |
|
1087 } |
|
1088 } |
|
1089 |
|
1090 User::LeaveIfError( error ); |
|
1091 CleanupClosePushL( etelServer ); |
|
1092 |
|
1093 User::LeaveIfError( etelServer.LoadPhoneModule( KMmTsyModuleName ) ); |
|
1094 |
|
1095 TUnloadModule unload; |
|
1096 unload.iServer = &etelServer; |
|
1097 unload.iName = &KMmTsyModuleName; |
|
1098 |
|
1099 TCleanupItem item( DoUnloadPhoneModule, &unload ); |
|
1100 CleanupStack::PushL( item ); |
|
1101 User::LeaveIfError( etelServer.EnumeratePhones( count ) ); |
|
1102 |
|
1103 for ( count2 = 0; count2 < count && !found; ++count2 ) |
|
1104 { |
|
1105 RTelServer::TPhoneInfo phoneInfo; |
|
1106 User::LeaveIfError( etelServer.GetTsyName( count2, phoneInfo.iName ) ); |
|
1107 |
|
1108 if ( phoneInfo.iName.CompareF(KMmTsyModuleName()) == 0 ) |
|
1109 { |
|
1110 User::LeaveIfError( etelServer.GetPhoneInfo( count2, phoneInfo ) ); |
|
1111 User::LeaveIfError( phone.Open( etelServer, phoneInfo.iName ) ); |
|
1112 CleanupClosePushL( phone ); |
|
1113 found = ETrue; |
|
1114 } |
|
1115 } |
|
1116 |
|
1117 if ( !found ) |
|
1118 { |
|
1119 // Not found. |
|
1120 User::Leave( KErrNotFound ); |
|
1121 } |
|
1122 |
|
1123 User::LeaveIfError( phone.GetIdentityCaps( caps ) ); |
|
1124 if (!( caps & RMobilePhone::KCapsGetSerialNumber )) |
|
1125 { |
|
1126 User::Leave( KErrNotFound ); |
|
1127 } |
|
1128 |
|
1129 RMobilePhone::TMobilePhoneIdentityV1 id; |
|
1130 TRequestStatus status; |
|
1131 |
|
1132 phone.GetPhoneId( status, id ); |
|
1133 |
|
1134 User::WaitForRequest( status ); |
|
1135 |
|
1136 User::LeaveIfError( status.Int() ); |
|
1137 |
|
1138 iImei = id.iSerialNumber.AllocL(); |
|
1139 |
|
1140 CleanupStack::PopAndDestroy( 3 ); // phone, item, etelServer |
|
1141 |
|
1142 HBufC8* buf = HBufC8::NewL( iImei->Size() ); |
|
1143 TPtr8 ptr( buf->Des() ); |
|
1144 ptr.Copy( *iImei ); |
|
1145 |
|
1146 LOG(_L("IMEI:")); |
|
1147 LOGHEX(ptr); |
|
1148 delete buf; |
|
1149 |
|
1150 return *iImei; |
|
1151 #endif /* __WINS__ , WINSCW */ |
|
1152 |
|
1153 } |
|
1154 |
|
1155 |
|
1156 // ----------------------------------------------------------------------------- |
|
1157 // CDrmStdKeyStorage::RandomDataGetL |
|
1158 // ----------------------------------------------------------------------------- |
|
1159 // |
|
1160 |
|
1161 void CDrmStdKeyStorage::RandomDataGetL( TDes8& aData, const TInt aLength ) |
|
1162 { |
|
1163 if ( aLength <= 0 ) |
|
1164 { |
|
1165 User::Leave(KErrArgument); |
|
1166 } |
|
1167 |
|
1168 TInt size = aData.MaxSize(); |
|
1169 |
|
1170 if( size < aLength ) |
|
1171 { |
|
1172 User::Leave(KErrOverflow); |
|
1173 } |
|
1174 |
|
1175 TRandom::Random( aData ); |
|
1176 } |
|
1177 |
|
1178 // end of file |