First public contribution.
2 * Copyright (c) 1997-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 __WTLSCERT_H__
26 #define __WTLSCERT_H__
32 #include <unifiedcertstore.h>
33 #include <wtlsnames.h>
41 const TInt KWTLSCertMaxDataElements = 6;
43 class CWTLSRSASignatureResult : public CRSASignatureResult
46 IMPORT_C static CWTLSRSASignatureResult* NewL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
47 IMPORT_C static CWTLSRSASignatureResult* NewLC(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
48 IMPORT_C virtual TBool VerifyL(const TDesC8& aResult);
50 void ConstructL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
53 class TWTLSKeyFactory : public TKeyFactory
56 virtual CRSAPublicKey* RSAPublicKeyL(const TDesC8& aEncoding) const;
57 virtual CRSASignatureResult* RSASignatureResultL(const CAlgorithmIdentifier& aDigestAlgorithm, TDesC8& aDigest) const;
58 virtual CDSAPublicKey* DSAPublicKeyL(const CDSAParameters& aParams, const TDesC8& aEncoding) const;
59 virtual CDSASignature* DSASignatureL(const TDesC8& aEncoding) const;
60 virtual CDSAParameters* DSAParametersL(const TDesC8& aEncoding) const;
61 virtual CDSAPublicKey* DSAPublicKeyL(const TDesC8& aParamsEncoding, const TDesC8& aEncoding) const;
64 class CWTLSValidityPeriod : public CValidityPeriod
67 IMPORT_C static CWTLSValidityPeriod* NewL(const TDesC8& aBinaryData);
68 IMPORT_C static CWTLSValidityPeriod* NewLC(const TDesC8& aBinaryData);
69 IMPORT_C static CWTLSValidityPeriod* NewL(const TDesC8& aBinaryData, TInt& aPos);
70 IMPORT_C static CWTLSValidityPeriod* NewLC(const TDesC8& aBinaryData, TInt& aPos);
72 CWTLSValidityPeriod();
73 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
76 class CWTLSAlgorithmIdentifier : public CAlgorithmIdentifier
79 IMPORT_C static CWTLSAlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
80 IMPORT_C static CWTLSAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
81 IMPORT_C static CWTLSAlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
82 IMPORT_C static CWTLSAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
84 CWTLSAlgorithmIdentifier();
85 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
88 class CWTLSSigningAlgorithmIdentifier : public CSigningAlgorithmIdentifier
91 IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
92 IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
93 IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
94 IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
96 CWTLSSigningAlgorithmIdentifier();
97 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
100 class CWTLSSubjectPublicKeyInfo : public CSubjectPublicKeyInfo
103 IMPORT_C static CWTLSSubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData);
104 IMPORT_C static CWTLSSubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData);
105 IMPORT_C static CWTLSSubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData, TInt& aPos);
106 IMPORT_C static CWTLSSubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData, TInt& aPos);
108 CWTLSSubjectPublicKeyInfo();
109 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
112 _LIT(KWTLSTCAType, " T");
113 _LIT(KWTLSTCAValue, "ca");
115 class CWTLSCertificate : public CCertificate
118 enum //enum values for encoded data element positions in tbsCert data structure
119 { //these values are to be used as params to DataElementEncoding() function
125 ESubjectPublicKeyInfo = 5,
129 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation.
131 * @param aBinaryData The encoded binary representation.
132 * @return The new CWTLSCertificate object.
134 IMPORT_C static CWTLSCertificate* NewL(const TDesC8& aBinaryData);
137 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation,
138 * and puts a pointer to it onto the cleanup stack.
140 * @param aBinaryData The encoded binary representation.
141 * @return The new CWTLSCertificate object.
143 IMPORT_C static CWTLSCertificate* NewLC(const TDesC8& aBinaryData);
146 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation.
148 * @param aBinaryData The encoded binary representation.
149 * @param aPos An offset into the descriptor, and is updated to the position at the end of the object.
150 * @return The new CWTLSCertificate object.
152 IMPORT_C static CWTLSCertificate* NewL(const TDesC8& aBinaryData, TInt& aPos);
155 * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation,
156 * and puts a pointer to it onto the cleanup stack.
158 * @param aBinaryData The encoded binary representation.
159 * @param aPos An offset into the descriptor, and is updated to the position at the end of the object.
160 * @return The new CWTLSCertificate object.
162 IMPORT_C static CWTLSCertificate* NewLC(const TDesC8& aBinaryData, TInt& aPos);
165 * Creates a new CWTLSCertificate object from a stream.
167 * The stream must have been written using the corresponding ExternalizeL() function.
169 * @param aStream The stream to be used as input.
170 * @return The new CWTLSCertificate object.
172 IMPORT_C static CWTLSCertificate* NewL(RReadStream& aStream);
175 * Creates a new CWTLSCertificate object from a stream,
176 * and puts a pointer to it onto the cleanup stack.
178 * The stream must have been written using the corresponding ExternalizeL() function.
180 * @param aStream The stream to be used as input.
181 * @return The new CWTLSCertificate object.
183 IMPORT_C static CWTLSCertificate* NewLC(RReadStream& aStream);
186 * Creates a new CWTLSCertificate object from an existing one in the certificate store.
188 * @param aCert The certificate to be copied.
189 * @return The new CWTLSCertificate object.
191 IMPORT_C static CWTLSCertificate* NewL(const CWTLSCertificate& aCert);
194 * Creates a new CWTLSCertificate object from an existing one in the certificate store,
195 * and puts a pointer to it onto the cleanup stack.
197 * @param aCert The certificate to be copied.
198 * @return The new CWTLSCertificate object.
200 IMPORT_C static CWTLSCertificate* NewLC(const CWTLSCertificate& aCert);
205 * Frees all resources owned by the object, prior to its destruction.
207 IMPORT_C ~CWTLSCertificate();
210 * Tests whether this WTLS certificate is the same as the specified WTLS certificate.
212 * This is not a simple as it sounds. For X.509 certificates equality means that the issuer name
213 * and serial number fields are the same. This guarantees equality since a CA must ensure that every
214 * certificate it issues has a unique serial number. But WTLS certificates do not include serial numbers,
215 * so there seems to be no definition of equality. This function uses a byte-for-byte comparison of the
216 * signatures on the certificates: this should not result in any false positives, but may give false
217 * negatives if CAs do naughty things like recertifying the same key (which they have been known to do).
219 * @param aCert A WTLS certificate
220 * @return ETrue, if the parameter is the same certificate; EFalse, otherwise.
222 IMPORT_C TBool IsEqualL(const CWTLSCertificate& aCert) const;
227 * Gets the version number of the WTLS certificate.
229 * @return The version number of the certificate. Always returns 1.
231 IMPORT_C TInt Version() const;
234 * Gets the name of the WTLS certificate's issuing authority.
236 * @return A WTLS name:
237 * @li If the name is an X.500 DN, then if the name contains a Common name, that will be returned.
238 * Otherwise, if the name contains an Organization name, that will be returned. Otherwise an empty
239 * string will be returned.
240 * @li If the name is of type text, then if the name is not a 'structured' name the entire string will
241 * be returned, otherwise the same procedure will be followed as for X.509 certificates.
242 * @li If the name is null an empty string will be returned.
244 // Unsupported -- If the name is a key hash or binary value the entire contents will be returned.
245 IMPORT_C const CWTLSName& IssuerName() const;
248 * Gets the name of the owner of the public key the WTLS certificate contains.
250 * @return A WTLS name.
252 IMPORT_C const CWTLSName& SubjectName() const;
253 IMPORT_C virtual TBool IsSelfSignedL() const;
254 IMPORT_C virtual HBufC* SubjectL() const;
255 IMPORT_C virtual HBufC* IssuerL() const;
258 * Initialises the certificate from a stream.
260 * This should not be called by client code; instead the static factory function above should be used.
261 * If a client is using the certstore component for storage then it should use CCertStore::AddL() for
262 * externalizing and CWTLSCert::NewL(CCertStore& aStore, const CCertStoreEntry& aEntry); for restoring.
266 IMPORT_C void InternalizeL(RReadStream& aStream);
269 * Gets the certificate's signed data.
271 * @return A non-modifiable pointer descriptor representing the certificate's signed data.
273 IMPORT_C const TPtrC8 SignedDataL() const;
276 * Gets the encoding for a data element at the specified index.
278 * @param aIndex The position of the encoded data element.
280 IMPORT_C virtual const TPtrC8* DataElementEncoding(const TUint aIndex) const;
283 * Tests whether a non-selfsigned certificate can be used to sign others.
285 * Currently this only supports structured text variety of WTLS certificates.
286 * Other certificate types will return EFalse.
288 * @return ETrue, if the certificate is capable of signing other certificates; otherwise, EFalse.
290 IMPORT_C TBool IsTCAL() const;
293 void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
294 void ConstructL(const CWTLSCertificate& aCertificate);
295 void ConstructCertL(const TDesC8& aBinaryData, TInt& aPos);
296 void InitEncodedDataElementsL();
299 CWTLSName* iIssuerName;
300 CWTLSName* iSubjectName;
301 TFixedArray<TPtrC8*, KWTLSCertMaxDataElements>* iDataElements;