1 /*
2  * Copyright (c) 2024 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 #ifndef TLS_UTILS_TEST_H
17 #define TLS_UTILS_TEST_H
18 
19 #include <fstream>
20 #include <gtest/gtest.h>
21 #include <iostream>
22 #include <openssl/rsa.h>
23 #include <openssl/ssl.h>
24 #include <sstream>
25 #include <string>
26 #include <string_view>
27 #include <unistd.h>
28 #include <vector>
29 
30 namespace OHOS {
31 namespace NetStack {
32 namespace TlsSocket {
33 const std::string_view PRIVATE_KEY_PEM = "/data/ClientCert/client_rsa_private.pem.unsecure";
34 const std::string_view CA_DER = "/data/ClientCert/ca.crt";
35 const std::string_view CLIENT_CRT = "/data/ClientCert/client.crt";
36 const std::string_view IP_ADDRESS = "/data/Ip/address.txt";
37 const std::string_view PORT = "/data/Ip/port.txt";
38 const std::string_view PRIVATE_KEY_PEM_CHAIN = "/data/ClientCertChain/privekey.pem.unsecure";
39 const std::string_view CA_PATH_CHAIN = "/data/ClientCertChain/cacert.crt";
40 const std::string_view MID_CA_PATH_CHAIN = "/data/ClientCertChain/caMidcert.crt";
41 const std::string_view CLIENT_CRT_CHAIN = "/data/ClientCertChain/secondServer.crt";
42 const std::string_view ROOT_CA_PATH_CHAIN = "/data/ClientCertChain/RootCa.pem";
43 const std::string_view MID_CA_CHAIN = "/data/ClientCertChain/MidCa.pem";
44 
45 class TlsUtilsTest {
46 public:
47     TlsUtilsTest();
48     ~TlsUtilsTest();
49 
50     static std::string ChangeToFile(const std::string_view fileName);
51     static std::string GetIp(std::string ip);
52     static bool CheckCaFileExistence(const char *function);
53     static bool CheckCaPathChainExistence(const char *function);
54 };
55 
56 class TlsSocketTest : public testing::Test {
57 public:
SetUpTestCase()58     static void SetUpTestCase() {}
59 
TearDownTestCase()60     static void TearDownTestCase() {}
61 
SetUp()62     virtual void SetUp() {}
63 
TearDown()64     virtual void TearDown() {}
65 };
66 } // namespace TlsSocket
67 } // namespace NetStack
68 } // namespace OHOS
69 #endif // TLS_UTILS_TEST_H
70