• 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 #ifndef HDC_PASSWORD_H
16 #define HDC_PASSWORD_H
17 #include <vector>
18 #include <string>
19 #include <memory>
20 #include <utility>
21 #include <iomanip>
22 
23 #include "credential_message.h"
24 #include "hdc_huks.h"
25 namespace Hdc {
26 #define PASSWORD_LENGTH 10
27 
28 const std::string HDC_CREDENTIAL_SOCKET_SANDBOX_PATH = "/data/hdc/hdc_huks/hdc_credential.socket";
29 
30 class HdcPassword {
31 public:
32     ~HdcPassword();
33     explicit HdcPassword(const std::string &pwdKeyAlias);
34     void GeneratePassword(void);
35     bool DecryptPwd(std::vector<uint8_t>& encryptData);
36     bool EncryptPwd(void);
37     std::pair<uint8_t*, int> GetPassword(void);
38     std::string GetEncryptPassword(void);
39     bool ResetPwdKey();
40     int GetEncryptPwdLength();
41     char GetHexChar(uint8_t data);
42 private:
43     uint8_t pwd[PASSWORD_LENGTH];
44     std::string encryptPwd;
45     HdcHuks hdcHuks;
46     void ByteToHex(std::vector<uint8_t>& byteData);
47     bool HexToByte(std::vector<uint8_t>& hexData);
48     uint8_t HexCharToInt(uint8_t data);
49     void ClearEncryptPwd(void);
50     std::string SplicMessageStr(const std::string& str, const size_t type);
51     std::string SendToUnixSocketAndRecvStr(const char* socketPath, const std::string& messageStr);
52     std::vector<uint8_t> EncryptGetPwdValue(uint8_t* pwd, int pwdLen);
53     std::pair<uint8_t*, int> DecryptGetPwdValue(const std::string& encryptData);
54 };
55 
56 } // namespace Hdc
57 #endif // HDC_PASSWORD_H