• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2025 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 OHOS_DM_AUTH_CERT_H
17 #define OHOS_DM_AUTH_CERT_H
18 
19 #include <dlfcn.h>
20 
21 #include "dm_cert.h"
22 #include "i_dm_auth_cert_ext.h"
23 #if defined(__LITEOS_M__)
24 #include "dm_mutex.h"
25 #else
26 #include <mutex>
27 #endif
28 
29 namespace OHOS {
30 namespace DistributedHardware {
31 class AuthCert {
32 public:
GetInstance(void)33     static AuthCert &GetInstance(void)
34     {
35         static AuthCert instance;
36         return instance;
37     }
38 
39     int32_t GenerateCertificate(DmCertChain &dmCertChain);
40     int32_t VerifyCertificate(const DmCertChain &dmCertChain, const char *deviceIdHash);
41     int32_t GenerateCertificateV2(DmCertChain &dmCertChain, const uint64_t random);
42     int32_t VerifyCertificateV2(const DmCertChain &dmCertChain, const char *deviceIdHash, const uint64_t random);
43 
44 private:
45     AuthCert();
46     ~AuthCert();
47     bool IsDMAdapterAuthCertLoaded();
48 
49     bool isAdapterAuthCertSoLoaded_ = false;
50     void *authCertSoHandle_ = nullptr;
51     std::mutex isAdapterAuthCertLoadedLock_;
52     std::shared_ptr<IDMAuthCertExt> dmAuthCertExt_;
53 };
54 } // namespace DistributedHardware
55 } // namespace OHOS
56 
57 #endif // OHOS_DM_AUTH_CERT_H