|
1 /* |
|
2 * Copyright (c) 2005-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 |
|
20 |
|
21 /** |
|
22 @file |
|
23 @publishedPartner |
|
24 @released |
|
25 */ |
|
26 |
|
27 #ifndef __PKCS7_ENCRYPTED_DATA_OBJECT_H__ |
|
28 #define __PKCS7_ENCRYPTED_DATA_OBJECT_H__ |
|
29 |
|
30 #include <asn1dec.h> |
|
31 #include <signed.h> |
|
32 #include <pbedata.h> |
|
33 #include <asnpkcs.h> |
|
34 #include <pkcs7contentinfo_v2.h> |
|
35 #include <pkcs12kdf.h> |
|
36 |
|
37 /** |
|
38 A representation of a PKCS7 (Encrypted data) entity |
|
39 This class decodes the PKCS7 Encrypted Data content. |
|
40 It provides various exported methods which will |
|
41 return the values present in the EncryptedData ::= SEQUENCE. |
|
42 */ |
|
43 class CPKCS7EncryptedDataObject : public CBase |
|
44 { |
|
45 public: |
|
46 enum TContentType |
|
47 /** |
|
48 Identifies the type of ContentType present in the EncryptedContentInfo ::= SEQUENCE |
|
49 */ |
|
50 { |
|
51 EPkcs7Data = 1 |
|
52 }; |
|
53 |
|
54 /** |
|
55 Creates a new PKCS#7 EncryptedData object. |
|
56 @param aContentInfo contains a reference to CPKCS7ContentInfo. |
|
57 @return A pointer to the newly allocated object. |
|
58 */ |
|
59 IMPORT_C static CPKCS7EncryptedDataObject* NewL(const CPKCS7ContentInfo& aContentInfo); |
|
60 |
|
61 /** |
|
62 Destructor. |
|
63 */ |
|
64 virtual ~CPKCS7EncryptedDataObject(); |
|
65 /** |
|
66 Provides access to the version number within the EncryptedData SEQUENCE. |
|
67 Version is the syntax version number.It shall be 0 for this version of the standard |
|
68 @return The version number |
|
69 */ |
|
70 IMPORT_C TInt Version() const; |
|
71 |
|
72 /** |
|
73 Provides access to the ContentType present within the EncryptedContentInfo. |
|
74 ContentType indicates the type of content.This is represented using the OID. |
|
75 @return ContentType present in the EncryptedContentInfo structure. |
|
76 */ |
|
77 IMPORT_C CPKCS7EncryptedDataObject::TContentType ContentType() const; |
|
78 |
|
79 /** |
|
80 Provides access to the encryptedContent within the EncryptedContentInfo SEQUENCE. |
|
81 encryptedContent is OPTIONAL in EncryptedContentInfo SEQUENCE |
|
82 This will return a NULL pointer in case there is no encryptedContent |
|
83 @return The encryptedContent |
|
84 */ |
|
85 IMPORT_C const TDesC8& EncryptedContentInfoData() const; |
|
86 |
|
87 /** |
|
88 Provides access to the contentEncryptionAlgorithm within the |
|
89 EncryptedContentInfo SEQUENCE. |
|
90 @return A CPBEncryptParms object which has the Encrypt Parameters |
|
91 EncryptedContent present in EncryptedContentInfo Sequence |
|
92 */ |
|
93 IMPORT_C const CPBEncryptParms& EncryptParams() const; |
|
94 |
|
95 /** |
|
96 This method decrypts the encrypted information. The caller assumes |
|
97 ownership of the returned object. |
|
98 @param aPassword is the password used for decryption. |
|
99 @return The plaintext data obtained after decryption. |
|
100 @leave KErrNotSupported if otherthan pkcs12 pbeIds used. |
|
101 @leave KErrGeneral if decrypt descriptor length is less than 0. |
|
102 @see PKCS12KDF, TPBPassword, CPBEncryptElement, CPBDecryptor. |
|
103 */ |
|
104 IMPORT_C HBufC8* DecryptDataL(const TDesC& aPassword) const; |
|
105 |
|
106 private: |
|
107 /** |
|
108 Constructor. |
|
109 */ |
|
110 CPKCS7EncryptedDataObject(void); |
|
111 |
|
112 /** |
|
113 Copy Constructor. |
|
114 @param aEncryptedDataObject A CPKCS7EncryptedDataObject object. |
|
115 */ |
|
116 CPKCS7EncryptedDataObject(const CPKCS7EncryptedDataObject& aEncryptedDataObject); |
|
117 |
|
118 /** |
|
119 Assignment operator. |
|
120 @param aEncryptedDataObject A CPKCS7EncryptedDataObject object. |
|
121 @return A reference to CPKCS7EncryptedDataObject class. |
|
122 */ |
|
123 CPKCS7EncryptedDataObject& operator=(const CPKCS7EncryptedDataObject& aEncryptedDataObject); |
|
124 |
|
125 /** |
|
126 This decrypt the encrypted data. Below is the ASN1 syntax. |
|
127 |
|
128 EncryptedData ::= SEQUENCE |
|
129 { |
|
130 version Version, |
|
131 encryptedContentInfo EncryptedContentInfo |
|
132 } |
|
133 EncryptedContentInfo ::= SEQUENCE |
|
134 { |
|
135 contentType PKCS7-CONTENT-TYPE.&id({PKCS7ContentTable}), |
|
136 contentEncryptionAlgorithm ContentEncryptionAlgorithmIdentifier, |
|
137 encryptedContent [0] ENCRYPTED{PKCS7-CONTENT-TYPE.&Type({PKCS7ContentTable}{@.contentType})} OPTIONAL |
|
138 } |
|
139 EncryptedContent ::= OCTET STRING |
|
140 |
|
141 ContentInfo ::= SEQUENCE |
|
142 { |
|
143 contentType ContentType, |
|
144 content[0] EXPLICIT ANY DEFINED BY contentType OPTIONAL |
|
145 } |
|
146 ContentType ::= OBJECT IDENTIFIER |
|
147 |
|
148 @param aContentInfo Contains a reference to CPKCS7ContentInfo |
|
149 @leave KErrArgument if the data is not valid PKCS#7 EncryptedData Structure. |
|
150 @see CPKCS7ContentInfo |
|
151 */ |
|
152 void ConstructL(const CPKCS7ContentInfo& aContentInfo); |
|
153 |
|
154 /** |
|
155 Provides access to the Encrypt Parameters present within the |
|
156 ContentEncryptionAlgorithm Sequence. Below is the ASN1 Syntax. |
|
157 |
|
158 ContentEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier |
|
159 AlgorithmIdentifier: A type that identifies an algorithm (by object identifier) and associated parameters |
|
160 AlgorithmIdentifier ::= SEQUENCE |
|
161 { |
|
162 algorithm ALGORITHM.&id({SupportedAlgorithms}), |
|
163 parameters ALGORITHM.&Type({SupportedAlgorithms}{@ algorithm}) OPTIONAL |
|
164 } |
|
165 |
|
166 @param aBinaryData which is the ContentEncryptionAlgorithmIdentifier |
|
167 and is AlgorithIdentifier Type. |
|
168 AlgorithmIdentifier: A type that identifies an |
|
169 algorithm (by object identifier) and associated parameters. |
|
170 @return Encrypt Parameters. This Identifies the |
|
171 content-encryption algorithm (and any associated parameters) |
|
172 under which the content is encrypted. |
|
173 @leave KErrArgument if the data is not valid PKCS#7 ContentEncryptionAlgorithm |
|
174 sequence. |
|
175 @see CPBEncryptParms, TASN1DecPKCS5. |
|
176 */ |
|
177 CPBEncryptParms* DecodeContentEncryptionAlgorithmL(const TDesC8& aBinaryData) const; |
|
178 |
|
179 |
|
180 private: |
|
181 /** version is the syntax version number in PKCS#7 EncryptedData ::= SEQUENCE*/ |
|
182 TInt iVersion; |
|
183 |
|
184 /** Indicates the type of content in PKCS7 EncryptedContentInfo Sequence */ |
|
185 TContentType iContentType; |
|
186 |
|
187 /** Identifies the content-encryption algorithm (and any associated parameters) |
|
188 under which the content is encrypted */ |
|
189 CPBEncryptParms* iEncryptParams; |
|
190 |
|
191 /** Contains the encrypted content */ |
|
192 TPtrC8 iEncryptedContent; |
|
193 }; |
|
194 |
|
195 #endif //__PKCS7_ENCRYPTED_DATA_OBJECT_H__ |