sl@0: /* sl@0: * Copyright (c) 2006-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 CMSSIGNERINFO_H sl@0: #define CMSSIGNERINFO_H sl@0: sl@0: #include sl@0: sl@0: class CX509AlgorithmIdentifier; sl@0: class CPKCS7IssuerAndSerialNumber; sl@0: class CCmsSignerIdentifier; sl@0: class CASN1EncSequence; sl@0: class CX509Certificate; sl@0: class CDSAPrivateKey; sl@0: class CRSAPrivateKey; sl@0: class CMessageDigest; sl@0: class CASN1EncOctetString; sl@0: class CASN1EncBase; sl@0: sl@0: sl@0: /** sl@0: Represents CMS signer information as defined in RFC2630. sl@0: SignedAttributes and UnsignedAttributes are not supported. sl@0: */ sl@0: class CCmsSignerInfo : public CBase sl@0: { sl@0: public: sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Creates a CMS signer info object as defined in RFC2630. sl@0: @param aDataToBeSigned The data content or its hash to be signed. sl@0: @param aIsHash Indicates whether the first parameter is a hash. sl@0: @param aKey The DSA private key used to sign. sl@0: @param aSignerIdentifier The signer identifier. Ownership of sl@0: the signer identifier is taken by this newly created signer info object. sl@0: If construction fails, ownership is not transferred. The user sl@0: needs to push aSignerIdentifier onto the cleanup stack before calling this sl@0: method, and pop it off the cleanup stack after successful construction. sl@0: @param aDigestAlgorithm The digest algorithm used to create the hash. sl@0: Ownership of the digest algorithm instance is taken by sl@0: this newly created signer info object. If construction fails, ownership sl@0: is not transferred. The user needs to push aDigestAlgorithm onto the cleanup stack before sl@0: calling this method and pop it off the cleanup stack after successful construction. sl@0: @param aSignatureAlgorithm The signature algorithm to create the signature. sl@0: Ownership of the signature algorithm instance is taken by this sl@0: newly created signer info object. If construction fails, ownership is not transferred. sl@0: The user needs to push aDigestAlgorithm onto the cleanup stack before calling this sl@0: method and pop it off the cleanup stack after successful construction. sl@0: @return The fully constructed object. sl@0: */ sl@0: static CCmsSignerInfo* NewL(const TDesC8& aDataToBeSigned, sl@0: TBool aIsHash, sl@0: const CDSAPrivateKey& aKey, sl@0: CCmsSignerIdentifier* aSignerIdentifier, sl@0: CX509AlgorithmIdentifier* aDigestAlgorithm, sl@0: CX509AlgorithmIdentifier* aSignatureAlgorithm); sl@0: /** sl@0: @internalComponent sl@0: sl@0: Creates a CMS signer info object as defined in RFC2630 sl@0: and leaves it on the cleanup stack. sl@0: @param aDataToBeSigned The data content or its hash to be signed. sl@0: @param aIsHash Indicates whether the first parameter is a hash. sl@0: @param aKey The DSA private key used to sign. sl@0: @param aSignerIdentifier The signer identifier. Ownership of sl@0: the signer identifier is taken by this newly created signer info object. sl@0: If construction fails, ownership is not transferred. The user sl@0: needs to push aSignerIdentifier onto the cleanup stack before calling this sl@0: method, and pop it off the cleanup stack after successful construction. sl@0: @param aDigestAlgorithm The digest algorithm used to create the hash. sl@0: Ownership of the digest algorithm instance is taken by sl@0: this newly created signer info object. If construction fails, ownership sl@0: is not transferred. The user needs to push aDigestAlgorithm onto the cleanup stack before sl@0: calling this method and pop it off the cleanup stack after successful construction. sl@0: @param aSignatureAlgorithm The signature algorithm to create the signature. sl@0: Ownership of the signature algorithm instance is taken by this sl@0: newly created signer info object. If construction fails, ownership is not transferred. sl@0: The user needs to push aDigestAlgorithm onto the cleanup stack before calling this sl@0: method and pop it off the cleanup stack after successful construction. sl@0: @return The fully constructed object. sl@0: */ sl@0: static CCmsSignerInfo* NewLC(const TDesC8& aDataToBeSigned, sl@0: TBool aIsHash, sl@0: const CDSAPrivateKey& aKey, sl@0: CCmsSignerIdentifier* aSignerIdentifier, sl@0: CX509AlgorithmIdentifier* aDigestAlgorithm, sl@0: CX509AlgorithmIdentifier* aSignatureAlgorithm); sl@0: /** sl@0: @internalComponent sl@0: sl@0: Creates a CMS signer info object as defined in RFC2630. sl@0: @param aDataToBeSigned The data content or its hash to be signed. sl@0: @param aIsHash Indicates whether the first parameter is a hash. sl@0: @param aKey The RSA private key used to sign. sl@0: @param aSignerIdentifier The signer identifier. Ownership of sl@0: the signer identifier is taken by this newly created signer info object. sl@0: If construction fails, ownership is not transferred. The user sl@0: needs to push aSignerIdentifier onto the cleanup stack before calling this sl@0: method, and pop it off the cleanup stack after successful construction. sl@0: @param aDigestAlgorithm The digest algorithm used to create the hash. sl@0: Ownership of the digest algorithm instance is taken by sl@0: this newly created signer info object. If construction fails, ownership sl@0: is not transferred. The user needs to push aDigestAlgorithm onto the cleanup stack before sl@0: calling this method and pop it off the cleanup stack after successful construction. sl@0: @param aSignatureAlgorithm The signature algorithm to create the signature. sl@0: Ownership of the signature algorithm instance is taken by this sl@0: newly created signer info object. If construction fails, ownership is not transferred. sl@0: The user needs to push aDigestAlgorithm onto the cleanup stack before calling this sl@0: method and pop it off the cleanup stack after successful construction. sl@0: @return The fully constructed object. sl@0: */ sl@0: static CCmsSignerInfo* NewL(const TDesC8& aDataToBeSigned, sl@0: TBool aIsHash, sl@0: const CRSAPrivateKey& aKey, sl@0: CCmsSignerIdentifier* aSignerIdentifier, sl@0: CX509AlgorithmIdentifier* aDigestAlgorithm, sl@0: CX509AlgorithmIdentifier* aSignatureAlgorithm); sl@0: /** sl@0: @internalComponent sl@0: sl@0: Creates a CMS signer info object as defined in RFC2630 sl@0: and leaves it on the cleanup stack. sl@0: @param aDataToBeSigned The data content or its hash to be signed. sl@0: @param aIsHash Indicates whether the first parameter is a hash. sl@0: @param aKey The RSA private key used to sign. sl@0: @param aSignerIdentifier The signer identifier. Ownership of sl@0: the signer identifier is taken by this newly created signer info object. sl@0: If construction fails, ownership is not transferred. The user sl@0: needs to push aSignerIdentifier onto the cleanup stack before calling this sl@0: method, and pop it off the cleanup stack after successful construction. sl@0: @param aDigestAlgorithm The digest algorithm used to create the hash. sl@0: Ownership of the digest algorithm instance is taken by sl@0: this newly created signer info object. If construction fails, ownership sl@0: is not transferred. The user needs to push aDigestAlgorithm onto the cleanup stack before sl@0: calling this method and pop it off the cleanup stack after successful construction. sl@0: @param aSignatureAlgorithm The signature algorithm to create the signature. sl@0: Ownership of the signature algorithm instance is taken by this sl@0: newly created signer info object. If construction fails, ownership is not transferred. sl@0: The user needs to push aDigestAlgorithm onto the cleanup stack before calling this sl@0: method and pop it off the cleanup stack after successful construction. sl@0: @return The fully constructed object. sl@0: */ sl@0: static CCmsSignerInfo* NewLC(const TDesC8& aDataToBeSigned, sl@0: TBool aIsHash, sl@0: const CRSAPrivateKey& aKey, sl@0: CCmsSignerIdentifier* aSignerIdentifier, sl@0: CX509AlgorithmIdentifier* aDigestAlgorithm, sl@0: CX509AlgorithmIdentifier* aSignatureAlgorithm); sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Creates a CMS signer info object as defined in RFC2630. sl@0: @param aRawData the encoded signer info. sl@0: @return The fully constructed object. sl@0: */ sl@0: static CCmsSignerInfo* NewL(const TDesC8& aRawData); sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Creates a CMS signer info object as defined in RFC2630 sl@0: and leaves it on the cleanup stack. sl@0: @param aRawData The encoded signer info. sl@0: @return The fully constructed object. sl@0: */ sl@0: static CCmsSignerInfo* NewLC(const TDesC8& aRawData); sl@0: virtual ~CCmsSignerInfo(); sl@0: sl@0: /** sl@0: Returns the version of the CMS signer info object. sl@0: @return The version of the CMS signer info object. sl@0: */ sl@0: IMPORT_C TInt Version() const; sl@0: sl@0: /** sl@0: Returns whether signed attributes are present or not. sl@0: @return Boolean indicating whether signed attributes are present or not. sl@0: */ sl@0: IMPORT_C TBool IsSignedAttributesPresent() const; sl@0: sl@0: /** sl@0: Returns whether unsigned attributes are present or not. sl@0: @return Boolean indicating whether unsigned attributes are present or not. sl@0: */ sl@0: IMPORT_C TBool IsUnsignedAttributesPresent() const; sl@0: sl@0: /** sl@0: Returns the digest algorithm identifier. sl@0: @return The digest algorithm identifier reference. sl@0: */ sl@0: IMPORT_C const CX509AlgorithmIdentifier& DigestAlgorithm() const; sl@0: sl@0: /** sl@0: Returns the signature algorithm identifier. sl@0: @return The signature algorithm identifier reference. sl@0: */ sl@0: IMPORT_C const CX509AlgorithmIdentifier& SignatureAlgorithm() const; sl@0: sl@0: /** sl@0: Returns the signature value. sl@0: @return The signature value. sl@0: */ sl@0: IMPORT_C const TPtrC8 SignatureValue() const; sl@0: sl@0: /** sl@0: Returns the signer identifier. sl@0: @return the signer identifier reference. sl@0: */ sl@0: IMPORT_C const CCmsSignerIdentifier& SignerIdentifier() const; sl@0: sl@0: /** sl@0: @internalComponent sl@0: sl@0: Creates the ASN.1 sequence of this CMS signed object and leaves it on the cleanup stack. sl@0: @return ASN.1 sequence of this object. sl@0: */ sl@0: CASN1EncSequence* EncodeASN1DERLC() const; sl@0: sl@0: private: sl@0: /** sl@0: Constructor. sl@0: */ sl@0: CCmsSignerInfo(); sl@0: sl@0: sl@0: private: sl@0: /** sl@0: second phase constructor sl@0: @param aDataToBeSigned the data or its hash sl@0: @param aIsHash a flag to represent if the first paramter is hash or data content sl@0: @param aKey the DSA private key used to create the signature. sl@0: @param aSignerIdentifier the signer identifier. sl@0: @param aDigestAlgorithm the digest algorithm used to create hash. sl@0: @param aSignatureAlgorithm the signature alogorithm to create signature sl@0: */ sl@0: void ConstructL(const TDesC8& aDataToBeSigned, sl@0: TBool aIsHash, sl@0: const CDSAPrivateKey& aKey, sl@0: CCmsSignerIdentifier* aSignerIdentifier, sl@0: CX509AlgorithmIdentifier* aDigestAlgorithm, sl@0: CX509AlgorithmIdentifier* aSignatureAlgorithm); sl@0: sl@0: /** sl@0: second phase constructor sl@0: @param aDataToBeSigned the data or its hash sl@0: @param aIsHash a flag to represent if the first paramter is hash or data content sl@0: @param aKey the RSA private key used to create the signature. sl@0: @param aSignerIdentifier the signer identifier. sl@0: @param aDigestAlgorithm the digest algorithm used to create hash. sl@0: @param aSignatureAlgorithm the signature alogorithm to create signature. sl@0: */ sl@0: void ConstructL(const TDesC8& aDataToBeSigned, sl@0: TBool aIsHash, sl@0: const CRSAPrivateKey& aKey, sl@0: CCmsSignerIdentifier* aSignerIdentifier, sl@0: CX509AlgorithmIdentifier* aDigestAlgorithm, sl@0: CX509AlgorithmIdentifier* aSignatureAlgorithm); sl@0: sl@0: /** sl@0: Second phase constructor sl@0: @param aRawData the encoded the CMS content info sl@0: */ sl@0: void ConstructL(const TDesC8& aRawData); sl@0: sl@0: /** sl@0: Encode the signer identifier sl@0: @return encoding of the signer identifier sl@0: */ sl@0: CASN1EncBase* EncodeSignerIdentifierLC() const; sl@0: sl@0: /** sl@0: Decode the signature sl@0: @param aRawData the encoded signature sl@0: */ sl@0: void DecodeEncryptedDigestL(const TDesC8& aRawData); sl@0: sl@0: /** sl@0: Decode the signer identifier sl@0: @param aRawData the encoded signer identifier sl@0: */ sl@0: void DecodeSignerIdentifierL(const TDesC8& aRawData); sl@0: sl@0: private: sl@0: /** sl@0: Represents if the Signed Attribute is present sl@0: */ sl@0: TBool iSignedAttributesPresent; sl@0: sl@0: /** sl@0: Represents if the Unsigned Attribute is present sl@0: */ sl@0: TBool iUnsignedAttributesPresent; sl@0: sl@0: /** sl@0: The version of the signer info sl@0: */ sl@0: TInt iVersion; sl@0: sl@0: /** sl@0: the signer identifier sl@0: */ sl@0: CCmsSignerIdentifier* iSignerIdentifier; sl@0: sl@0: /** sl@0: The digest algorithm identifier sl@0: */ sl@0: CX509AlgorithmIdentifier* iDigestAlgorithm; sl@0: /** sl@0: The signature algorithm identifier sl@0: */ sl@0: CX509AlgorithmIdentifier* iSignatureAlgorithm; sl@0: sl@0: /** sl@0: the signature value sl@0: */ sl@0: HBufC8* iSignatureValue; sl@0: }; sl@0: sl@0: #endif sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: sl@0: