williamr@2: /* williamr@2: * Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@2: * All rights reserved. williamr@2: * This component and the accompanying materials are made available williamr@2: * under the terms of the License "Eclipse Public License v1.0" williamr@2: * which accompanies this distribution, and is available williamr@2: * at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@2: * williamr@2: * Initial Contributors: williamr@2: * Nokia Corporation - initial contribution. williamr@2: * williamr@2: * Contributors: williamr@2: * williamr@2: * Description: williamr@2: * X509 certificate implementation williamr@2: * williamr@2: */ williamr@2: williamr@2: williamr@2: williamr@2: williamr@2: /** williamr@2: @file williamr@2: @internalAll williamr@2: */ williamr@2: williamr@2: #ifndef __X509CERT_H__ williamr@2: #define __X509CERT_H__ williamr@2: williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: #include williamr@2: williamr@2: _LIT(KMD2WithRSA,"1.2.840.113549.1.1.2"); williamr@2: _LIT(KMD5WithRSA,"1.2.840.113549.1.1.4"); williamr@2: _LIT(KSHA1WithRSA,"1.2.840.113549.1.1.5"); williamr@2: _LIT(KDSAWithSHA1,"1.2.840.10040.4.3"); williamr@2: williamr@2: _LIT(KRSA,"1.2.840.113549.1.1.1"); williamr@2: _LIT(KDH,"1.2.840.10046.2.1"); williamr@2: _LIT(KDSA,"1.2.840.10040.4.1"); williamr@2: _LIT(KMD5,"1.2.840.113549.2.5"); williamr@2: _LIT(KMD2,"1.2.840.113549.2.2"); williamr@2: _LIT(KSHA1,"1.3.14.3.2.26"); williamr@2: williamr@2: /** The maximum number of allowed data elements. williamr@2: * williamr@2: * @since v7.0 */ williamr@2: const TInt KX509MaxDataElements = 10; williamr@2: williamr@2: class CRSAPublicKey; williamr@2: class CDSAPublicKey; williamr@2: class CDSASignature; williamr@2: class CDSAParameters; williamr@2: williamr@2: class CPKCS1SignatureResult : public CRSASignatureResult williamr@2: /** The signature result in PKCS#1 format. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: * @since v6.0 */ williamr@2: { williamr@2: public: williamr@2: /** Creates a new algorithm ID object copied from an existing object. williamr@2: * williamr@2: * @param aDigestAlgorithm The algorithm ID object to be copied. williamr@2: * @param aDigest A non-modifiable descriptor representing the digest algorithm. williamr@2: * @return A pointer to the new algorithm ID object. */ williamr@2: IMPORT_C static CPKCS1SignatureResult* NewL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest); williamr@2: williamr@2: /** Creates a new algorithm ID object copied from an existing williamr@2: * object, and puts a pointer to the new object onto the cleanup stack. williamr@2: * williamr@2: * @param aDigestAlgorithm The algorithm ID object to be copied. williamr@2: * @param aDigest A non-modifiable descriptor representing the digest algorithm. williamr@2: * @return A pointer to the new algorithm ID object. */ williamr@2: IMPORT_C static CPKCS1SignatureResult* NewLC(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest); williamr@2: williamr@2: /** Tests whether the signature result is valid. williamr@2: * williamr@2: * @param aResult The signature result to be verified. williamr@2: * @return ETrue, if the signature result is verified; EFalse, otherwise. */ williamr@2: IMPORT_C virtual TBool VerifyL(const TDesC8& aResult); williamr@2: private: williamr@2: void ConstructL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest); williamr@2: TBool DoVerifyL(const TDesC8& aResult); williamr@2: }; williamr@2: williamr@2: class TX509KeyFactory : public TKeyFactory williamr@2: /** Constructs the public key objects used for signature verification, from their williamr@2: * encoded binary form, for X.509 certificates. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: * @since v6.0 */ williamr@2: { williamr@2: public: williamr@2: /** Gets the RSA public key from the encoding key. williamr@2: * williamr@2: * @param aEncoding A non-modifiable descriptor representing the entire encoding. williamr@2: * @return The RSA Public key. */ williamr@2: IMPORT_C CRSAPublicKey* RSAPublicKeyL(const TDesC8& aEncoding) const; williamr@2: williamr@2: /** Gets the RSA signature result. williamr@2: * williamr@2: * @param aDigestAlgorithm The digest algorithm ID. williamr@2: * @param aDigest A non-modifiable descriptor representing the digest algorithm. williamr@2: * @return The RSA signature result. */ williamr@2: IMPORT_C CRSASignatureResult* RSASignatureResultL(const CAlgorithmIdentifier& aDigestAlgorithm, TDesC8& aDigest) const; williamr@2: williamr@2: /** Gets the DSA public key from the encoding key. williamr@2: * williamr@2: * @param aParamsEncoding A non-modifiable descriptor representing williamr@2: * the encoded binary representation of the DSA parameters williamr@2: * @param aEncoding A non-modifiable descriptor representing the entire encoding. williamr@2: * @return The DSA public key. williamr@2: * @since v8.0 */ williamr@2: IMPORT_C CDSAPublicKey* DSAPublicKeyL(const TDesC8& aParamsEncoding, const TDesC8& aEncoding) const; williamr@2: williamr@2: /** Gets the digital DSA signature from the encoding key. williamr@2: * williamr@2: * @param aEncoding A non-modifiable descriptor representing the entire encoding. williamr@2: * @return The DSA signature. */ williamr@2: IMPORT_C CDSASignature* DSASignatureL(const TDesC8& aEncoding) const; williamr@2: williamr@2: /** Gets the DSA parameters from the encoding key. williamr@2: * williamr@2: * @param aEncoding A non-modifiable descriptor representing the entire encoding. williamr@2: * @return The DSA parameters. */ williamr@2: IMPORT_C CDSAParameters* DSAParametersL(const TDesC8& aEncoding) const; williamr@2: williamr@2: /** Gets the DSA public key from the encoding key. williamr@2: * williamr@2: * @param aParams The DSA parameters williamr@2: * @param aEncoding A non-modifiable descriptor representing the entire encoding. williamr@2: * @return The DSA public key. */ williamr@2: IMPORT_C CDSAPublicKey* DSAPublicKeyL(const CDSAParameters& aParams, const TDesC8& aEncoding) const; williamr@2: }; williamr@2: williamr@2: class CX509ValidityPeriod : public CValidityPeriod williamr@2: /** The period for which an X.509 certificate is valid. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: * @since v6.0 */ williamr@2: { williamr@2: public: williamr@2: /** Creates a new X.509 validity period object from the specified buffer containing williamr@2: * the binary coded representation. williamr@2: * williamr@2: * Initialises the object from its encoded binary form into an internal representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new validity period object. */ williamr@2: IMPORT_C static CX509ValidityPeriod* NewL(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new X.509 validity period object from the specified buffer containing williamr@2: * the binary coded representation, and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * Initialises the object from its encoded binary form into an internal representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new validity period object. */ williamr@2: IMPORT_C static CX509ValidityPeriod* NewLC(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new X.509 validity period object from the specified buffer containing williamr@2: * the binary coded representation, starting at the specified offset. williamr@2: * williamr@2: * Initialises the object from its encoded binary form into an internal representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The new validity period object. */ williamr@2: IMPORT_C static CX509ValidityPeriod* NewL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** Creates a new X.509 validity period object from the specified buffer containing williamr@2: * the binary coded representation, starting at the specified offset, and puts williamr@2: * a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * Initialises the object from its encoded binary form into an internal representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The new validity period object. */ williamr@2: IMPORT_C static CX509ValidityPeriod* NewLC(const TDesC8& aBinaryData, TInt& aPos); williamr@2: private: williamr@2: CX509ValidityPeriod(); williamr@2: void ConstructL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: }; williamr@2: williamr@2: class CX509AlgorithmIdentifier : public CAlgorithmIdentifier williamr@2: /** Algorithm identifier for an X.509 certificate. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: * @since v6.0 */ williamr@2: { williamr@2: public: williamr@2: /** Creates a new X.509 algorithm identifier object from the specified buffer containing williamr@2: * the binary coded representation. williamr@2: * williamr@2: * The function initialises the object from its encoded binary form into an internal williamr@2: * representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new algorithm identifier object. */ williamr@2: IMPORT_C static CX509AlgorithmIdentifier* NewL(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new X.509 algorithm identifier object from the specified buffer containing williamr@2: * the binary coded representation, and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new algorithm identifier object. */ williamr@2: IMPORT_C static CX509AlgorithmIdentifier* NewLC(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new X.509 algorithm identifier object from the specified buffer containing williamr@2: * the binary coded representation, starting at the specified offset. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The new algorithm identifier object. */ williamr@2: IMPORT_C static CX509AlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** Creates a new X.509 algorithm identifier object from the specified buffer containing williamr@2: * the binary coded representation, starting at the specified offset, and puts williamr@2: * a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The new algorithm identifier object. */ williamr@2: IMPORT_C static CX509AlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** williamr@2: Creates a X509 Algorithm Identifier object from the given algorithm ID and the encoded parameter. williamr@2: @param aAlgorithmId The algorithm Id used to build the object. williamr@2: @param aEncodedParams The encoded parameter for the algorithm ID. williamr@2: @return The fully constructed object. williamr@2: */ williamr@2: IMPORT_C static CX509AlgorithmIdentifier* NewL(TAlgorithmId aAlgorithmId, const TDesC8& aEncodedParams); williamr@2: williamr@2: /** williamr@2: Creates a X509 Algorithm Identifier object from the given algorithm ID and the encoded parameter williamr@2: and leaves the object on the cleanup stack. williamr@2: @param aAlgorithmId The algorithm Id used to build the object. williamr@2: @param aEncodedParams The encoded parameter for the algorithm ID. williamr@2: @return The fully constructed object. williamr@2: */ williamr@2: IMPORT_C static CX509AlgorithmIdentifier* NewLC(TAlgorithmId aAlgorithmId, const TDesC8& aEncodedParams); williamr@2: williamr@2: /** williamr@2: Creates the ASN1 DER sequence of the X509 algorithm identifier object williamr@2: and leaves it on the cleanup stack. williamr@2: @return ASN1 DER sequence of this object. williamr@2: */ williamr@2: IMPORT_C CASN1EncSequence* EncodeASN1DERLC() const; williamr@2: williamr@2: private: williamr@2: CX509AlgorithmIdentifier(); williamr@2: CX509AlgorithmIdentifier(TAlgorithmId& aAlgorithmId); williamr@2: void InitializeL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: }; williamr@2: williamr@2: class CX509SigningAlgorithmIdentifier : public CSigningAlgorithmIdentifier williamr@2: /** Encapsulates the IDs of the algorithms used for signing an X.509 certificate. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: * @since v6.0 */ williamr@2: { williamr@2: public: williamr@2: /** Creates a new X.509 signing algorithm Id object from the specified buffer containing williamr@2: * the binary coded representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new signing algorithm Id object. */ williamr@2: IMPORT_C static CX509SigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new X.509 signing algorithm Id object from the specified buffer containing williamr@2: * the binary coded representation, and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new signing algorithm Id object. */ williamr@2: IMPORT_C static CX509SigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new X.509 signing algorithm Id object from the specified buffer containing williamr@2: * the binary coded representation, starting at the specified offset. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The new signing algorithm Id object. */ williamr@2: IMPORT_C static CX509SigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** Creates a new X.509 signing algorithm Id object from the specified buffer containing williamr@2: * the binary coded representation,starting at the specified offset, and puts williamr@2: * a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The new signing algorithm Id object. */ williamr@2: IMPORT_C static CX509SigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos); williamr@2: /** Creates a new X.509 signing algorithm Id object from the specified algorithm pair williamr@2: * williamr@2: * @param aAsymmetricAlgorithm The asymmetric algorithm williamr@2: * @param aDigestAlgorithm The digest algorithm williamr@2: * @return The new signing algorithm Id object. */ williamr@2: IMPORT_C static CX509SigningAlgorithmIdentifier* NewL(const CAlgorithmIdentifier& aAsymmetricAlgorithm, const CAlgorithmIdentifier& aDigestAlgorithm); williamr@2: /** Creates a new X.509 signing algorithm Id object from the specified algorithm pair williamr@2: * williamr@2: * @param aAsymmetricAlgorithm The asymmetric algorithm williamr@2: * @param aDigestAlgorithm The digest algorithm williamr@2: * @return The new signing algorithm Id object. */ williamr@2: IMPORT_C static CX509SigningAlgorithmIdentifier* NewLC(const CAlgorithmIdentifier& aAsymmetricAlgorithm, const CAlgorithmIdentifier& aDigestAlgorithm); williamr@2: private: williamr@2: CX509SigningAlgorithmIdentifier(); williamr@2: void ConstructL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: void ConstructL(const CAlgorithmIdentifier& aAsymmetricAlgorithm, const CAlgorithmIdentifier& aDigestAlgorithm); williamr@2: }; williamr@2: williamr@2: class CX509SubjectPublicKeyInfo : public CSubjectPublicKeyInfo williamr@2: /** X.509 subject public key information. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: * @since v6.0 */ williamr@2: { williamr@2: public: williamr@2: /** Creates a new X.509 subject public key object from the specified buffer containing williamr@2: * the binary coded representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new subject public key object. */ williamr@2: IMPORT_C static CX509SubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new X.509 subject public key object from the specified buffer containing williamr@2: * the binary coded representation, and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new subject public key object. */ williamr@2: IMPORT_C static CX509SubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new X.509 subject public key object from the specified buffer containing williamr@2: * the binary coded representation, starting at the specified offset. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The subject public key object. */ williamr@2: IMPORT_C static CX509SubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** Creates a new X.509 subject public key object from the specified buffer containing williamr@2: * the binary coded representation, starting at the specified offset, and puts williamr@2: * a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The new subject public key object. */ williamr@2: IMPORT_C static CX509SubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData, TInt& aPos); williamr@2: private: williamr@2: CX509SubjectPublicKeyInfo(); williamr@2: void ConstructL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: }; williamr@2: williamr@2: class CX509CertExtension : public CBase williamr@2: /** A generic X.509 certificate extension. williamr@2: * williamr@2: * The creation of a generic extension is the first step in the creation of a williamr@2: * specific extension. Client code gets the decoded Object Identifier (OID) encapsulated williamr@2: * by an instance of this class and uses it to create the specific extension. williamr@2: * williamr@2: * Consists of an any-defined-by structure along with a boolean flag saying whether williamr@2: * the extension is critical or not. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: * @since v6.0 */ williamr@2: { williamr@2: public: williamr@2: /** Creates a new generic X.509 certificate extension object from an existing object. williamr@2: * williamr@2: * This is equivalent to a copy constructor. williamr@2: * williamr@2: * @param aExtension The generic certificate extension to be copied. williamr@2: * @return The new generic certificate extension object. */ williamr@2: IMPORT_C static CX509CertExtension* NewL(const CX509CertExtension& aExtension); williamr@2: williamr@2: /** Creates a new generic X.509 certificate extension object from an existing object, williamr@2: * and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * This is equivalent to a copy constructor. williamr@2: * williamr@2: * @param aExtension The generic certificate extension to be copied. williamr@2: * @return The new generic X.509 certificate extension object. */ williamr@2: IMPORT_C static CX509CertExtension* NewLC(const CX509CertExtension& aExtension); williamr@2: williamr@2: /** Creates a new generic X.509 certificate extension object from the specified williamr@2: * buffer containing the binary coded representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new generic X.509 certificate extension object. */ williamr@2: IMPORT_C static CX509CertExtension* NewL(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new generic X.509 certificate extension object from the specified williamr@2: * buffer containing the binary coded representation, and puts a pointer to it williamr@2: * onto the cleanup stack . williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new generic X.509 certificate extension object. */ williamr@2: IMPORT_C static CX509CertExtension* NewLC(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new generic X.509 certificate extension object from the specified williamr@2: * buffer containing the binary coded representation, starting at the specified offset. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The new generic X.509 certificate extension object. */ williamr@2: IMPORT_C static CX509CertExtension* NewL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** Creates a new generic X.509 certificate extension object from the specified williamr@2: * buffer containing the binary coded representation, starting at the specified williamr@2: * offset, and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The new generic X.509 certificate extension object. */ williamr@2: IMPORT_C static CX509CertExtension* NewLC(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** Creates a new generic X.509 certificate extension object from the specified williamr@2: * extension object id, the critcal flag and the extension data. williamr@2: * williamr@2: * @param aCertExtOID The OID of the certficate extension. williamr@2: * @param aCritical Flag to convey criticality of the extension. williamr@2: * @param aCertExtValue The data of the specific extension. williamr@2: * @return The new generic X.509 certificate extension object. */ williamr@2: IMPORT_C static CX509CertExtension* NewL(const TDesC& aCertExtOID, williamr@2: const TBool aCritical, williamr@2: const TDesC8& aCertExtValue); williamr@2: williamr@2: /** Creates a new generic X.509 certificate extension object from the specified williamr@2: * extension object id, the critcal flag and the extension data, and puts a williamr@2: * pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aCertExtOID The OID of the certficate extension. williamr@2: * @param aCritical Flag to convey criticality of the extension. williamr@2: * @param aCertExtValue The data of the specific extension. williamr@2: * @return The new generic X.509 certificate extension object. */ williamr@2: IMPORT_C static CX509CertExtension* NewLC(const TDesC& aCertExtOID, williamr@2: const TBool aCritical, williamr@2: const TDesC8& aCertExtValue); williamr@2: williamr@2: /** Destructor. williamr@2: * williamr@2: * Frees all resources owned by the object, prior to its destruction. */ williamr@2: IMPORT_C ~CX509CertExtension(); williamr@2: williamr@2: /** Tests whether certificate processing code must process this extension for certificate williamr@2: * validation to succeed. williamr@2: * williamr@2: * @return ETrue, if this extension must be processed for validation to succeed; williamr@2: * EFalse, otherwise. */ williamr@2: IMPORT_C TBool Critical() const; williamr@2: williamr@2: /** Gets the Object Identifier (OID) of the certficate extension. williamr@2: * williamr@2: * @return The OID of the certficate extension. */ williamr@2: IMPORT_C TPtrC Id() const; //OID for the extension williamr@2: williamr@2: /** Gets the encoded binary representation of the specific extension. williamr@2: * williamr@2: * @return A pointer descriptor representing the specific extension. */ williamr@2: IMPORT_C TPtrC8 Data() const; //the extension itself williamr@2: williamr@2: /** Creates and returns a DER encoded X.509 certificate extension object in the form williamr@2: * of a ASN.1 Sequence and puts it onto the cleanup stack. This method can be called williamr@2: * repeatedly to get copies of the sequence. williamr@2: * williamr@2: * @return A pointer to a DER encoded ASN.1 sequence */ williamr@2: IMPORT_C CASN1EncSequence * EncodeASN1DERLC() const; williamr@2: williamr@2: private: williamr@2: CX509CertExtension(); williamr@2: void ConstructL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: void ConstructL(const CX509CertExtension& aExtension); williamr@2: void ConstructL(const TDesC& aCertExtOID, williamr@2: const TBool aCritical, williamr@2: const TDesC8& aCertExtValue); williamr@2: HBufC* iId; williamr@2: TBool iCritical; williamr@2: HBufC8* iData; williamr@2: }; williamr@2: williamr@2: class CX509Certificate : public CCertificate williamr@2: /** An X.509 certificate. williamr@2: * williamr@2: * @publishedAll williamr@2: * @released williamr@2: * @since v6.0 */ williamr@2: { williamr@2: public: williamr@2: /** Enumerates values for encoded data element positions in the TBSCertificate data structure. williamr@2: * williamr@2: * These values are to be used as parameters to the DataElementEncoding() function. */ williamr@2: enum williamr@2: { williamr@2: EVersionNumber = 0, //optional - may be NULL williamr@2: ESerialNumber = 1, williamr@2: EAlgorithmId = 2, williamr@2: EIssuerName = 3, williamr@2: EValidityPeriod = 4, williamr@2: ESubjectName = 5, williamr@2: ESubjectPublicKeyInfo = 6, williamr@2: EIssuerUID = 7, //optional - may be NULL williamr@2: ESubjectUID = 8, //optional - may be NULL williamr@2: EExtensionList = 9 //optional - may be NULL williamr@2: }; williamr@2: williamr@2: /** Creates a new X.509 certificate object from the specified buffer containing williamr@2: * the binary coded representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new X.509 certificate object. */ williamr@2: IMPORT_C static CX509Certificate* NewL(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new X.509 certificate object from the specified buffer containing williamr@2: * the binary coded representation, and puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * Initialises the object from its encoded binary form into an internal representation. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @return The new X.509 certificate object. */ williamr@2: IMPORT_C static CX509Certificate* NewLC(const TDesC8& aBinaryData); williamr@2: williamr@2: /** Creates a new X.509 certificate object from the specified buffer containing williamr@2: * the binary coded representation, starting at the specified offset. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The new X.509 certificate object. */ williamr@2: IMPORT_C static CX509Certificate* NewL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** Creates a new X.509 certificate object from the specified buffer containing williamr@2: * the binary coded representation, starting at the specified offset, and puts williamr@2: * a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * @param aBinaryData The encoded binary representation. williamr@2: * @param aPos The offset position from which to start decoding. williamr@2: * @return The new X.509 certificate object. */ williamr@2: IMPORT_C static CX509Certificate* NewLC(const TDesC8& aBinaryData, TInt& aPos); williamr@2: williamr@2: /** Creates a new X.509 certificate object from the specified read stream. williamr@2: * williamr@2: * @param aStream Stream from which the contents should be internalised. williamr@2: * @return The new X.509 certificate object. */ williamr@2: IMPORT_C static CX509Certificate* NewL(RReadStream& aStream); williamr@2: williamr@2: /** Creates a new X.509 certificate object from the specified read stream, and williamr@2: * puts a pointer to it onto the cleanup stack. williamr@2: * williamr@2: * Construction is from the stream. williamr@2: * williamr@2: * @param aStream Stream from which the contents should be internalised. williamr@2: * @return The new X.509 certificate object. */ williamr@2: IMPORT_C static CX509Certificate* NewLC(RReadStream& aStream); williamr@2: williamr@2: /** Creates a new X.509 certificate object from an existing object. williamr@2: * williamr@2: * This is equivalent to a copy constructor. williamr@2: * williamr@2: * @param aCert The X.509 certificate to be copied. williamr@2: * @return The new X.509 certificate object. */ williamr@2: IMPORT_C static CX509Certificate* NewL(const CX509Certificate& aCert); williamr@2: williamr@2: /** Creates a new X.509 certificate object from an existing object. williamr@2: * williamr@2: * This is equivalent to a copy constructor. williamr@2: * williamr@2: * @param aCert The X.509 certificate to be copied. williamr@2: * @return The new X.509 certificate object. */ williamr@2: IMPORT_C static CX509Certificate* NewLC(const CX509Certificate& aCert); williamr@2: williamr@2: /** Destructor. williamr@2: * williamr@2: * Frees all resources owned by the object, prior to its destruction. */ williamr@2: IMPORT_C ~CX509Certificate(); williamr@2: williamr@2: /** Tests whether the specified X.509 certificate is equal to this X.509 certificate. williamr@2: * williamr@2: * X.509 certificates are equal if both the serial number and the issuer name williamr@2: * are the same. williamr@2: * williamr@2: * @param aCert The X.509 certificate to be compared. williamr@2: * @return ETrue, if the certificates are equal;EFalse, otherwise. */ williamr@2: IMPORT_C TBool IsEqualL(const CX509Certificate& aCert) const; williamr@2: williamr@2: //extra accessors williamr@2: /** Gets the certificate's signed data. williamr@2: * williamr@2: * @return A non-modifiable pointer descriptor representing the certificate's williamr@2: * signed data. */ williamr@2: IMPORT_C const TPtrC8 SignedDataL() const; williamr@2: williamr@2: /** Gets the version number of the certificate. williamr@2: * williamr@2: * @return The version number of the certificate. */ williamr@2: IMPORT_C TInt Version() const; williamr@2: williamr@2: /** Gets the X.500 Distinguished Name that identifies the issuer. williamr@2: * williamr@2: * @return The X.500 Distinguished Name that identifies the issuer. */ williamr@2: IMPORT_C const CX500DistinguishedName& IssuerName() const; williamr@2: williamr@2: /** Gets the X.500 Distinguished Name that identifies the subject. williamr@2: * williamr@2: * @return The X.500 Distinguished Name that identifies the subject. */ williamr@2: IMPORT_C const CX500DistinguishedName& SubjectName() const; williamr@2: williamr@2: //return all your generic extensions williamr@2: /** Gets all generic certificate extensions. williamr@2: * williamr@2: * @return The certificate extensions. */ williamr@2: IMPORT_C const CArrayPtrFlat& Extensions() const; williamr@2: williamr@2: //return a particular extension: this is NOT OWNED by the client williamr@2: //returns NULL if the ext is not found williamr@2: /** Gets the certificate extension identified by the specified object identifier (OID). williamr@2: * williamr@2: * @param aExtensionName The OID identifying the extension. williamr@2: * @return The certificate extension: Note that ownership is not transferred to williamr@2: * the caller. */ williamr@2: IMPORT_C const CX509CertExtension* Extension(const TDesC& aExtensionName) const; williamr@2: williamr@2: /** Internalises an object of this class from a read stream. williamr@2: * williamr@2: * The presence of this function means that the standard templated operator>>() williamr@2: * can be used to internalise objects of this class. williamr@2: * williamr@2: * Note that the function has assignment semantics. It replaces the old value williamr@2: * of the object with a new value read from the read stream. williamr@2: * williamr@2: * @param aStream Stream from which the object is to be internalised. */ williamr@2: IMPORT_C void InternalizeL(RReadStream& aStream); williamr@2: williamr@2: //return the encoding for a data element at the index specified williamr@2: /** Gets the encoded data for the specified encoded data element (in the To Be williamr@2: * Signed (TBS) certificate data structure) of the signed object. williamr@2: * williamr@2: * @param aIndex The encoded data element position in the TBSCertificate data williamr@2: * structure. (See the CX509Certificate enumeration.) williamr@2: * @return The encoded data for the specified data element of the signed object. williamr@2: * @since v7.0 */ williamr@2: IMPORT_C virtual const TPtrC8* DataElementEncoding(const TUint aIndex) const; williamr@2: williamr@2: public: // from CCertificate williamr@2: /** Gets the issuer of the certificate. williamr@2: * williamr@2: * @return A heap descriptor representing the issuer of the certificate. */ williamr@2: IMPORT_C HBufC* IssuerL() const; williamr@2: williamr@2: /** Gets the subject of the certificate. williamr@2: * williamr@2: * @return A heap descriptor representing the issuer of the certificate. */ williamr@2: IMPORT_C HBufC* SubjectL() const; williamr@2: williamr@2: /** Tests whether the certificate is self-signed. williamr@2: * williamr@2: * @return ETrue, if it is self-signed; EFalse, otherwise. */ williamr@2: IMPORT_C TBool IsSelfSignedL() const; williamr@2: williamr@2: /** Gets a key identifier for the certificate. This is a unique identifier, calculated according williamr@2: * to the recommended method of computing it from RFC3280, section 4.2.1.2. Please note that this williamr@2: * method does NOT return the value of the Subject Key Id extension, if it is present. williamr@2: * williamr@2: * @return A unique key identifier for the certificate. */ williamr@2: IMPORT_C TKeyIdentifier KeyIdentifierL() const; williamr@2: williamr@2: /** Gets the subject key identifier for the certificate. This identifier is extracted from the williamr@2: * certificate (if the corresponding extension exists), or calculated (if the extension doesn't exist). If calculated, the recommendation from williamr@2: * section 4.2.1.2, RFC3280 is used (hash of the public key). Please note, that for subject key ids williamr@2: * extracted from the certificate there is a length limit - if the extension is longer than 160 bits, williamr@2: * it is ignored and the value is calculated instead. williamr@2: * williamr@2: * @return The subject key identifier for the certificate. */ williamr@2: IMPORT_C TKeyIdentifier SubjectKeyIdentifierL() const; williamr@2: williamr@2: private: williamr@2: CX509Certificate(); williamr@2: void ConstructL(const TDesC8& aBinaryData, TInt& aPos); williamr@2: void ConstructL(const CX509Certificate& aCertificate); williamr@2: void ConstructCertL(); williamr@2: void InitDataElementsL(const CX509Certificate& aCertificate); williamr@2: HBufC8* DecodeUidL(const TDesC8& aBinaryData, TBool& aHasElementAlready); williamr@2: void DecodeExtsL(const TDesC8& aBinaryData, TBool& aHasElementAlready); williamr@2: //private data williamr@2: TInt iVersion; williamr@2: CX500DistinguishedName* iIssuerName; williamr@2: CX500DistinguishedName* iSubjectName; williamr@2: HBufC8* iIssuerUid; williamr@2: HBufC8* iSubjectUid; williamr@2: CArrayPtrFlat* iExtensions; williamr@2: TFixedArray* iDataElements; williamr@2: }; williamr@2: williamr@2: #endif