|
1 // Copyright (c) 2003-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 // This contains TLS test section 2 |
|
15 // |
|
16 // |
|
17 |
|
18 // EPOC includes |
|
19 #include <e32base.h> |
|
20 |
|
21 // from t_tls.cpp |
|
22 #include <e32cons.h> |
|
23 #include <c32comm.h> |
|
24 #include <f32file.h> |
|
25 #include <es_sock.h> |
|
26 |
|
27 #include <metadatabase.h> |
|
28 #include <commsdattypesv1_1.h> |
|
29 using namespace CommsDat; |
|
30 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
31 #include <commsdattypesv1_1_partner.h> |
|
32 #endif |
|
33 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
34 #include <commsdattypeinfov1_1_internal.h> |
|
35 #endif |
|
36 |
|
37 #include <securesocketinterface.h> |
|
38 #include <securesocket.h> |
|
39 |
|
40 // Test system includes |
|
41 #include <networking/log.h> |
|
42 #include <networking/teststep.h> |
|
43 |
|
44 #include "T_TLS_test.h" |
|
45 #include "TestSuiteTls.h" |
|
46 #include "TlsTestSection2.h" |
|
47 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
48 #include <securesocket_internal.h> |
|
49 #endif |
|
50 |
|
51 GLREF_C void CommInitL(); |
|
52 |
|
53 |
|
54 CTlsTestSection2_1::CTlsTestSection2_1() : |
|
55 iCommDbModified(EFalse) |
|
56 /** |
|
57 * Constructor. |
|
58 * Store the name of this test case. |
|
59 */ |
|
60 |
|
61 { |
|
62 iTestStepName = _L("tls_TestSection2_1"); |
|
63 } |
|
64 |
|
65 |
|
66 CTlsTestSection2_1::~CTlsTestSection2_1() |
|
67 /** |
|
68 * Destructor |
|
69 */ |
|
70 { |
|
71 } |
|
72 |
|
73 void CTlsTestSection2_1::ModifyCommDbL(const TDesC& aProtocolName, TBool aBreak) |
|
74 /** |
|
75 * @test Create a special CommDb Database for this test |
|
76 */ |
|
77 { |
|
78 if (aBreak) |
|
79 { |
|
80 Log(_L("Changing CommDb ssladaptor to non-existent one")); |
|
81 } |
|
82 else if (!iCommDbModified) |
|
83 { |
|
84 Log(_L("Attempt to Changing CommDb ssladaptor back to original when not changed")); |
|
85 User::Leave(KErrGeneral); |
|
86 } |
|
87 else |
|
88 { |
|
89 Log(_L("Changing CommDb ssladaptor back to original")); |
|
90 } |
|
91 |
|
92 // Create new session to CommsDat |
|
93 #ifdef SYMBIAN_NON_SEAMLESS_NETWORK_BEARER_MOBILITY |
|
94 CMDBSession* session = CMDBSession::NewL(KCDVersion1_2); |
|
95 #else |
|
96 CMDBSession* session = CMDBSession::NewL(KCDVersion1_2); |
|
97 #endif |
|
98 CleanupStack::PushL(session); |
|
99 CCDSecureSocketRecord* ptrRecord = static_cast<CCDSecureSocketRecord*>(CCDRecordBase::RecordFactoryL(KCDTIdSSProtoRecord)); |
|
100 CleanupStack::PushL(ptrRecord); |
|
101 ptrRecord->iSSProtoName = aProtocolName; |
|
102 User::LeaveIfError(ptrRecord->FindL(*session)); |
|
103 |
|
104 if (aBreak) |
|
105 { |
|
106 // need to read existing value before updating value |
|
107 iOldSslAdaptor = ptrRecord->iSSProtoLibrary; |
|
108 |
|
109 ptrRecord->iSSProtoLibrary = KBadSslLibrary; |
|
110 } |
|
111 else |
|
112 { |
|
113 ptrRecord->iSSProtoLibrary = iOldSslAdaptor; |
|
114 } |
|
115 |
|
116 ptrRecord->ModifyL(*session); |
|
117 iCommDbModified = aBreak; |
|
118 |
|
119 CleanupStack::PopAndDestroy(ptrRecord); |
|
120 CleanupStack::PopAndDestroy(session); |
|
121 } |
|
122 |
|
123 // This is the test code for testing use of commdb-specified adaptor |
|
124 // The script has loaded a commdb with an invalid ProtoLibrary in the |
|
125 // SecureSocketTable. So when we attempt to open a secure socket we |
|
126 // should get KErrNotFound |
|
127 TVerdict CTlsTestSection2_1::doTestStepL( ) |
|
128 { |
|
129 Log(_L("Starting Bad SSL Adaptor test")); |
|
130 |
|
131 // if the test has not left yet it must be a Pass |
|
132 iTestStepResult = EPass; |
|
133 |
|
134 __UHEAP_MARK; |
|
135 |
|
136 // Create an active scheduler |
|
137 CActiveScheduler* myActiveScheduler = new(ELeave) CActiveScheduler(); |
|
138 CleanupStack::PushL( myActiveScheduler ); |
|
139 CActiveScheduler::Install( myActiveScheduler ); |
|
140 |
|
141 TRAPD(error, CommInitL()); // init needed comms libs |
|
142 TESTEL(error == KErrNone, error); |
|
143 |
|
144 // Connect the socket server |
|
145 RSocketServ socketServ; |
|
146 error = socketServ.Connect(); |
|
147 TESTEL(error == KErrNone, error); |
|
148 CleanupClosePushL(socketServ); |
|
149 |
|
150 // Open a socket |
|
151 RSocket socket; |
|
152 error = socket.Open( socketServ, KAfInet, KSockStream, KProtocolInetTcp ); |
|
153 TESTEL(error == KErrNone, error); |
|
154 CleanupClosePushL(socket); |
|
155 |
|
156 // now currupt the ssladaptor to force failure |
|
157 ModifyCommDbL(KDefCfgProtocol, ETrue); |
|
158 |
|
159 Log(_L("Creating a secure socket")); |
|
160 CSecureSocket* secureSocket = NULL; |
|
161 TRAP(error, secureSocket = CSecureSocket::NewL( socket, KDefCfgProtocol ) ); |
|
162 TPtrC errorText = EpocErrorToText(error); |
|
163 Log(_L("CSecureSocket::NewL returned %S"), &errorText); |
|
164 TESTE(KErrNotFound == error, error); |
|
165 if (KErrNone == error) |
|
166 { |
|
167 secureSocket->Close(); |
|
168 delete secureSocket; |
|
169 } |
|
170 |
|
171 // reset the ssladaptor |
|
172 ModifyCommDbL(KDefCfgProtocol, EFalse); |
|
173 |
|
174 CleanupStack::PopAndDestroy(); // socket |
|
175 CleanupStack::PopAndDestroy(); // socketServ |
|
176 |
|
177 CActiveScheduler::Install( NULL ); |
|
178 CleanupStack::PopAndDestroy( myActiveScheduler ); |
|
179 |
|
180 // unload the securesocket library |
|
181 CSecureSocketLibraryLoader::Unload(); |
|
182 |
|
183 __UHEAP_MARKEND; |
|
184 |
|
185 return iTestStepResult; |
|
186 } |