os/security/cryptoservices/certificateandkeymgmt/pkcs7/pkcs7signerinfo.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/pkcs7/pkcs7signerinfo.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,117 @@
     1.4 +/*
     1.5 +* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.6 +* All rights reserved.
     1.7 +* This component and the accompanying materials are made available
     1.8 +* under the terms of the License "Eclipse Public License v1.0"
     1.9 +* which accompanies this distribution, and is available
    1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.11 +*
    1.12 +* Initial Contributors:
    1.13 +* Nokia Corporation - initial contribution.
    1.14 +*
    1.15 +* Contributors:
    1.16 +*
    1.17 +* Description: 
    1.18 +*
    1.19 +*/
    1.20 +
    1.21 +
    1.22 +#include "pkcs7signerinfo.h"
    1.23 +#include "pkcs7issuerserial.h"
    1.24 +#include "pkcs7asn1.h"
    1.25 +#include "signed.h"
    1.26 +#include <asn1dec.h>
    1.27 +#include <x509cert.h>
    1.28 +
    1.29 +CPKCS7SignerInfo* CPKCS7SignerInfo::NewL(const TDesC8& aRawData)
    1.30 +	{
    1.31 +	CPKCS7SignerInfo* self = new (ELeave) CPKCS7SignerInfo();
    1.32 +	CleanupStack::PushL(self);
    1.33 +	self->ConstructL(aRawData);
    1.34 +	CleanupStack::Pop(self);
    1.35 +	return self;
    1.36 +	}
    1.37 +
    1.38 +CPKCS7SignerInfo::~CPKCS7SignerInfo(void)
    1.39 +	{
    1.40 +	delete iIssuerAndSerialNumber;
    1.41 +	delete iDigestAlgorithm;
    1.42 +	delete iDigestEncryptionAlgorithm;
    1.43 +	delete iEncryptedDigest;
    1.44 +	}
    1.45 +
    1.46 +CPKCS7SignerInfo::CPKCS7SignerInfo(void)
    1.47 +	{
    1.48 +	}
    1.49 +
    1.50 +EXPORT_C TInt CPKCS7SignerInfo::Version() const
    1.51 +	{
    1.52 +	return iVersion;
    1.53 +	}
    1.54 +
    1.55 +EXPORT_C const CPKCS7IssuerAndSerialNumber& CPKCS7SignerInfo::IssuerAndSerialNumber() const
    1.56 +	{
    1.57 +	return *iIssuerAndSerialNumber;
    1.58 +	}
    1.59 +
    1.60 +EXPORT_C const CX509AlgorithmIdentifier& CPKCS7SignerInfo::DigestAlgorithm() const
    1.61 +	{
    1.62 +	return *iDigestAlgorithm;
    1.63 +	}
    1.64 +
    1.65 +EXPORT_C const CX509AlgorithmIdentifier& CPKCS7SignerInfo::DigestEncryptionAlgorithm() const
    1.66 +	{
    1.67 +	return *iDigestEncryptionAlgorithm;
    1.68 +	}
    1.69 +
    1.70 +EXPORT_C const TPtrC8 CPKCS7SignerInfo::EncryptedDigest() const
    1.71 +	{
    1.72 +	return *iEncryptedDigest;
    1.73 +	}
    1.74 +
    1.75 +
    1.76 +void CPKCS7SignerInfo::ConstructL(const TDesC8& aRawData)
    1.77 +	{
    1.78 +	CArrayPtr<TASN1DecGeneric>* signerInfo = PKCS7ASN1::DecodeSequenceLC(aRawData, 5, 7);
    1.79 +	TASN1DecInteger decInt;
    1.80 +	TInt pos = 3;
    1.81 +
    1.82 +	// decodes version
    1.83 +	iVersion = decInt.DecodeDERShortL(*signerInfo->At(0));	
    1.84 +
    1.85 +	iIssuerAndSerialNumber = CPKCS7IssuerAndSerialNumber::NewL(signerInfo->At(1)->Encoding());
    1.86 +
    1.87 +	iDigestAlgorithm = CX509AlgorithmIdentifier::NewL(signerInfo->At(2)->Encoding());
    1.88 +
    1.89 +	if(signerInfo->At(pos)->Tag() == 0)
    1.90 +		{
    1.91 +		// authenticated attributes not supported at this time
    1.92 +		pos++;
    1.93 +		}
    1.94 +	iDigestEncryptionAlgorithm = CX509AlgorithmIdentifier::NewL(signerInfo->At(pos++)->Encoding());
    1.95 +	DecodeEncryptedDigestL(signerInfo->At(pos++)->Encoding());
    1.96 +
    1.97 +	if(pos < signerInfo->Count() && (signerInfo->At(pos)->Tag() == 0))
    1.98 +		{
    1.99 +		// unauthenticated attributes not supported at this time
   1.100 +		pos++;		
   1.101 +		}
   1.102 +
   1.103 +	CleanupStack::PopAndDestroy(signerInfo);
   1.104 +	}
   1.105 +
   1.106 +void CPKCS7SignerInfo::DecodeEncryptedDigestL(const TDesC8& aRawData)
   1.107 +	{
   1.108 +	TASN1DecGeneric decGen(aRawData);
   1.109 +	decGen.InitL();
   1.110 +
   1.111 +	if(decGen.Tag() == EASN1OctetString)
   1.112 +		{
   1.113 +		TASN1DecOctetString decOct;
   1.114 +		iEncryptedDigest = decOct.DecodeDERL(decGen);
   1.115 +		}
   1.116 +	else
   1.117 +		{
   1.118 +		User::Leave(KErrArgument);
   1.119 +		}
   1.120 +	}