|
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 verifyCreateMethodStep.cpp |
|
18 @internalTechnology |
|
19 */ |
|
20 #include "verifyCreateMethodStep.h" |
|
21 |
|
22 #include <tlsprovinterface.h> |
|
23 #include <tlstypedef.h> |
|
24 |
|
25 |
|
26 CCreateMethodStep::CCreateMethodStep() |
|
27 { |
|
28 SetTestStepName(KCreateMethodStep); |
|
29 } |
|
30 |
|
31 TVerdict CCreateMethodStep::doTestStepPreambleL() |
|
32 { |
|
33 ConstructL(); |
|
34 |
|
35 CTlsCryptoAttributes* atts = Provider()->Attributes(); |
|
36 |
|
37 // read the "server" random |
|
38 HBufC8* random = ServerRandomL(); |
|
39 atts->iMasterSecretInput.iServerRandom.Copy(*random); |
|
40 delete random; |
|
41 |
|
42 // and the client random |
|
43 random = ClientRandomL(); |
|
44 atts->iMasterSecretInput.iClientRandom.Copy(*random); |
|
45 delete random; |
|
46 |
|
47 // we only support null compression... |
|
48 atts->iCompressionMethod = ENullCompression; |
|
49 |
|
50 // read the cipher suite for the test |
|
51 atts->iCurrentCipherSuite = CipherSuiteL(); |
|
52 |
|
53 // read the protocol version |
|
54 TTLSProtocolVersion version = ProtocolVersionL(); |
|
55 atts->iNegotiatedProtocol = version; |
|
56 atts->iProposedProtocol = version; |
|
57 |
|
58 // set the session ID and "server" name (localhost) |
|
59 atts->iSessionNameAndID.iSessionId = SessionId(); |
|
60 atts->iSessionNameAndID.iServerName.iAddress = KLocalHost; |
|
61 atts->iSessionNameAndID.iServerName.iPort = 443; |
|
62 atts->idomainName.Copy(DomainNameL()); |
|
63 |
|
64 // try and read DH params, this section may not exist |
|
65 RInteger gen; |
|
66 CleanupClosePushL(gen); |
|
67 |
|
68 RInteger prime; |
|
69 CleanupClosePushL(prime); |
|
70 |
|
71 TRAPD(err, ReadDHParamsL()); |
|
72 if (err == KErrNone) |
|
73 { |
|
74 atts->iPublicKeyParams->iKeyType = EDHE; |
|
75 |
|
76 // The params are: |
|
77 // 1 - Prime |
|
78 // 2 - Generator |
|
79 // 3 - generator ^ random mod prime |
|
80 |
|
81 atts->iPublicKeyParams->iValue1 = Prime().BufferLC(); |
|
82 CleanupStack::Pop(atts->iPublicKeyParams->iValue1); |
|
83 |
|
84 atts->iPublicKeyParams->iValue2 = Generator().BufferLC(); |
|
85 CleanupStack::Pop(atts->iPublicKeyParams->iValue2); |
|
86 |
|
87 atts->iPublicKeyParams->iValue3 = KeyPair()->PublicKey().X().BufferLC(); |
|
88 CleanupStack::Pop(atts->iPublicKeyParams->iValue3); |
|
89 } |
|
90 |
|
91 CleanupStack::PopAndDestroy(2, &gen); // prime |
|
92 |
|
93 // No client auth, no dialogs |
|
94 atts->iClientAuthenticate = EFalse; |
|
95 atts->iDialogNonAttendedMode = ETrue; |
|
96 |
|
97 return EPass; |
|
98 } |
|
99 |
|
100 |
|
101 TVerdict CCreateMethodStep::doTestStepL() |
|
102 { |
|
103 INFO_PRINTF1(_L("Calling TLS Provider to fetch cipher suites.")); |
|
104 |
|
105 // first we have to retrieve the available cipher suites |
|
106 TInt err = GetCipherSuitesL(); |
|
107 |
|
108 if (err != KErrNone) |
|
109 { |
|
110 INFO_PRINTF2(_L("Failed! Cannot retrieve supported cipher suites! (Error %d)"), |
|
111 err); |
|
112 SetTestStepResult(EFail); |
|
113 return TestStepResult(); |
|
114 } |
|
115 |
|
116 // we have to verify the server certificate, to supply the certificate |
|
117 // and its parameters to the TLS provider. |
|
118 |
|
119 INFO_PRINTF1(_L("Calling TLS Provider to verify server certificate.")); |
|
120 |
|
121 CX509Certificate* cert = NULL; |
|
122 err = VerifyServerCertificateL(cert); |
|
123 delete cert; |
|
124 |
|
125 // make sure it completed sucessfully. |
|
126 if (err != KErrNone) |
|
127 { |
|
128 INFO_PRINTF2(_L("Failed! Server Certificate did not verify correctly! (Error %d)"), |
|
129 err); |
|
130 SetTestStepResult(EFail); |
|
131 return TestStepResult(); |
|
132 } |
|
133 |
|
134 |
|
135 INFO_PRINTF1(_L("Creating TLS Session.")); |
|
136 err = CreateSessionL(); |
|
137 |
|
138 if(err != KErrNone) |
|
139 { |
|
140 INFO_PRINTF2(_L("Failed! Create Session failed! (Error %d)"),err); |
|
141 SetTestStepResult(EFail); |
|
142 return TestStepResult(); |
|
143 } |
|
144 err = CreateSessionAddedL(0,-3); |
|
145 if(err == KErrNone) |
|
146 { |
|
147 INFO_PRINTF1(_L("Failed! Create Session Passed for invalid data)")); |
|
148 SetTestStepResult(EFail); |
|
149 return TestStepResult(); |
|
150 } |
|
151 |
|
152 INFO_PRINTF1(_L("Create Session Test step Passed.")); |
|
153 SetTestStepResult(EPass); |
|
154 return TestStepResult(); |
|
155 } |
|
156 |