|
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Declase engine for testing OCSP module. Knows nothing about the details of the |
|
15 // script syntax. Is point of contact between script-reading classes and the |
|
16 // actual OCSP module itself. |
|
17 // |
|
18 // |
|
19 |
|
20 /** |
|
21 @file |
|
22 @internalTechnology |
|
23 */ |
|
24 |
|
25 #ifndef __TOCSP_ENGINE_H__ |
|
26 #define __TOCSP_ENGINE_H__ |
|
27 |
|
28 #include <e32base.h> |
|
29 #include <ocsp.h> |
|
30 #include <callbacktimer.h> |
|
31 #include "tcertutils.h" |
|
32 #include "ocsprequestandresponse.h" |
|
33 |
|
34 class CTOCSPLogger; |
|
35 |
|
36 class COCSPRequest; |
|
37 class COCSPTransaction; |
|
38 class COCSPValidator; |
|
39 class MOCSPTransport; |
|
40 |
|
41 class CX509Certificate; |
|
42 class CUnifiedCertStore; |
|
43 |
|
44 class TTransportLog |
|
45 { |
|
46 public: |
|
47 TBuf8<4> iHttpMethod; |
|
48 TInt iTransDurationMs; |
|
49 }; |
|
50 |
|
51 class CTOCSPEngine : public CActive, private MTimerObserver |
|
52 { |
|
53 public: |
|
54 static CTOCSPEngine* NewL(CTOCSPLogger& aLog); |
|
55 ~CTOCSPEngine(); |
|
56 |
|
57 // COMMANDS TO ACCESS OCSP MODULE |
|
58 |
|
59 void StartL(TRequestStatus& aStatus); // Delete all old objects, create a new transaction object |
|
60 void EndL(TRequestStatus& aStatus); // Clean up after tests run |
|
61 void SetURIL(const TDesC8& aURI, TBool aUseAIA=ETrue); |
|
62 |
|
63 |
|
64 void SetDefaultTransportL(); |
|
65 void SetTestTransportL(const TDesC& aResponseFile, const TDesC* aRequestFile); |
|
66 void SetOcspSupportTransportL(); |
|
67 void SetTransportRetryCount(TUint aRetryCount); |
|
68 void SetTransportTimeout(TInt aTimeout); |
|
69 |
|
70 void SetNonce(const TBool aNonce); |
|
71 void AddCertL(const TDesC8& aSubject, const TDesC8& aIssuer); |
|
72 |
|
73 void SetValidationTimeL(const TTime& aWhen); |
|
74 void AddDirectAuthorisationCert(const TDesC& aCert, const TDesC& aLabel, |
|
75 TRequestStatus& aStatus); |
|
76 void UseDirectAuthorisation(); |
|
77 void UseCADelegateAuthorisation(); |
|
78 void UseCADirectAuthorisation(); |
|
79 void UseAllAuthorisationSchemes(); |
|
80 void SetMaxStatusAgeL(TUint aMaxAge); |
|
81 |
|
82 void SetCancelTime(TInt aTime); |
|
83 void Check(TRequestStatus& aStatus); |
|
84 TBool TestSummaryL(OCSP::TResult aExpected); |
|
85 TBool TestOutcomeL(TInt aCertIndex, const TOCSPOutcome& aExpected); |
|
86 TBool TestTransportL(TInt aRetryCountNum, const TDesC& aExpectedHttpMethod, |
|
87 TInt aExpectedRespTimeMin, TInt aExpectedRespTimeMax); |
|
88 TBool TestTransportRetryL(TInt aRetryCount); |
|
89 |
|
90 void LogResponseL(const TDesC& aFilename); |
|
91 void LogRequestL(const TDesC& aFilename); |
|
92 |
|
93 static TPtrC TranslateStatusL(OCSP::TStatus aStatus); |
|
94 static TPtrC TranslateResultL(OCSP::TResult aResult); |
|
95 |
|
96 /** Set whether to print informational messages. */ |
|
97 void SetVerbose(TBool aVerbose); |
|
98 |
|
99 void SetReponderCertCheck(); |
|
100 void AddCertToStore(const TDesC& aCertFileName, const TDesC& aLabel, |
|
101 TCertificateOwnerType aCertType, TRequestStatus& aStatus); |
|
102 void SetFilterParameters(TInt aCountDropResp, TInt aNumDelayResp, |
|
103 TInt countCorruptHTTPDataHeader, TInt countCorruptHTTPDataBodySizeLarge, TInt countCorruptHTTPDataBodySizeSmall, |
|
104 TInt aCountCorruptOCSPData, |
|
105 TInt aCountInternalErrorResp, TInt aCountTryLaterResp, |
|
106 TInt aCountSigValidateFailure); |
|
107 void SetCheckCertsWithAiaOnly(TBool aCheckCertsWithAiaOnly); |
|
108 void SetUseAIA(TBool aUseAIA); |
|
109 |
|
110 private: |
|
111 CTOCSPEngine(CTOCSPLogger& aLog); |
|
112 void ConstructL(); |
|
113 void Destroy(); |
|
114 |
|
115 void Reset(); |
|
116 void PrepareAuthorisationL(); |
|
117 void DefineAndSetFilterParametersL(); |
|
118 void DeleteFilterParameters(); |
|
119 void LogValidationL(const TOCSPOutcome& aOutcome) const; |
|
120 void LogRequestCompleteL(); |
|
121 void ReadTransportLogL(); |
|
122 TBool ReadLineL(const TDesC8& aBuffer, TInt& aPos, TPtrC8& aLine) const; |
|
123 void LogResponseDetailsL(void); |
|
124 void InitDirectAuthL(); |
|
125 void CleanUpDirectAuthL(TRequestStatus& aStatus); |
|
126 void SetTransportL(MOCSPTransport* aTransport); |
|
127 |
|
128 // Implementation of CActive |
|
129 void RunL(); |
|
130 void DoCancel(); |
|
131 TInt RunError(TInt aError); |
|
132 |
|
133 // Implementation of MTimerRun |
|
134 void TimerRun(TInt aError); |
|
135 |
|
136 |
|
137 HBufC8* ReadDataL(RFs& session, const TDesC& aFileName) const; |
|
138 |
|
139 void DoAddDirectAuthorisationCertL(const TDesC& aCert, const TDesC& aLabel, |
|
140 TRequestStatus& aStatus); |
|
141 void DoCheckL(TRequestStatus& aStatus); |
|
142 |
|
143 private: |
|
144 enum TState |
|
145 { |
|
146 EInitCertStore, |
|
147 EAddingCert, |
|
148 ERemovingCerts, |
|
149 EChecking, |
|
150 }; |
|
151 |
|
152 private: |
|
153 RFs iFs; |
|
154 CUnifiedCertStore* iUnifiedCertStore; |
|
155 TState iState; |
|
156 TRequestStatus* iOriginalRequestStatus; |
|
157 |
|
158 CTOCSPLogger& iLog; |
|
159 |
|
160 // OCSP objects |
|
161 COCSPParameters* iParams; |
|
162 COCSPClient* iClient; |
|
163 |
|
164 // Have we added a direct authorisation scheme object? |
|
165 TBool iUseDirectAuthorisation; |
|
166 /** Set to use CA Delegate authorisation when the certificate is checked. */ |
|
167 TBool iUseCADelegateAuthorisation; |
|
168 /** |
|
169 When this is set the response is checked to see if it signed |
|
170 by the issuing CA. |
|
171 */ |
|
172 TBool iUseCADirectAuthorisation; |
|
173 /** |
|
174 Set when "ALLSCHEMES" command is parsed. This uses the |
|
175 COCSPParameters::AddAllAuthorisationSchemesL() function. |
|
176 */ |
|
177 TBool iUseAllSchemes; |
|
178 |
|
179 // The cert objects - we own them |
|
180 RPointerArray<CX509Certificate> iSubjectCerts; |
|
181 RPointerArray<CX509Certificate> iIssuerCerts; |
|
182 RPointerArray<CX509Certificate> iSigningCerts; |
|
183 |
|
184 CCertUtils* iCertUtils; |
|
185 |
|
186 TBuf<100> iCert; |
|
187 TBuf<100> iLabel; |
|
188 |
|
189 TBool iVerbose; |
|
190 |
|
191 // The filename to log requests to, or null |
|
192 HBufC* iRequestLog; |
|
193 |
|
194 TUint32 iIap; |
|
195 |
|
196 MOCSPTransport* iTransport; |
|
197 |
|
198 // Http transport filter settings |
|
199 TInt iNumDelayResp; |
|
200 TInt iCountDropResp; |
|
201 TInt iCountCorruptHTTPDataHeader; |
|
202 TInt iCountCorruptHTTPDataBodySizeLarge; |
|
203 TInt iCountCorruptHTTPDataBodySizeSmall; |
|
204 TInt iCountCorruptOCSPData; |
|
205 TInt iCountInternalErrorResp; |
|
206 TInt iCountTryLaterResp; |
|
207 TInt iCountSigValidateFailure; |
|
208 |
|
209 // Hold information read from the transport filter log |
|
210 RArray<TTransportLog> iTransportLog; |
|
211 |
|
212 // If non-zero the time interval in milliseconds to cancel issued request |
|
213 TInt iCancelTime; |
|
214 CCallbackTimer* iTimer; |
|
215 }; |
|
216 |
|
217 #endif |