First public contribution.
2 * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
25 #ifndef __PKCS12_BAGS_H__
26 #define __PKCS12_BAGS_H__
31 #include <pkcs12kdf.h>
32 #include <pkcs12safebag.h>
33 #include <pkcs12attribute.h>
34 #include <pkcs7contentinfo_v2.h>
35 #include <pkcs7encrypteddataobject.h>
39 /** Object identifier for KeyBag */
40 _LIT(KPkcs12KeyBagOID, "1.2.840.113549.1.12.10.1.1");
42 /** Object identifier for ShroudedKeyBag */
43 _LIT(KPkcs12ShroudedKeyBagOID, "1.2.840.113549.1.12.10.1.2");
45 /** Object identifier for CertBag */
46 _LIT(KPkcs12CertBagOID, "1.2.840.113549.1.12.10.1.3");
48 /** Object identifier for CrlBag */
49 _LIT(KPkcs12CrlBagOID, "1.2.840.113549.1.12.10.1.4");
51 /** Object identifier for SecretBag */
52 _LIT(KPkcs12SecretBagOID, "1.2.840.113549.1.12.10.1.5");
54 /** Object identifier for SafeContentsBag */
55 _LIT(KPkcs12SafeContentsBagOID, "1.2.840.113549.1.12.10.1.6");
57 /** Object identifier for x509 certificate */
58 _LIT(KX509CertificateOID,"1.2.840.113549.1.9.22.1");
61 This class decodes the KeyBag present in the SafeBag.
62 It has a method to get the PrivatKeyInfo
64 class CDecPkcs12KeyBag : public CDecPkcs12SafeBag
68 Creates a new PKCS#12KeyBag object.
70 @param aSafeBagData Contains a PKCS#12 SafeBag Structure.
71 @return A pointer to the newly allocated object.
72 @leave KErrAgrument if the data is not a sequence or class tag name
73 is not Universal and if iPrivateKeyInfo is NULL.
75 IMPORT_C static CDecPkcs12KeyBag* NewL(const TDesC8& aSafeBagData);
78 The PrivateKey information present in the KeyBag.
79 The returned ASN1 sequence respects the following grammar:
81 PrivateKeyInfo ::= SEQUENCE {
83 privateKeyAlgorithm PrivateKeyAlgorithmIdentifier,
84 privateKey PrivateKey,
85 attributes [0] IMPLICIT Attributes OPTIONAL }
88 PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier
89 PrivateKey ::= OCTET STRING
90 Attributes ::= SET OF Attribute
92 @return A pointer to a CDecPKCS8Data object. Ownership of memory is transferred
96 IMPORT_C CDecPKCS8Data* PrivateKeyInfoL() const;
101 virtual ~CDecPkcs12KeyBag();
105 Decodes the entire KeyBag structure.
106 @param aSafeBagData Contains a PKCS#12 SafeBag Structure.
107 @leave KErrAgrument if the data is not a sequence or class tag name
108 is not Universal and if iPrivateKeyInfo is NULL.
111 void ConstructL(const TDesC8& aSafeBagData);
120 @param aDecPkcs12keyBag A CDecPkcs12KeyBag object.
122 CDecPkcs12KeyBag(const CDecPkcs12KeyBag& aDecPkcs12keyBag);
126 @param aDecPkcs12keyBag A CDecPkcs12KeyBag object.
127 @return A CDecPkcs12KeyBag class.
129 CDecPkcs12KeyBag& operator=(const CDecPkcs12KeyBag& aDecPkcs12keyBag);
134 This class decodes the ShroudedKeyBag present in the SafeBag.
135 It has a method to get the PrivatKeyInfo
137 class CDecPkcs12ShroudedKeyBag : public CDecPkcs12SafeBag
141 Creates a new PKCS#12KeyBag object.
143 @param aSafeBagData Contains a PKCS#12 shroudedKeyBag structure.
144 @return A pointer to the newly allocated object.
145 @leave KErrAgrument if the data is not safeBag structure.
147 IMPORT_C static CDecPkcs12ShroudedKeyBag* NewL(const TDesC8& aSafeBagData);
150 The PrivateKey Information present in the ShroudKeyBag.
151 Below is the ASN.1 sequence.
153 ContentEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
155 AlgorithmIdentifier: A type that identifies an algorithm (by object identifier) and associated parameters
156 AlgorithmIdentifier ::= SEQUENCE
158 algorithm ALGORITHM.&id({SupportedAlgorithms}),
159 parameters ALGORITHM.&Type({SupportedAlgorithms}{@ algorithm}) OPTIONAL
162 @return A pointer to a CDecPKCS8Data object. Ownership is transferred to the caller.
163 @leave KErrAgrument if the data is not a sequence or class tag name
165 @leave KErrNotSupported if otherthan PKCS12 pbeIds.
166 @leave KErrGeneral if the decryption of the final part length is less than 0.
167 @see TASN1DecPKCS5, CPBEncryptElement, PKCS12KDF, CPBDecryptor, CDecPKCS8Data.
169 IMPORT_C CDecPKCS8Data* PrivateKeyInfoL(TDesC& aPassword) const;
174 virtual ~CDecPkcs12ShroudedKeyBag();
178 This decodes the entire KeyBag structure.
179 @param aSafeBagData Contains a PKCS#12 shroudedKeyBag Structure.
180 @leave KErrAgrument if the data is not a sequence or class tag name
184 void ConstructL(const TDesC8& aSafeBagData);
189 CDecPkcs12ShroudedKeyBag();
193 @param aDecPkcs12ShroudedKeyBag A CDecPkcs12ShroudedKeyBag object.
194 @return A CDecPkcs12ShroudedKeyBag class.
196 CDecPkcs12ShroudedKeyBag(const CDecPkcs12ShroudedKeyBag& aDecPkcs12ShroudedKeyBag);
200 @param aDecPkcs12ShroudedKeyBag A CDecPkcs12ShroudedKeyBag object.
202 CDecPkcs12ShroudedKeyBag& operator=(const CDecPkcs12ShroudedKeyBag& aDecPkcs12ShroudedKeyBag);
207 This class decodes the CertBag
208 It has methods to get the CertId and the CertValue present in the CertBag
209 The X509Certificate() method returns the x509 certificate
210 in case the CertId is x509
212 class CDecPkcs12CertBag : public CDecPkcs12SafeBag
216 Creates a new PKCS#12CertBag object.
218 @param aCertBagData contains a PKCS#12 CertBag Structure.
219 @leave KErrArgument if the data is not a sequence or class tag name
221 @leave KErrNotSupported if otherthan X509 certificate is present.
222 @return A pointer to the newly allocated object.
224 IMPORT_C static CDecPkcs12CertBag* NewL(const TDesC8& aCertBagData);
227 This method returns the OID present in the certId field of CertBag sequence.
228 @return Returns OID present in the certId feild of CertBag sequence
230 IMPORT_C const TDesC& CertId() const;
233 This method returns the DER encoded certValue present in the CertBag sequence.
234 @return The DER encoded certValue present in the CertBag sequence.
237 IMPORT_C const TDesC8& CertValue() const;
240 This method returns the decoded x509 certificate.
241 @return Returns a pointer to a CX509Certificate object if the certificate of type
242 X509; otherwise, null is returned. Ownership of memory is transferred to the caller.
245 IMPORT_C CX509Certificate* X509CertificateL() const;
250 virtual ~CDecPkcs12CertBag();
253 This decodes the entire CertBag structure.
254 @param aCertBagData contains a PKCS#12 CertBag Structure.
255 @leave KErrArgument if the data is not a sequence or class tag name
257 @see CDecPkcs12SafeBag, CX509Certificate.
259 void ConstructL(const TDesC8& aCertBagData);
268 @param aDecPkcs12CertBag A CDecPkcs12CertBag object.
270 CDecPkcs12CertBag(const CDecPkcs12CertBag& aDecPkcs12CertBag);
274 @param aDecPkcs12CertBag A CDecPkcs12CertBag object.
275 @return A CDecPkcs12CertBag class.
277 CDecPkcs12CertBag& operator=(const CDecPkcs12CertBag& aDecPkcs12CertBag);
280 /** Contains Object identifier indicating the certificate type*/
283 /** Contains the certificate which is encoded and is an OCTET String */
288 Decodes the SafeContents bag present within a SafeBag and
289 returns an array of Safebags present within this SafeContents bag.
291 class CDecPkcs12SafeContentsBag : public CDecPkcs12SafeBag
295 Creates a new PKCS#12SafeContentsBag object.
297 @param aSafeContentsBagData Contains a PKCS#12 SafeBag structure.
298 @return A pointer to the newly allocated object.
299 @leave KErrArgument if the data is not a sequence or class tag name
302 IMPORT_C static CDecPkcs12SafeContentsBag* NewL(const TDesC8& aSafeContentsBagData);
304 The SafeContents Bag contains one or more Safe Bags in it.This
305 method returns the reference to all these SafeBags.
307 @return An array of SafeBags present within the SafeContentsBag
309 IMPORT_C const RPointerArray<CDecPkcs12SafeBag>& SafeBags() const;
314 virtual ~CDecPkcs12SafeContentsBag();
318 This decodes the entire SafeContentsBag structure.
319 @param aSafeContentsBagData Contains a PKCS#12 SafeBag structure.
320 @leave KErrArgument if the data is not a sequence or class tag name
322 @see CDecPkcs12SafeBag
324 void ConstructL(const TDesC8& aSafeContentsBagData);
329 CDecPkcs12SafeContentsBag();
333 @param aDecPkcs12SafeContentsBag A CDecPkcs12SafeContentsBag object.
335 CDecPkcs12SafeContentsBag(const CDecPkcs12SafeContentsBag& aDecPkcs12SafeContentsBag);
339 @param aDecPkcs12SafeContentsBag A CDecPkcs12SafeContentsBag object.
340 @return A reference to CDecPkcs12SafeContentsBag class.
342 CDecPkcs12SafeContentsBag& operator=(const CDecPkcs12SafeContentsBag& aDecPkcs12SafeContentsBag);
345 /** Contains an array of SafeBags present within the SafeContents Bag */
346 RPointerArray<CDecPkcs12SafeBag> iSafeBags;
349 class CDecPkcs12SafeContents : public CBase
353 Creates a new CDecPkcs12SafeContents object for plain Data.
355 @param aSafeContentsBagData Contains a PKCS#7 ContentInfo Structure.
356 @return A pointer to the newly allocated object.
357 @leave KErrArgument if the data is not a sequence or class tag name
360 IMPORT_C static CDecPkcs12SafeContents* NewL(const CPKCS7ContentInfo& aSafeContentsBagData);
363 Creates a new CDecPkcs12SafeContents object for Encrypted Data.
365 @param aSafeContentsBagData Contains a PKCS#7 ContentInfo Structure.
366 @param aPassword aPassword is the password used for decryption.
367 @return A pointer to the newly allocated object.
368 @leave KErrArgument if the data is not a sequence or class tag name
371 IMPORT_C static CDecPkcs12SafeContents* NewL(const CPKCS7ContentInfo& aSafeContentsBagData, const TDesC& aPassword);
374 Creates a new CDecPkcs12SafeContents object for Enveloped Data.
375 The class doesn't support the public key privacy mode if the
376 ContentInfo contains an EnvelopedData object.Client should decrypt
377 the Envelope Data. A recipient opens the envelope by decrypting the
378 one of the encrypted content-encryption keys with the recipient's
379 private key and decrypts the encrypted content with the recovered
380 content-encryption key and pass the plain data.
381 @param aSafeContentsBagData Contains a PKCS#7 ContentInfo Structure ContentData.
382 @return A pointer to the newly allocated object.
383 @leave KErrArgument if the data is not a sequence or class tag name
386 IMPORT_C static CDecPkcs12SafeContents* NewL(const TDesC8& aSafeContentsBagData);
389 The method returns the plain data.
390 @return A pointer to descriptor containing decrypted data.
391 Returns NULL pointer if the decrypted data is not present.
393 IMPORT_C const TDesC8* DecryptedData() const;
396 The method returns array of safebags objects.
397 @return A pointer to array of safeBag objects.
399 IMPORT_C const RPointerArray<CDecPkcs12SafeBag>& SafeContentsBags() const;
404 virtual ~CDecPkcs12SafeContents();
408 These objects represents the SafeBag Sequences present in the
409 SafeContents Bag Sequence.
411 @param aSafeContent Contains data to decode the bags.
412 @leave KErrArgument if the aSafeContent is not a Sequence and class tag is not Universal.
413 @leave KErrNotSupported if any bag otherthan keyBag, shroudedKeyBag,CertBag,CRLBag,SecretBag
415 @see CDecPkcs12SafeBag
417 void ConstructL(const TDesC8& aSafeContent);
420 This method decrypts the encrypted information.
421 @param aContentInfo Contains a PKCS#7 ContentInfo Structure.
422 @param aPassword is the password used for decryption.
424 void DecodeEncryptedDataL(const CPKCS7ContentInfo& aContentInfo, const TDesC& aPassword);
429 CDecPkcs12SafeContents();
433 @param aDecPkcs12SafeContents A CDecPkcs12SafeContents object.
435 CDecPkcs12SafeContents(const CDecPkcs12SafeContents& aDecPkcs12SafeContents);
439 @param aDecPkcs12SafeContents A CDecPkcs12SafeContents object.
440 @return A reference to CDecPkcs12SafeContents class.
442 CDecPkcs12SafeContents& operator=(const CDecPkcs12SafeContents& aDecPkcs12SafeContents);
446 /** Contains an array of SafeBags objects */
447 RPointerArray<CDecPkcs12SafeBag> iSafeBags;
449 /** Contains plain data */
450 HBufC8* iDecryptedData;
453 } // namespace PKCS12
454 #endif // __PKCS12BAGS_H__