|
1 /* |
|
2 * Copyright (c) 2003-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "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". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Header of class used to parse and validate a certificate or PKCS#12 PFX. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef CERTPARSER_H |
|
20 #define CERTPARSER_H |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <mpkcs12.h> |
|
25 |
|
26 // CONSTANTS |
|
27 const TInt KHashLength( 20 ); |
|
28 // CertSaver panic category |
|
29 _LIT( KCertSaverPanic, "Certificate saver" ); |
|
30 // Panic reasons |
|
31 const TInt KPanicNullPointer( 0 ); |
|
32 const TInt KErrWrongCryptoLib( 1 ); |
|
33 const TInt KErrExitApp( -333333 ); |
|
34 |
|
35 // FORWARD DECLARATIONS |
|
36 class CCertificate; |
|
37 class CX509Certificate; |
|
38 class CX500DistinguishedName; |
|
39 class CPKCS12; |
|
40 class RFs; |
|
41 class CEikonEnv; |
|
42 |
|
43 // CLASS DECLARATION |
|
44 |
|
45 /** |
|
46 * CCertParser - X.509 certificate and PKCS#12 PFX parsing class. |
|
47 */ |
|
48 class CCertParser :public CBase |
|
49 { |
|
50 public: // Constructors and destructor |
|
51 |
|
52 /** |
|
53 * Two-phased constructor. |
|
54 */ |
|
55 static CCertParser* NewL(); |
|
56 |
|
57 /** |
|
58 * Destructor. |
|
59 */ |
|
60 virtual ~CCertParser(); |
|
61 |
|
62 public: // New functions |
|
63 |
|
64 enum TCertType |
|
65 { |
|
66 ETypeX509, |
|
67 ETypeURL, |
|
68 ETypeX509CA, |
|
69 ETypeX509Peer, |
|
70 ETypePKCS12, |
|
71 ETypeCorrupt |
|
72 }; |
|
73 |
|
74 /** |
|
75 * Sets parsers state according to aBuffer. If certificate or PKCS#12 |
|
76 * is corrupted, any of the query functions can't be called. |
|
77 * @param aBuffer, buffer containing the certificate |
|
78 * @return Type of certificate, can also be corrupted. |
|
79 */ |
|
80 void SetContentL( RFile& aFile ); |
|
81 |
|
82 /** |
|
83 * Returns the type of the certificate. |
|
84 * @return TCertType, type of certificate. |
|
85 */ |
|
86 TCertType CertType() const; |
|
87 |
|
88 /** |
|
89 * Returns the content of the certificate. |
|
90 * Returned data is valid so long as state of this object |
|
91 * is not modified. |
|
92 * @return TPtrC8, the certificate |
|
93 */ |
|
94 const TPtrC8 CertificateBuf() const; |
|
95 |
|
96 /** |
|
97 * Returns the X.509 certificate object. |
|
98 * Returned data is valid so long as state of this object |
|
99 * is not modified. |
|
100 * @return TPtrC8, the certificate |
|
101 */ |
|
102 const CX509Certificate& Certificate() const; |
|
103 |
|
104 |
|
105 /** |
|
106 * Returns the private key of the PKCS#12 PDU. |
|
107 * Returned data is valid so long as state of this object |
|
108 * is not modified. |
|
109 * @return TPtrC8, the certificate |
|
110 */ |
|
111 const CArrayPtr<HBufC8>& Keys() const; |
|
112 |
|
113 /** |
|
114 * Returns the CA certificates from the PKCS#12 PDU. |
|
115 * Returned data is valid so long as state of this object |
|
116 * is not modified. |
|
117 * @return TPtrC8, the certificate |
|
118 */ |
|
119 const CArrayPtr<CX509Certificate>& CACertificates() const; |
|
120 |
|
121 /** |
|
122 * Returns the user certificates from the PKCS#12 PDU. |
|
123 * Returned data is valid so long as state of this object |
|
124 * is not modified. |
|
125 * @return TPtrC8, the certificate |
|
126 */ |
|
127 const CArrayPtr<CX509Certificate>& UserCertificates() const; |
|
128 |
|
129 public: // Functions from base classes |
|
130 |
|
131 protected: // New functions |
|
132 |
|
133 protected: // Functions from base classes |
|
134 |
|
135 private: |
|
136 |
|
137 /** |
|
138 * C++ default constructor. |
|
139 */ |
|
140 CCertParser(); |
|
141 |
|
142 /** |
|
143 * By default EPOC constructor is private. |
|
144 */ |
|
145 void ConstructL(); |
|
146 |
|
147 TInt CheckIfX509CertificateL( const TDesC8& aCert ); |
|
148 |
|
149 void CreatePKCS12L(); |
|
150 TBool CheckIfPKCS12L( const TDesC8& aPKCS12, const TDesC& aFileName ); |
|
151 |
|
152 TInt GetPasswordL( TDes& aPassword, const TDesC& aFileName ); |
|
153 |
|
154 void ShowErrorNoteL( TInt aResourceID ); |
|
155 |
|
156 public: // Data |
|
157 |
|
158 protected: // Data |
|
159 |
|
160 private: // Data |
|
161 TCertType iCertType; // The type of the response |
|
162 CX509Certificate* iCert; |
|
163 MPKCS12* iPKCS12; |
|
164 RLibrary iLibrary; |
|
165 CEikonEnv* iEikEnv; |
|
166 |
|
167 public: // Friend classes |
|
168 protected: // Friend classes |
|
169 private: // Friend classes |
|
170 |
|
171 }; |
|
172 |
|
173 #endif // CERTPARSER_H |
|
174 |
|
175 // End of File |