예제 #1
0
EXPORT_C void CX509Certificate::InternalizeL(RReadStream& aStream)
	{
	if (iIssuerName != NULL) //just to check cert is uninitialised
		{
		User::Leave(KErrArgument);
		}
	iKeyFactory = new(ELeave) TX509KeyFactory;
	
	TInt len = aStream.ReadInt32L(); //Read the length of the streamed encoding
	HBufC8* temp= HBufC8::NewLC(len);	
	TPtr8 ptr=temp->Des();
	aStream.ReadL(ptr,len);
	iEncoding=temp->AllocL();
	CleanupStack::PopAndDestroy(); // temp

	TASN1DecSequence encSeq;
	TInt pos = 0;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(*iEncoding, pos, 3, 3);	
	TASN1DecGeneric* encSigAlg = seq->At(1);
	iSigningAlgorithm = CX509SigningAlgorithmIdentifier::NewL(encSigAlg->Encoding());
	TASN1DecBitString encBS;
	iSignature = encBS.ExtractOctetStringL(*(seq->At(2)));
	CleanupStack::PopAndDestroy();//seq	

	CSHA1* hash = CSHA1::NewL();
	CleanupStack::PushL(hash);
	iFingerprint = hash->Final(Encoding()).AllocL();
	CleanupStack::PopAndDestroy();//hash

	ConstructCertL();
	}
예제 #2
0
void CX509CertExtension::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
	{
	TASN1DecSequence encSeq;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(aBinaryData, aPos, 2, KMaxTInt);

	TASN1DecObjectIdentifier encOID;
	iId = encOID.DecodeDERL(*(seq->At(0)));
	//second is either critical flag, or the ext
	TASN1DecGeneric* second = seq->At(1);
	if (second->Tag() != EASN1Boolean)
		{
		iData = second->Encoding().AllocL();
		aPos += second->LengthDER();
		}
	else
		{
		TASN1DecBoolean encBool;
		iCritical = encBool.DecodeDERL(*second);
		if (seq->Count() != 3)
			{
			User::Leave(KErrArgument);
			}

		TASN1DecGeneric* third = seq->At(2);
		iData = third->Encoding().AllocL();
		}
	CleanupStack::PopAndDestroy();//seq
	}
예제 #3
0
void CWapDgrmTestStep::_Parse2L(CArrayPtrFlat<CSmsMessage>& aSmsArray,
						CWapReassemblyStore* aWapStore)
/**
 *  This method tests mainly CWapDatagram::DecodeConcatenatedMessagesL
 */
{
    TInt Count = aSmsArray.Count();

    // In reverse order
    // Note ! You can test additional features by changing value of
    // i or a global variable (insertSms). For example:
    // incrementing i by 1: a duplicate test
    // decrementing i by 1: not all datagrams are pushed to the store
    // ncreasing insertSms causes datagrams to be appended to the reserve array
    // Remember to set flush the reserve array on a later phase
    // by setting iIsFlushReserveArray true


    for (TInt i=Count-1;i>=iInsertSms;i--)
    {
        CWapDatagram* Wap=CWapDatagram::NewL(*(aSmsArray.At(i)));
        if (!Wap->IsComplete())
        {
            TInt Index = 0;
            TBool IsComplete = EFalse;
            IsComplete = aWapStore->AddMessageL(Index,*Wap);
            if (IsComplete)
            {
                aWapStore->GetDatagramL(Index,*Wap);
				aWapStore->BeginTransactionLC();
                aWapStore->DeleteEntryL(Index);
				aWapStore->CommitTransactionL();
                _Print(*Wap);
            }
        }
        else
            _Print(*Wap);

        delete Wap;
    }

	// append rest of the datagrams to the ReserveArray
	if (iInsertSms>0 && Count>1)
	{
		// reserve order here too
        for (TInt i=iInsertSms-1;i>=0;i--)
        {
            CWapDatagram* Wap=CWapDatagram::NewL(*(aSmsArray.At(i)));
            iReserveArray->AppendL(Wap);
        }
	}

    if (iIsFlushReserveArray)
    {
        _FlushReserveArrayL(aWapStore);
        iInsertSms = 0;
        iIsFlushReserveArray = EFalse;
    }
}
예제 #4
0
void CX509SubjectPublicKeyInfo::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
	{
	TASN1DecSequence encSeq;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(aBinaryData, aPos, 2, KMaxTInt);
	iAlgId = CX509AlgorithmIdentifier::NewL(seq->At(0)->Encoding());
	TASN1DecBitString encBS;
	iEncodedKeyData = encBS.ExtractOctetStringL(*(seq->At(1)));
	CleanupStack::PopAndDestroy();//seq
	}
예제 #5
0
void CX509ValidityPeriod::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
	{
	TASN1DecSequence encSeq;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(aBinaryData, aPos);
	if (seq->Count() != 2)
		{
		User::Leave(KErrArgument);
		}
	TASN1DecX509Time decTime;
	iStart = decTime.DecodeDERL(*(seq->At(0)));
	iFinish = decTime.DecodeDERL(*(seq->At(1)));
	CleanupStack::PopAndDestroy();//seq + contents
	}
예제 #6
0
void CDecPkcs12Attribute::ConstructL(const TDesC8& aBagAttributes)
	{
	TASN1DecGeneric seqGen(aBagAttributes);
	seqGen.InitL();
	
	// Check if this is a Sequence
	if (seqGen.Tag() != EASN1Sequence || seqGen.Class() != EUniversal)
		{
		User::Leave(KErrArgument);
		}
	
	TASN1DecSequence seq;
	CArrayPtrFlat<TASN1DecGeneric>* attributeSet = seq.DecodeDERLC(seqGen);
	const TASN1DecGeneric* attributeSetAt0 = attributeSet->At(0);
	if(attributeSetAt0->Tag() != EASN1ObjectIdentifier || attributeSetAt0->Class() != EUniversal)
		{
		User::Leave(KErrArgument);
		}
		
	// Decode the ObjectIdentifier
	TASN1DecObjectIdentifier oid;
	iAttributeId = oid.DecodeDERL(*attributeSetAt0); 
	 
	const TASN1DecGeneric* attributeSetAt1 = attributeSet->At(1);
	if(attributeSetAt1->Tag() != EASN1Set || attributeSetAt1->Class() != EUniversal)
		{
		User::Leave(KErrArgument);
		}
			
	// Attribute Set
	TASN1DecSet decSet;
    CArrayPtrFlat<TASN1DecGeneric>* attributeValues = decSet.NewDERLC(attributeSetAt1->Encoding());
    
    TInt attributeCount = attributeValues->Count();
		    
    for(TInt index = 0; index < attributeCount; ++index)         
	   	{
	   	const TASN1DecGeneric* attributeValuesAt = attributeValues->At(index);
		TASN1DecGeneric seqGen(*attributeValuesAt);
		seqGen.InitL();
		TPtrC8 attrValue = seqGen.Encoding();
		TDesC8* attributeVal = attrValue.AllocL();
		CleanupStack::PushL(attributeVal);
		iAttributeValue.AppendL(attributeVal);
		CleanupStack::Pop(attributeVal);
	   	}
    CleanupStack::PopAndDestroy(2,attributeSet); // attributeSet,attributeValues    
	}	
void CClearConfig::ClearL(RULogger& loggerSession)
{	
	loggerSession.Stop();//C.A. previously:loggerSession.StopOutputting();
	loggerSession.DeActivateInputPlugin();
	CArrayPtrFlat<HBufC8> *allplugins = new (ELeave)CArrayPtrFlat<HBufC8>(1);
	loggerSession.GetInstalledOutputPlugins(*allplugins);//C.A. previously:loggerSession.InstalledOutputPlugins(*allplugins);
	for(TInt i=0;i<(allplugins->Count());i++)
	if(allplugins->Count())
	{
		TBuf8<50> dataBuf;
		dataBuf.Copy(allplugins->At(i)->Des());
		loggerSession.RemovePluginConfigurations(dataBuf);
	}
	CArrayFixFlat<TUint8> *getfilter = new (ELeave)CArrayFixFlat<TUint8>(1);
	loggerSession.GetPrimaryFiltersEnabled(*getfilter);//C.A. previously:loggerSession.GetEnabledClassifications(*getfilter);
	TInt Result=loggerSession.SetPrimaryFiltersEnabled(*getfilter,EFalse);//C.A. previously:TInt Result=loggerSession.DisableClassifications(*getfilter);
	RArray<TUint32> get2filter;	
	loggerSession.GetSecondaryFiltersEnabled(get2filter);//C.A. previously:loggerSession.GetEnabledModuleUids(get2filter);
	loggerSession.SetSecondaryFiltersEnabled(get2filter,EFalse);//C.A. previously:loggerSession.DisableModuleUids(get2filter);
	//C.A. previously:loggerSession.EnableClassificationFiltering();
	loggerSession.SetSecondaryFilteringEnabled(ETrue);//C.A. previously:loggerSession.EnableModuleUidFiltering();
	loggerSession.SetBufferSize(1024);
	loggerSession.SetNotificationSize(512);
	loggerSession.SetBufferMode(1);//C.A. previously:loggerSession.SetBufferMode(EStraight);
}
예제 #8
0
//***************************************************************************************//
//extra accessors
EXPORT_C const TPtrC8 CX509Certificate::SignedDataL() const
	{
	TASN1DecSequence encSeq;
	TInt pos = 0;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(*iEncoding, pos, 3, 3);
	TASN1DecGeneric* gen = seq->At(0);
	TPtrC8 res = gen->Encoding();
	CleanupStack::PopAndDestroy();
	return res;
	}
예제 #9
0
void CX509Certificate::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
	{
	TASN1DecGeneric gen(aBinaryData.Right(aBinaryData.Length() - aPos));
	gen.InitL();
	
	// The outermost tag for X509 certificates is always a sequence.
	// Since this tag does not form part of the signed data it is possible
	// to corrupt the tag by changing it to any other ASN.1 tag and process
	// the rest of the certificate as normal.
	// However, we still reject the certificate anyway to avoid 
	// confusion because the data does not match the X.509 specification.	
	if (gen.Tag() != EASN1Sequence)
		{
		User::Leave(KErrArgument);
		}
	
	aPos += gen.LengthDER();
	iKeyFactory = new(ELeave) TX509KeyFactory;

	iEncoding = gen.Encoding().AllocL();

	TASN1DecSequence encSeq;
	TInt pos = 0;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(*iEncoding, pos, 3, 3);	
	TASN1DecGeneric* encSigAlg = seq->At(1);
	iSigningAlgorithm = CX509SigningAlgorithmIdentifier::NewL(encSigAlg->Encoding());
	TASN1DecBitString encBS;
	iSignature = encBS.ExtractOctetStringL(*(seq->At(2)));
	CleanupStack::PopAndDestroy();//seq

	CSHA1* hash = CSHA1::NewL();
	CleanupStack::PushL(hash);
	iFingerprint = hash->Final(Encoding()).AllocL();
	CleanupStack::PopAndDestroy();//hash
	ConstructCertL();
	}
예제 #10
0
void CX509Certificate::DecodeExtsL(const TDesC8& aBinaryData, TBool& aHasElementAlready)
	{
	TASN1DecSequence encSeq;
	TInt pos = 0;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(aBinaryData, pos);
	TInt count = seq->Count();
	for (TInt i = 0; i < count; i++)
		{
		TASN1DecGeneric* gen = seq->At(i);
		CX509CertExtension* ext = CX509CertExtension::NewLC(gen->Encoding());
		iExtensions->AppendL(ext);
		CleanupStack::Pop();//ext
		}
	CleanupStack::PopAndDestroy();//
	aHasElementAlready = ETrue;
	}
예제 #11
0
/**
 Sets the animation frames to the player.
*/
void RBitmapAnim::SetFrameArrayL(const CArrayPtrFlat<CBitmapFrameData>& aFrameArray)
	{
	const TInt count = aFrameArray.Count();

	if (count > 0)
		{
		User::LeaveIfError(CommandReply(EBitmapAnimCommandResetFrameArray));
		CBitmapFrameData* frameData;
		User::LeaveIfError(CommandReply(EBitmapAnimCommandClearDataFrames));

		TInt index = 0;

		for (index = 0; index < count; index++)
			{
			frameData = aFrameArray.At(index);
			SetFrameL(*frameData, EBitmapAnimCommandSetDataFrame);
			}
		}
	}
예제 #12
0
void CX509Certificate::InitDataElementsL(const CX509Certificate& aCertificate)
	{
	iDataElements = new(ELeave) TFixedArray<TPtrC8*, KX509MaxDataElements>;
	iDataElements->Reset();
	TPtrC8 signedData = SignedDataL();
	TASN1DecSequence encSeq;
	TInt pos = 0;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(signedData, pos, 6, KMaxTInt);//6 is the minimum number of elements in an x509 cert
	pos = 0;

	TPtrC8** pElement = iDataElements->Begin();
	*pElement++ = aCertificate.DataElementEncoding(CX509Certificate::EVersionNumber)? new(ELeave) TPtrC8(seq->At(pos++)->Encoding()):NULL;
	for (TInt i = 0; i < 6; i++)	//init all the non-optional elements
		{
		*pElement++ = new(ELeave) TPtrC8(seq->At(pos++)->Encoding());
		}
	*pElement++ = aCertificate.DataElementEncoding(CX509Certificate::EIssuerUID)? new(ELeave) TPtrC8(seq->At(pos++)->Encoding()):NULL;
	*pElement++ = aCertificate.DataElementEncoding(CX509Certificate::ESubjectUID)? new(ELeave) TPtrC8(seq->At(pos++)->Encoding()):NULL;
	*pElement++ = aCertificate.DataElementEncoding(CX509Certificate::EExtensionList)? new(ELeave) TPtrC8(seq->At(pos++)->Encoding()):NULL;
	CleanupStack::PopAndDestroy();
	}
예제 #13
0
TBool IkePkiUtils::VerifySignatureL(TInt aIkeVersion, 
                                    const TDesC8& aSignature, 
                                    const TDesC8& aRefHash, 
                                    const CX509Certificate& aCert)
    {
	//
	// Verify IKE signature. 
	//
	TBool status = EFalse;
	
	if ( aSignature.Length() > 0 )	
	    {	    	
    	CIkePublicKey* publicKey = CIkePublicKey::NewL(aCert);
    	if ( !publicKey )
    	    {	    
    		return EFalse;			
    	    }

    	CleanupStack::PushL(publicKey);			

    	switch (publicKey->Algorithm())
    	    {
    		case EPKIRSA:
    			{
                HBufC8 *resBuf;
                TUtlCrypto::RsaPublicKeyDecryptL(publicKey->KeyData(), aSignature, resBuf);
                CleanupStack::PushL(resBuf);							
                
                if ( aIkeVersion == MAJORV1 ) 
                    {
                    //
                    // Because IKEv1 signature is not a "real" PKCS1
                    // encoded signature but pure private encrypted has
                    // signature is verified by using RSA public key
                    // decrypt and result comparison to reference hash
                    //
                    status = (aRefHash.Compare(*resBuf) == 0); //Compare the result with the hash to see if they match
                    }
                else
    				{
                    //
                    // IKEv2(n) signature is encoded as PKCS1v1_5
                    // signature (EMSA-PKCS1-v1_5)
                    // ASN1 encoding of signature is the following:
                    //	DigestInfo::=SEQUENCE{
                    //	  digestAlgorithm  AlgorithmIdentifier,
                    //	  digest OCTET STRING }
                    //
                    CArrayPtrFlat<TASN1DecGeneric>* seq = NULL;
                    TInt position = 0;
    									
                    TRAPD(err, seq = DecodeDERL(*resBuf, position));
                    if ( err == KErrNone )
                        {
                        TCleanupItem CleanupSeq(IkeCert::CleanupSequence, seq);						
                        CleanupStack::PushL(CleanupSeq);
                        if (seq->Count() == 2)
                            {
                            //
                            // Currently the digestAlgorithm is not
                            // verified, but only digest value itself is
                            // compared with reference hash.
                            // ( see CPKCS1SignatureResult::DoVerifyL() in
                            //   x509cert.cpp)
                            // 
                            const TASN1DecGeneric* gen2 = seq->At(1);                            
                            TPtrC8 digest(gen2->GetContentDER());
                            status = (aRefHash.Compare(digest) == 0);
                            }
                        CleanupStack::PopAndDestroy(); //CleanupSeq
                        }
                    else
                        {
                        //
                        // Verify signature as pure encrypted (SHA1)
                        // hash as old IKEv1 style "signature" 
                        //
                        //DEB(iService.PrintText(_L("Old IKEv1 style signature used by IKEv2 peer !\n"));)					   
                        status = (aRefHash.Compare(*resBuf) == 0); //Compare the result with the hash to see if they match					   
                        }	
    				}
                CleanupStack::PopAndDestroy(resBuf);
    			break;
    			}
            case EPKIDSA:
                {
                const TPtrC8 sigR = aSignature.Left(aSignature.Length() / 2);
                const TPtrC8 sigS = aSignature.Right(aSignature.Length() / 2);

                status = TUtlCrypto::DsaVerifySignatureL(publicKey->KeyData(), 
                                                         publicKey->KeyParams(), 
                                                         sigR, sigS, aRefHash);
                break;
                }
            default:        //Only RSA and DSA are valid
                User::Invariant();
            	break;
    		}

    	CleanupStack::PopAndDestroy(publicKey);
	    }
	return status;
    }	
예제 #14
0
void CX509Certificate::ConstructCertL()
	{
	TPtrC8 signedData = SignedDataL();
	TASN1DecSequence encSeq;
	TInt pos = 0;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(signedData, pos, 6, KMaxTInt);//6 is the minimum number of elements in an x509 cert
	TInt count = seq->Count();
	pos = 0;
	TASN1DecGeneric* curr = seq->At(pos);
	pos++;
	iDataElements = new(ELeave) TFixedArray<TPtrC8*, KX509MaxDataElements>;
	iDataElements->Reset();
	TPtrC8** pElement = iDataElements->Begin();
	if ((curr->Class() == EContextSpecific) && (curr->Tag() == 0))
		{
		//version!
		TASN1DecGeneric ver(curr->GetContentDER());
		ver.InitL();
		TPtrC8 pVer8 = ver.GetContentDER();
		if(pVer8.Length() != 1)
			{
			User::Leave(KErrArgument);
			}
		iVersion = (pVer8[0]) + 1;
		if ((iVersion < 1) || (iVersion > 3) || (count < 7))
			{
			User::Leave(KErrArgument);
			}
		*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
		curr = seq->At(pos);
		pos++;
		}
	else
		{
		*pElement++ = NULL;
		}
	if (curr->Tag() != EASN1Integer)
		{
		User::Leave(KErrArgument);
		}
	iSerialNumber = (curr->GetContentDER()).AllocL();
	*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
	curr = seq->At(pos);
	pos++;
	CX509SigningAlgorithmIdentifier* algorithmId = CX509SigningAlgorithmIdentifier::NewLC(curr->Encoding());
	if (!(SigningAlgorithm() == *(algorithmId)))
		{
		User::Leave(KErrArgument);
		}
	CleanupStack::PopAndDestroy();//algorithmId
	*pElement++ = new(ELeave) TPtrC8(curr->Encoding());

	curr = seq->At(pos);
	pos++;
	iIssuerName = CX500DistinguishedName::NewL(curr->Encoding());
	*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
	curr = seq->At(pos);
	pos++;
	iValidityPeriod = CX509ValidityPeriod::NewL(curr->Encoding());
	*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
	curr = seq->At(pos);
	pos++;
	iSubjectName = CX500DistinguishedName::NewL(curr->Encoding());
	*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
	curr = seq->At(pos);
	pos++;
	iSubjectPublicKeyInfo = CX509SubjectPublicKeyInfo::NewL(curr->Encoding());
	*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
	//do issuer uid, subject uid, exts
	//these are all optional
	TBool hasIssuerUid = EFalse;
	TBool hasSubjectUid = EFalse;
	TBool hasExts = EFalse;
	iExtensions = new(ELeave)CArrayPtrFlat<CX509CertExtension> (1);
	if (pos < count)//otherwise there aren't any of 'em
		{
		curr = seq->At(pos);
		pos++;
		if (curr->Class() != EContextSpecific)
			{
			User::Leave(KErrArgument);
			}
		switch(curr->Tag())
			{
			case 1:
				{
				iIssuerUid = DecodeUidL(curr->GetContentDER(), hasIssuerUid);
				*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
				break;
				}
			case 2:
				{
				iSubjectUid = DecodeUidL(curr->GetContentDER(), hasSubjectUid);
				*pElement++ = NULL;
				*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
				break;
				}
			case 3:
				{
				DecodeExtsL(curr->GetContentDER(), hasExts);
				*pElement++ = NULL;
				*pElement++ = NULL;
				*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
				break;
				}
			default:
				{
				User::Leave(KErrArgument);
				}
			}
		if (pos < count)
			{
			curr = seq->At(pos);
			pos++;
			switch(curr->Tag())
				{
				case 2:
					{
					iSubjectUid = DecodeUidL(curr->GetContentDER(), hasSubjectUid);
					*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
					break;
					}
				case 3:
					{
					DecodeExtsL(curr->GetContentDER(), hasExts);
					*pElement++ = NULL;
					*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
					break;
					}
				default:
					{
					User::Leave(KErrArgument);
					}
				}
			if (pos < count)
				{
				curr = seq->At(pos);
				pos++;
				if (curr->Tag() == 3)
					{
					DecodeExtsL(curr->GetContentDER(), hasExts);
					*pElement++ = new(ELeave) TPtrC8(curr->Encoding());
					}
				else
					{
					User::Leave(KErrArgument);
					}
				}
			}
		}
	if (pos != count)
		{
		User::Leave(KErrArgument);
		}
	if (!iIssuerUid)
		{
		iIssuerUid = HBufC8::NewL(1);
		*iIssuerUid = KNullDesC8;
		}
	if (!iSubjectUid)
		{
		iSubjectUid = HBufC8::NewL(1);
		*iSubjectUid = KNullDesC8;
		}
		
	// we have not checked for the certificate version number based on 
	// the certificate contents. This is primarily done to avoid BC for 
	// clients who are still using malformed certificates.
	
	CleanupStack::PopAndDestroy();//seq
	}
예제 #15
0
//===============================================
//		CNSmlDSSettings::CreateXMLProfiles()
//		
//		
//===============================================	
void CNSmlDSSettings::CreateXMLProfilesL(TBool aRestore)
	{
	
	TBool status = TRUE;
	TInt error = KErrNone;
		
	//file server
	RFs wSession;
	error = wSession.Connect();
	if (error != KErrNone)
	{
	return;
	}
	
	RXMLReader DSProfileParser;
	DSProfileParser.CreateL();
	CArrayPtrFlat<CNSmlDSProfile>* customProfileArray = new (ELeave) CArrayPtrFlat<CNSmlDSProfile> (5);
	CleanupStack::PushL(customProfileArray);
	
	CNSmlProfileContentHandler* cb = CNSmlProfileContentHandler::NewL(this ,customProfileArray);
	CleanupStack::PushL(cb);

	DSProfileParser.SetContentHandler(cb);

	DSProfileParser.SetFeature(EXMLValidation, ETrue);
	DSProfileParser.SetFeature(EXMLValidation, EFalse);
	DSProfileParser.GetFeature(EXMLBinary, status);
	DSProfileParser.GetFeature(EXMLValidation, status);

	status = TRUE;

	RFile wFile;
	TInt err =wFile.Open(wSession, Kinfile, EFileRead | EFileShareReadersOnly); 
	if (err != KErrNone)
	{
		CleanupStack::PopAndDestroy(2);	
		return;	
	}
	
	CleanupClosePushL(wFile);
	//parse file
	TRAP(error, DSProfileParser.ParseL(wFile));
	if (error != KErrNone)
	{
	CleanupStack::PopAndDestroy(3);	
	return;
	}
	TInt index;
	TBuf<150> buf;
    
    if(aRestore)
    {
    //handling back up-restore for custom profiles
    CNSmlDSProfileList* profList = new (ELeave) CArrayPtrFlat<CNSmlDSProfileListItem>(1);
	CleanupStack::PushL(profList);
    GetAllProfileListL( profList );
    for( TInt i = 0 ; i < profList->Count() ; i++ )
     {
     	TInt id = profList->At(i)->IntValue( EDSProfileId );
     	CNSmlDSProfile* prof = ProfileL(id);
     	CleanupStack::PushL( prof );
     	buf = prof->StrValue(EDSProfileServerId);
     	
     	if (buf.Compare(KEmpty) != 0)
     	{
     		for (index = 0; index < customProfileArray->Count(); index++ )
     		{
     		if (buf.Compare(customProfileArray->At(index)->StrValue(EDSProfileServerId)) == 0)
     			{
     			DeleteProfileL(id);
     			}
     		}	
     	}
     	
     	else
     	{
     		buf = prof->StrValue(EDSProfileServerURL);
     		for (index = 0; index < customProfileArray->Count(); index++ )
     		{
     		if (buf.Compare(customProfileArray->At(index)->StrValue(EDSProfileServerURL)) == 0)
     			{
     			DeleteProfileL(id);
     			}
     		}	
     	}
       	CleanupStack::PopAndDestroy(); // prof
     }
    
    profList->ResetAndDestroy();
    CleanupStack::PopAndDestroy();
    }
    
    //save profiles
    TBool defaultprofilefound = EFalse;
    //Set the ProfileID to default
    WriteRepositoryL( KCRUidDSDefaultProfileInternalKeys, KNsmlDsDefaultProfile, -1 );
	for ( index = 0; index < customProfileArray->Count(); index++ )
		{
		if (CheckXMLProfileSettings(customProfileArray ,index))
			{
			customProfileArray->At(index)->SaveL();
			if(!defaultprofilefound && customProfileArray->At(index)->IntValue(EDSProfileDefaultProfile))
			    {
			    //Set the ProfileID to be used as a Default Profile
			    WriteRepositoryL( KCRUidDSDefaultProfileInternalKeys, KNsmlDsDefaultProfile, 
			                      customProfileArray->At(index)->IntValue(EDSProfileId) );
			    defaultprofilefound = ETrue;
			    }		
			}
		}
		
	CleanupStack::PopAndDestroy(); // wFile
	CleanupStack::PopAndDestroy(); // cb
	
	customProfileArray->ResetAndDestroy();
	CleanupStack::PopAndDestroy(); //customProfileArray
	
	
	}
예제 #16
0
void CX509SigningAlgorithmIdentifier::ConstructL(const TDesC8& aBinaryData, TInt& aPos)
	{
	TASN1DecSequence encSeq;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(aBinaryData, aPos, 1, KMaxTInt);
	TInt count = seq->Count();
	TASN1DecObjectIdentifier encOID;
	HBufC* oid = encOID.DecodeDERL(*(seq->At(0)));
	CleanupStack::PushL(oid);
	TPtrC oidDes(oid->Des()); 
	//none of the signing algorithms we support have parameters here...
	HBufC8* encodedParams = HBufC8::NewLC(1);
	*encodedParams = KNullDesC8;

	if (oidDes == KDSAWithSHA1)
		{
		//should be no params, but we allow params encoded as NULL for interop reasons
		TAlgorithmId algId = EDSA;
		TAlgorithmId digestId = ESHA1;
		iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des());
		iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des());
		if (count == 1)
			{			
			CleanupStack::PopAndDestroy(3);//seq, oid, encodedParams
			return;
			}
		}

	if (oidDes == KMD2WithRSA)
		{
		TAlgorithmId algId = ERSA;
		TAlgorithmId digestId = EMD2;
		iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des());
		iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des());
		}

	if (oidDes == KMD5WithRSA)
		{
		TAlgorithmId algId = ERSA;
		TAlgorithmId digestId = EMD5;
		iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des());
		iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des());
		}

	if (oidDes == KSHA1WithRSA  || oidDes == KSHA1WithRSASignature)
		{
		TAlgorithmId algId = ERSA;
		TAlgorithmId digestId = ESHA1;
		iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des());
		iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des());
		}

	if (oidDes == KSHA224WithRSA)
         {
         TAlgorithmId algId = ERSA;
         TAlgorithmId digestId = ESHA224;
         iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des());
         iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des());
         }
	
	if (oidDes == KSHA256WithRSA)
         {
         TAlgorithmId algId = ERSA;
         TAlgorithmId digestId = ESHA256;
         iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des());
         iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des());
         }

	if (oidDes == KSHA384WithRSA)
         {
         TAlgorithmId algId = ERSA;
         TAlgorithmId digestId = ESHA384;
         iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des());
         iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des());
         }

	if (oidDes == KSHA512WithRSA)
         {
         TAlgorithmId algId = ERSA;
         TAlgorithmId digestId = ESHA512;
         iDigestAlgorithm = CAlgorithmIdentifier::NewL(digestId, encodedParams->Des());
         iAsymmetricAlgorithm = CAlgorithmIdentifier::NewL(algId, encodedParams->Des());
         }

		//???not sure if we should just leave here...
	if (iDigestAlgorithm == NULL)
		{	
		User::Leave(KErrNotSupported);
		}
	else
		{
		if (count != 2)
			{
			// Shouldn't ever get here, since RFC2459 mandates having 2
			// data items.  However, some people miss out the second
			// when it's NULL, so we'll not report and error here
			}
		else
			{
			TASN1DecGeneric* gen = seq->At(1);
			TASN1DecNull null;
			null.DecodeDERL(*gen);//just to check the syntax is OK
			}
		}
	CleanupStack::PopAndDestroy(3);//seq, oid, encodedParams
	}
// -----------------------------------------------------------------------------
// TSTSDistinguishedNameConverter::CreateDNL
// Create CX500DistinguishedName
// -----------------------------------------------------------------------------
CX500DistinguishedName* TSTSDistinguishedNameConverter::CreateDNL(
    const TDesC& aNameInfo)
{

    CArrayPtrFlat< CX520AttributeTypeAndValue>* elements =
        new(ELeave) CArrayPtrFlat<CX520AttributeTypeAndValue> (1);
    CleanupStack::PushL(elements);
    CleanupResetAndDestroyPushL(*elements);
    TInt pos(0);
    TInt nameLength(aNameInfo.Length());
    TInt elementStart(0);

    while (pos < nameLength)
    {
        if (aNameInfo[ pos ] == '\\')
        {
            // next character is escaped, so we jump over it
            pos++;
        }
        else if ((aNameInfo[ pos ] == ',') || (pos == (nameLength - 1)))
        {
            // found the end of single element, parse it
            TInt elementLength = pos - elementStart;
            if (pos == (nameLength - 1))
            {
                elementLength++;
            }
            TPtrC elementDes(aNameInfo.Mid(elementStart, elementLength));
            CX520AttributeTypeAndValue* element =
                ParseDNElementL(elementDes);
            if (element)
            {
                CleanupStack::PushL(element);
                elements->AppendL(element);
                CleanupStack::Pop();  // element
            }
            elementStart = pos + 1;
        }
        pos++;
    }

    TInt elementCount = elements->Count();

    if (elementCount == 0)
    {
        CX520AttributeTypeAndValue* element = GenerateDNElementLC();
        elements->AppendL(element);
        CleanupStack::Pop();  // element
        elementCount++;
    }

    // In certificates the element order is reversed
    CArrayPtrFlat< CX520AttributeTypeAndValue>* reversedElements =
        new(ELeave) CArrayPtrFlat<CX520AttributeTypeAndValue> (elementCount);
    CleanupStack::PushL(reversedElements);

    for (TInt i = elementCount - 1; i >= 0; i--)
    {
        reversedElements->AppendL(elements->At(i));
    }

    CX500DistinguishedName* dn =
        CX500DistinguishedName::NewL(*reversedElements);

    CleanupStack::PopAndDestroy(3);   // elements, reversedElements


    return dn;
}
예제 #18
0
void CX509AlgorithmIdentifier::InitializeL(const TDesC8& aBinaryData, TInt& aPos)
	{
	TASN1DecSequence encSeq;
	CArrayPtrFlat<TASN1DecGeneric>* seq = encSeq.DecodeDERLC(aBinaryData, aPos, 1, KMaxTInt);
	TInt count = seq->Count();
	TASN1DecObjectIdentifier encOID;
	HBufC* oid = encOID.DecodeDERL(*(seq->At(0)));
	CleanupStack::PushL(oid);
	TPtrC oidDes(oid->Des()); 
	if (oidDes == KDSA)
		{
		//optional params
		if (count > 1)//if we still have stuff left
			{
			TASN1DecGeneric* gen = seq->At(1);
			iEncodedParams = gen->Encoding().AllocL();
			}
		else
			{
			iEncodedParams = HBufC8::NewL(1);
			*iEncodedParams = KNullDesC8;
			}
		iAlgorithmId = EDSA;
		CleanupStack::PopAndDestroy(2);//seq, oid
		return;
		}
	if (count > 1)
		{
		TASN1DecGeneric* gen = seq->At(1);
		if (oidDes == KDH)
			{
			iEncodedParams = gen->Encoding().AllocL();
			iAlgorithmId = EDH;
			CleanupStack::PopAndDestroy(2);//seq, oid
			return;
			}
		if (oidDes == KRSA)
			{
			iAlgorithmId = ERSA;
			TASN1DecNull null;
			null.DecodeDERL(*gen);//just to check the syntax is OK
			iEncodedParams = HBufC8::NewL(1);
			*iEncodedParams = KNullDesC8;
			CleanupStack::PopAndDestroy(2);//seq, oid
			return;
			}
		if (oidDes == KMD5)
			{
			iAlgorithmId = EMD5;
			TASN1DecNull null;
			null.DecodeDERL(*gen);//just to check the syntax is OK
			iEncodedParams = HBufC8::NewL(1);
			*iEncodedParams = KNullDesC8;
			CleanupStack::PopAndDestroy(2);//seq, oid
			return;
			}
		if (oidDes == KMD2)
			{
			iAlgorithmId = EMD2;
			TASN1DecNull null;
			null.DecodeDERL(*gen);//just to check the syntax is OK
			iEncodedParams = HBufC8::NewL(1);
			*iEncodedParams = KNullDesC8;
			CleanupStack::PopAndDestroy(2);//seq, oid
			return;
			}
		if (oidDes == KSHA1)
			{
			iAlgorithmId = ESHA1;
			TASN1DecNull null;
			null.DecodeDERL(*gen);//just to check the syntax is OK
			iEncodedParams = HBufC8::NewL(1);
			*iEncodedParams = KNullDesC8;
			CleanupStack::PopAndDestroy(2);//seq, oid
			return;
			}

        if (oidDes == KSHA224)
            {
            iAlgorithmId = ESHA224;
            TASN1DecNull null;
            null.DecodeDERL(*gen);//just to check the syntax is OK
            iEncodedParams = HBufC8::NewL(1);
            *iEncodedParams = KNullDesC8;
            CleanupStack::PopAndDestroy(2);//seq, oid
            return;
            }
        if (oidDes == KSHA256)
            {
            iAlgorithmId = ESHA256;
            TASN1DecNull null;
            null.DecodeDERL(*gen);//just to check the syntax is OK
            iEncodedParams = HBufC8::NewL(1);
            *iEncodedParams = KNullDesC8;
            CleanupStack::PopAndDestroy(2);//seq, oid
            return;
            }      
        if (oidDes == KSHA384)
            {
            iAlgorithmId = ESHA384;
            TASN1DecNull null;
            null.DecodeDERL(*gen);//just to check the syntax is OK
            iEncodedParams = HBufC8::NewL(1);
            *iEncodedParams = KNullDesC8;
            CleanupStack::PopAndDestroy(2);//seq, oid
            return;
            }        
        if (oidDes == KSHA512)
            {
            iAlgorithmId = ESHA512;
            TASN1DecNull null;
            null.DecodeDERL(*gen);//just to check the syntax is OK
            iEncodedParams = HBufC8::NewL(1);
            *iEncodedParams = KNullDesC8;
            CleanupStack::PopAndDestroy(2);//seq, oid
            return;
            }         
	
		}
	User::Leave(KErrNotSupported);
	}
CCoeControl* CUploadContainer::ComponentControl(TInt aIndex) const
{
	CALLSTACKITEM_N(_CL("CUploadContainer"), _CL("ComponentControl"));

	return iControls->At(aIndex);
}