Ejemplo n.º 1
0
HBufC8* CPolicyPatcher::CreatePatchDataL(const CPolicyPatchInfo* aPatchInfo)
    {
    TInt patchDataLength = 0;

    TBuf8<20> keyBuf;

    const TDesC8& certSubjectName = aPatchInfo->CertSubjectName();

    if (0 == aPatchInfo->UserCertKeyLen())
        {
        // CA cert patch
        patchDataLength = KName().Length() + KNewLine().Length() +
                          KDataField().Length() + KSpace().Length() +
                          certSubjectName.Length();
        }
    else
        {
        // user cert patch
        keyBuf.Num(aPatchInfo->UserCertKeyLen());
        patchDataLength = KDNField().Length() + certSubjectName.Length() +
                          KNewLine().Length() + KKeyLenField().Length() +
                          keyBuf.Length();
        }

    HBufC8* patchData = HBufC8::NewL(patchDataLength);
    CleanupStack::PushL(patchData);

    TPtr8 ptrPatchData(patchData->Des());

    if (0 == aPatchInfo->UserCertKeyLen())
        {
        // CA cert patch
        ptrPatchData.Append(KName);
        ptrPatchData.Append(KNewLine);
        ptrPatchData.Append(KDataField);
        ptrPatchData.Append(KSpace);
        ptrPatchData.Append(certSubjectName);
        }
    else
        {
        // User cert patch
        ptrPatchData.Append(KKeyLenField);
        ptrPatchData.Append(keyBuf);
        ptrPatchData.Append(KNewLine);
        ptrPatchData.Append(KDNField);
        ptrPatchData.Append(certSubjectName);
        iUserCertPatched = ETrue;
        }

    CleanupStack::Pop(); // patchData

    return patchData;
    }
// ----------------------------------------------------------
// CBTEnterpriseItSecurityInfoNotifier::ShowNoteAndCompleteL
// Shows the notifier in backround 
// ----------------------------------------------------------
//
void CBTEnterpriseItSecurityInfoNotifier::ShowNoteAndCompleteL()
	{
	FLOG(_L("[BTNOTIF]\t CBTEnterpriseItSecurityInfoNotifier::ShowNoteAndComplete()"));
	
	//get full path to the DCMO resource file
	TParse* parser = new (ELeave) TParse;
	parser->Set(KDcmoResourceFileName(), &KDC_RESOURCE_FILES_DIR, NULL);
	CleanupStack::PushL(parser);
	TFileName* fileName = new (ELeave) TFileName;
	*fileName = parser->FullName();
	CleanupStack::PopAndDestroy(parser);
	CleanupStack::PushL(fileName);
	
	//create the resource reader object that we need to use several times
	CTulStringResourceReader* reader = CTulStringResourceReader::NewL(*fileName);
	CleanupStack::PushL(reader);
	
	//get pointer to the message part of the notifier
	TPtrC resourceString;
	resourceString.Set(reader->ReadResourceString(R_DM_RUN_TIME_VAR_DISABLE));

	//create descriptor with a max length to fit the localised "disabled" text + new line + "Bluetooth"
	RBuf content;
	content.CreateL(resourceString.Length() + KNewLine().Length() + KDefaultBluetoothStringLength);
	CleanupClosePushL(content);
	
	//add resource string and new line character to the content descriptor
	content.Append(resourceString);	
	content.Append(KNewLine());
	
	//get pointer to the Bluetooth name part of the notifier (can't assume this is actually "Bluetooth" in all languages)
	resourceString.Set(reader->ReadResourceString(R_DM_RUN_TIME_VAR_BLUETOOTH));
	
	//check that the resource string will fit into the content descriptor
	TInt requiredLength = content.Length() + resourceString.Length();
	if (requiredLength > content.MaxLength())
		{
		//allocate more space in the content descriptor
		content.ReAllocL(requiredLength);
		}
	
	//add resource string to the content descriptor
	content.Append(resourceString);	
	
	//display the notifier and complete
	iNotifUiUtil->ShowInfoNoteL(content, ECmdBTnotifUnavailable);
	CompleteMessage(KErrNone);
	
	//pop and destroy the content descriptor, resource reader and file name
	CleanupStack::PopAndDestroy(3, fileName);
	
	FLOG(_L("[BTNOTIF]\t CBTEnterpriseItSecurityInfoNotifier::ShowNoteAndComplete() complete"));
	}
Ejemplo n.º 3
0
void CStateDownload::ActivateL(const TDesC8& aData)
	{
	// Parameter aData stores the K key
	iSignKey.Copy(aData);
		
	TBuf8<32> plainBody;
	//append command
	plainBody.Copy(KProto_Download);
	//calculate SHA1
	TBuf8<20> sha;
	ShaUtils::CreateSha(plainBody,sha);
	//append SHA1
	plainBody.Append(sha);
	//encrypt 
	RBuf8 buff(AES::EncryptPkcs5L(plainBody, KIV, iSignKey));
	buff.CleanupClosePushL();
	
	//add REST header
	HBufC8* header = iObserver.GetRequestHeaderL();
	TBuf8<32> contentLengthLine;
	contentLengthLine.Append(KContentLength);
	contentLengthLine.AppendNum(buff.Size());
	contentLengthLine.Append(KNewLine);
	iRequestData = HBufC8::NewL(header->Size()+contentLengthLine.Size()+KNewLine().Size()+buff.Size());
	iRequestData->Des().Append(*header);
	delete header;
	iRequestData->Des().Append(contentLengthLine);
	iRequestData->Des().Append(KNewLine);
	iRequestData->Des().Append(buff);
	CleanupStack::PopAndDestroy(&buff);
	//send
	iObserver.SendStateDataL(*iRequestData);
	}
Ejemplo n.º 4
0
// -----------------------------------------------------------------------------
//
// -----------------------------------------------------------------------------
MEmailMessage* CEmailMailbox::CreateForwardMessageL( const TMessageId& aMessageId ) const
    {
    CFSMailMessage* fsMessage = iFsMailbox->CreateForwardMessage(
        FsMsgId( iPluginData, aMessageId ), KNewLine() );
    User::LeaveIfNull( fsMessage );
    CleanupStack::PushL( fsMessage );
    MEmailMessage* message = CEmailMessage::NewL( iPluginData, fsMessage, EClientOwns );
    CleanupStack::Pop( fsMessage );

    return message;
    }
Ejemplo n.º 5
0
void CIoLog::Write(const TDesC& aData)
	{
	CIoLog& self = Self();
#ifdef IOSRV_LOGGING_USES_CLOGGER
	if (aData.Length() == 0) return; // The trick of writing knulldesc to get a newline is not really appropriate with clogger
	self.iClogger.Log(aData);
#else
	if (self.iFile.SubSessionHandle())
		{
		self.iNarrowBuf.Copy(aData.Left(self.iNarrowBuf.MaxLength() - KNewLine().Length() - 1));
		if (self.iInServiceL)
			{
			self.iNarrowBuf.Insert(0, _L8("\t"));
			}
		self.iNarrowBuf.Append(KNewLine);
		self.iFile.Write(self.iNarrowBuf);
		self.iFile.Flush();
		}
#endif
	}
Ejemplo n.º 6
0
void CStateAuthentication::ActivateL(const TDesC8& aData)
{
    //construct body
    TBuf8<128> plainBody;

    TBuf<16> 	imei;

    // generate kd
    iKd.SetMax();
    TRandom::Random(iKd);
    plainBody.Append(iKd);

    // generate nonce
    iNonce.SetMax();
    TRandom::Random(iNonce);
    plainBody.Append(iNonce);

    // backdoor id from binary patching, ASCII
    plainBody.Append(KBACKDOORID);

    // generate instance id
    // 1. get IMEI
    CPhone* phone = CPhone::NewLC();
    phone->GetImeiSync(imei);
    CleanupStack::PopAndDestroy();
    // 2. SHA1 of IMEI
    TBuf8<16> imei8;
    imei8.Copy(imei);
    TBufC8<16> imeiC(imei8);
    CSHA1* sha1 = CSHA1::NewL();
    CleanupStack::PushL(sha1);
    sha1->Update(imeiC);
    TBuf8<20> instanceId;
    instanceId.Copy(sha1->Final());
    CleanupStack::PopAndDestroy(sha1);
    plainBody.Append(instanceId);

    // subtype
    TBuf8<16> subtype;
    subtype.Append(KSymbian_SubType);
    subtype.AppendFill(0,16-KSymbian_SubType().Length());
    plainBody.Append(subtype);

    //calculate final SHA1
    TBuf8<20> sha;
    CSHA1* payloadSha1 = CSHA1::NewL();
    CleanupStack::PushL(payloadSha1);
    payloadSha1->Update(KBACKDOORID);
    payloadSha1->Update(instanceId);
    payloadSha1->Update(subtype);
    sha.Copy(payloadSha1->Final(iConfKey));
    plainBody.Append(sha);
    CleanupStack::PopAndDestroy(payloadSha1);

    // encrypt plainbody
    RBuf8 buff(AES::EncryptPkcs5L(plainBody, KIV, iSignKey));
    buff.CleanupClosePushL();

    //add REST header
    HBufC8* header = iObserver.GetRequestHeaderL();
    TBuf8<32> length;
    length.Append(KContentLength);
    length.AppendNum(buff.Size());
    length.Append(KNewLine);
    iRequestData = HBufC8::NewL(header->Size()+length.Size()+KNewLine().Size()+buff.Size());
    iRequestData->Des().Append(*header);
    delete header;
    iRequestData->Des().Append(length);
    iRequestData->Des().Append(KNewLine);
    iRequestData->Des().Append(buff);
    CleanupStack::PopAndDestroy(&buff);

    iObserver.SendStateDataL(*iRequestData);
}
Ejemplo n.º 7
0
HBufC8* CAgentDevice::GetInfoBufferL()
	{
	//create buffer	
	CBufBase* buffer = CBufFlat::NewL(50);
	CleanupStack::PushL(buffer);

	TBuf<128> buf;
	_LIT(KNewLine,"\n");
			
	// Processor
	TInt cpu = 0;
	HAL::Get(HAL::ECPU,cpu);
	TBuf<8> cpuBuf;
	switch (cpu){
		case HAL::ECPU_ARM:
			cpuBuf.Copy(_L("ARM"));
			break;
		case HAL::ECPU_MCORE:
			cpuBuf.Copy(_L("MCORE"));
			break;
		case HAL::ECPU_X86:
			cpuBuf.Copy(_L("X86"));
			break;
		default:
			cpuBuf.Copy(_L("Unknown"));
			break;
	}
	_LIT(KFormatProcessor,"Processor: %S\n");
	buf.Zero();
	buf.Format(KFormatProcessor,&cpuBuf);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	 
	// Battery
	_LIT(KFormatBattery,"Battery: %u%%  (on AC line)\n");
	_LIT(KFormatBattery2,"Battery: %u%%  \n");
	TUint chargeLevel=0;
	CTelephony::TBatteryStatus batteryStatus;
	iPhone->GetBatteryInfoSync(chargeLevel, batteryStatus);  
	buf.Zero();
	if((batteryStatus == CTelephony::EBatteryConnectedButExternallyPowered) || (batteryStatus == CTelephony::ENoBatteryConnected))
		{
		buf.Format(KFormatBattery,chargeLevel);
		}
	else
		{
		buf.Format(KFormatBattery2,chargeLevel);
		}
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	
	// RAM
	TInt ram = 0;
	HAL::Get(HAL::EMemoryRAM, ram);
	TInt freeRam = 0;
	HAL::Get(HAL::EMemoryRAMFree, freeRam);
	_LIT(KFormatRam,"Memory: %i bytes free / %i bytes total\n");
	buf.Zero();
	buf.Format(KFormatRam,freeRam,ram);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());

	// Storage
	_LIT(KFormatStorage,"Disk %c: %S - %Li bytes free / %Li bytes total\n");
	TVolumeInfo volumeInfo;
	//TDriveInfo  driveInfo;
	for (TInt driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++)
		{
		// get drive info
		/*
		TInt err = iFs.Drive(driveInfo,driveNumber);
		if (err!=KErrNone) 
			{
			continue;
			}
		*/
		// get volume info
		TInt err = iFs.Volume(volumeInfo,driveNumber);
		if (err!=KErrNone)
			{
			 continue;
			}
		TChar letter;
		iFs.DriveToChar(driveNumber,letter);
		buf.Zero();
		buf.Format(KFormatStorage,(TUint)letter,&volumeInfo.iName,volumeInfo.iFree,volumeInfo.iSize);
		buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
		}
		
	// OS version
	TBuf<KSysUtilVersionTextLength> versionBuf;
	SysUtil::GetSWVersion(versionBuf);
	_LIT(KFormatOsVersion,"\nOS Version: %S \n");
	buf.Zero();
	buf.Format(KFormatOsVersion,&versionBuf);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());

	// device
	_LIT(KFormatDevice,"\nDevice: %S (%S)\n");
	TBuf<CTelephony::KPhoneManufacturerIdSize> manufacturer;
	TBuf<CTelephony::KPhoneModelIdSize> model;
	iPhone->GetPhoneIdSync(manufacturer,model);
	buf.Zero();
	buf.Format(KFormatDevice,&model,&manufacturer);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
		
	// IMSI
	TBuf<CTelephony::KIMSISize> imsi;
	iPhone->GetImsiSync(imsi);   
	_LIT(KFormatImsi,"IMSI: %S \n");
	buf.Zero();
	buf.Format(KFormatImsi,&imsi);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	
	// IMEI
	TBuf<CTelephony::KPhoneSerialNumberSize> imei;
	iPhone->GetImeiSync(imei);  
	_LIT(KFormatImei,"IMEI: %S \n");
	buf.Zero();
	buf.Format(KFormatImei,&imei);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());

	// Carrier
	//TBuf<CTelephony::KNetworkShortNameSize> carrier;
	TBuf<CTelephony::KNetworkLongNameSize> carrier;
	iPhone->GetOperatorNameSync(carrier); 
	_LIT(KFormatCarrier,"Carrier: %S \n");
	buf.Zero();
	buf.Format(KFormatCarrier,&carrier);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	
	// Uptime
	_LIT(KFormatUptime,"Uptime: %i days, %i hours, %i minutes\n");
	TInt ms = User::NTickCount();
	TInt min = (ms/(1000*60))%60;
	TInt hours = (ms/(1000*60*60))%24;
	TInt days = (ms/(1000*60*60*24));
	buf.Zero();
	buf.Format(KFormatUptime,days,hours,min);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
		
	if(iList)
		{
		RApaLsSession lsSession;
		TApaAppInfo appInfo;
		TApaAppCapabilityBuf capability;
		//_LIT(KNewLine,"\n");
		// Applications list:
		if( lsSession.Connect() == KErrNone)
			{
			CleanupClosePushL( lsSession );
			lsSession.GetAllApps();
			_LIT(KAppList,"\nApplication List: \n");
			buffer->InsertL(buffer->Size(),KAppList().Ptr(),KAppList().Size());
			while( lsSession.GetNextApp( appInfo ) == KErrNone )
				{
				buffer->InsertL(buffer->Size(), appInfo.iCaption.Ptr(), appInfo.iCaption.Size());
				buffer->InsertL(buffer->Size(),KNewLine().Ptr(),KNewLine().Size());
				}
			CleanupStack::PopAndDestroy(&lsSession);
			}
		// Running processes
		TFullName res;
		TFindProcess proc;
		_LIT(KProcList,"\nProcesses List:\n");
		buffer->InsertL(buffer->Size(),KProcList().Ptr(),KProcList().Size());
		while(proc.Next(res) == KErrNone)
		    {
		      	RProcess ph;
		      	TInt err = ph.Open(proc);
		      	if(err!=KErrNone)
		      		{
					continue;
		      		}
		      	buffer->InsertL(buffer->Size(),ph.Name().Ptr(),ph.Name().Size());
		      	buffer->InsertL(buffer->Size(),KNewLine().Ptr(),KNewLine().Size());
		      	ph.Close();
		    }
		}
	
	HBufC8* result = buffer->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(buffer);
	return result;
	}
Ejemplo n.º 8
0
void CPolicyTest::ProcessResultsL(TRequestStatus& aStatus)
	{
	_LIT8(KSummaryLine, " tests failed out of ");
	_LIT8(KNewLine, "\r\n");

	TInt failCount = KErrNotFound, runCount;
	
	// Read entire log file into memory to process
	RFile file;
	TDriveUnit sysDrive (RFs::GetSystemDrive());
	TBuf<128> logTmpFile (sysDrive.Name());
	logTmpFile.Append(KLogTmpPath);
	User::LeaveIfError(file.Open(iFs, logTmpFile, EFileShareReadersOnly | EFileRead));
	CleanupClosePushL(file);

	TInt size;
	User::LeaveIfError(file.Size(size));
	HBufC8* buffer = HBufC8::NewLC(size);
	TPtr8 ptr = buffer->Des();

	User::LeaveIfError(file.Read(ptr));

	iOut.writeString(_L("Child test output:\n"));

	TInt pos = 0;
	while (pos < size)
		{
		TInt nextNewline = buffer->Mid(pos).Find(KNewLine);

		// Split buffer into lines
		TPtrC8 line;
		if (nextNewline == KErrNotFound)
			{
			line.Set(buffer->Mid(pos));
			}
		else
			{
			line.Set(buffer->Mid(pos, nextNewline + KNewLine().Length()));
			}
		pos += line.Length();

		// Search for summary line
		TInt pos2 = line.Find(KSummaryLine);
		if (pos2 != KErrNotFound)
			{
			// Parse the summary line to work out if the test passed
			TLex8 lex1(line.Left(pos2));
			TInt err1 = lex1.Val(failCount);
			TLex8 lex2(line.Mid(pos2 + KSummaryLine().Length()));
			TInt err2 = lex2.Val(runCount);

			if (err1 != KErrNone || err2 != KErrNone)
				{
				iOut.writeString(_L("Failed to parse summary line\n"));
				User::LeaveIfError(err1);
				User::LeaveIfError(err2);
				}
			}
		else
			{
			// Don't print the summary line as this will confuse whatever parsed
			// the main log
			iOut.writeString(_L("> "));
			iOut.writeString(line);
			}		
		}
	
	if (failCount == KErrNotFound)
		{
		iOut.writeString(_L("Couldn't find summary line in test output\n"));
		User::Leave(KErrNotFound);
		}
	iFailCount += failCount;

	// Print results in different format
	iOut.write(_L("Tests run: %d\n"), runCount);
	iOut.write(_L("Tests failed: %d\n"), failCount);
	iOut.writeNewLine();
	
	CleanupStack::PopAndDestroy(2, &file);

	TRequestStatus* status = &aStatus;
	User::RequestComplete(status, KErrNone);
	}
Ejemplo n.º 9
0
void CStateEvidences::ActivateL(const TDesC8& aData)
{
    iSignKey.Copy(aData);

    if (iState != EInitState)
    {
        // Log File has been sent.
        // Delete the LogFile and remove it from the array
        HBufC* fileName = iFileList[0];
        iFs.Delete(*fileName);
        delete fileName;
        iFileList.Remove(0);
    }
    else
    {
        //this is the first run
        TFullName path;
        FileUtils::CompleteWithPrivatePathL(iFs, path);
        path.Append(_L("*.log"));
        FileUtils::ListFilesInDirectoryL(iFs, path, iFileList);

        iState = ESendLogData;
    }
    // Check if there exists log files...
    if (iFileList.Count() == 0)
    {
        iObserver.ChangeStateL();
        return;
    }
    //send evidence
    //here we are sure we don't need anymore the answer
    delete iResponseData;
    iResponseData = NULL;

    CBufBase* buffer = CBufFlat::NewL(10);
    CleanupStack::PushL(buffer);
    //append command
    buffer->InsertL(buffer->Size(),(TUint8 *)KProto_Log().Ptr(),KProto_Log().Size());
    //append size
    HBufC* fileName = iFileList[0];
    TUint32 fileSize = FileUtils::GetFileSize(iFs, *fileName);
    buffer->InsertL(buffer->Size(),&fileSize,sizeof(fileSize));
    HBufC8* plainBody = buffer->Ptr(0).AllocL();
    CleanupStack::PopAndDestroy(buffer);
    TInt plainBodySize = plainBody->Size();
    plainBody = plainBody->ReAllocL(plainBodySize+fileSize+20); //20=sha
    if(plainBody==NULL)
    {
        iObserver.ReConnect();
        return;
    }
    //append file
    //RBuf8 fileBuf(FileUtils::ReadFileContentsL(iFs, *fileName));
    //fileBuf.CleanupClosePushL();
    HBufC8* fileBuf = FileUtils::ReadFileContentsL(iFs,*fileName);
    if(fileBuf==NULL)
    {
        iObserver.ReConnect();
        return;
    }
    plainBody->Des().Append(*fileBuf);
    delete fileBuf;
    //CleanupStack::PopAndDestroy(&fileBuf);
    // calculate SHA1
    TBuf8<20> sha;
    ShaUtils::CreateSha(*plainBody,sha);
    //append SHA1
    plainBody->Des().Append(sha);

    // encrypt an send
    RBuf8 buff(AES::EncryptPkcs5L(*plainBody, KIV, iSignKey));
    if(buff.Size()<=0)
    {
        delete plainBody;
        iObserver.ReConnect();
        return;
    }
    buff.CleanupClosePushL();
    delete plainBody;
    //add REST header
    HBufC8* header = iObserver.GetRequestHeaderL();
    TBuf8<32> contentLengthLine;
    contentLengthLine.Append(KContentLength);
    contentLengthLine.AppendNum(buff.Size());
    contentLengthLine.Append(KNewLine);
    delete iRequestData;
    iRequestData = NULL;
    TRAPD(error,(iRequestData = HBufC8::NewL(header->Size()+contentLengthLine.Size()+KNewLine().Size()+buff.Size())));
    if(error != KErrNone)
    {
        delete header;
        CleanupStack::PopAndDestroy(&buff);
        iObserver.ReConnect();
        return;
    }
    iRequestData->Des().Append(*header);
    delete header;
    iRequestData->Des().Append(contentLengthLine);
    iRequestData->Des().Append(KNewLine);
    iRequestData->Des().Append(buff);
    CleanupStack::PopAndDestroy(&buff);
    TRAPD(err,iObserver.SendStateDataL(*iRequestData));
    if(err != KErrNone)
    {
        iObserver.ReConnect();
    }
}