1 /*
2 * Copyright (c) 2023 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 "ohos_adapter/bridge/ark_cert_manager_adapter_wrapper.h"
17
18 namespace OHOS::ArkWeb {
19
ArkCertManagerAdapterWrapper(ArkWebRefPtr<ArkCertManagerAdapter> ref)20 ArkCertManagerAdapterWrapper::ArkCertManagerAdapterWrapper(ArkWebRefPtr<ArkCertManagerAdapter> ref) : ctocpp_(ref) {}
21
GetCertMaxSize()22 uint32_t ArkCertManagerAdapterWrapper::GetCertMaxSize()
23 {
24 return ctocpp_->GetCertMaxSize();
25 }
26
GetAppCertMaxSize()27 uint32_t ArkCertManagerAdapterWrapper::GetAppCertMaxSize()
28 {
29 return ctocpp_->GetAppCertMaxSize();
30 }
31
GetSytemRootCertData(uint32_t certCount,uint8_t * certData)32 int32_t ArkCertManagerAdapterWrapper::GetSytemRootCertData(uint32_t certCount, uint8_t* certData)
33 {
34 return ctocpp_->GetSytemRootCertData(certCount, certData);
35 }
36
GetSytemRootCertSum()37 uint32_t ArkCertManagerAdapterWrapper::GetSytemRootCertSum()
38 {
39 return ctocpp_->GetSytemRootCertSum();
40 }
41
GetUserRootCertData(uint32_t certCount,uint8_t * certData)42 int32_t ArkCertManagerAdapterWrapper::GetUserRootCertData(uint32_t certCount, uint8_t* certData)
43 {
44 return ctocpp_->GetUserRootCertData(certCount, certData);
45 }
46
GetUserRootCertSum()47 uint32_t ArkCertManagerAdapterWrapper::GetUserRootCertSum()
48 {
49 return ctocpp_->GetUserRootCertSum();
50 }
51
GetAppCert(uint8_t * uriData,uint8_t * certData,uint32_t * len)52 int32_t ArkCertManagerAdapterWrapper::GetAppCert(uint8_t* uriData, uint8_t* certData, uint32_t* len)
53 {
54 return ctocpp_->GetAppCert(uriData, certData, len);
55 }
56
Sign(const uint8_t * uri,const uint8_t * certData,uint32_t certDataLen,uint8_t * signData,uint32_t signDataLen)57 int32_t ArkCertManagerAdapterWrapper::Sign(
58 const uint8_t* uri, const uint8_t* certData, uint32_t certDataLen, uint8_t* signData, uint32_t signDataLen)
59 {
60 return ctocpp_->Sign(uri, certData, certDataLen, signData, signDataLen);
61 }
62
GetCertDataBySubject(const char * subjectName,uint8_t * certData,int32_t certType)63 int32_t ArkCertManagerAdapterWrapper::GetCertDataBySubject(const char* subjectName, uint8_t* certData, int32_t certType)
64 {
65 return ctocpp_->GetCertDataBySubject(subjectName, certData, certType);
66 }
67
VerifyCertFromNetSsl(uint8_t * certData,uint32_t certSize)68 int ArkCertManagerAdapterWrapper::VerifyCertFromNetSsl(uint8_t* certData, uint32_t certSize)
69 {
70 return ctocpp_->VerifyCertFromNetSsl(certData, certSize);
71 }
72
GetTrustAnchorsForHostName(const std::string & hostname,std::vector<std::string> & certs)73 bool ArkCertManagerAdapterWrapper::GetTrustAnchorsForHostName(
74 const std::string& hostname, std::vector<std::string>& certs)
75 {
76 ArkWebString ark_hostname = ArkWebStringClassToStruct(hostname);
77 ArkWebStringVector ark_certs = ArkWebStringVectorClassToStruct(certs);
78 bool result = ctocpp_->GetTrustAnchorsForHostName(ark_hostname, ark_certs);
79 certs = ArkWebStringVectorStructToClass(ark_certs);
80 ArkWebStringStructRelease(ark_hostname);
81 ArkWebStringVectorStructRelease(ark_certs);
82 return result;
83 }
84
GetPinSetForHostName(const std::string & hostname,std::vector<std::string> & pins)85 bool ArkCertManagerAdapterWrapper::GetPinSetForHostName(const std::string& hostname, std::vector<std::string>& pins)
86 {
87 ArkWebString ark_hostname = ArkWebStringClassToStruct(hostname);
88 ArkWebStringVector ark_pins = ArkWebStringVectorClassToStruct(pins);
89 bool result = ctocpp_->GetPinSetForHostName(ark_hostname, ark_pins);
90 pins = ArkWebStringVectorStructToClass(ark_pins);
91 ArkWebStringStructRelease(ark_hostname);
92 ArkWebStringVectorStructRelease(ark_pins);
93 return result;
94 }
95
96 } // namespace OHOS::ArkWeb
97