|
1 // Copyright (c) 2006-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 // |
|
15 |
|
16 /** |
|
17 @file verifyCancellationStep.cpp |
|
18 @internalTechnology |
|
19 */ |
|
20 #include "verifyCancellationstep.h" |
|
21 |
|
22 #include <tlsprovinterface.h> |
|
23 |
|
24 CVerifyCancellationStep::CVerifyCancellationStep() |
|
25 { |
|
26 SetTestStepName(KVerifyCancellationStep); |
|
27 } |
|
28 |
|
29 TVerdict CVerifyCancellationStep::doTestStepPreambleL() |
|
30 { |
|
31 ConstructL(); |
|
32 |
|
33 CTlsCryptoAttributes* atts = Provider()->Attributes(); |
|
34 |
|
35 // read the "server" random |
|
36 HBufC8* random = ServerRandomL(); |
|
37 atts->iMasterSecretInput.iServerRandom.Copy(*random); |
|
38 delete random; |
|
39 |
|
40 // and the client random |
|
41 random = ClientRandomL(); |
|
42 atts->iMasterSecretInput.iClientRandom.Copy(*random); |
|
43 delete random; |
|
44 |
|
45 // we only support null compression... |
|
46 atts->iCompressionMethod = ENullCompression; |
|
47 |
|
48 // read the cipher suite for the test |
|
49 atts->iCurrentCipherSuite = CipherSuiteL(); |
|
50 |
|
51 // read the protocol version |
|
52 TTLSProtocolVersion version = ProtocolVersionL(); |
|
53 atts->iNegotiatedProtocol = version; |
|
54 atts->iProposedProtocol = version; |
|
55 |
|
56 // set the session ID and "server" name (localhost) |
|
57 atts->iSessionNameAndID.iSessionId = SessionId(); |
|
58 atts->iSessionNameAndID.iServerName.iAddress = KLocalHost; |
|
59 atts->iSessionNameAndID.iServerName.iPort = 443; |
|
60 atts->idomainName.Copy(DomainNameL()); |
|
61 |
|
62 // try and read DH params, this section may not exist |
|
63 RInteger gen; |
|
64 CleanupClosePushL(gen); |
|
65 |
|
66 RInteger prime; |
|
67 CleanupClosePushL(prime); |
|
68 |
|
69 TRAPD(err, ReadDHParamsL()); |
|
70 if (err == KErrNone) |
|
71 { |
|
72 atts->iPublicKeyParams->iKeyType = EDHE; |
|
73 |
|
74 // The params are: |
|
75 // 1 - Prime |
|
76 // 2 - Generator |
|
77 // 3 - generator ^ random mod prime |
|
78 |
|
79 atts->iPublicKeyParams->iValue1 = Prime().BufferLC(); |
|
80 CleanupStack::Pop(atts->iPublicKeyParams->iValue1); |
|
81 |
|
82 atts->iPublicKeyParams->iValue2 = Generator().BufferLC(); |
|
83 CleanupStack::Pop(atts->iPublicKeyParams->iValue2); |
|
84 |
|
85 atts->iPublicKeyParams->iValue3 = KeyPair()->PublicKey().X().BufferLC(); |
|
86 CleanupStack::Pop(atts->iPublicKeyParams->iValue3); |
|
87 } |
|
88 |
|
89 CleanupStack::PopAndDestroy(2, &gen); // prime |
|
90 |
|
91 // No client auth, no dialogs |
|
92 atts->iClientAuthenticate = EFalse; |
|
93 atts->iDialogNonAttendedMode = ETrue; |
|
94 |
|
95 return EPass; |
|
96 } |
|
97 |
|
98 TVerdict CVerifyCancellationStep::doTestStepL() |
|
99 { |
|
100 INFO_PRINTF1(_L("Calling TLS Provider to fetch cipher suites.")); |
|
101 |
|
102 // first we have to retrieve the available cipher suites |
|
103 TInt err = GetCipherSuitesL(); |
|
104 |
|
105 if (err != KErrNone) |
|
106 { |
|
107 INFO_PRINTF2(_L("Failed! Cannot retrieve supported cipher suites! (Error %d)"), |
|
108 err); |
|
109 SetTestStepResult(EFail); |
|
110 return TestStepResult(); |
|
111 } |
|
112 |
|
113 // we have to verify the server certificate, to supply the certificate |
|
114 // and its parameters to the TLS provider. |
|
115 |
|
116 INFO_PRINTF1(_L("Calling TLS Provider to verify server certificate.")); |
|
117 |
|
118 CX509Certificate* cert = NULL; |
|
119 err = VerifyServerCertificateL(cert); |
|
120 |
|
121 // Request for provider cancel |
|
122 ProviderCancelReq(); |
|
123 delete cert; |
|
124 cert = NULL; |
|
125 err = VerifyServerCertificateL(cert); |
|
126 // make sure it completed sucessfully. |
|
127 if (err != KErrNone) |
|
128 { |
|
129 INFO_PRINTF2(_L("Failed! Server Certificate did not verify correctly! (Error %d)"), |
|
130 err); |
|
131 SetTestStepResult(EFail); |
|
132 return TestStepResult(); |
|
133 } |
|
134 |
|
135 |
|
136 INFO_PRINTF1(_L("Creating TLS Session.")); |
|
137 |
|
138 // now, create a session with the parameters set in the preamble |
|
139 err = CreateSessionL(); |
|
140 |
|
141 // ensure we succeeded |
|
142 if (err != KErrNone) |
|
143 { |
|
144 INFO_PRINTF2(_L("Failed! Create Session failed! (Error %d)"), err); |
|
145 SetTestStepResult(EFail); |
|
146 return TestStepResult(); |
|
147 } |
|
148 |
|
149 INFO_PRINTF1(_L("Calling TLS session key exchange.")); |
|
150 |
|
151 HBufC8* keyExMessage = NULL; |
|
152 err = ClientKeyExchange(keyExMessage); |
|
153 |
|
154 if (err != KErrNone) |
|
155 { |
|
156 INFO_PRINTF2(_L("Failed! Key exchange failed! (Error %d)"), err); |
|
157 delete keyExMessage; |
|
158 SetTestStepResult(EFail); |
|
159 return TestStepResult(); |
|
160 } |
|
161 // Request for session cancel |
|
162 SessionCancelReq(); |
|
163 err = ClientKeyExchange(keyExMessage); |
|
164 |
|
165 if (err != KErrNone) |
|
166 { |
|
167 INFO_PRINTF2(_L("Failed! Key exchange failed! (Error %d)"), err); |
|
168 delete keyExMessage; |
|
169 SetTestStepResult(EFail); |
|
170 return TestStepResult(); |
|
171 } |
|
172 INFO_PRINTF1(_L("Deriving premaster secret.")); |
|
173 |
|
174 // derive the premaster secret from the key exchange method |
|
175 CleanupStack::PushL(keyExMessage); |
|
176 HBufC8* premaster = DerivePreMasterSecretL(*keyExMessage); |
|
177 CleanupStack::PopAndDestroy(keyExMessage); |
|
178 |
|
179 INFO_PRINTF1(_L("Deriving master secret.")); |
|
180 |
|
181 // compute the master secret from the premaster. |
|
182 CleanupStack::PushL(premaster); |
|
183 HBufC8* master = ComputeMasterSecretL(*premaster); |
|
184 CleanupStack::PopAndDestroy(premaster); |
|
185 delete master; |
|
186 return TestStepResult(); |
|
187 } |
|
188 |