sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @publishedPartner sl@0: @released sl@0: */ sl@0: sl@0: #ifndef __PKCS12_BAGS_H__ sl@0: #define __PKCS12_BAGS_H__ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: #include sl@0: sl@0: namespace PKCS12 sl@0: { sl@0: /** Object identifier for KeyBag */ sl@0: _LIT(KPkcs12KeyBagOID, "1.2.840.113549.1.12.10.1.1"); sl@0: sl@0: /** Object identifier for ShroudedKeyBag */ sl@0: _LIT(KPkcs12ShroudedKeyBagOID, "1.2.840.113549.1.12.10.1.2"); sl@0: sl@0: /** Object identifier for CertBag */ sl@0: _LIT(KPkcs12CertBagOID, "1.2.840.113549.1.12.10.1.3"); sl@0: sl@0: /** Object identifier for CrlBag */ sl@0: _LIT(KPkcs12CrlBagOID, "1.2.840.113549.1.12.10.1.4"); sl@0: sl@0: /** Object identifier for SecretBag */ sl@0: _LIT(KPkcs12SecretBagOID, "1.2.840.113549.1.12.10.1.5"); sl@0: sl@0: /** Object identifier for SafeContentsBag */ sl@0: _LIT(KPkcs12SafeContentsBagOID, "1.2.840.113549.1.12.10.1.6"); sl@0: sl@0: /** Object identifier for x509 certificate */ sl@0: _LIT(KX509CertificateOID,"1.2.840.113549.1.9.22.1"); sl@0: sl@0: /** sl@0: This class decodes the KeyBag present in the SafeBag. sl@0: It has a method to get the PrivatKeyInfo sl@0: */ sl@0: class CDecPkcs12KeyBag : public CDecPkcs12SafeBag sl@0: { sl@0: public: sl@0: /** sl@0: Creates a new PKCS#12KeyBag object. sl@0: sl@0: @param aSafeBagData Contains a PKCS#12 SafeBag Structure. sl@0: @return A pointer to the newly allocated object. sl@0: @leave KErrAgrument if the data is not a sequence or class tag name sl@0: is not Universal and if iPrivateKeyInfo is NULL. sl@0: */ sl@0: IMPORT_C static CDecPkcs12KeyBag* NewL(const TDesC8& aSafeBagData); sl@0: sl@0: /** sl@0: The PrivateKey information present in the KeyBag. sl@0: The returned ASN1 sequence respects the following grammar: sl@0: sl@0: PrivateKeyInfo ::= SEQUENCE { sl@0: version Version, sl@0: privateKeyAlgorithm PrivateKeyAlgorithmIdentifier, sl@0: privateKey PrivateKey, sl@0: attributes [0] IMPLICIT Attributes OPTIONAL } sl@0: sl@0: Version ::= INTEGER sl@0: PrivateKeyAlgorithmIdentifier ::= AlgorithmIdentifier sl@0: PrivateKey ::= OCTET STRING sl@0: Attributes ::= SET OF Attribute sl@0: sl@0: @return A pointer to a CDecPKCS8Data object. Ownership of memory is transferred sl@0: to the caller. sl@0: @see CDecPKCS8Data sl@0: */ sl@0: IMPORT_C CDecPKCS8Data* PrivateKeyInfoL() const; sl@0: sl@0: /** sl@0: Destructor. sl@0: */ sl@0: virtual ~CDecPkcs12KeyBag(); sl@0: sl@0: private: sl@0: /** sl@0: Decodes the entire KeyBag structure. sl@0: @param aSafeBagData Contains a PKCS#12 SafeBag Structure. sl@0: @leave KErrAgrument if the data is not a sequence or class tag name sl@0: is not Universal and if iPrivateKeyInfo is NULL. sl@0: @see TASN1DecPKCS8 sl@0: */ sl@0: void ConstructL(const TDesC8& aSafeBagData); sl@0: sl@0: /** sl@0: Constructor. sl@0: */ sl@0: CDecPkcs12KeyBag(); sl@0: sl@0: /** sl@0: Copy Constructor. sl@0: @param aDecPkcs12keyBag A CDecPkcs12KeyBag object. sl@0: */ sl@0: CDecPkcs12KeyBag(const CDecPkcs12KeyBag& aDecPkcs12keyBag); sl@0: sl@0: /** sl@0: Assignment operator. sl@0: @param aDecPkcs12keyBag A CDecPkcs12KeyBag object. sl@0: @return A CDecPkcs12KeyBag class. sl@0: */ sl@0: CDecPkcs12KeyBag& operator=(const CDecPkcs12KeyBag& aDecPkcs12keyBag); sl@0: }; sl@0: sl@0: sl@0: /** sl@0: This class decodes the ShroudedKeyBag present in the SafeBag. sl@0: It has a method to get the PrivatKeyInfo sl@0: */ sl@0: class CDecPkcs12ShroudedKeyBag : public CDecPkcs12SafeBag sl@0: { sl@0: public: sl@0: /** sl@0: Creates a new PKCS#12KeyBag object. sl@0: sl@0: @param aSafeBagData Contains a PKCS#12 shroudedKeyBag structure. sl@0: @return A pointer to the newly allocated object. sl@0: @leave KErrAgrument if the data is not safeBag structure. sl@0: */ sl@0: IMPORT_C static CDecPkcs12ShroudedKeyBag* NewL(const TDesC8& aSafeBagData); sl@0: sl@0: /** sl@0: The PrivateKey Information present in the ShroudKeyBag. sl@0: Below is the ASN.1 sequence. sl@0: sl@0: ContentEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier sl@0: sl@0: AlgorithmIdentifier: A type that identifies an algorithm (by object identifier) and associated parameters sl@0: AlgorithmIdentifier ::= SEQUENCE sl@0: { sl@0: algorithm ALGORITHM.&id({SupportedAlgorithms}), sl@0: parameters ALGORITHM.&Type({SupportedAlgorithms}{@ algorithm}) OPTIONAL sl@0: } sl@0: sl@0: @return A pointer to a CDecPKCS8Data object. Ownership is transferred to the caller. sl@0: @leave KErrAgrument if the data is not a sequence or class tag name sl@0: is not Universal. sl@0: @leave KErrNotSupported if otherthan PKCS12 pbeIds. sl@0: @leave KErrGeneral if the decryption of the final part length is less than 0. sl@0: @see TASN1DecPKCS5, CPBEncryptElement, PKCS12KDF, CPBDecryptor, CDecPKCS8Data. sl@0: */ sl@0: IMPORT_C CDecPKCS8Data* PrivateKeyInfoL(TDesC& aPassword) const; sl@0: sl@0: /** sl@0: Destructor. sl@0: */ sl@0: virtual ~CDecPkcs12ShroudedKeyBag(); sl@0: sl@0: private: sl@0: /** sl@0: This decodes the entire KeyBag structure. sl@0: @param aSafeBagData Contains a PKCS#12 shroudedKeyBag Structure. sl@0: @leave KErrAgrument if the data is not a sequence or class tag name sl@0: is not Universal. sl@0: @see TASN1DecPKCS8 sl@0: */ sl@0: void ConstructL(const TDesC8& aSafeBagData); sl@0: sl@0: /** sl@0: Constructor. sl@0: */ sl@0: CDecPkcs12ShroudedKeyBag(); sl@0: sl@0: /** sl@0: Copy Constructor. sl@0: @param aDecPkcs12ShroudedKeyBag A CDecPkcs12ShroudedKeyBag object. sl@0: @return A CDecPkcs12ShroudedKeyBag class. sl@0: */ sl@0: CDecPkcs12ShroudedKeyBag(const CDecPkcs12ShroudedKeyBag& aDecPkcs12ShroudedKeyBag); sl@0: sl@0: /** sl@0: Assignment operator. sl@0: @param aDecPkcs12ShroudedKeyBag A CDecPkcs12ShroudedKeyBag object. sl@0: */ sl@0: CDecPkcs12ShroudedKeyBag& operator=(const CDecPkcs12ShroudedKeyBag& aDecPkcs12ShroudedKeyBag); sl@0: }; sl@0: sl@0: sl@0: /** sl@0: This class decodes the CertBag sl@0: It has methods to get the CertId and the CertValue present in the CertBag sl@0: The X509Certificate() method returns the x509 certificate sl@0: in case the CertId is x509 sl@0: */ sl@0: class CDecPkcs12CertBag : public CDecPkcs12SafeBag sl@0: { sl@0: public: sl@0: /** sl@0: Creates a new PKCS#12CertBag object. sl@0: sl@0: @param aCertBagData contains a PKCS#12 CertBag Structure. sl@0: @leave KErrArgument if the data is not a sequence or class tag name sl@0: is not Universal. sl@0: @leave KErrNotSupported if otherthan X509 certificate is present. sl@0: @return A pointer to the newly allocated object. sl@0: */ sl@0: IMPORT_C static CDecPkcs12CertBag* NewL(const TDesC8& aCertBagData); sl@0: sl@0: /** sl@0: This method returns the OID present in the certId field of CertBag sequence. sl@0: @return Returns OID present in the certId feild of CertBag sequence sl@0: */ sl@0: IMPORT_C const TDesC& CertId() const; sl@0: sl@0: /** sl@0: This method returns the DER encoded certValue present in the CertBag sequence. sl@0: @return The DER encoded certValue present in the CertBag sequence. sl@0: @see X509Certificate sl@0: */ sl@0: IMPORT_C const TDesC8& CertValue() const; sl@0: sl@0: /** sl@0: This method returns the decoded x509 certificate. sl@0: @return Returns a pointer to a CX509Certificate object if the certificate of type sl@0: X509; otherwise, null is returned. Ownership of memory is transferred to the caller. sl@0: @see CertValue sl@0: */ sl@0: IMPORT_C CX509Certificate* X509CertificateL() const; sl@0: sl@0: /** sl@0: Destructor. sl@0: */ sl@0: virtual ~CDecPkcs12CertBag(); sl@0: private: sl@0: /** sl@0: This decodes the entire CertBag structure. sl@0: @param aCertBagData contains a PKCS#12 CertBag Structure. sl@0: @leave KErrArgument if the data is not a sequence or class tag name sl@0: is not Universal. sl@0: @see CDecPkcs12SafeBag, CX509Certificate. sl@0: */ sl@0: void ConstructL(const TDesC8& aCertBagData); sl@0: sl@0: /** sl@0: Constructor. sl@0: */ sl@0: CDecPkcs12CertBag(); sl@0: sl@0: /** sl@0: Copy Constructor. sl@0: @param aDecPkcs12CertBag A CDecPkcs12CertBag object. sl@0: */ sl@0: CDecPkcs12CertBag(const CDecPkcs12CertBag& aDecPkcs12CertBag); sl@0: sl@0: /** sl@0: Assignment operator. sl@0: @param aDecPkcs12CertBag A CDecPkcs12CertBag object. sl@0: @return A CDecPkcs12CertBag class. sl@0: */ sl@0: CDecPkcs12CertBag& operator=(const CDecPkcs12CertBag& aDecPkcs12CertBag); sl@0: sl@0: private: sl@0: /** Contains Object identifier indicating the certificate type*/ sl@0: HBufC* iCertId; sl@0: sl@0: /** Contains the certificate which is encoded and is an OCTET String */ sl@0: TPtrC8 iCertValue; sl@0: }; sl@0: sl@0: /** sl@0: Decodes the SafeContents bag present within a SafeBag and sl@0: returns an array of Safebags present within this SafeContents bag. sl@0: */ sl@0: class CDecPkcs12SafeContentsBag : public CDecPkcs12SafeBag sl@0: { sl@0: public: sl@0: /** sl@0: Creates a new PKCS#12SafeContentsBag object. sl@0: sl@0: @param aSafeContentsBagData Contains a PKCS#12 SafeBag structure. sl@0: @return A pointer to the newly allocated object. sl@0: @leave KErrArgument if the data is not a sequence or class tag name sl@0: is not Universal. sl@0: */ sl@0: IMPORT_C static CDecPkcs12SafeContentsBag* NewL(const TDesC8& aSafeContentsBagData); sl@0: /** sl@0: The SafeContents Bag contains one or more Safe Bags in it.This sl@0: method returns the reference to all these SafeBags. sl@0: sl@0: @return An array of SafeBags present within the SafeContentsBag sl@0: */ sl@0: IMPORT_C const RPointerArray& SafeBags() const; sl@0: sl@0: /** sl@0: Destructor. sl@0: */ sl@0: virtual ~CDecPkcs12SafeContentsBag(); sl@0: sl@0: private: sl@0: /** sl@0: This decodes the entire SafeContentsBag structure. sl@0: @param aSafeContentsBagData Contains a PKCS#12 SafeBag structure. sl@0: @leave KErrArgument if the data is not a sequence or class tag name sl@0: is not Universal. sl@0: @see CDecPkcs12SafeBag sl@0: */ sl@0: void ConstructL(const TDesC8& aSafeContentsBagData); sl@0: sl@0: /** sl@0: Constructor. sl@0: */ sl@0: CDecPkcs12SafeContentsBag(); sl@0: sl@0: /** sl@0: Copy Constructor. sl@0: @param aDecPkcs12SafeContentsBag A CDecPkcs12SafeContentsBag object. sl@0: */ sl@0: CDecPkcs12SafeContentsBag(const CDecPkcs12SafeContentsBag& aDecPkcs12SafeContentsBag); sl@0: sl@0: /** sl@0: Assignment operator. sl@0: @param aDecPkcs12SafeContentsBag A CDecPkcs12SafeContentsBag object. sl@0: @return A reference to CDecPkcs12SafeContentsBag class. sl@0: */ sl@0: CDecPkcs12SafeContentsBag& operator=(const CDecPkcs12SafeContentsBag& aDecPkcs12SafeContentsBag); sl@0: sl@0: private: sl@0: /** Contains an array of SafeBags present within the SafeContents Bag */ sl@0: RPointerArray iSafeBags; sl@0: }; sl@0: sl@0: class CDecPkcs12SafeContents : public CBase sl@0: { sl@0: public: sl@0: /** sl@0: Creates a new CDecPkcs12SafeContents object for plain Data. sl@0: sl@0: @param aSafeContentsBagData Contains a PKCS#7 ContentInfo Structure. sl@0: @return A pointer to the newly allocated object. sl@0: @leave KErrArgument if the data is not a sequence or class tag name sl@0: is not Universal. sl@0: */ sl@0: IMPORT_C static CDecPkcs12SafeContents* NewL(const CPKCS7ContentInfo& aSafeContentsBagData); sl@0: sl@0: /** sl@0: Creates a new CDecPkcs12SafeContents object for Encrypted Data. sl@0: sl@0: @param aSafeContentsBagData Contains a PKCS#7 ContentInfo Structure. sl@0: @param aPassword aPassword is the password used for decryption. sl@0: @return A pointer to the newly allocated object. sl@0: @leave KErrArgument if the data is not a sequence or class tag name sl@0: is not Universal. sl@0: */ sl@0: IMPORT_C static CDecPkcs12SafeContents* NewL(const CPKCS7ContentInfo& aSafeContentsBagData, const TDesC& aPassword); sl@0: sl@0: /** sl@0: Creates a new CDecPkcs12SafeContents object for Enveloped Data. sl@0: The class doesn't support the public key privacy mode if the sl@0: ContentInfo contains an EnvelopedData object.Client should decrypt sl@0: the Envelope Data. A recipient opens the envelope by decrypting the sl@0: one of the encrypted content-encryption keys with the recipient's sl@0: private key and decrypts the encrypted content with the recovered sl@0: content-encryption key and pass the plain data. sl@0: @param aSafeContentsBagData Contains a PKCS#7 ContentInfo Structure ContentData. sl@0: @return A pointer to the newly allocated object. sl@0: @leave KErrArgument if the data is not a sequence or class tag name sl@0: is not Universal. sl@0: */ sl@0: IMPORT_C static CDecPkcs12SafeContents* NewL(const TDesC8& aSafeContentsBagData); sl@0: sl@0: /** sl@0: The method returns the plain data. sl@0: @return A pointer to descriptor containing decrypted data. sl@0: Returns NULL pointer if the decrypted data is not present. sl@0: */ sl@0: IMPORT_C const TDesC8* DecryptedData() const; sl@0: sl@0: /** sl@0: The method returns array of safebags objects. sl@0: @return A pointer to array of safeBag objects. sl@0: */ sl@0: IMPORT_C const RPointerArray& SafeContentsBags() const; sl@0: sl@0: /** sl@0: Destructor. sl@0: */ sl@0: virtual ~CDecPkcs12SafeContents(); sl@0: sl@0: private: sl@0: /** sl@0: These objects represents the SafeBag Sequences present in the sl@0: SafeContents Bag Sequence. sl@0: sl@0: @param aSafeContent Contains data to decode the bags. sl@0: @leave KErrArgument if the aSafeContent is not a Sequence and class tag is not Universal. sl@0: @leave KErrNotSupported if any bag otherthan keyBag, shroudedKeyBag,CertBag,CRLBag,SecretBag sl@0: and SafeContentBag. sl@0: @see CDecPkcs12SafeBag sl@0: */ sl@0: void ConstructL(const TDesC8& aSafeContent); sl@0: sl@0: /** sl@0: This method decrypts the encrypted information. sl@0: @param aContentInfo Contains a PKCS#7 ContentInfo Structure. sl@0: @param aPassword is the password used for decryption. sl@0: */ sl@0: void DecodeEncryptedDataL(const CPKCS7ContentInfo& aContentInfo, const TDesC& aPassword); sl@0: sl@0: /** sl@0: Constructor. sl@0: */ sl@0: CDecPkcs12SafeContents(); sl@0: sl@0: /** sl@0: Copy Constructor. sl@0: @param aDecPkcs12SafeContents A CDecPkcs12SafeContents object. sl@0: */ sl@0: CDecPkcs12SafeContents(const CDecPkcs12SafeContents& aDecPkcs12SafeContents); sl@0: sl@0: /** sl@0: Assignment operator. sl@0: @param aDecPkcs12SafeContents A CDecPkcs12SafeContents object. sl@0: @return A reference to CDecPkcs12SafeContents class. sl@0: */ sl@0: CDecPkcs12SafeContents& operator=(const CDecPkcs12SafeContents& aDecPkcs12SafeContents); sl@0: sl@0: sl@0: private: sl@0: /** Contains an array of SafeBags objects */ sl@0: RPointerArray iSafeBags; sl@0: sl@0: /** Contains plain data */ sl@0: HBufC8* iDecryptedData; sl@0: sl@0: }; sl@0: } // namespace PKCS12 sl@0: #endif // __PKCS12BAGS_H__