sl@0
|
1 |
/*
|
sl@0
|
2 |
* Copyright (c) 2006-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 |
/**
|
sl@0
|
20 |
@file
|
sl@0
|
21 |
@internalComponent
|
sl@0
|
22 |
@released
|
sl@0
|
23 |
*/
|
sl@0
|
24 |
|
sl@0
|
25 |
#ifndef CMSUTILS_H
|
sl@0
|
26 |
#define CMSUTILS_H
|
sl@0
|
27 |
|
sl@0
|
28 |
#include <signed.h>
|
sl@0
|
29 |
#include <hash.h>
|
sl@0
|
30 |
#include <cmscertchoice.h>
|
sl@0
|
31 |
|
sl@0
|
32 |
class CCmsCertificateChoice;
|
sl@0
|
33 |
class CX509AlgorithmIdentifier;
|
sl@0
|
34 |
class CX509Certificate;
|
sl@0
|
35 |
class CMessageDigest;
|
sl@0
|
36 |
class CRSAPrivateKey;
|
sl@0
|
37 |
class CDSAPrivateKey;
|
sl@0
|
38 |
class TASN1DecGeneric;
|
sl@0
|
39 |
class CASN1EncObjectIdentifier;
|
sl@0
|
40 |
class CASN1EncBase;
|
sl@0
|
41 |
|
sl@0
|
42 |
/**
|
sl@0
|
43 |
A utility class contains a set of static functions for encoding and decoding the
|
sl@0
|
44 |
CMS signed data relevant CMS structures.
|
sl@0
|
45 |
*/
|
sl@0
|
46 |
class CmsUtils
|
sl@0
|
47 |
{
|
sl@0
|
48 |
public:
|
sl@0
|
49 |
/**
|
sl@0
|
50 |
Decode the content type in CMS content info and encapsulated info.
|
sl@0
|
51 |
@param aASN1DecGeneric the ASN decoded structure of the content info
|
sl@0
|
52 |
@return the type of the content info.
|
sl@0
|
53 |
*/
|
sl@0
|
54 |
static TInt DecodeContentTypeL(const TASN1DecGeneric* aASN1DecGeneric);
|
sl@0
|
55 |
|
sl@0
|
56 |
/**
|
sl@0
|
57 |
Encode the content type in CMS content info and encapsulated info.
|
sl@0
|
58 |
@param aContentType the type of the content info
|
sl@0
|
59 |
@return the ASN.1 oid instance of the content type.
|
sl@0
|
60 |
*/
|
sl@0
|
61 |
static CASN1EncObjectIdentifier* EncodeContentTypeLC(TInt aContentType);
|
sl@0
|
62 |
|
sl@0
|
63 |
/**
|
sl@0
|
64 |
Add an encoded attribute certificate in the certificate set if it is not in the list already.
|
sl@0
|
65 |
@param aCertList the certificate list to which the certificate is added
|
sl@0
|
66 |
@param aCert the encoded certificate to be added.
|
sl@0
|
67 |
@param aType the type of the encoded certificate.
|
sl@0
|
68 |
*/
|
sl@0
|
69 |
static void AddCertificateL(RPointerArray<CCmsCertificateChoice>& aCertList, const TDesC8& aCert, CCmsCertificateChoice::TCertificateType aType);
|
sl@0
|
70 |
|
sl@0
|
71 |
/**
|
sl@0
|
72 |
Add an X509 certificate in the certificate set if it is not in the list already.
|
sl@0
|
73 |
@param aCertList the certificate list to which the certificate is added
|
sl@0
|
74 |
@param aCert the x509 certificate to be added.
|
sl@0
|
75 |
*/
|
sl@0
|
76 |
static void AddCertificateL(RPointerArray<CCmsCertificateChoice>& aCertList, const CX509Certificate& aCert);
|
sl@0
|
77 |
|
sl@0
|
78 |
/**
|
sl@0
|
79 |
Add an algorithm in the algorithm set if it is not in the list already.
|
sl@0
|
80 |
@param aAlgorithmIdList the algorithm list to which the algorithm is added
|
sl@0
|
81 |
@param aDigestAlgorithm the digest algorithm identifier
|
sl@0
|
82 |
*/
|
sl@0
|
83 |
static void AddAlgorithmIdentifierL(RPointerArray<CX509AlgorithmIdentifier>& aAlgorithmIdList, TAlgorithmId aDigestAlgorithm);
|
sl@0
|
84 |
|
sl@0
|
85 |
/**
|
sl@0
|
86 |
Decode the algorithm identifier set
|
sl@0
|
87 |
@param aDigestAlgorithms the algorithm list to which the decoded algorithms is added
|
sl@0
|
88 |
@param aRawData the encoded algorithm identifier set
|
sl@0
|
89 |
*/
|
sl@0
|
90 |
static void DecodeDigestAlgorithmsL(RPointerArray<CX509AlgorithmIdentifier>& aDigestAlgorithms, const TDesC8& aRawData);
|
sl@0
|
91 |
|
sl@0
|
92 |
/**
|
sl@0
|
93 |
Decode the certificate set
|
sl@0
|
94 |
@param aDigestAlgorithms the certficate list to which the decoded certificates is added
|
sl@0
|
95 |
@param aRawData the encoded certficate set
|
sl@0
|
96 |
*/
|
sl@0
|
97 |
static void DecodeCertificatesL(RPointerArray<CCmsCertificateChoice>& aCertificates, const TDesC8& aRawData);
|
sl@0
|
98 |
|
sl@0
|
99 |
/**
|
sl@0
|
100 |
Encode the certficate set and put the encoding on the cleanup stack
|
sl@0
|
101 |
@param aCertList the certificates list to be encoded.
|
sl@0
|
102 |
@return the ASN.1 DER encoding of certificate set
|
sl@0
|
103 |
*/
|
sl@0
|
104 |
static CASN1EncBase* EncodeCertificatesLC(const RPointerArray<CCmsCertificateChoice>& aCertList);
|
sl@0
|
105 |
|
sl@0
|
106 |
/**
|
sl@0
|
107 |
Encode the digest algorithm set and put the encoding on the cleanup stack.
|
sl@0
|
108 |
@param aCertList the certificates list to be encoded.
|
sl@0
|
109 |
@return the ASN.1 DER encoding of certificate set
|
sl@0
|
110 |
*/
|
sl@0
|
111 |
static CASN1EncBase* EncodeDigestAlgorithmsLC(const RPointerArray<CX509AlgorithmIdentifier>& aDigestAlgorithms);
|
sl@0
|
112 |
|
sl@0
|
113 |
/**
|
sl@0
|
114 |
Dncode the octet string
|
sl@0
|
115 |
@param aRawData the certificates list to be encoded.
|
sl@0
|
116 |
@param aBuf the buffer to hold the octet string.
|
sl@0
|
117 |
*/
|
sl@0
|
118 |
static void DecodeOctetStringL(const TDesC8& aRawData, HBufC8*& aBuf);
|
sl@0
|
119 |
|
sl@0
|
120 |
/**
|
sl@0
|
121 |
Create a hash from the given algorithm identifier and put it on the cleanup stack.
|
sl@0
|
122 |
@param aAlgorithm the hash identifier.
|
sl@0
|
123 |
@return the hash
|
sl@0
|
124 |
*/
|
sl@0
|
125 |
static CMessageDigest* CreateHashLC(TAlgorithmId aAlgorithm);
|
sl@0
|
126 |
|
sl@0
|
127 |
/**
|
sl@0
|
128 |
Create the DSA signature of the given hash.
|
sl@0
|
129 |
@param aHash the hash used to create signature.
|
sl@0
|
130 |
@param aKey the DSA private key used to create signature
|
sl@0
|
131 |
@return the descriptor holds the signature.
|
sl@0
|
132 |
*/
|
sl@0
|
133 |
static HBufC8* CreateSignatureL(const TDesC8& aHash, const CDSAPrivateKey& aKey);
|
sl@0
|
134 |
|
sl@0
|
135 |
/**
|
sl@0
|
136 |
Create the RSA signature of the given hash.
|
sl@0
|
137 |
@param aHash the hash used to create signature.
|
sl@0
|
138 |
@param aKey the RSA private key used to create signature
|
sl@0
|
139 |
@return the descriptor holds the signature.
|
sl@0
|
140 |
*/
|
sl@0
|
141 |
static HBufC8* CreateSignatureL(const TDesC8& aHash, const CRSAPrivateKey& aKey);
|
sl@0
|
142 |
|
sl@0
|
143 |
/**
|
sl@0
|
144 |
Create the RSA signature of the given data, algorithm and private key.
|
sl@0
|
145 |
@param aDataToBeSigned the data content to be signed.
|
sl@0
|
146 |
@param aIsHash if the first paramter is a hash
|
sl@0
|
147 |
@param aAlgorithm the digest algorithm used to create hash
|
sl@0
|
148 |
@param aKey the RSA private key.
|
sl@0
|
149 |
@return the descriptor holds the signature.
|
sl@0
|
150 |
*/
|
sl@0
|
151 |
static HBufC8* CreateSignatureL(const TDesC8& aDataToBeSigned, TBool aIsHash, TAlgorithmId aAlgorithm, const CRSAPrivateKey& aKey);
|
sl@0
|
152 |
|
sl@0
|
153 |
/**
|
sl@0
|
154 |
Create the DSA signature of the given data, algorithm and private key.
|
sl@0
|
155 |
@param aDataToBeSigned the data content to be signed.
|
sl@0
|
156 |
@param aIsHash if the first paramter is a hash
|
sl@0
|
157 |
@param aAlgorithm the digest algorithm used to create hash
|
sl@0
|
158 |
@param aKey the DSA private key.
|
sl@0
|
159 |
@return the descriptor holds the signature.
|
sl@0
|
160 |
*/
|
sl@0
|
161 |
static HBufC8* CreateSignatureL(const TDesC8& aDataToBeSigned, TBool aIsHash, TAlgorithmId aAlgorithm, const CDSAPrivateKey& aKey);
|
sl@0
|
162 |
|
sl@0
|
163 |
/**
|
sl@0
|
164 |
Create the raw data from the ASN.1 class.
|
sl@0
|
165 |
@param aEncoding the reference of the ASN.1 class
|
sl@0
|
166 |
@return the descritor holds the raw data.
|
sl@0
|
167 |
*/
|
sl@0
|
168 |
static HBufC8* CreateDEREncodingLC(const CASN1EncBase& aEncoding);
|
sl@0
|
169 |
};
|
sl@0
|
170 |
|
sl@0
|
171 |
#endif // CMSUTILS_H
|
sl@0
|
172 |
|