• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #include "net_ssl_exec.h"
17 
18 #include "napi_utils.h"
19 #include "net_ssl_async_work.h"
20 #include "netstack_common_utils.h"
21 #include "netstack_log.h"
22 
23 namespace OHOS::NetStack::Ssl {
ExecVerify(CertContext * context)24 bool SslExec::ExecVerify(CertContext *context)
25 {
26     context->SetPermissionDenied(true);
27 
28     if (context->GetErrorCode() == PARSE_ERROR_CODE) {
29         return false;
30     }
31 
32     if (context->GetCertBlob() == nullptr) {
33         return false;
34     }
35 
36     if (context->GetCertBlobClient() == nullptr) {
37         context->SetErrorCode(NetStackVerifyCertification(context->GetCertBlob()));
38         NETSTACK_LOGD("verifyResult is %{public}d\n", context->GetErrorCode());
39 
40         if (context->GetErrorCode() != 0) {
41             return false;
42         }
43     } else {
44         context->SetErrorCode(NetStackVerifyCertification(context->GetCertBlob(), context->GetCertBlobClient()));
45         NETSTACK_LOGD("verifyResult is %{public}d\n", context->GetErrorCode());
46         if (context->GetErrorCode() != 0) {
47             return false;
48         }
49     }
50 
51     return true;
52 }
53 
VerifyCallback(CertContext * context)54 napi_value SslExec::VerifyCallback(CertContext *context)
55 {
56     napi_value result;
57     napi_create_int32(context->GetEnv(), static_cast<int32_t>(context->GetErrorCode()), &result);
58     return result;
59 }
60 
61 #ifndef MAC_PLATFORM
AsyncRunVerify(CertContext * context)62 void SslExec::AsyncRunVerify(CertContext *context)
63 {
64     NetSslAsyncWork::ExecVerify(context->GetEnv(), context);
65 }
66 #endif
67 } // namespace OHOS::NetStack::Ssl
68