11e934351Sopenharmony_ci/*
21e934351Sopenharmony_ci * Copyright (c) 2022-2024 Huawei Device Co., Ltd.
31e934351Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
41e934351Sopenharmony_ci * you may not use this file except in compliance with the License.
51e934351Sopenharmony_ci * You may obtain a copy of the License at
61e934351Sopenharmony_ci *
71e934351Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
81e934351Sopenharmony_ci *
91e934351Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
101e934351Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
111e934351Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
121e934351Sopenharmony_ci * See the License for the specific language governing permissions and
131e934351Sopenharmony_ci * limitations under the License.
141e934351Sopenharmony_ci */
151e934351Sopenharmony_ci
161e934351Sopenharmony_ci#include "net_address.h"
171e934351Sopenharmony_ci#include "secure_data.h"
181e934351Sopenharmony_ci#include "socket_error.h"
191e934351Sopenharmony_ci#include "socket_state_base.h"
201e934351Sopenharmony_ci#include "tls.h"
211e934351Sopenharmony_ci#include "tls_certificate.h"
221e934351Sopenharmony_ci#include "tls_configuration.h"
231e934351Sopenharmony_ci#include "tls_key.h"
241e934351Sopenharmony_ci#include "tls_socket.h"
251e934351Sopenharmony_ci#include "tls_utils_test.h"
261e934351Sopenharmony_ci
271e934351Sopenharmony_cinamespace OHOS {
281e934351Sopenharmony_cinamespace NetStack {
291e934351Sopenharmony_cinamespace TlsSocket {
301e934351Sopenharmony_civoid MockCertChainOneWayNetAddress(Socket::NetAddress &address)
311e934351Sopenharmony_ci{
321e934351Sopenharmony_ci    address.SetAddress(TlsUtilsTest::GetIp(TlsUtilsTest::ChangeToFile(IP_ADDRESS)));
331e934351Sopenharmony_ci    address.SetPort(std::atoi(TlsUtilsTest::ChangeToFile(PORT).c_str()));
341e934351Sopenharmony_ci    address.SetFamilyBySaFamily(AF_INET);
351e934351Sopenharmony_ci}
361e934351Sopenharmony_ci
371e934351Sopenharmony_civoid MockCertChainOneWayParamOptions(
381e934351Sopenharmony_ci    Socket::NetAddress &address, TLSSecureOptions &secureOption, TLSConnectOptions &options)
391e934351Sopenharmony_ci{
401e934351Sopenharmony_ci    secureOption.SetKey(SecureData(TlsUtilsTest::ChangeToFile(PRIVATE_KEY_PEM_CHAIN)));
411e934351Sopenharmony_ci    secureOption.SetCert(TlsUtilsTest::ChangeToFile(CLIENT_CRT_CHAIN));
421e934351Sopenharmony_ci
431e934351Sopenharmony_ci    MockCertChainOneWayNetAddress(address);
441e934351Sopenharmony_ci    options.SetTlsSecureOptions(secureOption);
451e934351Sopenharmony_ci    options.SetNetAddress(address);
461e934351Sopenharmony_ci}
471e934351Sopenharmony_ci
481e934351Sopenharmony_civoid SetCertChainOneWayHwTestShortParam(TLSSocket &server)
491e934351Sopenharmony_ci{
501e934351Sopenharmony_ci    TLSConnectOptions options;
511e934351Sopenharmony_ci    TLSSecureOptions secureOption;
521e934351Sopenharmony_ci    Socket::NetAddress address;
531e934351Sopenharmony_ci
541e934351Sopenharmony_ci    std::vector<std::string> caVec = { TlsUtilsTest::ChangeToFile(CA_PATH_CHAIN),
551e934351Sopenharmony_ci        TlsUtilsTest::ChangeToFile(MID_CA_PATH_CHAIN) };
561e934351Sopenharmony_ci    secureOption.SetCaChain(caVec);
571e934351Sopenharmony_ci    MockCertChainOneWayParamOptions(address, secureOption, options);
581e934351Sopenharmony_ci    server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
591e934351Sopenharmony_ci    server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
601e934351Sopenharmony_ci}
611e934351Sopenharmony_ci
621e934351Sopenharmony_civoid SetCertChainOneWayHwTestLongParam(TLSSocket &server)
631e934351Sopenharmony_ci{
641e934351Sopenharmony_ci    TLSConnectOptions options;
651e934351Sopenharmony_ci    TLSSecureOptions secureOption;
661e934351Sopenharmony_ci    Socket::NetAddress address;
671e934351Sopenharmony_ci
681e934351Sopenharmony_ci    std::vector<std::string> caVec = { TlsUtilsTest::ChangeToFile(CA_PATH_CHAIN),
691e934351Sopenharmony_ci        TlsUtilsTest::ChangeToFile(MID_CA_PATH_CHAIN) };
701e934351Sopenharmony_ci    std::string protocolV13 = "TLSv1.3";
711e934351Sopenharmony_ci    std::vector<std::string> protocolVec = { protocolV13 };
721e934351Sopenharmony_ci    secureOption.SetCaChain(caVec);
731e934351Sopenharmony_ci    secureOption.SetCipherSuite("AES256-SHA256");
741e934351Sopenharmony_ci    secureOption.SetProtocolChain(protocolVec);
751e934351Sopenharmony_ci    MockCertChainOneWayParamOptions(address, secureOption, options);
761e934351Sopenharmony_ci
771e934351Sopenharmony_ci    server.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
781e934351Sopenharmony_ci    server.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
791e934351Sopenharmony_ci}
801e934351Sopenharmony_ci
811e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, bindInterface, testing::ext::TestSize.Level2)
821e934351Sopenharmony_ci{
831e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaPathChainExistence("bindInterface")) {
841e934351Sopenharmony_ci        return;
851e934351Sopenharmony_ci    }
861e934351Sopenharmony_ci
871e934351Sopenharmony_ci    TLSSocket srv;
881e934351Sopenharmony_ci    Socket::NetAddress address;
891e934351Sopenharmony_ci    MockCertChainOneWayNetAddress(address);
901e934351Sopenharmony_ci    srv.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
911e934351Sopenharmony_ci}
921e934351Sopenharmony_ci
931e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, connectInterface, testing::ext::TestSize.Level2)
941e934351Sopenharmony_ci{
951e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaPathChainExistence("connectInterface")) {
961e934351Sopenharmony_ci        return;
971e934351Sopenharmony_ci    }
981e934351Sopenharmony_ci    TLSSocket certChainOneWayService;
991e934351Sopenharmony_ci    SetCertChainOneWayHwTestShortParam(certChainOneWayService);
1001e934351Sopenharmony_ci
1011e934351Sopenharmony_ci    const std::string data = "how do you do? this is connectInterface";
1021e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
1031e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
1041e934351Sopenharmony_ci    certChainOneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1051e934351Sopenharmony_ci    sleep(2);
1061e934351Sopenharmony_ci
1071e934351Sopenharmony_ci    (void)certChainOneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1081e934351Sopenharmony_ci    sleep(2);
1091e934351Sopenharmony_ci}
1101e934351Sopenharmony_ci
1111e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, closeInterface, testing::ext::TestSize.Level2)
1121e934351Sopenharmony_ci{
1131e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaPathChainExistence("closeInterface")) {
1141e934351Sopenharmony_ci        return;
1151e934351Sopenharmony_ci    }
1161e934351Sopenharmony_ci    TLSSocket certChainOneWayService;
1171e934351Sopenharmony_ci    SetCertChainOneWayHwTestShortParam(certChainOneWayService);
1181e934351Sopenharmony_ci
1191e934351Sopenharmony_ci    const std::string data = "how do you do? this is closeInterface";
1201e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
1211e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
1221e934351Sopenharmony_ci
1231e934351Sopenharmony_ci    certChainOneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1241e934351Sopenharmony_ci    sleep(2);
1251e934351Sopenharmony_ci
1261e934351Sopenharmony_ci    (void)certChainOneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1271e934351Sopenharmony_ci}
1281e934351Sopenharmony_ci
1291e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, sendInterface, testing::ext::TestSize.Level2)
1301e934351Sopenharmony_ci{
1311e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaPathChainExistence("sendInterface")) {
1321e934351Sopenharmony_ci        return;
1331e934351Sopenharmony_ci    }
1341e934351Sopenharmony_ci    TLSSocket certChainOneWayService;
1351e934351Sopenharmony_ci    SetCertChainOneWayHwTestShortParam(certChainOneWayService);
1361e934351Sopenharmony_ci
1371e934351Sopenharmony_ci    const std::string data = "how do you do? this is sendInterface";
1381e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
1391e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
1401e934351Sopenharmony_ci
1411e934351Sopenharmony_ci    certChainOneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1421e934351Sopenharmony_ci    sleep(2);
1431e934351Sopenharmony_ci
1441e934351Sopenharmony_ci    (void)certChainOneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1451e934351Sopenharmony_ci}
1461e934351Sopenharmony_ci
1471e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, getRemoteAddressInterface, testing::ext::TestSize.Level2)
1481e934351Sopenharmony_ci{
1491e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaPathChainExistence("getRemoteAddressInterface")) {
1501e934351Sopenharmony_ci        return;
1511e934351Sopenharmony_ci    }
1521e934351Sopenharmony_ci    TLSSocket certChainOneWayService;
1531e934351Sopenharmony_ci    TLSConnectOptions options;
1541e934351Sopenharmony_ci    TLSSecureOptions secureOption;
1551e934351Sopenharmony_ci    Socket::NetAddress address;
1561e934351Sopenharmony_ci
1571e934351Sopenharmony_ci    std::vector<std::string> caVec = { TlsUtilsTest::ChangeToFile(CA_PATH_CHAIN),
1581e934351Sopenharmony_ci        TlsUtilsTest::ChangeToFile(MID_CA_PATH_CHAIN) };
1591e934351Sopenharmony_ci    secureOption.SetCaChain(caVec);
1601e934351Sopenharmony_ci    MockCertChainOneWayParamOptions(address, secureOption, options);
1611e934351Sopenharmony_ci
1621e934351Sopenharmony_ci    certChainOneWayService.Bind(address, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1631e934351Sopenharmony_ci    certChainOneWayService.Connect(options, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1641e934351Sopenharmony_ci
1651e934351Sopenharmony_ci    Socket::NetAddress netAddress;
1661e934351Sopenharmony_ci    certChainOneWayService.GetRemoteAddress([&netAddress](int32_t errCode, const Socket::NetAddress &address) {
1671e934351Sopenharmony_ci        EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
1681e934351Sopenharmony_ci        netAddress.SetPort(address.GetPort());
1691e934351Sopenharmony_ci        netAddress.SetAddress(address.GetAddress());
1701e934351Sopenharmony_ci        netAddress.SetFamilyBySaFamily(address.GetSaFamily());
1711e934351Sopenharmony_ci    });
1721e934351Sopenharmony_ci    EXPECT_STREQ(netAddress.GetAddress().c_str(),
1731e934351Sopenharmony_ci        TlsUtilsTest::GetIp(TlsUtilsTest::ChangeToFile(IP_ADDRESS)).c_str());
1741e934351Sopenharmony_ci    EXPECT_EQ(address.GetPort(), std::atoi(TlsUtilsTest::ChangeToFile(PORT).c_str()));
1751e934351Sopenharmony_ci    EXPECT_EQ(netAddress.GetSaFamily(), AF_INET);
1761e934351Sopenharmony_ci
1771e934351Sopenharmony_ci    const std::string data = "how do you do? this is getRemoteAddressInterface";
1781e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
1791e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
1801e934351Sopenharmony_ci
1811e934351Sopenharmony_ci    certChainOneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1821e934351Sopenharmony_ci    sleep(2);
1831e934351Sopenharmony_ci
1841e934351Sopenharmony_ci    (void)certChainOneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
1851e934351Sopenharmony_ci}
1861e934351Sopenharmony_ci
1871e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, getStateInterface, testing::ext::TestSize.Level2)
1881e934351Sopenharmony_ci{
1891e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaPathChainExistence("getRemoteAddressInterface")) {
1901e934351Sopenharmony_ci        return;
1911e934351Sopenharmony_ci    }
1921e934351Sopenharmony_ci    TLSSocket certChainOneWayService;
1931e934351Sopenharmony_ci    SetCertChainOneWayHwTestShortParam(certChainOneWayService);
1941e934351Sopenharmony_ci
1951e934351Sopenharmony_ci    Socket::SocketStateBase TlsSocketstate;
1961e934351Sopenharmony_ci    certChainOneWayService.GetState([&TlsSocketstate](int32_t errCode, const Socket::SocketStateBase &state) {
1971e934351Sopenharmony_ci        EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
1981e934351Sopenharmony_ci        TlsSocketstate = state;
1991e934351Sopenharmony_ci    });
2001e934351Sopenharmony_ci    std::cout << "TlsSocketOneWayTest TlsSocketstate.IsClose(): " << TlsSocketstate.IsClose() << std::endl;
2011e934351Sopenharmony_ci    EXPECT_TRUE(TlsSocketstate.IsBound());
2021e934351Sopenharmony_ci    EXPECT_TRUE(!TlsSocketstate.IsClose());
2031e934351Sopenharmony_ci    EXPECT_TRUE(TlsSocketstate.IsConnected());
2041e934351Sopenharmony_ci
2051e934351Sopenharmony_ci    const std::string tlsSocketOneWayTestData = "how do you do? this is getStateInterface";
2061e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
2071e934351Sopenharmony_ci    tcpSendOptions.SetData(tlsSocketOneWayTestData);
2081e934351Sopenharmony_ci    certChainOneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2091e934351Sopenharmony_ci
2101e934351Sopenharmony_ci    sleep(2);
2111e934351Sopenharmony_ci
2121e934351Sopenharmony_ci    (void)certChainOneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2131e934351Sopenharmony_ci}
2141e934351Sopenharmony_ci
2151e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, getRemoteCertificateInterface, testing::ext::TestSize.Level2)
2161e934351Sopenharmony_ci{
2171e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaPathChainExistence("getRemoteCertificateInterface")) {
2181e934351Sopenharmony_ci        return;
2191e934351Sopenharmony_ci    }
2201e934351Sopenharmony_ci    TLSSocket certChainOneWayService;
2211e934351Sopenharmony_ci    SetCertChainOneWayHwTestShortParam(certChainOneWayService);
2221e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
2231e934351Sopenharmony_ci
2241e934351Sopenharmony_ci    const std::string data = "how do you do? This is UT test getRemoteCertificateInterface";
2251e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
2261e934351Sopenharmony_ci    certChainOneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2271e934351Sopenharmony_ci
2281e934351Sopenharmony_ci    certChainOneWayService.GetRemoteCertificate(
2291e934351Sopenharmony_ci        [](int32_t errCode, const X509CertRawData &cert) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2301e934351Sopenharmony_ci
2311e934351Sopenharmony_ci    sleep(2);
2321e934351Sopenharmony_ci    (void)certChainOneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2331e934351Sopenharmony_ci}
2341e934351Sopenharmony_ci
2351e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, protocolInterface, testing::ext::TestSize.Level2)
2361e934351Sopenharmony_ci{
2371e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaPathChainExistence("protocolInterface")) {
2381e934351Sopenharmony_ci        return;
2391e934351Sopenharmony_ci    }
2401e934351Sopenharmony_ci    TLSSocket certChainOneWayService;
2411e934351Sopenharmony_ci    SetCertChainOneWayHwTestLongParam(certChainOneWayService);
2421e934351Sopenharmony_ci
2431e934351Sopenharmony_ci    const std::string testData = "how do you do? this is protocolInterface";
2441e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
2451e934351Sopenharmony_ci    tcpSendOptions.SetData(testData);
2461e934351Sopenharmony_ci
2471e934351Sopenharmony_ci    certChainOneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2481e934351Sopenharmony_ci    std::string getProtocolResult;
2491e934351Sopenharmony_ci    certChainOneWayService.GetProtocol([&getProtocolResult](int32_t errCode, const std::string &protocol) {
2501e934351Sopenharmony_ci        EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
2511e934351Sopenharmony_ci        getProtocolResult = protocol;
2521e934351Sopenharmony_ci    });
2531e934351Sopenharmony_ci    EXPECT_STREQ(getProtocolResult.c_str(), "TLSv1.3");
2541e934351Sopenharmony_ci    sleep(2);
2551e934351Sopenharmony_ci
2561e934351Sopenharmony_ci    (void)certChainOneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2571e934351Sopenharmony_ci}
2581e934351Sopenharmony_ci
2591e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, getCipherSuiteInterface, testing::ext::TestSize.Level2)
2601e934351Sopenharmony_ci{
2611e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaPathChainExistence("getCipherSuiteInterface")) {
2621e934351Sopenharmony_ci        return;
2631e934351Sopenharmony_ci    }
2641e934351Sopenharmony_ci    TLSSocket certChainOneWayService;
2651e934351Sopenharmony_ci    SetCertChainOneWayHwTestLongParam(certChainOneWayService);
2661e934351Sopenharmony_ci
2671e934351Sopenharmony_ci    bool oneWayTestFlag = false;
2681e934351Sopenharmony_ci    const std::string data = "how do you do? This is getCipherSuiteInterface";
2691e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
2701e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
2711e934351Sopenharmony_ci    certChainOneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2721e934351Sopenharmony_ci
2731e934351Sopenharmony_ci    std::vector<std::string> oneWayTestSuite;
2741e934351Sopenharmony_ci    certChainOneWayService.GetCipherSuite([&oneWayTestSuite](int32_t errCode, const std::vector<std::string> &suite) {
2751e934351Sopenharmony_ci        EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS);
2761e934351Sopenharmony_ci        oneWayTestSuite = suite;
2771e934351Sopenharmony_ci    });
2781e934351Sopenharmony_ci
2791e934351Sopenharmony_ci    for (auto const &iter : oneWayTestSuite) {
2801e934351Sopenharmony_ci        if (iter == "AES256-SHA256") {
2811e934351Sopenharmony_ci            oneWayTestFlag = true;
2821e934351Sopenharmony_ci        }
2831e934351Sopenharmony_ci    }
2841e934351Sopenharmony_ci
2851e934351Sopenharmony_ci    EXPECT_TRUE(oneWayTestFlag);
2861e934351Sopenharmony_ci    sleep(2);
2871e934351Sopenharmony_ci
2881e934351Sopenharmony_ci    (void)certChainOneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
2891e934351Sopenharmony_ci}
2901e934351Sopenharmony_ci
2911e934351Sopenharmony_ciHWTEST_F(TlsSocketTest, onMessageDataInterface, testing::ext::TestSize.Level2)
2921e934351Sopenharmony_ci{
2931e934351Sopenharmony_ci    if (!TlsUtilsTest::CheckCaPathChainExistence("tlsSocketOnMessageData")) {
2941e934351Sopenharmony_ci        return;
2951e934351Sopenharmony_ci    }
2961e934351Sopenharmony_ci    std::string getData = "server->client";
2971e934351Sopenharmony_ci    TLSSocket certChainOneWayService;
2981e934351Sopenharmony_ci    SetCertChainOneWayHwTestLongParam(certChainOneWayService);
2991e934351Sopenharmony_ci
3001e934351Sopenharmony_ci    certChainOneWayService.OnMessage([&getData](const std::string &data, const Socket::SocketRemoteInfo &remoteInfo) {
3011e934351Sopenharmony_ci        if (data == getData) {
3021e934351Sopenharmony_ci            EXPECT_TRUE(true);
3031e934351Sopenharmony_ci        } else {
3041e934351Sopenharmony_ci            EXPECT_TRUE(false);
3051e934351Sopenharmony_ci        }
3061e934351Sopenharmony_ci    });
3071e934351Sopenharmony_ci
3081e934351Sopenharmony_ci    const std::string data = "how do you do? this is tlsSocketOnMessageData";
3091e934351Sopenharmony_ci    Socket::TCPSendOptions tcpSendOptions;
3101e934351Sopenharmony_ci    tcpSendOptions.SetData(data);
3111e934351Sopenharmony_ci    certChainOneWayService.Send(tcpSendOptions, [](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
3121e934351Sopenharmony_ci
3131e934351Sopenharmony_ci    sleep(2);
3141e934351Sopenharmony_ci    (void)certChainOneWayService.Close([](int32_t errCode) { EXPECT_TRUE(errCode == TLSSOCKET_SUCCESS); });
3151e934351Sopenharmony_ci}
3161e934351Sopenharmony_ci} // namespace TlsSocket
3171e934351Sopenharmony_ci} // namespace NetStack
3181e934351Sopenharmony_ci} // namespace OHOS
319