1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoservices/certificateandkeymgmt/inc/wtlscert.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,304 @@
1.4 +/*
1.5 +* Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @publishedAll
1.25 + @released
1.26 +*/
1.27 +
1.28 +#ifndef __WTLSCERT_H__
1.29 +#define __WTLSCERT_H__
1.30 +
1.31 +#include <e32base.h>
1.32 +#include <e32std.h>
1.33 +#include <s32std.h>
1.34 +#include <signed.h>
1.35 +#include <unifiedcertstore.h>
1.36 +#include <wtlsnames.h>
1.37 +
1.38 +
1.39 +class CRSAPublicKey;
1.40 +class CDSAPublicKey;
1.41 +class CDSASignature;
1.42 +class CDSAParameters;
1.43 +
1.44 +const TInt KWTLSCertMaxDataElements = 6;
1.45 +
1.46 +class CWTLSRSASignatureResult : public CRSASignatureResult
1.47 + {
1.48 +public:
1.49 + IMPORT_C static CWTLSRSASignatureResult* NewL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
1.50 + IMPORT_C static CWTLSRSASignatureResult* NewLC(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
1.51 + IMPORT_C virtual TBool VerifyL(const TDesC8& aResult);
1.52 +private:
1.53 + void ConstructL(const CAlgorithmIdentifier& aDigestAlgorithm, const TDesC8& aDigest);
1.54 + };
1.55 +
1.56 +class TWTLSKeyFactory : public TKeyFactory
1.57 + {
1.58 +public:
1.59 + virtual CRSAPublicKey* RSAPublicKeyL(const TDesC8& aEncoding) const;
1.60 + virtual CRSASignatureResult* RSASignatureResultL(const CAlgorithmIdentifier& aDigestAlgorithm, TDesC8& aDigest) const;
1.61 + virtual CDSAPublicKey* DSAPublicKeyL(const CDSAParameters& aParams, const TDesC8& aEncoding) const;
1.62 + virtual CDSASignature* DSASignatureL(const TDesC8& aEncoding) const;
1.63 + virtual CDSAParameters* DSAParametersL(const TDesC8& aEncoding) const;
1.64 + virtual CDSAPublicKey* DSAPublicKeyL(const TDesC8& aParamsEncoding, const TDesC8& aEncoding) const;
1.65 + };
1.66 +
1.67 +class CWTLSValidityPeriod : public CValidityPeriod
1.68 + {
1.69 +public:
1.70 + IMPORT_C static CWTLSValidityPeriod* NewL(const TDesC8& aBinaryData);
1.71 + IMPORT_C static CWTLSValidityPeriod* NewLC(const TDesC8& aBinaryData);
1.72 + IMPORT_C static CWTLSValidityPeriod* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.73 + IMPORT_C static CWTLSValidityPeriod* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.74 +private:
1.75 + CWTLSValidityPeriod();
1.76 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.77 + };
1.78 +
1.79 +class CWTLSAlgorithmIdentifier : public CAlgorithmIdentifier
1.80 + {
1.81 +public:
1.82 + IMPORT_C static CWTLSAlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
1.83 + IMPORT_C static CWTLSAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
1.84 + IMPORT_C static CWTLSAlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.85 + IMPORT_C static CWTLSAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.86 +private:
1.87 + CWTLSAlgorithmIdentifier();
1.88 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.89 + };
1.90 +
1.91 +class CWTLSSigningAlgorithmIdentifier : public CSigningAlgorithmIdentifier
1.92 + {
1.93 +public:
1.94 + IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData);
1.95 + IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData);
1.96 + IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.97 + IMPORT_C static CWTLSSigningAlgorithmIdentifier* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.98 +private:
1.99 + CWTLSSigningAlgorithmIdentifier();
1.100 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.101 + };
1.102 +
1.103 +class CWTLSSubjectPublicKeyInfo : public CSubjectPublicKeyInfo
1.104 + {
1.105 +public:
1.106 + IMPORT_C static CWTLSSubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData);
1.107 + IMPORT_C static CWTLSSubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData);
1.108 + IMPORT_C static CWTLSSubjectPublicKeyInfo* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.109 + IMPORT_C static CWTLSSubjectPublicKeyInfo* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.110 +private:
1.111 + CWTLSSubjectPublicKeyInfo();
1.112 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.113 + };
1.114 +
1.115 +_LIT(KWTLSTCAType, " T");
1.116 +_LIT(KWTLSTCAValue, "ca");
1.117 +
1.118 +class CWTLSCertificate : public CCertificate
1.119 + {
1.120 +public:
1.121 + enum //enum values for encoded data element positions in tbsCert data structure
1.122 + { //these values are to be used as params to DataElementEncoding() function
1.123 + EVersionNumber = 0,
1.124 + EAlgorithmId = 1,
1.125 + EIssuerName = 2,
1.126 + EValidityPeriod = 3,
1.127 + ESubjectName = 4,
1.128 + ESubjectPublicKeyInfo = 5,
1.129 + };
1.130 +
1.131 + /**
1.132 + * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation.
1.133 + *
1.134 + * @param aBinaryData The encoded binary representation.
1.135 + * @return The new CWTLSCertificate object.
1.136 + */
1.137 + IMPORT_C static CWTLSCertificate* NewL(const TDesC8& aBinaryData);
1.138 +
1.139 + /**
1.140 + * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation,
1.141 + * and puts a pointer to it onto the cleanup stack.
1.142 + *
1.143 + * @param aBinaryData The encoded binary representation.
1.144 + * @return The new CWTLSCertificate object.
1.145 + */
1.146 + IMPORT_C static CWTLSCertificate* NewLC(const TDesC8& aBinaryData);
1.147 +
1.148 + /**
1.149 + * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation.
1.150 + *
1.151 + * @param aBinaryData The encoded binary representation.
1.152 + * @param aPos An offset into the descriptor, and is updated to the position at the end of the object.
1.153 + * @return The new CWTLSCertificate object.
1.154 + */
1.155 + IMPORT_C static CWTLSCertificate* NewL(const TDesC8& aBinaryData, TInt& aPos);
1.156 +
1.157 + /**
1.158 + * Creates a new CWTLSCertificate object from the specified buffer containing the binary coded representation,
1.159 + * and puts a pointer to it onto the cleanup stack.
1.160 + *
1.161 + * @param aBinaryData The encoded binary representation.
1.162 + * @param aPos An offset into the descriptor, and is updated to the position at the end of the object.
1.163 + * @return The new CWTLSCertificate object.
1.164 + */
1.165 + IMPORT_C static CWTLSCertificate* NewLC(const TDesC8& aBinaryData, TInt& aPos);
1.166 +
1.167 + /**
1.168 + * Creates a new CWTLSCertificate object from a stream.
1.169 + *
1.170 + * The stream must have been written using the corresponding ExternalizeL() function.
1.171 + *
1.172 + * @param aStream The stream to be used as input.
1.173 + * @return The new CWTLSCertificate object.
1.174 + */
1.175 + IMPORT_C static CWTLSCertificate* NewL(RReadStream& aStream);
1.176 +
1.177 + /**
1.178 + * Creates a new CWTLSCertificate object from a stream,
1.179 + * and puts a pointer to it onto the cleanup stack.
1.180 + *
1.181 + * The stream must have been written using the corresponding ExternalizeL() function.
1.182 + *
1.183 + * @param aStream The stream to be used as input.
1.184 + * @return The new CWTLSCertificate object.
1.185 + */
1.186 + IMPORT_C static CWTLSCertificate* NewLC(RReadStream& aStream);
1.187 +
1.188 + /**
1.189 + * Creates a new CWTLSCertificate object from an existing one in the certificate store.
1.190 + *
1.191 + * @param aCert The certificate to be copied.
1.192 + * @return The new CWTLSCertificate object.
1.193 + */
1.194 + IMPORT_C static CWTLSCertificate* NewL(const CWTLSCertificate& aCert);
1.195 +
1.196 + /**
1.197 + * Creates a new CWTLSCertificate object from an existing one in the certificate store,
1.198 + * and puts a pointer to it onto the cleanup stack.
1.199 + *
1.200 + * @param aCert The certificate to be copied.
1.201 + * @return The new CWTLSCertificate object.
1.202 + */
1.203 + IMPORT_C static CWTLSCertificate* NewLC(const CWTLSCertificate& aCert);
1.204 +
1.205 + /**
1.206 + * Destructor.
1.207 + *
1.208 + * Frees all resources owned by the object, prior to its destruction.
1.209 + */
1.210 + IMPORT_C ~CWTLSCertificate();
1.211 +
1.212 + /**
1.213 + * Tests whether this WTLS certificate is the same as the specified WTLS certificate.
1.214 + *
1.215 + * This is not a simple as it sounds. For X.509 certificates equality means that the issuer name
1.216 + * and serial number fields are the same. This guarantees equality since a CA must ensure that every
1.217 + * certificate it issues has a unique serial number. But WTLS certificates do not include serial numbers,
1.218 + * so there seems to be no definition of equality. This function uses a byte-for-byte comparison of the
1.219 + * signatures on the certificates: this should not result in any false positives, but may give false
1.220 + * negatives if CAs do naughty things like recertifying the same key (which they have been known to do).
1.221 + *
1.222 + * @param aCert A WTLS certificate
1.223 + * @return ETrue, if the parameter is the same certificate; EFalse, otherwise.
1.224 + */
1.225 + IMPORT_C TBool IsEqualL(const CWTLSCertificate& aCert) const;
1.226 +
1.227 + //extra accessors
1.228 +
1.229 + /**
1.230 + * Gets the version number of the WTLS certificate.
1.231 + *
1.232 + * @return The version number of the certificate. Always returns 1.
1.233 + */
1.234 + IMPORT_C TInt Version() const;
1.235 +
1.236 + /**
1.237 + * Gets the name of the WTLS certificate's issuing authority.
1.238 + *
1.239 + * @return A WTLS name:
1.240 + * @li If the name is an X.500 DN, then if the name contains a Common name, that will be returned.
1.241 + * Otherwise, if the name contains an Organization name, that will be returned. Otherwise an empty
1.242 + * string will be returned.
1.243 + * @li If the name is of type text, then if the name is not a 'structured' name the entire string will
1.244 + * be returned, otherwise the same procedure will be followed as for X.509 certificates.
1.245 + * @li If the name is null an empty string will be returned.
1.246 + */
1.247 + // Unsupported -- If the name is a key hash or binary value the entire contents will be returned.
1.248 + IMPORT_C const CWTLSName& IssuerName() const;
1.249 +
1.250 + /**
1.251 + * Gets the name of the owner of the public key the WTLS certificate contains.
1.252 + *
1.253 + * @return A WTLS name.
1.254 + */
1.255 + IMPORT_C const CWTLSName& SubjectName() const;
1.256 + IMPORT_C virtual TBool IsSelfSignedL() const;
1.257 + IMPORT_C virtual HBufC* SubjectL() const;
1.258 + IMPORT_C virtual HBufC* IssuerL() const;
1.259 +
1.260 + /**
1.261 + * Initialises the certificate from a stream.
1.262 + *
1.263 + * This should not be called by client code; instead the static factory function above should be used.
1.264 + * If a client is using the certstore component for storage then it should use CCertStore::AddL() for
1.265 + * externalizing and CWTLSCert::NewL(CCertStore& aStore, const CCertStoreEntry& aEntry); for restoring.
1.266 + *
1.267 + * @param aStream
1.268 + */
1.269 + IMPORT_C void InternalizeL(RReadStream& aStream);
1.270 +
1.271 + /**
1.272 + * Gets the certificate's signed data.
1.273 + *
1.274 + * @return A non-modifiable pointer descriptor representing the certificate's signed data.
1.275 + */
1.276 + IMPORT_C const TPtrC8 SignedDataL() const;
1.277 +
1.278 + /**
1.279 + * Gets the encoding for a data element at the specified index.
1.280 + *
1.281 + * @param aIndex The position of the encoded data element.
1.282 + */
1.283 + IMPORT_C virtual const TPtrC8* DataElementEncoding(const TUint aIndex) const;
1.284 +
1.285 + /**
1.286 + * Tests whether a non-selfsigned certificate can be used to sign others.
1.287 + *
1.288 + * Currently this only supports structured text variety of WTLS certificates.
1.289 + * Other certificate types will return EFalse.
1.290 + *
1.291 + * @return ETrue, if the certificate is capable of signing other certificates; otherwise, EFalse.
1.292 + */
1.293 + IMPORT_C TBool IsTCAL() const;
1.294 +private:
1.295 + CWTLSCertificate();
1.296 + void ConstructL(const TDesC8& aBinaryData, TInt& aPos);
1.297 + void ConstructL(const CWTLSCertificate& aCertificate);
1.298 + void ConstructCertL(const TDesC8& aBinaryData, TInt& aPos);
1.299 + void InitEncodedDataElementsL();
1.300 + //private data
1.301 + TInt iVersion;
1.302 + CWTLSName* iIssuerName;
1.303 + CWTLSName* iSubjectName;
1.304 + TFixedArray<TPtrC8*, KWTLSCertMaxDataElements>* iDataElements;
1.305 + };
1.306 +
1.307 +#endif