379 |
379 |
380 aMessage.ReadL(FIRST_ARGUMENT, pckgPolicyDetails); |
380 aMessage.ReadL(FIRST_ARGUMENT, pckgPolicyDetails); |
381 |
381 |
382 // Read policy data |
382 // Read policy data |
383 TInt len = aMessage.GetDesLength(SECOND_ARGUMENT); |
383 TInt len = aMessage.GetDesLength(SECOND_ARGUMENT); |
384 HBufC8* policyData = HBufC8::NewL(len); |
384 HBufC8* policyData = HBufC8::NewLC(len); |
385 CleanupStack::PushL(policyData); |
|
386 |
|
387 TPtr8 ptrPolicyData = policyData->Des(); |
385 TPtr8 ptrPolicyData = policyData->Des(); |
388 aMessage.ReadL(SECOND_ARGUMENT, ptrPolicyData); |
386 aMessage.ReadL(SECOND_ARGUMENT, ptrPolicyData); |
389 |
387 |
390 |
388 //Make a validy check to the policy data |
|
389 //by parsing it and checking certificate formats |
|
390 HBufC* policyData16 = HBufC::NewLC(policyData->Length()); |
|
391 policyData16->Des().Copy(*policyData); |
|
392 |
|
393 CIkeDataArray* ikeDataArray = CIkeDataArray::NewL(1); |
|
394 CleanupStack::PushL(ikeDataArray); |
|
395 |
|
396 TIkeParser* ikeParser = new (ELeave) TIkeParser(*policyData16); |
|
397 CleanupStack::PushL(ikeParser); |
|
398 ikeParser->ParseIKESectionsL(ikeDataArray); |
|
399 |
|
400 for (TInt i = 0; i < ikeDataArray->Count(); ++i) |
|
401 { |
|
402 const CIkeData* ikeData = ikeDataArray->At(i); |
|
403 if (ikeData->iCAList != NULL) |
|
404 { |
|
405 for (TInt j = 0; j < ikeData->iCAList->Count(); j++) |
|
406 { |
|
407 if (ikeData->iCAList->At(j)->iFormat == BIN_CERT) |
|
408 { |
|
409 LOG(Log::Printf(_L("Policy contains BIN certificates --> Failing"))); |
|
410 //Ca cert in wrong format --> Error |
|
411 User::Leave(KVpnErrInvalidPolicyFile); |
|
412 } |
|
413 } |
|
414 } |
|
415 if ((ikeData->iOwnCert.iData.Length() > 0 && |
|
416 ikeData->iOwnCert.iFormat == BIN_CERT) || |
|
417 (ikeData->iPrivKey.iData.Length() > 0 && |
|
418 ikeData->iPrivKey.iFormat == BIN_CERT) || |
|
419 (ikeData->iPeerCert.iData.Length() > 0 && |
|
420 ikeData->iPeerCert.iFormat == BIN_CERT)) |
|
421 { |
|
422 LOG(Log::Printf(_L("Policy contains BIN certificates --> Failing"))); |
|
423 //Key or user cert in wrong format |
|
424 User::Leave(KVpnErrInvalidPolicyFile); |
|
425 } |
|
426 } |
|
427 |
|
428 CleanupStack::PopAndDestroy(); //ikeParser |
|
429 CleanupStack::PopAndDestroy(ikeDataArray); |
|
430 CleanupStack::PopAndDestroy(policyData16); |
|
431 |
391 LOG(Log::Printf(_L("Calling: iPolicyStore->AddNewPolicyL"))); |
432 LOG(Log::Printf(_L("Calling: iPolicyStore->AddNewPolicyL"))); |
392 // Add the policy to the policy store |
|
393 TRAPD(err, iPolicyStore->AddNewPolicyL(*policyDetails, *policyData)); |
433 TRAPD(err, iPolicyStore->AddNewPolicyL(*policyDetails, *policyData)); |
394 if (err == KErrNone) |
434 if (err == KErrNone) |
395 { |
435 { |
396 TBuf<20> serverName(_L("VPN DM Server")); |
436 TBuf<20> serverName(_L("VPN DM Server")); |
397 TPtrC8 tempCastPtr8(reinterpret_cast<const TUint8*>(serverName.Ptr()), serverName.Length() * 2); |
437 TPtrC8 tempCastPtr8(reinterpret_cast<const TUint8*>(serverName.Ptr()), serverName.Length() * 2); |