os/security/cryptoservices/certificateandkeymgmt/pkcs7/pkcs7signerinfo.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2003-2009 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 the License "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: 
    15 *
    16 */
    17 
    18 
    19 #include "pkcs7signerinfo.h"
    20 #include "pkcs7issuerserial.h"
    21 #include "pkcs7asn1.h"
    22 #include "signed.h"
    23 #include <asn1dec.h>
    24 #include <x509cert.h>
    25 
    26 CPKCS7SignerInfo* CPKCS7SignerInfo::NewL(const TDesC8& aRawData)
    27 	{
    28 	CPKCS7SignerInfo* self = new (ELeave) CPKCS7SignerInfo();
    29 	CleanupStack::PushL(self);
    30 	self->ConstructL(aRawData);
    31 	CleanupStack::Pop(self);
    32 	return self;
    33 	}
    34 
    35 CPKCS7SignerInfo::~CPKCS7SignerInfo(void)
    36 	{
    37 	delete iIssuerAndSerialNumber;
    38 	delete iDigestAlgorithm;
    39 	delete iDigestEncryptionAlgorithm;
    40 	delete iEncryptedDigest;
    41 	}
    42 
    43 CPKCS7SignerInfo::CPKCS7SignerInfo(void)
    44 	{
    45 	}
    46 
    47 EXPORT_C TInt CPKCS7SignerInfo::Version() const
    48 	{
    49 	return iVersion;
    50 	}
    51 
    52 EXPORT_C const CPKCS7IssuerAndSerialNumber& CPKCS7SignerInfo::IssuerAndSerialNumber() const
    53 	{
    54 	return *iIssuerAndSerialNumber;
    55 	}
    56 
    57 EXPORT_C const CX509AlgorithmIdentifier& CPKCS7SignerInfo::DigestAlgorithm() const
    58 	{
    59 	return *iDigestAlgorithm;
    60 	}
    61 
    62 EXPORT_C const CX509AlgorithmIdentifier& CPKCS7SignerInfo::DigestEncryptionAlgorithm() const
    63 	{
    64 	return *iDigestEncryptionAlgorithm;
    65 	}
    66 
    67 EXPORT_C const TPtrC8 CPKCS7SignerInfo::EncryptedDigest() const
    68 	{
    69 	return *iEncryptedDigest;
    70 	}
    71 
    72 
    73 void CPKCS7SignerInfo::ConstructL(const TDesC8& aRawData)
    74 	{
    75 	CArrayPtr<TASN1DecGeneric>* signerInfo = PKCS7ASN1::DecodeSequenceLC(aRawData, 5, 7);
    76 	TASN1DecInteger decInt;
    77 	TInt pos = 3;
    78 
    79 	// decodes version
    80 	iVersion = decInt.DecodeDERShortL(*signerInfo->At(0));	
    81 
    82 	iIssuerAndSerialNumber = CPKCS7IssuerAndSerialNumber::NewL(signerInfo->At(1)->Encoding());
    83 
    84 	iDigestAlgorithm = CX509AlgorithmIdentifier::NewL(signerInfo->At(2)->Encoding());
    85 
    86 	if(signerInfo->At(pos)->Tag() == 0)
    87 		{
    88 		// authenticated attributes not supported at this time
    89 		pos++;
    90 		}
    91 	iDigestEncryptionAlgorithm = CX509AlgorithmIdentifier::NewL(signerInfo->At(pos++)->Encoding());
    92 	DecodeEncryptedDigestL(signerInfo->At(pos++)->Encoding());
    93 
    94 	if(pos < signerInfo->Count() && (signerInfo->At(pos)->Tag() == 0))
    95 		{
    96 		// unauthenticated attributes not supported at this time
    97 		pos++;		
    98 		}
    99 
   100 	CleanupStack::PopAndDestroy(signerInfo);
   101 	}
   102 
   103 void CPKCS7SignerInfo::DecodeEncryptedDigestL(const TDesC8& aRawData)
   104 	{
   105 	TASN1DecGeneric decGen(aRawData);
   106 	decGen.InitL();
   107 
   108 	if(decGen.Tag() == EASN1OctetString)
   109 		{
   110 		TASN1DecOctetString decOct;
   111 		iEncryptedDigest = decOct.DecodeDERL(decGen);
   112 		}
   113 	else
   114 		{
   115 		User::Leave(KErrArgument);
   116 		}
   117 	}