• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <fstream>
17 #include <gtest/gtest.h>
18 #include <iostream>
19 #include <openssl/rsa.h>
20 #include <openssl/ssl.h>
21 #include <sstream>
22 #include <string>
23 #include <string_view>
24 #include <unistd.h>
25 #include <vector>
26 
27 #include "net_address.h"
28 #include "secure_data.h"
29 #include "socket_error.h"
30 #include "socket_state_base.h"
31 #include "tls.h"
32 #include "tls_certificate.h"
33 #include "tls_configuration.h"
34 #include "tls_key.h"
35 #include "tls_socket.h"
36 
37 namespace OHOS {
38 namespace NetStack {
39 namespace {
40 const std::string_view PRIVATE_KEY_PEM = "/data/ClientCert/client_rsa_private.pem.unsecure";
41 const std::string_view CA_DER = "/data/ClientCert/ca.crt";
42 const std::string_view CLIENT_CRT = "/data/ClientCert/client.crt";
43 const std::string_view IP_ADDRESS = "/data/Ip/address.txt";
44 const std::string_view PORT = "/data/Ip/port.txt";
45 
CheckCaFileExistence(const char * function)46 inline bool CheckCaFileExistence(const char *function)
47 {
48     if (access(CA_DER.data(), 0)) {
49         std::cout << "CA file does not exist! (" << function << ")";
50         return false;
51     }
52     return true;
53 }
54 
ChangeToFile(std::string_view fileName)55 std::string ChangeToFile(std::string_view fileName)
56 {
57     std::ifstream file;
58     file.open(fileName);
59     std::stringstream ss;
60     ss << file.rdbuf();
61     std::string infos = ss.str();
62     file.close();
63     return infos;
64 }
65 
GetIp(std::string ip)66 std::string GetIp(std::string ip)
67 {
68     return ip.substr(0, ip.length() - 1);
69 }
70 } // namespace
71 
72 class TlsSocketTest : public testing::Test {
73 public:
SetUpTestCase()74     static void SetUpTestCase() {}
75 
TearDownTestCase()76     static void TearDownTestCase() {}
77 
SetUp()78     virtual void SetUp() {}
79 
TearDown()80     virtual void TearDown() {}
81 };
82 
83 HWTEST_F(TlsSocketTest, bindInterface, testing::ext::TestSize.Level2)
84 {
85     if (!CheckCaFileExistence("bindInterface")) {
86         return;
87     }
88 
89     TLSSocket server;
90     NetAddress address;
91 
92     address.SetAddress(GetIp(ChangeToFile(IP_ADDRESS)));
93     address.SetPort(std::atoi(ChangeToFile(PORT).c_str()));
94     address.SetFamilyBySaFamily(AF_INET);
95 
__anon5ad3c6580202(int32_t errCode) 96     server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
97 }
98 
99 HWTEST_F(TlsSocketTest, connectInterface, testing::ext::TestSize.Level2)
100 {
101     if (!CheckCaFileExistence("connectInterface")) {
102         return;
103     }
104 
105     TLSConnectOptions options;
106     TLSSocket server;
107 
108     TLSSecureOptions secureOption;
109     NetAddress address;
110 
111     address.SetAddress(GetIp(ChangeToFile(IP_ADDRESS)));
112     address.SetPort(std::atoi(ChangeToFile(PORT).c_str()));
113     address.SetFamilyBySaFamily(AF_INET);
114 
115     secureOption.SetKey(SecureData(ChangeToFile(PRIVATE_KEY_PEM)));
116     std::vector<std::string> caVec = {ChangeToFile(CA_DER)};
117     secureOption.SetCaChain(caVec);
118     secureOption.SetCert(ChangeToFile(CLIENT_CRT));
119 
120     options.SetNetAddress(address);
121     options.SetTlsSecureOptions(secureOption);
122 
__anon5ad3c6580302(int32_t errCode) 123     server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
124 
__anon5ad3c6580402(int32_t errCode) 125     server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
126 
127     const std::string data = "how do you do? this is connectInterface";
128     TCPSendOptions tcpSendOptions;
129     tcpSendOptions.SetData(data);
__anon5ad3c6580502(int32_t errCode) 130     server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
131     sleep(2);
132 
__anon5ad3c6580602(int32_t errCode) 133     (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
134     sleep(2);
135 }
136 
137 HWTEST_F(TlsSocketTest, closeInterface, testing::ext::TestSize.Level2)
138 {
139     if (!CheckCaFileExistence("closeInterface")) {
140         return;
141     }
142 
143     TLSConnectOptions options;
144     TLSSocket server;
145 
146     TLSSecureOptions secureOption;
147     NetAddress address;
148 
149     address.SetAddress(GetIp(ChangeToFile(IP_ADDRESS)));
150     address.SetPort(std::atoi(ChangeToFile(PORT).c_str()));
151     address.SetFamilyBySaFamily(AF_INET);
152 
153     secureOption.SetKey(SecureData(ChangeToFile(PRIVATE_KEY_PEM)));
154     std::vector<std::string> caVec = {ChangeToFile(CA_DER)};
155     secureOption.SetCaChain(caVec);
156     secureOption.SetCert(ChangeToFile(CLIENT_CRT));
157 
158     options.SetNetAddress(address);
159     options.SetTlsSecureOptions(secureOption);
160 
__anon5ad3c6580702(int32_t errCode) 161     server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
162 
__anon5ad3c6580802(int32_t errCode) 163     server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
164 
165     const std::string data = "how do you do? this is closeInterface";
166     TCPSendOptions tcpSendOptions;
167     tcpSendOptions.SetData(data);
168 
__anon5ad3c6580902(int32_t errCode) 169     server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
170     sleep(2);
171 
__anon5ad3c6580a02(int32_t errCode) 172     (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
173 }
174 
175 HWTEST_F(TlsSocketTest, sendInterface, testing::ext::TestSize.Level2)
176 {
177     if (!CheckCaFileExistence("sendInterface")) {
178         return;
179     }
180     TLSConnectOptions options;
181     TLSSocket server;
182 
183     TLSSecureOptions secureOption;
184     NetAddress address;
185 
186     address.SetAddress(GetIp(ChangeToFile(IP_ADDRESS)));
187     address.SetPort(std::atoi(ChangeToFile(PORT).c_str()));
188     address.SetFamilyBySaFamily(AF_INET);
189 
190     secureOption.SetKey(SecureData(ChangeToFile(PRIVATE_KEY_PEM)));
191     std::vector<std::string> caVec = {ChangeToFile(CA_DER)};
192     secureOption.SetCaChain(caVec);
193     secureOption.SetCert(ChangeToFile(CLIENT_CRT));
194 
195     options.SetNetAddress(address);
196     options.SetTlsSecureOptions(secureOption);
197 
__anon5ad3c6580b02(int32_t errCode) 198     server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
199 
__anon5ad3c6580c02(int32_t errCode) 200     server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
201 
202     const std::string data = "how do you do? this is sendInterface";
203     TCPSendOptions tcpSendOptions;
204     tcpSendOptions.SetData(data);
205 
__anon5ad3c6580d02(int32_t errCode) 206     server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
207     sleep(2);
208 
__anon5ad3c6580e02(int32_t errCode) 209     (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
210 }
211 
212 HWTEST_F(TlsSocketTest, getRemoteAddressInterface, testing::ext::TestSize.Level2)
213 {
214     if (!CheckCaFileExistence("getRemoteAddressInterface")) {
215         return;
216     }
217 
218     TLSConnectOptions options;
219     TLSSocket server;
220     TLSSecureOptions secureOption;
221     NetAddress address;
222 
223     address.SetAddress(GetIp(ChangeToFile(IP_ADDRESS)));
224     address.SetPort(std::atoi(ChangeToFile(PORT).c_str()));
225     address.SetFamilyBySaFamily(AF_INET);
226 
227     secureOption.SetKey(SecureData(ChangeToFile(PRIVATE_KEY_PEM)));
228     std::vector<std::string> caVec = {ChangeToFile(CA_DER)};
229     secureOption.SetCaChain(caVec);
230     secureOption.SetCert(ChangeToFile(CLIENT_CRT));
231 
232     options.SetNetAddress(address);
233     options.SetTlsSecureOptions(secureOption);
234 
__anon5ad3c6580f02(int32_t errCode) 235     server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
236 
__anon5ad3c6581002(int32_t errCode) 237     server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
238 
239     NetAddress netAddress;
__anon5ad3c6581102(int32_t errCode, const NetAddress &address) 240     server.GetRemoteAddress([&netAddress](int32_t errCode, const NetAddress &address) {
241         EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
242         netAddress.SetAddress(address.GetAddress());
243         netAddress.SetPort(address.GetPort());
244         netAddress.SetFamilyBySaFamily(address.GetSaFamily());
245     });
246     EXPECT_STREQ(netAddress.GetAddress().c_str(), GetIp(ChangeToFile(IP_ADDRESS)).c_str());
247     EXPECT_EQ(address.GetPort(), std::atoi(ChangeToFile(PORT).c_str()));
248     EXPECT_EQ(netAddress.GetSaFamily(), AF_INET);
249 
250     const std::string data = "how do you do? this is getRemoteAddressInterface";
251     TCPSendOptions tcpSendOptions;
252     tcpSendOptions.SetData(data);
253 
__anon5ad3c6581202(int32_t errCode) 254     server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
255 
__anon5ad3c6581302(int32_t errCode) 256     (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
257 }
258 
259 HWTEST_F(TlsSocketTest, getStateInterface, testing::ext::TestSize.Level2)
260 {
261     if (!CheckCaFileExistence("getRemoteAddressInterface")) {
262         return;
263     }
264 
265     TLSConnectOptions options;
266     TLSSocket server;
267     TLSSecureOptions secureOption;
268     NetAddress address;
269 
270     address.SetAddress(GetIp(ChangeToFile(IP_ADDRESS)));
271     address.SetPort(std::atoi(ChangeToFile(PORT).c_str()));
272     address.SetFamilyBySaFamily(AF_INET);
273 
274     secureOption.SetKey(SecureData(ChangeToFile(PRIVATE_KEY_PEM)));
275     std::vector<std::string> caVec = {ChangeToFile(CA_DER)};
276     secureOption.SetCaChain(caVec);
277     secureOption.SetCert(ChangeToFile(CLIENT_CRT));
278 
279     options.SetNetAddress(address);
280     options.SetTlsSecureOptions(secureOption);
281 
__anon5ad3c6581402(int32_t errCode) 282     server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
__anon5ad3c6581502(int32_t errCode) 283     server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
284 
285     SocketStateBase TlsSocketstate;
__anon5ad3c6581602(int32_t errCode, const SocketStateBase &state) 286     server.GetState([&TlsSocketstate](int32_t errCode, const SocketStateBase &state) {
287         EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
288         TlsSocketstate = state;
289     });
290     std::cout << "TlsSocketstate.IsClose(): " << TlsSocketstate.IsClose() << std::endl;
291     EXPECT_TRUE(TlsSocketstate.IsBound());
292     EXPECT_TRUE(!TlsSocketstate.IsClose());
293     EXPECT_TRUE(TlsSocketstate.IsConnected());
294 
295     const std::string data = "how do you do? this is getStateInterface";
296     TCPSendOptions tcpSendOptions;
297     tcpSendOptions.SetData(data);
__anon5ad3c6581702(int32_t errCode) 298     server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
299 
300     sleep(2);
301 
__anon5ad3c6581802(int32_t errCode) 302     (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
303 }
304 
305 HWTEST_F(TlsSocketTest, getRemoteCertificateInterface, testing::ext::TestSize.Level2)
306 {
307     if (!CheckCaFileExistence("getRemoteCertificateInterface")) {
308         return;
309     }
310     TLSSocket server;
311     TLSConnectOptions options;
312     TCPSendOptions tcpSendOptions;
313     TLSSecureOptions secureOption;
314     NetAddress address;
315     const std::string data = "how do you do? This is UT test getRemoteCertificateInterface";
316 
317     address.SetAddress(GetIp(ChangeToFile(IP_ADDRESS)));
318     address.SetPort(std::atoi(ChangeToFile(PORT).c_str()));
319     address.SetFamilyBySaFamily(AF_INET);
320 
321     secureOption.SetKey(SecureData(ChangeToFile(PRIVATE_KEY_PEM)));
322     std::vector<std::string> caVec = {ChangeToFile(CA_DER)};
323     secureOption.SetCaChain(caVec);
324     secureOption.SetCert(ChangeToFile(CLIENT_CRT));
325 
326     options.SetNetAddress(address);
327     options.SetTlsSecureOptions(secureOption);
328 
__anon5ad3c6581902(int32_t errCode) 329     server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
330 
__anon5ad3c6581a02(int32_t errCode) 331     server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
332 
333     tcpSendOptions.SetData(data);
334 
__anon5ad3c6581b02(int32_t errCode) 335     server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
336 
337     server.GetRemoteCertificate(
__anon5ad3c6581c02(int32_t errCode, const X509CertRawData &cert) 338     [](int32_t errCode, const X509CertRawData &cert) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
339 
340     sleep(2);
__anon5ad3c6581d02(int32_t errCode) 341     (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
342 }
343 
344 HWTEST_F(TlsSocketTest, protocolInterface, testing::ext::TestSize.Level2)
345 {
346     if (!CheckCaFileExistence("protocolInterface")) {
347         return;
348     }
349     TLSConnectOptions options;
350     TLSSocket server;
351     TLSSecureOptions secureOption;
352     NetAddress address;
353 
354     address.SetAddress(GetIp(ChangeToFile(IP_ADDRESS)));
355     address.SetPort(std::atoi(ChangeToFile(PORT).c_str()));
356     address.SetFamilyBySaFamily(AF_INET);
357 
358     secureOption.SetKey(SecureData(ChangeToFile(PRIVATE_KEY_PEM)));
359     std::vector<std::string> caVec = {ChangeToFile(CA_DER)};
360     secureOption.SetCaChain(caVec);
361     secureOption.SetCert(ChangeToFile(CLIENT_CRT));
362     secureOption.SetCipherSuite("AES256-SHA256");
363     std::string protocolV13 = "TLSv1.3";
364     std::vector<std::string> protocolVec = {protocolV13};
365     secureOption.SetProtocolChain(protocolVec);
366 
367     options.SetNetAddress(address);
368     options.SetTlsSecureOptions(secureOption);
369 
__anon5ad3c6581e02(int32_t errCode) 370     server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
371 
__anon5ad3c6581f02(int32_t errCode) 372     server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
373 
374     const std::string data = "how do you do? this is protocolInterface";
375     TCPSendOptions tcpSendOptions;
376     tcpSendOptions.SetData(data);
377 
__anon5ad3c6582002(int32_t errCode) 378     server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
379     std::string getProtocolVal;
__anon5ad3c6582102(int32_t errCode, const std::string &protocol) 380     server.GetProtocol([&getProtocolVal](int32_t errCode, const std::string &protocol) {
381         EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
382         getProtocolVal = protocol;
383     });
384     EXPECT_STREQ(getProtocolVal.c_str(), "TLSv1.3");
385 
386     SocketStateBase stateBase;
__anon5ad3c6582202(int32_t errCode, SocketStateBase state) 387     server.GetState([&stateBase](int32_t errCode, SocketStateBase state) {
388         if (errCode == TLSSOCKET_SUCCESS) {
389             EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
390             stateBase.SetIsBound(state.IsBound());
391             stateBase.SetIsClose(state.IsClose());
392             stateBase.SetIsConnected(state.IsConnected());
393         }
394     });
395     EXPECT_TRUE(stateBase.IsConnected());
396     sleep(2);
397 
__anon5ad3c6582302(int32_t errCode) 398     (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
399 }
400 
401 HWTEST_F(TlsSocketTest, getCipherSuiteInterface, testing::ext::TestSize.Level2)
402 {
403     if (!CheckCaFileExistence("getCipherSuiteInterface")) {
404         return;
405     }
406 
407     TLSConnectOptions options;
408     TLSSocket server;
409     TLSSecureOptions secureOption;
410     NetAddress address;
411 
412     address.SetAddress(GetIp(ChangeToFile(IP_ADDRESS)));
413     address.SetPort(std::atoi(ChangeToFile(PORT).c_str()));
414     address.SetFamilyBySaFamily(AF_INET);
415 
416     secureOption.SetKey(SecureData(ChangeToFile(PRIVATE_KEY_PEM)));
417     std::vector<std::string> caVec = {ChangeToFile(CA_DER)};
418     secureOption.SetCaChain(caVec);
419     secureOption.SetCert(ChangeToFile(CLIENT_CRT));
420     secureOption.SetCipherSuite("AES256-SHA256");
421     std::string protocolV13 = "TLSv1.3";
422     std::vector<std::string> protocolVec = {protocolV13};
423     secureOption.SetProtocolChain(protocolVec);
424 
425     options.SetNetAddress(address);
426     options.SetTlsSecureOptions(secureOption);
427 
428     bool flag = false;
__anon5ad3c6582402(int32_t errCode) 429     server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
__anon5ad3c6582502(int32_t errCode) 430     server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
431 
432     const std::string data = "how do you do? This is getCipherSuiteInterface";
433     TCPSendOptions tcpSendOptions;
434     tcpSendOptions.SetData(data);
__anon5ad3c6582602(int32_t errCode) 435     server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
436 
437     std::vector<std::string> cipherSuite;
__anon5ad3c6582702(int32_t errCode, const std::vector<std::string> &suite) 438     server.GetCipherSuite([&cipherSuite](int32_t errCode, const std::vector<std::string> &suite) {
439         if (errCode == TLSSOCKET_SUCCESS) {
440             cipherSuite = suite;
441         }
442     });
443 
444     for (auto const &iter : cipherSuite) {
445         if (iter == "AES256-SHA256") {
446             flag = true;
447         }
448     }
449 
450     EXPECT_TRUE(flag);
451     sleep(2);
452 
__anon5ad3c6582802(int32_t errCode) 453     (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
454 }
455 
456 HWTEST_F(TlsSocketTest, onMessageDataInterface, testing::ext::TestSize.Level2)
457 {
458     if (!CheckCaFileExistence("tlsSocketOnMessageData")) {
459         return;
460     }
461     std::string getData = "server->client";
462     TLSConnectOptions options;
463     TLSSocket server;
464     TLSSecureOptions secureOption;
465     NetAddress address;
466 
467     address.SetAddress(GetIp(ChangeToFile(IP_ADDRESS)));
468     address.SetPort(std::atoi(ChangeToFile(PORT).c_str()));
469     address.SetFamilyBySaFamily(AF_INET);
470 
471     secureOption.SetKey(SecureData(ChangeToFile(PRIVATE_KEY_PEM)));
472     std::vector<std::string> caVec = {ChangeToFile(CA_DER)};
473     secureOption.SetCaChain(caVec);
474     secureOption.SetCert(ChangeToFile(CLIENT_CRT));
475     secureOption.SetCipherSuite("AES256-SHA256");
476     std::string protocolV13 = "TLSv1.3";
477     std::vector<std::string> protocolVec = {protocolV13};
478     secureOption.SetProtocolChain(protocolVec);
479 
480     options.SetNetAddress(address);
481     options.SetTlsSecureOptions(secureOption);
482 
__anon5ad3c6582902(int32_t errCode) 483     server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
484 
__anon5ad3c6582a02(int32_t errCode) 485     server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
__anon5ad3c6582b02(const std::string &data, const SocketRemoteInfo &remoteInfo) 486     server.OnMessage([&getData](const std::string &data, const SocketRemoteInfo &remoteInfo) {
487         EXPECT_TRUE(data == getData);
488     });
489 
490     const std::string data = "how do you do? this is tlsSocketOnMessageData";
491     TCPSendOptions tcpSendOptions;
492     tcpSendOptions.SetData(data);
__anon5ad3c6582c02(int32_t errCode) 493     server.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
494 
495     sleep(2);
__anon5ad3c6582d02(int32_t errCode) 496     (void)server.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
497 }
498 } // namespace NetStack
499 } // namespace OHOS
500