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 <cstring>
17 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19
20 #include "accesstoken_kit.h"
21 #include "cert_manager_api.h"
22 #include "nativetoken_kit.h"
23 #include "token_setproc.h"
24 #include "securec.h"
25 #include "syspara/parameters.h"
26
27 #define private public
28 #include "cert_mgr_adapter_impl.h"
29
30 using namespace testing;
31 using namespace testing::ext;
32
33 namespace OHOS::NWeb {
34 namespace {
35 constexpr uint32_t DEFAULT_SIGNATURE_LEN = 1024;
36 uint32_t TEST_FAILURE = -1;
37 uint32_t TEST_OK = 0;
38 uint32_t g_cerSize = 0;
39 uint32_t g_certSum = 0;
40 uint32_t g_userCertSum = 0;
41 uint32_t g_appMaxSize = 0;
42 const uint8_t g_rsa2048P12CertInfo[] = {
43 0x30, 0x82, 0x0b, 0xc1, 0x02, 0x01, 0x03, 0x30, 0x82, 0x0b, 0x87, 0x06, 0x09, 0x2a, 0x86, 0x48,
44 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x82, 0x0b, 0x78, 0x04, 0x82, 0x0b, 0x74, 0x30, 0x82,
45 0x0b, 0x70, 0x30, 0x82, 0x06, 0x27, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07,
46 0x06, 0xa0, 0x82, 0x06, 0x18, 0x30, 0x82, 0x06, 0x14, 0x02, 0x01, 0x00, 0x30, 0x82, 0x06, 0x0d,
47 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0x30, 0x1c, 0x06, 0x0a, 0x2a,
48 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x0c, 0x01, 0x03, 0x30, 0x0e, 0x04, 0x08, 0x1a, 0x8f, 0xc1,
49 0xd1, 0xda, 0x6c, 0xd1, 0xa9, 0x02, 0x02, 0x08, 0x00, 0x80, 0x82, 0x05, 0xe0, 0xd0, 0x2f, 0x2d,
50 0x52, 0x09, 0x86, 0x55, 0x53, 0xf0, 0x49, 0x8f, 0x00, 0xa1, 0x4d, 0x21, 0xc8, 0xb4, 0xad, 0x27,
51 0x12, 0x44, 0xab, 0x4d, 0x10, 0x14, 0xe3, 0x3c, 0x9a, 0x05, 0x77, 0x51, 0x90, 0x4a, 0x3a, 0x8a,
52 0x09, 0xa9, 0x4b, 0x36, 0x50, 0x60, 0x22, 0x4b, 0x77, 0x12, 0x5c, 0x2f, 0x60, 0xd3, 0xd9, 0x30,
53 0x94, 0x4d, 0x9e, 0x81, 0xc3, 0xe9, 0x9d, 0xd9, 0x47, 0xb3, 0x54, 0xa2, 0x9a, 0x8f, 0xe7, 0x58,
54 0x95, 0xd7, 0x48, 0x87, 0xc4, 0x40, 0xad, 0x9a, 0x42, 0x1d, 0x36, 0xb7, 0x48, 0xbc, 0x70, 0x8c,
55 0x84, 0xcb, 0x3c, 0x02, 0x25, 0x9f, 0xfe, 0x2c, 0x4a, 0x76, 0xb1, 0x27, 0x94, 0x8f, 0xb0, 0x07,
56 0xf0, 0xc0, 0x00, 0x3a, 0x69, 0x16, 0xe1, 0x63, 0x0c, 0xe5, 0x92, 0xc2, 0x7d, 0x99, 0xd9, 0x11,
57 0x40, 0xd8, 0x64, 0xab, 0x13, 0xda, 0x73, 0x7b, 0x12, 0x53, 0xb1, 0x0b, 0x0c, 0x67, 0x81, 0xe1,
58 0xf5, 0x59, 0x3a, 0xc7, 0xe0, 0xe9, 0xda, 0x12, 0xc7, 0x2b, 0xab, 0x3d, 0xb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0xe8, 0xb8, 0x3a, 0x64, 0xfe, 0xb8, 0x2f, 0x69, 0xc4, 0xdd, 0x78, 0xdd, 0x92, 0xeb,
71 0xc3, 0x08, 0xc2, 0x05, 0xef, 0xa6, 0x9c, 0x12, 0xd5, 0x48, 0x27, 0xfb, 0x19, 0x66, 0x66, 0x24,
72 0x52, 0x47, 0xf1, 0x7c, 0xad, 0xc9, 0xb8, 0x1a, 0xd0, 0x2d, 0x40, 0xe9, 0x36, 0xce, 0x9e, 0x07,
73 0x06, 0xd0, 0xe3, 0x5d, 0x98, 0xfb, 0x67, 0x1a, 0xd1, 0x62, 0x35, 0x03, 0xe8, 0x34, 0xf0, 0xfd,
74 0x24, 0xe4, 0x06, 0x52, 0x03, 0xda, 0x8e, 0x68, 0x6d, 0x74, 0xfd, 0xda, 0x9b, 0xca, 0x8e, 0x52,
75 0x71, 0x9c, 0x14, 0x05, 0x10, 0x61, 0x63, 0xa4, 0x53, 0x72, 0x4a, 0xda, 0x15, 0xf8, 0x0a, 0x56,
76 0x89, 0x00, 0xdd, 0x87, 0xf5, 0xdd, 0x69, 0xd6, 0x6c, 0x89, 0x15, 0x1a, 0x1f, 0x48, 0xd6, 0x2c,
77 0x1e, 0x4f, 0x23, 0x06, 0x6e, 0x34, 0x0d, 0x4e, 0xe3, 0x17, 0x40, 0x22, 0x7a, 0x68, 0x37, 0xad,
78 0x05, 0xdb, 0x99, 0xde, 0x1a, 0x47, 0x2f, 0xb1, 0x9e, 0x7e, 0xdb, 0xad, 0x69, 0x06, 0x25, 0xd5,
79 0xd9, 0x8e, 0xaf, 0xe2, 0xaa, 0x5a, 0x9a, 0x79, 0xd6, 0xeb, 0x02, 0x10, 0xf8, 0x72, 0x78, 0x4e,
80 0x51, 0x2a, 0x53, 0x55, 0xb9, 0xd3, 0x7c, 0x31, 0x42, 0xff, 0x59, 0x39, 0x92, 0xd6, 0xec, 0x46,
81 0x2d, 0x4f, 0xea, 0xf1, 0x0e, 0x83, 0x57, 0x55, 0x7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0xee, 0x27, 0x4f, 0x45, 0xb7, 0x06, 0x46, 0x53, 0x65, 0x49, 0xca, 0x4c, 0x12, 0xc9, 0x5b, 0x05,
105 0xb6, 0xf6, 0x26, 0x5d, 0x90, 0x4a, 0x9b, 0x50, 0xaf, 0x65, 0x92, 0x13, 0xfc, 0xc2, 0x47, 0xff,
106 0xe8, 0xb6, 0x4e, 0xd2, 0xa7, 0x48, 0x8c, 0xbe, 0x3a, 0x13, 0x2e, 0xe6, 0xb9, 0xb7, 0x29, 0x2d,
107 0x30, 0xaa, 0x80, 0xcf, 0x74, 0x77, 0x14, 0xb2, 0x78, 0x52, 0x25, 0xf6, 0x97, 0x99, 0x40, 0x9a,
108 0xea, 0xce, 0x92, 0x68, 0xb9, 0x5c, 0x9e, 0xf4, 0xbf, 0xd9, 0xd4, 0x43, 0x7d, 0xf6, 0x10, 0x05,
109 0x9d, 0xa4, 0xe2, 0x8f, 0x8e, 0x2e, 0xce, 0x07, 0x57, 0x7b, 0xa2, 0xb2, 0x90, 0xd7, 0xd5, 0x66,
110 0x12, 0xaa, 0x27, 0xce, 0xcb, 0x0a, 0xe9, 0x59, 0x47, 0xbd, 0x3e, 0x65, 0xd9, 0x83, 0xa2, 0x65,
111 0x27, 0x06, 0x7f, 0x04, 0xc3, 0x35, 0xba, 0x55, 0x3d, 0x68, 0xc7, 0x0c, 0xa2, 0x50, 0xc3, 0xb1,
112 0x66, 0x65, 0x7f, 0x74, 0xda, 0x05, 0x11, 0x89, 0xaf, 0xf2, 0x04, 0x8b, 0x60, 0x1d, 0xbf, 0x06,
113 0x84, 0x7c, 0x1d, 0xcd, 0xcb, 0x5e, 0xf3, 0xfa, 0xfd, 0x1a, 0xb0, 0x1f, 0xc1, 0x6e, 0x91, 0x67,
114 0xaa, 0x05, 0x9e, 0x2d, 0x6f, 0x4c, 0xdb, 0xab, 0x99, 0x83, 0x81, 0x80, 0x21, 0xbd, 0x17, 0x50,
115 0x59, 0x3b, 0x16, 0x3a, 0x66, 0x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 0x1c, 0x9b, 0xa5, 0x2d,
138 0xcf, 0xff, 0x0e, 0x80, 0xf5, 0xa4, 0x3c, 0x52, 0xa6, 0xf3, 0x16, 0x96, 0xa6, 0x64, 0xac, 0x7e,
139 0xaf, 0xb7, 0xc6, 0x34, 0xfd, 0xf7, 0x0a, 0x10, 0xe6, 0x2b, 0xda, 0x10, 0xdd, 0xb2, 0x44, 0x8d,
140 0x95, 0x71, 0xbf, 0xb1, 0xf3, 0x91, 0xac, 0xc6, 0x93, 0xe1, 0x91, 0x62, 0x05, 0x90, 0x38, 0x33,
141 0xcf, 0x36, 0xff, 0xa5, 0x82, 0x4e, 0x14, 0x78, 0x33, 0x40, 0x18, 0x22, 0xd6, 0x60, 0x6b, 0x0b,
142 0x97, 0x4f, 0x2d, 0xd0, 0x36, 0x82, 0xb3, 0x1a, 0xe8, 0xd7, 0x93, 0xff, 0x19, 0xd1, 0x74, 0xd2,
143 0x29, 0xe1, 0x97, 0x60, 0x09, 0x48, 0xef, 0xc9, 0x61, 0xae, 0x3b, 0x4f, 0xd4, 0x30, 0x82, 0x05,
144 0x41, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x82, 0x05, 0x32,
145 0x04, 0x82, 0x05, 0x2e, 0x30, 0x82, 0x05, 0x2a, 0x30, 0x82, 0x05, 0x26, 0x06, 0x0b, 0x2a, 0x86,
146 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x0c, 0x0a, 0x01, 0x02, 0xa0, 0x82, 0x04, 0xee, 0x30, 0x82, 0x04,
147 0xea, 0x30, 0x1c, 0x06, 0x0a, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x0c, 0x01, 0x03, 0x30,
148 0x0e, 0x04, 0x08, 0x2b, 0xef, 0x2d, 0x9b, 0x33, 0xf6, 0x82, 0x62, 0x02, 0x02, 0x08, 0x00, 0x04,
149 0x82, 0x04, 0xc8, 0x59, 0x60, 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0x61, 0x2a, 0x18, 0x96, 0xa2, 0x17, 0xe2,
161 0x63, 0x75, 0xfd, 0xf0, 0x82, 0xd6, 0x36, 0x5b, 0x44, 0xf3, 0x9a, 0x96, 0x29, 0x1c, 0x50, 0x91,
162 0x20, 0xbb, 0x7b, 0x2d, 0x96, 0xe1, 0x0e, 0xc6, 0xce, 0x01, 0x40, 0xe8, 0x22, 0xc5, 0xac, 0x3f,
163 0xfa, 0xd0, 0xac, 0xc9, 0x4e, 0x1e, 0x20, 0x8a, 0xc6, 0x40, 0xed, 0x6b, 0xb6, 0xc4, 0xc1, 0x43,
164 0xec, 0x3c, 0xfe, 0xb7, 0x50, 0x19, 0x09, 0x1b, 0x21, 0x83, 0x63, 0x93, 0x18, 0xbd, 0x73, 0x42,
165 0x73, 0x25, 0x4f, 0xda, 0xdb, 0x4f, 0xf9, 0xba, 0x11, 0xf3, 0x91, 0xc0, 0x5b, 0x9d, 0x93, 0xfd,
166 0x94, 0x89, 0xb6, 0xea, 0x90, 0x15, 0xe5, 0xf0, 0xe8, 0xd8, 0x31, 0x2c, 0xe0, 0x92, 0x6a, 0xb7,
167 0xe3, 0x43, 0x51, 0xfc, 0xa0, 0x20, 0x2b, 0x5c, 0xbb, 0xf0, 0x22, 0x2b, 0xa5, 0x00, 0x40, 0xe9,
168 0x0d, 0x64, 0xf0, 0xe7, 0xca, 0x29, 0x85, 0xfc, 0x89, 0x38, 0x03, 0xaa, 0x0c, 0xad, 0x71, 0xe6,
169 0xc9, 0xde, 0x42, 0x5e, 0x97, 0x74, 0x35, 0x6a, 0x88, 0x94, 0x99, 0xd5, 0xbd, 0x91, 0xa5, 0x92,
170 0x35, 0x1d, 0xf4, 0x11, 0xf7, 0x7e, 0x47, 0x96, 0xe4, 0x2f, 0x85, 0x75, 0x3a, 0x16, 0x2a, 0x45,
171 0x96, 0xd7, 0xb1, 0x8f, 0xd5, 0x64, 0x87, 0x5d, 0xd0, 0x44, 0x1e, 0xd6, 0x67, 0x0c, 0xc6, 0xdb,
172 0xb4, 0x0a, 0xe4, 0x18, 0x0c, 0x12, 0x73, 0xb5, 0x4f, 0x44, 0xc8, 0xd6, 0x97, 0x8b, 0x99, 0x19,
173 0x66, 0x55, 0x08, 0xcb, 0xa0, 0xca, 0x9e, 0x09, 0x0f, 0xe1, 0x8b, 0xd7, 0xa1, 0x12, 0x54, 0x46,
174 0x2d, 0x09, 0x44, 0x27, 0x30, 0xcd, 0x02, 0xcc, 0x88, 0x8f, 0x69, 0x22, 0xed, 0x31, 0x25, 0x14,
175 0x5f, 0x37, 0x5f, 0xce, 0x91, 0x95, 0x30, 0x07, 0x32, 0xaa, 0x2e, 0x55, 0x9a, 0xc4, 0x33, 0xab,
176 0xd0, 0x55, 0x3d, 0x04, 0xe3, 0x84, 0x0c, 0xf1, 0xe4, 0xe6, 0x52, 0x39, 0x0e, 0x22, 0x8b, 0x4f,
177 0xf3, 0x5c, 0xc2, 0xc7, 0xc3, 0xd4, 0xc1, 0x5c, 0x45, 0x83, 0xee, 0x37, 0x3e, 0xa7, 0xd9, 0xa2,
178 0x9c, 0x5b, 0x4b, 0x6b, 0xdf, 0xc5, 0x5c, 0x50, 0x12, 0x1d, 0x6c, 0x73, 0xea, 0xf4, 0xdc, 0x70,
179 0x3f, 0x11, 0x70, 0x0e, 0x3d, 0x4d, 0x8c, 0x69, 0xaf, 0x8b, 0x6a, 0x20, 0x75, 0x55, 0xeb, 0x6e,
180 0x27, 0x21, 0x5d, 0x9c, 0xdb, 0xbb, 0xf7, 0xf9, 0x3e, 0x81, 0x2f, 0x4f, 0x96, 0xcb, 0x2e, 0xb1,
181 0xc3, 0x01, 0x1f, 0xa7, 0x87, 0x43, 0xc8, 0x89, 0xec, 0x5b, 0x41, 0x42, 0x2e, 0x19, 0x0b, 0xdf,
182 0x3a, 0x90, 0xaa, 0x98, 0x2f, 0xe9, 0xad, 0x02, 0xf9, 0x96, 0x40, 0x51, 0xdd, 0x4b, 0x8b, 0xe5,
183 0xca, 0x84, 0xe2, 0x93, 0xdd, 0xad, 0x43, 0x37, 0x62, 0x14, 0xa1, 0x07, 0x17, 0x5d, 0x71, 0x73,
184 0xc0, 0xd8, 0x02, 0x0f, 0x44, 0xcf, 0x5e, 0x6f, 0x55, 0x44, 0x70, 0xa6, 0x22, 0xe7, 0x2d, 0xc3,
185 0x2c, 0x44, 0xc3, 0x0e, 0xf1, 0xda, 0x02, 0x57, 0x40, 0x24, 0x36, 0xc8, 0xf9, 0x4f, 0x17, 0x0b,
186 0x9b, 0x2a, 0xa8, 0x0d, 0x84, 0xf1, 0x49, 0x3b, 0x6d, 0x23, 0xb9, 0x97, 0x47, 0x2a, 0x0b, 0xc3,
187 0x80, 0xe5, 0xdf, 0x4e, 0x1f, 0x94, 0xd1, 0x0e, 0x69, 0xb5, 0xb0, 0xf8, 0xa5, 0x7d, 0x9c, 0x9f,
188 0x68, 0x7d, 0x04, 0x18, 0x42, 0x32, 0x72, 0xdc, 0xab, 0xdc, 0xe6, 0xba, 0x09, 0xe8, 0xd4, 0x27,
189 0x53, 0x95, 0x9c, 0x39, 0xd5, 0x70, 0x0d, 0x1e, 0xb5, 0xb7, 0x2b, 0x0a, 0x79, 0xc7, 0xd6, 0x0b,
190 0xee, 0xea, 0xf8, 0x6f, 0x6a, 0xb1, 0xfc, 0x90, 0x35, 0xce, 0x46, 0x99, 0xfa, 0x88, 0x01, 0x48,
191 0xd5, 0x70, 0x26, 0x4c, 0x08, 0x2a, 0x13, 0x60, 0xb0, 0x96, 0x91, 0xa7, 0xc5, 0x05, 0xd3, 0xcd,
192 0x5e, 0xcb, 0x9f, 0xa4, 0x5c, 0x29, 0x98, 0xbc, 0xd6, 0x2e, 0x6a, 0xeb, 0xc8, 0xfa, 0x58, 0x45,
193 0x79, 0x15, 0x30, 0x98, 0x59, 0x65, 0x30, 0x7f, 0x14, 0x14, 0xbd, 0x27, 0xd1, 0x0c, 0xbc, 0x52,
194 0xda, 0x42, 0x09, 0xc5, 0xc4, 0x58, 0xdb, 0x04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fb, 0x6e,
217 0x44, 0x62, 0xd8, 0x96, 0x4f, 0x61, 0xdb, 0x62, 0x0d, 0x03, 0xa6, 0x2f, 0x11, 0x91, 0x95, 0x38,
218 0xf3, 0x49, 0x94, 0xf0, 0x93, 0x0e, 0xaf, 0xff, 0x28, 0xe6, 0x24, 0xbc, 0xc4, 0x1d, 0x0d, 0xfb,
219 0x00, 0xc4, 0x5b, 0xef, 0xda, 0x55, 0x76, 0xbf, 0x52, 0xf9, 0x00, 0xab, 0xd5, 0xef, 0xa5, 0x31,
220 0x37, 0x60, 0xcf, 0xad, 0x79, 0x45, 0xef, 0x0f, 0x97, 0xc8, 0x0e, 0x88, 0x61, 0x56, 0x58, 0x3b,
221 0xd5, 0x1c, 0xe8, 0xb0, 0x93, 0x02, 0xdf, 0xa5, 0x6c, 0xaf, 0x4b, 0x5e, 0x66, 0x7d, 0xfe, 0xaa,
222 0xaf, 0xa0, 0xd4, 0x35, 0xcd, 0x81, 0xa0, 0x71, 0xe4, 0x45, 0x12, 0x24, 0x1e, 0x0d, 0x06, 0x96,
223 0x1e, 0x23, 0xa3, 0x39, 0xd8, 0xcc, 0x72, 0xd7, 0xac, 0x72, 0x5c, 0x8c, 0xdf, 0x6c, 0xb4, 0xc4,
224 0x2b, 0xbc, 0x1c, 0xeb, 0xbe, 0x1b, 0xbb, 0xf3, 0xbc, 0x45, 0x34, 0xe9, 0x5a, 0x7f, 0x11, 0x61,
225 0xd7, 0x61, 0x15, 0x18, 0x0e, 0xf8, 0x8b, 0x23, 0x97, 0xa7, 0x46, 0x31, 0x25, 0x30, 0x23, 0x06,
226 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x15, 0x31, 0x16, 0x04, 0x14, 0x8b, 0x4e,
227 0x13, 0x2a, 0xf1, 0x4d, 0xa3, 0xe9, 0x31, 0x5c, 0x6d, 0xce, 0x5a, 0x09, 0x93, 0x0a, 0xf4, 0x12,
228 0x19, 0x7b, 0x30, 0x31, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05,
229 0x00, 0x04, 0x14, 0x00, 0x3b, 0x70, 0x95, 0x68, 0xd3, 0xd8, 0x4f, 0x71, 0xd0, 0x7d, 0x41, 0x49,
230 0x48, 0xef, 0x88, 0x6d, 0xe0, 0x9d, 0x53, 0x04, 0x08, 0x0e, 0x46, 0xa3, 0xb5, 0x73, 0x88, 0x7c,
231 0x22, 0x02, 0x02, 0x08, 0x00
232 };
233 }
234 class CertMgrAdapterTest : public testing::Test {
235 public:
236 static void SetUpTestCase(void);
237 static void TearDownTestCase(void);
238 void SetUp();
239 void TearDown();
240 };
241
SetUpTestCase(void)242 void CertMgrAdapterTest::SetUpTestCase(void)
243 {
244 const char **perms = new const char *[2]; // 2 permissions
245 perms[0] = "ohos.permission.ACCESS_CERT_MANAGER_INTERNAL"; // system_basic
246 perms[1] = "ohos.permission.ACCESS_CERT_MANAGER"; // normal
247 NativeTokenInfoParams infoInstance = {
248 .dcapsNum = 0,
249 .permsNum = 2,
250 .dcaps = nullptr,
251 .perms = perms,
252 .acls = nullptr,
253 .processName = "TestCertManager",
254 .aplStr = "system_basic",
255 };
256
257 auto tokenId = GetAccessTokenId(&infoInstance);
258 SetSelfTokenID(tokenId);
259 OHOS::Security::AccessToken::AccessTokenKit::ReloadNativeTokenInfo();
260 delete[] perms;
261 *perms = nullptr;
262 }
263
TearDownTestCase(void)264 void CertMgrAdapterTest::TearDownTestCase(void)
265 {}
266
SetUp(void)267 void CertMgrAdapterTest::SetUp(void)
268 {}
269
TearDown(void)270 void CertMgrAdapterTest::TearDown(void)
271 {}
272
273 /**
274 * @tc.name: CertMgrAdapterTest_GetCertMaxSize_001
275 * @tc.desc: GetCertMaxSize.
276 * @tc.type: FUNC
277 * @tc.require:
278 */
279 HWTEST_F(CertMgrAdapterTest, CertMgrAdapterTest_GetCertMaxSize_001, TestSize.Level1)
280 {
281 CertManagerAdapterImpl adapter;
282 g_cerSize = adapter.GetCertMaxSize();
283 EXPECT_NE(g_cerSize, TEST_FAILURE);
284 g_appMaxSize = adapter.GetAppCertMaxSize();
285 EXPECT_NE(g_appMaxSize, TEST_FAILURE);
286 g_certSum = adapter.GetSytemRootCertSum();
287 std::string deviceType = OHOS::system::GetDeviceType();
288 if (deviceType == "phone" || deviceType == "default") {
289 EXPECT_NE(g_certSum, TEST_OK);
290 } else {
291 EXPECT_EQ(g_certSum, TEST_OK);
292 }
293 }
294
295 /**
296 * @tc.name: CertMgrAdapterTest_GetAppCert_002
297 * @tc.desc: GetAppCert.
298 * @tc.type: FUNC
299 * @tc.require:
300 */
301 HWTEST_F(CertMgrAdapterTest, CertMgrAdapterTest_GetAppCert_002, TestSize.Level1)
302 {
303 CertManagerAdapterImpl adapter;
304 uint8_t* certData = static_cast<uint8_t *>(malloc(g_cerSize));
305 EXPECT_NE(certData, nullptr);
306 int32_t result = adapter.GetSytemRootCertData(0, certData);
307 std::string deviceType = OHOS::system::GetDeviceType();
308 if (deviceType == "phone" || deviceType == "default") {
309 EXPECT_NE(result, -1);
310 } else {
311 EXPECT_EQ(result, -1);
312 }
313 free(certData);
314 certData = nullptr;
315 }
316
317 /**
318 * @tc.name: CertMgrAdapterTest_GetUserRootCertSum_003
319 * @tc.desc: GetUserRootCertSum.
320 * @tc.type: FUNC
321 * @tc.require:
322 */
323 HWTEST_F(CertMgrAdapterTest, CertMgrAdapterTest_GetUserRootCertSum_003, TestSize.Level1)
324 {
325 CertManagerAdapterImpl adapter;
326 g_userCertSum = adapter.GetUserRootCertSum();
327 EXPECT_EQ(g_userCertSum, TEST_OK);
328 }
329
330 /**
331 * @tc.name: CertMgrAdapterTest_GetUserRootCertData_004
332 * @tc.desc: GetUserRootCertData.
333 * @tc.type: FUNC
334 * @tc.require:
335 */
336 HWTEST_F(CertMgrAdapterTest, CertMgrAdapterTest_GetUserRootCertData_004, TestSize.Level1)
337 {
338 CertManagerAdapterImpl adapter;
339 uint8_t* userData = static_cast<uint8_t *>(malloc(g_cerSize));
340 EXPECT_NE(userData, nullptr);
341 int32_t result = adapter.GetUserRootCertData(g_userCertSum, userData);
342 EXPECT_EQ(result, -1);
343 free(userData);
344 userData = nullptr;
345 }
346
347 /**
348 * @tc.name: CertMgrAdapterTest_GetAppCert_005
349 * @tc.desc: GetAppCert.
350 * @tc.type: FUNC
351 * @tc.require:
352 */
353 HWTEST_F(CertMgrAdapterTest, CertMgrAdapterTest_GetAppCert_005, TestSize.Level1)
354 {
355 CertManagerAdapterImpl adapter;
356 uint8_t uriData[] = "oh:t=ak;o=inner020;u=0;a=0";
357 uint32_t len;
358 uint8_t* certData = static_cast<uint8_t *>(malloc(g_appMaxSize));
359 EXPECT_NE(certData, nullptr);
360 int32_t result = adapter.GetAppCert(uriData, certData, &len);
361 EXPECT_EQ(result, -1);
362 free(certData);
363 certData = nullptr;
364 }
365
366 /**
367 * @tc.name: CertMgrAdapterTest_Sign_006
368 * @tc.desc: Sign.
369 * @tc.type: FUNC
370 * @tc.require:
371 */
372 HWTEST_F(CertMgrAdapterTest, CertMgrAdapterTest_Sign_006, TestSize.Level1)
373 {
374 CertManagerAdapterImpl adapter;
375 uint8_t aliasData[] = "inner020";
376 struct CmBlob alias = { sizeof(aliasData), aliasData };
377 const uint8_t certPwd[] = "123456";
378 struct CmBlob appCert = { sizeof(g_rsa2048P12CertInfo), const_cast<uint8_t *>(g_rsa2048P12CertInfo) };
379 struct CmBlob appCertPwd = { sizeof(certPwd), const_cast<uint8_t *>(certPwd) };
380 uint8_t data[MAX_LEN_URI] = {0};
381 struct CmBlob keyUri = { sizeof(data), data };
382 int32_t result = CmInstallAppCert(&appCert, &appCertPwd, &alias, CM_PRI_CREDENTIAL_STORE, &keyUri);
383 uint8_t uriData[] = "oh:t=ak;o=inner020;u=0;a=0";
384 const uint8_t messageData[] = "this is message for private credential sign and verify";
385 uint8_t signData[DEFAULT_SIGNATURE_LEN] = {0};
386 result = adapter.Sign(uriData, messageData, sizeof(messageData),
387 signData, sizeof(signData));
388 std::string deviceType = OHOS::system::GetDeviceType();
389 if (deviceType == "phone" || deviceType == "default") {
390 EXPECT_NE(result, -1);
391 } else {
392 EXPECT_EQ(result, -1);
393 }
394 result = adapter.Sign(uriData, messageData, sizeof(messageData), nullptr, 0);
395 EXPECT_EQ(result, -1);
396 result = adapter.Sign(uriData, nullptr, 0, signData, sizeof(signData));
397 EXPECT_EQ(result, -1);
398
399 std::string hostname = "";
400 std::vector<std::string> certs;
401 bool getNameValue = adapter.GetTrustAnchorsForHostName(hostname, certs);
402 EXPECT_TRUE(getNameValue);
403 getNameValue = adapter.GetTrustAnchorsForHostName("hostnametest", certs);
404 EXPECT_TRUE(getNameValue);
405 }
406
407 /**
408 * @tc.name: CertMgrAdapterTest_InitCertList_007
409 * @tc.desc: InitCertList.
410 * @tc.type: FUNC
411 * @tc.require:
412 */
413 HWTEST_F(CertMgrAdapterTest, CertMgrAdapterTest_InitCertList_007, TestSize.Level1)
414 {
415 CertManagerAdapterImpl adapter;
416 int32_t result = adapter.InitCertInfo(nullptr);
417 EXPECT_NE(result, 0);
418 adapter.FreeCMBlobData(nullptr);
419 struct CmBlob *blob = static_cast<CmBlob *>(malloc(g_appMaxSize));
420 EXPECT_NE(blob, nullptr);
421 blob->data = nullptr;
422 adapter.FreeCMBlobData(blob);
423 adapter.FreeCertList(nullptr);
424 struct CertList *certList = static_cast<CertList *>(malloc(g_appMaxSize));
425 EXPECT_NE(certList, nullptr);
426 certList->certAbstract = nullptr;
427 adapter.FreeCertList(certList);
428
429 char uri[] = "webtest";
430 struct CertInfo certInfo;
431 unsigned int len = sizeof(struct CertInfo);
432 (void)memset_s(&certInfo, len, 0, len);
433 result = adapter.GetCertInfo(uri, &certInfo, CM_USER_TRUSTED_STORE);
434 EXPECT_NE(result, 0);
435 result = adapter.GetCertInfo(uri, &certInfo, CM_SYSTEM_TRUSTED_STORE);
436 EXPECT_NE(result, 0);
437 result = adapter.GetCertInfo(uri, &certInfo, CM_CREDENTIAL_STORE);
438 EXPECT_NE(result, 0);
439
440 char subjectName[] = "test";
441 uint8_t certData[] = "inner020";
442 result = adapter.GetCertDataBySubject(subjectName, certData, CM_CREDENTIAL_STORE);
443 EXPECT_NE(result, 0);
444 result = adapter.GetCertDataBySubject(subjectName, certData, CM_USER_TRUSTED_STORE);
445 EXPECT_NE(result, 0);
446 result = adapter.GetCertDataBySubject(subjectName, certData, CM_SYSTEM_TRUSTED_STORE);
447 EXPECT_NE(result, 0);
448 }
449
450 /**
451 * @tc.name: CertMgrAdapterTest_GetPinSetForHostName_008
452 * @tc.desc: GetPinSetForHostName.
453 * @tc.type: FUNC
454 * @tc.require:
455 */
456 HWTEST_F(CertMgrAdapterTest, CertMgrAdapterTest_GetPinSetForHostName_008, TestSize.Level1)
457 {
458 CertManagerAdapterImpl adapter;
459 const std::string hostname = "testweb";
460 std::vector<std::string> pins;
461 bool result = adapter.GetPinSetForHostName(hostname, pins);
462 EXPECT_TRUE(result);
463 }
464 } // namespace OHOS