• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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 STORAGE_DAEMON_CRYPTO_FSCRYPT_KEY_V1_EXT_H
17 #define STORAGE_DAEMON_CRYPTO_FSCRYPT_KEY_V1_EXT_H
18 
19 #include <string>
20 
21 #include "key_blob.h"
22 
23 namespace OHOS {
24 namespace StorageDaemon {
25 class FscryptKeyV1Ext {
26 public:
27     FscryptKeyV1Ext() = default;
28     ~FscryptKeyV1Ext() = default;
SetDir(const std::string & dir)29     void SetDir(const std::string &dir)
30     {
31         dir_ = dir;
32         userId_ = GetUserIdFromDir();
33         type_ = GetTypeFromDir();
34     }
35     int32_t ActiveKeyExt(uint32_t flag, KeyBlob &iv, uint32_t &elType, const KeyBlob &authToken);
36     int32_t ActiveDoubleKeyExt(uint32_t flag, KeyBlob &iv, uint32_t &elType, const KeyBlob &authToken);
37     int32_t InactiveKeyExt(uint32_t flag);
38     int32_t LockUserScreenExt(uint32_t flag, uint32_t &elType);
39     int32_t UnlockUserScreenExt(uint32_t flag, uint8_t *iv, uint32_t size, const KeyBlob &authToken);
40     int32_t AddClassE(bool &isNeedEncryptClassE, bool &isSupport, uint32_t status);
41     int32_t DeleteClassEPinCode(uint32_t userId);
42     int32_t ChangePinCodeClassE(uint32_t userId, bool &isFbeSupport);
43     int32_t UpdateClassEBackUp(uint32_t userId);
44     int32_t ReadClassE(uint32_t status, KeyBlob &classEBuffer, const KeyBlob &authToken, bool &isFbeSupport);
45     int32_t WriteClassE(uint32_t status, uint8_t *classEBuffer, uint32_t length);
46     int32_t GenerateAppkey(uint32_t userId, uint32_t appUid, std::unique_ptr<uint8_t[]> &keyId, uint32_t size);
47     int32_t LockUeceExt(bool &isFbeSupport);
48 
49 private:
50     uint32_t GetUserIdFromDir();
51     uint32_t GetTypeFromDir();
52     uint32_t GetMappedUserId(uint32_t userId, uint32_t type);
53     uint32_t GetMappedDeUserId(uint32_t userId);
54 
55     std::string dir_;
56     uint32_t userId_ = 0;
57     uint32_t type_ = 0;
58 };
59 } // namespace StorageDaemon
60 } // namespace OHOS
61 
62 #endif // STORAGE_DAEMON_CRYPTO_FSCRYPT_KEY_V1_EXT_H