sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
|
sl@0
|
3 |
* All rights reserved.
|
sl@0
|
4 |
* This component and the accompanying materials are made available
|
sl@0
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
sl@0
|
6 |
* which accompanies this distribution, and is available
|
sl@0
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
sl@0
|
8 |
*
|
sl@0
|
9 |
* Initial Contributors:
|
sl@0
|
10 |
* Nokia Corporation - initial contribution.
|
sl@0
|
11 |
*
|
sl@0
|
12 |
* Contributors:
|
sl@0
|
13 |
*
|
sl@0
|
14 |
* Description:
|
sl@0
|
15 |
*
|
sl@0
|
16 |
*/
|
sl@0
|
17 |
|
sl@0
|
18 |
|
sl@0
|
19 |
#include "pkcs7signerinfo.h"
|
sl@0
|
20 |
#include "pkcs7issuerserial.h"
|
sl@0
|
21 |
#include "pkcs7asn1.h"
|
sl@0
|
22 |
#include "signed.h"
|
sl@0
|
23 |
#include <asn1dec.h>
|
sl@0
|
24 |
#include <x509cert.h>
|
sl@0
|
25 |
|
sl@0
|
26 |
CPKCS7SignerInfo* CPKCS7SignerInfo::NewL(const TDesC8& aRawData)
|
sl@0
|
27 |
{
|
sl@0
|
28 |
CPKCS7SignerInfo* self = new (ELeave) CPKCS7SignerInfo();
|
sl@0
|
29 |
CleanupStack::PushL(self);
|
sl@0
|
30 |
self->ConstructL(aRawData);
|
sl@0
|
31 |
CleanupStack::Pop(self);
|
sl@0
|
32 |
return self;
|
sl@0
|
33 |
}
|
sl@0
|
34 |
|
sl@0
|
35 |
CPKCS7SignerInfo::~CPKCS7SignerInfo(void)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
delete iIssuerAndSerialNumber;
|
sl@0
|
38 |
delete iDigestAlgorithm;
|
sl@0
|
39 |
delete iDigestEncryptionAlgorithm;
|
sl@0
|
40 |
delete iEncryptedDigest;
|
sl@0
|
41 |
}
|
sl@0
|
42 |
|
sl@0
|
43 |
CPKCS7SignerInfo::CPKCS7SignerInfo(void)
|
sl@0
|
44 |
{
|
sl@0
|
45 |
}
|
sl@0
|
46 |
|
sl@0
|
47 |
EXPORT_C TInt CPKCS7SignerInfo::Version() const
|
sl@0
|
48 |
{
|
sl@0
|
49 |
return iVersion;
|
sl@0
|
50 |
}
|
sl@0
|
51 |
|
sl@0
|
52 |
EXPORT_C const CPKCS7IssuerAndSerialNumber& CPKCS7SignerInfo::IssuerAndSerialNumber() const
|
sl@0
|
53 |
{
|
sl@0
|
54 |
return *iIssuerAndSerialNumber;
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
EXPORT_C const CX509AlgorithmIdentifier& CPKCS7SignerInfo::DigestAlgorithm() const
|
sl@0
|
58 |
{
|
sl@0
|
59 |
return *iDigestAlgorithm;
|
sl@0
|
60 |
}
|
sl@0
|
61 |
|
sl@0
|
62 |
EXPORT_C const CX509AlgorithmIdentifier& CPKCS7SignerInfo::DigestEncryptionAlgorithm() const
|
sl@0
|
63 |
{
|
sl@0
|
64 |
return *iDigestEncryptionAlgorithm;
|
sl@0
|
65 |
}
|
sl@0
|
66 |
|
sl@0
|
67 |
EXPORT_C const TPtrC8 CPKCS7SignerInfo::EncryptedDigest() const
|
sl@0
|
68 |
{
|
sl@0
|
69 |
return *iEncryptedDigest;
|
sl@0
|
70 |
}
|
sl@0
|
71 |
|
sl@0
|
72 |
|
sl@0
|
73 |
void CPKCS7SignerInfo::ConstructL(const TDesC8& aRawData)
|
sl@0
|
74 |
{
|
sl@0
|
75 |
CArrayPtr<TASN1DecGeneric>* signerInfo = PKCS7ASN1::DecodeSequenceLC(aRawData, 5, 7);
|
sl@0
|
76 |
TASN1DecInteger decInt;
|
sl@0
|
77 |
TInt pos = 3;
|
sl@0
|
78 |
|
sl@0
|
79 |
// decodes version
|
sl@0
|
80 |
iVersion = decInt.DecodeDERShortL(*signerInfo->At(0));
|
sl@0
|
81 |
|
sl@0
|
82 |
iIssuerAndSerialNumber = CPKCS7IssuerAndSerialNumber::NewL(signerInfo->At(1)->Encoding());
|
sl@0
|
83 |
|
sl@0
|
84 |
iDigestAlgorithm = CX509AlgorithmIdentifier::NewL(signerInfo->At(2)->Encoding());
|
sl@0
|
85 |
|
sl@0
|
86 |
if(signerInfo->At(pos)->Tag() == 0)
|
sl@0
|
87 |
{
|
sl@0
|
88 |
// authenticated attributes not supported at this time
|
sl@0
|
89 |
pos++;
|
sl@0
|
90 |
}
|
sl@0
|
91 |
iDigestEncryptionAlgorithm = CX509AlgorithmIdentifier::NewL(signerInfo->At(pos++)->Encoding());
|
sl@0
|
92 |
DecodeEncryptedDigestL(signerInfo->At(pos++)->Encoding());
|
sl@0
|
93 |
|
sl@0
|
94 |
if(pos < signerInfo->Count() && (signerInfo->At(pos)->Tag() == 0))
|
sl@0
|
95 |
{
|
sl@0
|
96 |
// unauthenticated attributes not supported at this time
|
sl@0
|
97 |
pos++;
|
sl@0
|
98 |
}
|
sl@0
|
99 |
|
sl@0
|
100 |
CleanupStack::PopAndDestroy(signerInfo);
|
sl@0
|
101 |
}
|
sl@0
|
102 |
|
sl@0
|
103 |
void CPKCS7SignerInfo::DecodeEncryptedDigestL(const TDesC8& aRawData)
|
sl@0
|
104 |
{
|
sl@0
|
105 |
TASN1DecGeneric decGen(aRawData);
|
sl@0
|
106 |
decGen.InitL();
|
sl@0
|
107 |
|
sl@0
|
108 |
if(decGen.Tag() == EASN1OctetString)
|
sl@0
|
109 |
{
|
sl@0
|
110 |
TASN1DecOctetString decOct;
|
sl@0
|
111 |
iEncryptedDigest = decOct.DecodeDERL(decGen);
|
sl@0
|
112 |
}
|
sl@0
|
113 |
else
|
sl@0
|
114 |
{
|
sl@0
|
115 |
User::Leave(KErrArgument);
|
sl@0
|
116 |
}
|
sl@0
|
117 |
}
|