• 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 #ifndef OHOS_LOCAL_SIGN_KEY_H
17 #define OHOS_LOCAL_SIGN_KEY_H
18 
19 #include <memory>
20 #include <mutex>
21 #include <string>
22 
23 #include "byte_buffer.h"
24 #include "errcode.h"
25 #include "huks_param_set.h"
26 #include "log.h"
27 #include "bundle_mgr_proxy.h"
28 #include "sign_key.h"
29 
30 namespace OHOS {
31 namespace Security {
32 namespace CodeSign {
33 class LocalSignKey : public SignKey {
34 public:
35     static LocalSignKey &GetInstance();
36     const ByteBuffer *GetSignCert() override;
37     bool Sign(const ByteBuffer &data, ByteBuffer &ret) override;
38     const HksCertChain *GetCertChain();
39     void SetChallenge(const ByteBuffer &challenge);
40     bool InitKey();
41     int32_t GetFormattedCertChain(ByteBuffer &buffer);
42 
43 private:
44     LocalSignKey();
45     ~LocalSignKey();
46 
47     LocalSignKey(const LocalSignKey &source) = delete;
48     LocalSignKey &operator = (const LocalSignKey &source) = delete;
49 
50     bool GenerateKey();
51     HksCertChain *QueryCertChain();
52     bool GetKeyParamSet(HUKSParamSet &paramSet);
53     bool GetAttestParamSet(HUKSParamSet &paramSet);
54     bool GetSignParamSet(HUKSParamSet &paramSet);
55     bool SignByHUKS(const struct HksBlob *inData, struct HksBlob *outData);
56     sptr<AppExecFwk::IBundleMgr> Connect();
57     bool UpdateKey();
58 
59 private:
60     ByteBuffer *cert_ = nullptr;
61     HksCertChain *certChain_ = nullptr;
62     std::unique_ptr<ByteBuffer> challenge_ = nullptr;
63     std::mutex lock_;
64     std::string algorithm_ = "ECDSA256";
65 };
66 }
67 }
68 }
69 
70 #endif