First public contribution.
2 * Copyright (c) 2002-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.
15 * Declares classes for producing PKCS#10 certificate requests.
31 #include <mctkeystore.h>
34 class CX500DistinguishedName;
36 class CPKCS10Attributes;
37 class CPKCS10KeyHelper;
39 class TX509KeyEncoder;
42 * Class for making PKCS#10 Certificate Request objects.
44 * Keys are specified by a cryptotokens key info object - this means that this
45 * API can only be used to generate cert requests for keys that are held in a
46 * keystore on the device.
49 class CPKCS10Request : public CActive
53 * Creates a new PKCS#10 request object.
55 * @param aDN X500 distinguished name of the entity provided by caller.
56 * Stored in iDN member variable. Ownership is not transferred.
57 * @param aKeyInfo The key info object of the key to sign the request with.
58 * Does not take ownership.
59 * @param aAttr (Optional) The PKCS10 attributes to include in the request.
61 * @return A pointer to the newly allocated object.
63 IMPORT_C static CPKCS10Request* NewL(const CX500DistinguishedName& aDN,
64 const CCTKeyInfo& aKeyInfo,
65 CPKCS10Attributes* aAttr = NULL);
68 * Creates a new PKCS#10 request object.
70 * @param aDN X500 distinguished name of the entity provided by caller.
71 * Stored in iDN member variable. Ownership is not transferred.
72 * @param aKeyInfo The key info object of the key to sign the request with.
73 * Does not take ownership.
74 * @param aAttr (Optional) The PKCS10 attributes to include in the request.
76 * @return A pointer to the newly allocated object that is left on the
79 IMPORT_C static CPKCS10Request* NewLC(const CX500DistinguishedName& aDN,
80 const CCTKeyInfo& aKeyInfo,
81 CPKCS10Attributes* aAttr = NULL);
84 * Destructs PKCS#10 object, deletes encoding buffer and attributes.
86 IMPORT_C virtual ~CPKCS10Request();
91 * Set the attributes to be encoded in the request. It replaces existing
93 * @param aAttr The attributes - this object takes ownership.
95 IMPORT_C void SetAttributes(CPKCS10Attributes* aAttr);
98 * Set the digest algorithm to use when signing the request. If this method
99 * is not called, the default SHA-1 is used.
101 * @param aDigest For RSA keys, one of EMD2, EMD5 or ESHA1.
102 * For DSA keys, ESHA1 is the only permitted value.
103 * @leave KErrArgument if the specified algorithm is not supported.
105 IMPORT_C void SetDigestAlgL(TAlgorithmId aDigest);
108 * Set the distinguished name of the entity. It replaces existing
110 * @param aDN X500 distinguished name of the entity provided by caller.
111 * Stored in iDN member variable. Ownership is not transferred.
113 IMPORT_C void SetDistinguishedNameL(const CX500DistinguishedName& aDN);
116 * Set the information of the key to sign with. It replaces existing
118 * @param aKeyInfo The key info object of the key to sign the request with.
119 * Does not take ownership.
121 IMPORT_C void SetKeyInfoL(const CCTKeyInfo& aKeyInfo);
124 * Create the ASN.1 DER encoding of the certificate request. This is an
125 * asynchronous method. The Cancel() method can be called to cancel an
126 * outstanding request. This method can be called repeatedly to create
127 * certificate requests after setting the various parameters. However an
128 * outstanding request must complete or be cancelled before calling this
132 * @param aResult On successful completion, this points to a newly
133 * allocated buffer containing the encoded certificate request.
134 * @param aStatus Asynchronous status notification
136 IMPORT_C void CreateEncoding(HBufC8*& aResult, TRequestStatus& aStatus);
141 virtual TInt RunError(TInt aErr);
142 virtual void DoCancel();
155 /** Private constructor that initializes essential member variables. */
156 CPKCS10Request(const CX500DistinguishedName* aDN,
157 const CCTKeyInfo* aKeyInfo,
158 CPKCS10Attributes* aAttr);
160 // Methods making ASN.1 encoding objects
163 * Performs the actual ASN.1 encoding of the request without signing it.
164 * certRequestInfo is what gets signed with private key.
165 * @return Pointer to a newly allocated CASN1EncSequence object.
167 CASN1EncSequence* MakeCertRequestInfoEncLC();
170 * Encodes desired certificate attributes into ASN1. Takes whatever
171 * attributes are in the iAttributes and adds them below a
172 * sequence. If there are no attributes stored, leaves the set empty.
174 * The structure of the attribute node is as follows:
176 * Context-specific[0]
178 * OID of the organization
180 * SEQUENCE-OF (stored in iAttributes)
189 * @return Pointer to a newly allocated encoding object containing
190 * desired certificate attributes.
192 CASN1EncBase* MakeAttrEncLC();
195 * Generates data to be signed.
197 void EncodeTBSDataL();
199 void CreateFinalEncodingL();
204 const CX500DistinguishedName* iDN;
205 const CCTKeyInfo* iKeyInfo;
206 CPKCS10Attributes* iAttributes;
207 TAlgorithmId iDigestId;
208 TRequestStatus* iClientStatus;
211 MCTKeyStore* iKeyStore;
212 CPKCS10KeyHelper* iKeyHelper;
213 HBufC8* iExportedKey;