author | William Roberts <williamr@symbian.org> |
Wed, 31 Mar 2010 12:27:01 +0100 | |
branch | Symbian2 |
changeset 3 | e1b950c65cb4 |
parent 0 | 061f57f2323e |
child 4 | 837f303aceeb |
permissions | -rw-r--r-- |
williamr@2 | 1 |
/* |
williamr@2 | 2 |
* Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
williamr@2 | 3 |
* All rights reserved. |
williamr@2 | 4 |
* This component and the accompanying materials are made available |
williamr@2 | 5 |
* under the terms of the License "Eclipse Public License v1.0" |
williamr@2 | 6 |
* which accompanies this distribution, and is available |
williamr@2 | 7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html". |
williamr@2 | 8 |
* |
williamr@2 | 9 |
* Initial Contributors: |
williamr@2 | 10 |
* Nokia Corporation - initial contribution. |
williamr@2 | 11 |
* |
williamr@2 | 12 |
* Contributors: |
williamr@2 | 13 |
* |
williamr@2 | 14 |
* Description: |
williamr@2 | 15 |
* X509 certificate chain and the validation status implementations |
williamr@2 | 16 |
* |
williamr@2 | 17 |
*/ |
williamr@2 | 18 |
|
williamr@2 | 19 |
|
williamr@2 | 20 |
|
williamr@2 | 21 |
|
williamr@2 | 22 |
/** |
williamr@2 | 23 |
@file |
williamr@2 | 24 |
@publishedAll |
williamr@2 | 25 |
@released |
williamr@2 | 26 |
*/ |
williamr@2 | 27 |
|
williamr@2 | 28 |
#ifndef __X509CERTCHAIN_H__ |
williamr@2 | 29 |
#define __X509CERTCHAIN_H__ |
williamr@2 | 30 |
|
williamr@2 | 31 |
#include <e32std.h> |
williamr@2 | 32 |
#include <x509cert.h> |
williamr@2 | 33 |
#include <ct.h> |
williamr@2 | 34 |
|
williamr@2 | 35 |
class TValidationStatus |
williamr@2 | 36 |
/** The validation status. |
williamr@2 | 37 |
* |
williamr@2 | 38 |
* Some errors cannot be blamed on any single certificate, in which case the |
williamr@2 | 39 |
* iCert value is meaningless. The same structure is used for errors and for |
williamr@2 | 40 |
* warnings. |
williamr@2 | 41 |
* |
williamr@2 | 42 |
* @publishedAll |
williamr@2 | 43 |
* @released |
williamr@2 | 44 |
* @since v6.0 */ |
williamr@2 | 45 |
{ |
williamr@2 | 46 |
public: |
williamr@2 | 47 |
/** Creates a validation status object. |
williamr@2 | 48 |
* |
williamr@2 | 49 |
* @param aError The error type that occurred when validating the certificate chain. |
williamr@2 | 50 |
* @param aCert The index number identifying the certificate that gave rise to |
williamr@2 | 51 |
* the error. */ |
williamr@2 | 52 |
IMPORT_C TValidationStatus(const TValidationError aError, const TInt aCert); |
williamr@2 | 53 |
|
williamr@2 | 54 |
/** The reason for the error. */ |
williamr@2 | 55 |
TValidationError iReason; |
williamr@2 | 56 |
|
williamr@2 | 57 |
/** The index number identifying the certificate that gave rise to the error. */ |
williamr@2 | 58 |
TInt iCert; |
williamr@2 | 59 |
}; |
williamr@2 | 60 |
|
williamr@2 | 61 |
class CX509CertChain : public CBase |
williamr@2 | 62 |
/** Abstract base class for X.509 certificate chain validation; |
williamr@2 | 63 |
* derive from this to suit your profile. |
williamr@2 | 64 |
* |
williamr@2 | 65 |
* @publishedAll |
williamr@2 | 66 |
* @released |
williamr@2 | 67 |
* @since v6.0 */ |
williamr@2 | 68 |
{ |
williamr@2 | 69 |
public: |
williamr@2 | 70 |
/** Gets the number of certificates in the chain. |
williamr@2 | 71 |
* |
williamr@2 | 72 |
* @return The number of certificates in the chain. */ |
williamr@2 | 73 |
IMPORT_C TInt Count() const; |
williamr@2 | 74 |
|
williamr@2 | 75 |
/** Gets the certificate identified by the specified index. |
williamr@2 | 76 |
* Note that Cert(Count()) corresponds to the root (if any) |
williamr@2 | 77 |
* whilst Cert(0) corresponds to the outmost certificate in the chain. |
williamr@2 | 78 |
* |
williamr@2 | 79 |
* @param aIndex The ordinal number representing the position of the certificate |
williamr@2 | 80 |
* within the chain. |
williamr@2 | 81 |
* @return The X.509 certificate at the specified index. */ |
williamr@2 | 82 |
IMPORT_C const CX509Certificate& Cert(TInt aIndex) const; |
williamr@2 | 83 |
|
williamr@2 | 84 |
/** Decodes the individual elements of the signed data to construct the certificates. |
williamr@2 | 85 |
* |
williamr@2 | 86 |
* @param aBinaryData The encoded binary representation. |
williamr@2 | 87 |
* @return The certificate objects. */ |
williamr@2 | 88 |
IMPORT_C CArrayPtrFlat<CX509Certificate>* CX509CertChain::DecodeCertsL(const TDesC8& aBinaryData); |
williamr@2 | 89 |
|
williamr@2 | 90 |
/** Destructor. |
williamr@2 | 91 |
* |
williamr@2 | 92 |
* Frees all resources owned by the object, prior to its destruction. */ |
williamr@2 | 93 |
IMPORT_C ~CX509CertChain(); |
williamr@2 | 94 |
|
williamr@2 | 95 |
/** Tests whether the specified X.509 certificate chain is equal to this X.509 |
williamr@2 | 96 |
* certificate chain. |
williamr@2 | 97 |
* |
williamr@2 | 98 |
* @param aOther The X.509 certificate chain to be compared. |
williamr@2 | 99 |
* @return ETrue, if the certificate chains are equal;EFalse, otherwise. */ |
williamr@2 | 100 |
IMPORT_C TBool IsEqualL(const CX509CertChain& aOther) const; |
williamr@2 | 101 |
protected: |
williamr@2 | 102 |
//certificate chain |
williamr@2 | 103 |
CArrayPtrFlat<CX509Certificate>* iChain; |
williamr@2 | 104 |
private: |
williamr@2 | 105 |
static void CleanupCertArray(TAny* aArray); |
williamr@2 | 106 |
}; |
williamr@2 | 107 |
|
williamr@2 | 108 |
class CCertificateValidationWarnings : public CBase |
williamr@2 | 109 |
/** Encapsulates the critical extensions encountered and any warnings found |
williamr@2 | 110 |
* for a particular certificate in the chain during the process of validation. |
williamr@2 | 111 |
* |
williamr@2 | 112 |
* @publishedAll |
williamr@2 | 113 |
* @released |
williamr@2 | 114 |
* @since v9.5 */ |
williamr@2 | 115 |
{ |
williamr@2 | 116 |
public: |
williamr@2 | 117 |
/** Creates an instance of CCertificateValidationWarnings. |
williamr@2 | 118 |
* |
williamr@2 | 119 |
* @param aIndex The index of aCert in the certificate chain. |
williamr@2 | 120 |
* @return A pointer to the new CCertificateWarning object. */ |
williamr@2 | 121 |
IMPORT_C static CCertificateValidationWarnings* NewL(TInt aIndex); |
williamr@2 | 122 |
|
williamr@2 | 123 |
/** Creates an instance of CCertificateValidationWarnings. |
williamr@2 | 124 |
* |
williamr@2 | 125 |
* @param aIndex The index of aCert in the certificate chain. |
williamr@2 | 126 |
* @return A pointer to the new CCertificateWarning object. */ |
williamr@2 | 127 |
IMPORT_C static CCertificateValidationWarnings* NewLC(TInt aIndex); |
williamr@2 | 128 |
|
williamr@2 | 129 |
/** Gets a list of critical extension OIDs found in the certificate. |
williamr@2 | 130 |
* |
williamr@2 | 131 |
* @return An array of critical extensions found. */ |
williamr@2 | 132 |
IMPORT_C const RPointerArray<TDesC>& CriticalExtensionsFound() const; |
williamr@2 | 133 |
|
williamr@2 | 134 |
/** Gets a list of warnings generated by the certificate. |
williamr@2 | 135 |
* |
williamr@2 | 136 |
* @return An array of warnings generated. */ |
williamr@2 | 137 |
IMPORT_C const RArray<TValidationStatus>& Warnings() const; |
williamr@2 | 138 |
|
williamr@2 | 139 |
/** Gets the index of the certificate in the chain. |
williamr@2 | 140 |
* |
williamr@2 | 141 |
* @return The certificate index number. */ |
williamr@2 | 142 |
IMPORT_C TInt CertIndex() const; |
williamr@2 | 143 |
|
williamr@2 | 144 |
/** Externalises an object of this class to a write stream. |
williamr@2 | 145 |
* |
williamr@2 | 146 |
* The presence of this function means that the standard templated operator<<() |
williamr@2 | 147 |
* can be used to externalise objects of this class. |
williamr@2 | 148 |
* |
williamr@2 | 149 |
* @param aStream Stream to which the object should be externalised. */ |
williamr@2 | 150 |
IMPORT_C void ExternalizeL(RWriteStream& aStream) const; |
williamr@2 | 151 |
|
williamr@2 | 152 |
/** Internalises an object of this class from a read stream. |
williamr@2 | 153 |
* |
williamr@2 | 154 |
* The presence of this function means that the standard templated operator>>() |
williamr@2 | 155 |
* can be used to internalise objects of this class. |
williamr@2 | 156 |
* |
williamr@2 | 157 |
* Note that this function has assignment semantics: it replaces the old value |
williamr@2 | 158 |
* of the object with a new value read from the read stream. |
williamr@2 | 159 |
* |
williamr@2 | 160 |
* @param aStream Stream from which the object should be internalised. |
williamr@2 | 161 |
* @return A pointer to the new CCertificateWarning object. */ |
williamr@2 | 162 |
IMPORT_C static CCertificateValidationWarnings* InternalizeL(RReadStream& aStream); |
williamr@2 | 163 |
|
williamr@2 | 164 |
/** The destructor. |
williamr@2 | 165 |
* |
williamr@2 | 166 |
* Frees all resources owned by the object. */ |
williamr@2 | 167 |
IMPORT_C ~CCertificateValidationWarnings(); |
williamr@2 | 168 |
|
williamr@2 | 169 |
public: |
williamr@2 | 170 |
/** Adds a warning. |
williamr@2 | 171 |
* |
williamr@2 | 172 |
* @internalComponent |
williamr@2 | 173 |
* @released */ |
williamr@2 | 174 |
IMPORT_C void AppendWarningL(TValidationStatus aWarning); |
williamr@2 | 175 |
|
williamr@2 | 176 |
/** Adds a critical extension OID warning. |
williamr@2 | 177 |
* |
williamr@2 | 178 |
* @internalComponent |
williamr@2 | 179 |
* @released */ |
williamr@2 | 180 |
IMPORT_C void AppendCriticalExtensionWarningL(TDesC& aCriticalExt); |
williamr@2 | 181 |
|
williamr@2 | 182 |
private: |
williamr@2 | 183 |
CCertificateValidationWarnings(TInt aIndex); |
williamr@2 | 184 |
|
williamr@2 | 185 |
private: |
williamr@2 | 186 |
TInt iCertIndex; |
williamr@2 | 187 |
RPointerArray<TDesC> iCriticalExtsFound; |
williamr@2 | 188 |
RArray<TValidationStatus> iWarnings; |
williamr@2 | 189 |
}; |
williamr@2 | 190 |
|
williamr@2 | 191 |
#endif |