Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Startup Init Lite
提交
e8a8502c
S
Startup Init Lite
项目概览
OpenHarmony
/
Startup Init Lite
1 年多 前同步成功
通知
3
Star
37
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Startup Init Lite
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
e8a8502c
编写于
8月 01, 2022
作者:
O
openharmony_ci
提交者:
Gitee
8月 01, 2022
浏览文件
操作
浏览文件
下载
差异文件
!933 fscrypt: add file crypto implementation
Merge pull request !933 from qilongzhang/dev_0713
上级
19efb3c8
3d01c25c
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
131 addition
and
56 deletion
+131
-56
interfaces/innerkits/fs_manager/fstab.c
interfaces/innerkits/fs_manager/fstab.c
+61
-1
interfaces/innerkits/fs_manager/fstab_mount.c
interfaces/innerkits/fs_manager/fstab_mount.c
+2
-1
interfaces/innerkits/include/fs_manager/fs_manager.h
interfaces/innerkits/include/fs_manager/fs_manager.h
+5
-1
services/etc/init.cfg
services/etc/init.cfg
+4
-1
services/init/include/init_cmds.h
services/init/include/init_cmds.h
+1
-1
services/init/init_common_cmds.c
services/init/init_common_cmds.c
+5
-24
services/init/lite/init_cmds.c
services/init/lite/init_cmds.c
+4
-5
services/init/standard/BUILD.gn
services/init/standard/BUILD.gn
+8
-1
services/init/standard/init_cmds.c
services/init/standard/init_cmds.c
+29
-18
test/unittest/BUILD.gn
test/unittest/BUILD.gn
+11
-0
test/unittest/init/cmds_unittest.cpp
test/unittest/init/cmds_unittest.cpp
+0
-2
test/unittest/innerkits/innerkits_unittest.cpp
test/unittest/innerkits/innerkits_unittest.cpp
+1
-1
未找到文件。
interfaces/innerkits/fs_manager/fstab.c
浏览文件 @
e8a8502c
...
...
@@ -42,6 +42,8 @@ struct MountFlags {
unsigned
long
flags
;
};
static
char
*
g_fscryptPolicy
=
NULL
;
static
unsigned
int
ConvertFlags
(
char
*
flagBuffer
)
{
static
struct
FsManagerFlags
fsFlags
[]
=
{
...
...
@@ -384,7 +386,60 @@ static unsigned long ParseDefaultMountFlag(const char *str)
return
flags
;
}
unsigned
long
GetMountFlags
(
char
*
mountFlag
,
char
*
fsSpecificData
,
size_t
fsSpecificDataSize
)
static
bool
IsFscryptOption
(
const
char
*
option
)
{
BEGET_LOGI
(
"IsFscryptOption start"
);
if
(
!
option
)
{
return
false
;
}
char
*
fscryptPre
=
"fscrypt="
;
if
(
strncmp
(
option
,
fscryptPre
,
strlen
(
fscryptPre
))
==
0
)
{
return
true
;
}
return
false
;
}
static
void
StoreFscryptPolicy
(
const
char
*
option
)
{
if
(
option
==
NULL
)
{
return
;
}
if
(
g_fscryptPolicy
!=
NULL
)
{
BEGET_LOGW
(
"StoreFscryptPolicy:inited policy is not empty"
);
free
(
g_fscryptPolicy
);
}
g_fscryptPolicy
=
strdup
(
option
);
if
(
g_fscryptPolicy
==
NULL
)
{
BEGET_LOGE
(
"StoreFscryptPolicy:no memory"
);
return
;
}
BEGET_LOGI
(
"StoreFscryptPolicy:store fscrypt policy, %s"
,
option
);
}
int
LoadFscryptPolicy
(
char
*
buf
,
size_t
size
)
{
BEGET_LOGI
(
"LoadFscryptPolicy start"
);
if
(
buf
==
NULL
||
g_fscryptPolicy
==
NULL
)
{
BEGET_LOGE
(
"LoadFscryptPolicy:buf or fscrypt policy is empty"
);
return
-
ENOMEM
;
}
if
(
size
<=
0
)
{
BEGET_LOGE
(
"LoadFscryptPloicy:size is invalid"
);
return
-
EINVAL
;
}
if
(
strcpy_s
(
buf
,
size
,
g_fscryptPolicy
)
!=
0
)
{
BEGET_LOGE
(
"loadFscryptPolicy:strcmp failed, error = %d"
,
errno
);
return
-
EFAULT
;
}
free
(
g_fscryptPolicy
);
g_fscryptPolicy
=
NULL
;
BEGET_LOGI
(
"LoadFscryptPolicy success"
);
return
0
;
}
unsigned
long
GetMountFlags
(
char
*
mountFlag
,
char
*
fsSpecificData
,
size_t
fsSpecificDataSize
,
const
char
*
mountPoint
)
{
unsigned
long
flags
=
0
;
BEGET_CHECK_RETURN_VALUE
(
mountFlag
!=
NULL
&&
fsSpecificData
!=
NULL
,
0
);
...
...
@@ -408,6 +463,11 @@ unsigned long GetMountFlags(char *mountFlag, char *fsSpecificData, size_t fsSpec
if
(
IsDefaultMountFlags
(
p
))
{
flags
|=
ParseDefaultMountFlag
(
p
);
}
else
{
if
(
IsFscryptOption
(
p
)
&&
!
strncmp
(
mountPoint
,
"/data"
,
strlen
(
"/data"
)))
{
StoreFscryptPolicy
(
p
+
strlen
(
"fscrypt="
));
continue
;
}
if
(
strncat_s
(
fsSpecificData
,
fsSpecificDataSize
-
1
,
p
,
strlen
(
p
))
!=
EOK
)
{
BEGET_LOGW
(
"Failed to append mount flag
\"
%s
\"
, ignore it."
,
p
);
continue
;
...
...
interfaces/innerkits/fs_manager/fstab_mount.c
浏览文件 @
e8a8502c
...
...
@@ -293,7 +293,8 @@ int MountOneItem(FstabItem *item)
unsigned
long
mountFlags
;
char
fsSpecificData
[
FS_MANAGER_BUFFER_SIZE
]
=
{
0
};
mountFlags
=
GetMountFlags
(
item
->
mountOptions
,
fsSpecificData
,
sizeof
(
fsSpecificData
));
mountFlags
=
GetMountFlags
(
item
->
mountOptions
,
fsSpecificData
,
sizeof
(
fsSpecificData
),
item
->
mountPoint
);
if
(
!
IsSupportedFilesystem
(
item
->
fsType
))
{
BEGET_LOGE
(
"Unsupported file system
\"
%s
\"
"
,
item
->
fsType
);
return
0
;
...
...
interfaces/innerkits/include/fs_manager/fs_manager.h
浏览文件 @
e8a8502c
...
...
@@ -70,9 +70,13 @@ MountStatus GetMountStatusForMountPoint(const char *mp);
int
MountAllWithFstabFile
(
const
char
*
fstabFile
,
bool
required
);
int
MountAllWithFstab
(
const
Fstab
*
fstab
,
bool
required
);
int
UmountAllWithFstabFile
(
const
char
*
file
);
unsigned
long
GetMountFlags
(
char
*
mountFlag
,
char
*
fsSpecificFlags
,
size_t
fsSpecificFlagSize
);
unsigned
long
GetMountFlags
(
char
*
mountFlag
,
char
*
fsSpecificFlags
,
size_t
fsSpecificFlagSize
,
const
char
*
mountPoint
);
int
GetBlockDevicePath
(
const
char
*
partName
,
char
*
path
,
int
size
);
// Get fscrypt policy if exist
int
LoadFscryptPolicy
(
char
*
buf
,
size_t
size
);
#ifdef __cplusplus
#if __cplusplus
}
...
...
services/etc/init.cfg
浏览文件 @
e8a8502c
...
...
@@ -21,7 +21,8 @@
"load_persist_params ",
"bootchart start",
"chown access_token access_token /dev/access_token_id",
"chmod 0666 /dev/access_token_id"
"chmod 0666 /dev/access_token_id",
"start samgr"
]
}, {
"name" : "init",
...
...
@@ -105,6 +106,7 @@
}, {
"name" : "post-fs-data",
"cmds" : [
"init_global_key /data",
"mkdir /data/app 0711 root root",
"mkdir /data/app/el1 0711 root root",
"mkdir /data/app/el1/bundle 0711 root root",
...
...
@@ -121,6 +123,7 @@
"mkdir /data/chipset/el1 0711 root root",
"mkdir /data/chipset/el1/public 0711 root root",
"mkdir /data/chipset/el2 0711 root root",
"init_main_user ",
"mkdir /data/app/el1/0 0711 root root",
"mkdir /data/app/el1/0/base 0711 root root",
"mkdir /data/app/el1/0/database 0711 system system",
...
...
services/init/include/init_cmds.h
浏览文件 @
e8a8502c
...
...
@@ -81,7 +81,7 @@ const struct CmdTable *GetCmdByName(const char *name);
void
ExecReboot
(
const
char
*
value
);
char
*
BuildStringFromCmdArg
(
const
struct
CmdArgs
*
ctx
,
int
startIndex
);
void
ExecCmd
(
const
struct
CmdTable
*
cmd
,
const
char
*
cmdContent
);
int
FileCryptEnable
(
char
*
fileCryptOption
);
int
SetFileCryptPolicy
(
const
char
*
dir
);
void
OpenHidebug
(
const
char
*
name
);
#ifdef __cplusplus
...
...
services/init/init_common_cmds.c
浏览文件 @
e8a8502c
...
...
@@ -41,8 +41,6 @@
#endif
#include "securec.h"
static
char
*
g_fileCryptOptions
=
NULL
;
static
char
*
AddOneArg
(
const
char
*
param
,
size_t
paramLen
)
{
int
valueCount
=
1
;
...
...
@@ -345,6 +343,11 @@ static void DoMkDir(const struct CmdArgs *ctx)
if
(
ret
!=
0
)
{
INIT_LOGE
(
"Failed to change owner %s, err %d."
,
ctx
->
argv
[
0
],
errno
);
}
ret
=
SetFileCryptPolicy
(
ctx
->
argv
[
0
]);
if
(
ret
!=
0
)
{
INIT_LOGW
(
"failed to set file fscrypt"
);
}
return
;
}
...
...
@@ -397,16 +400,6 @@ static int GetMountFlag(unsigned long *mountflag, const char *targetStr, const c
WaitForFile
(
source
,
WAIT_MAX_SECOND
);
return
1
;
}
const
char
*
fileCryptPre
=
"filecrypt="
;
size_t
len
=
strlen
(
fileCryptPre
);
if
(
strncmp
(
targetStr
,
fileCryptPre
,
len
)
==
0
)
{
size_t
maxLen
=
strlen
(
targetStr
)
+
1
;
g_fileCryptOptions
=
calloc
(
sizeof
(
char
),
maxLen
);
INIT_ERROR_CHECK
(
g_fileCryptOptions
!=
NULL
,
return
0
,
"Failed to alloc memory"
);
int
ret
=
snprintf_s
(
g_fileCryptOptions
,
maxLen
,
maxLen
-
1
,
"%s"
,
targetStr
+
len
);
INIT_ERROR_CHECK
(
ret
>=
0
,
return
0
,
"Failed to snprintf"
);
return
1
;
}
return
0
;
}
...
...
@@ -449,18 +442,6 @@ static void DoMount(const struct CmdArgs *ctx)
if
(
ret
!=
0
)
{
INIT_LOGE
(
"Failed to mount for %s, err %d."
,
target
,
errno
);
}
if
((
g_fileCryptOptions
!=
NULL
)
&&
(
strncmp
(
target
,
"/data"
,
strlen
(
"/data"
))
==
0
))
{
ret
=
FileCryptEnable
(
g_fileCryptOptions
);
if
(
ret
<
0
)
{
INIT_LOGE
(
"File Crypt enabled failed"
);
free
(
g_fileCryptOptions
);
g_fileCryptOptions
=
NULL
;
return
;
}
free
(
g_fileCryptOptions
);
g_fileCryptOptions
=
NULL
;
INIT_LOGI
(
"File Crypt enabled success"
);
}
}
static
int
DoWriteWithMultiArgs
(
const
struct
CmdArgs
*
ctx
,
int
fd
)
...
...
services/init/lite/init_cmds.c
浏览文件 @
e8a8502c
...
...
@@ -108,11 +108,6 @@ static void DoLoadCfg(const struct CmdArgs *ctx)
(
void
)
fclose
(
fp
);
}
int
FileCryptEnable
(
char
*
fileCryptOption
)
{
return
0
;
}
static
const
struct
CmdTable
g_cmdTable
[]
=
{
{
"exec "
,
1
,
10
,
DoExec
},
{
"loadcfg "
,
1
,
1
,
DoLoadCfg
},
...
...
@@ -133,4 +128,8 @@ void PluginExecCmdByCmdIndex(int index, const char *cmdContent)
const
char
*
PluginGetCmdIndex
(
const
char
*
cmdStr
,
int
*
index
)
{
return
NULL
;
}
int
SetFileCryptPolicy
(
const
char
*
dir
)
{
return
0
;
}
\ No newline at end of file
services/init/standard/BUILD.gn
浏览文件 @
e8a8502c
...
...
@@ -24,6 +24,9 @@ init_common_sources = [
"../main.c",
]
FSCRYPT_PATH =
"//foundation/filemanagement/storage_service/services/storage_daemon"
import("//build/ohos.gni")
import("//build/ohos/native_stub/native_stub.gni")
...
...
@@ -51,7 +54,10 @@ ohos_executable("init") {
sources += modulemgr_sources
sources += init_common_sources
include_dirs = [ "//base/startup/init/services/init/include" ]
include_dirs = [
"//base/startup/init/services/init/include",
"${FSCRYPT_PATH}/include/libfscrypt",
]
deps = [
"//base/startup/init/interfaces/innerkits/control_fd:libcontrolfd",
...
...
@@ -76,6 +82,7 @@ ohos_executable("init") {
deps += [ "//base/startup/init/interfaces/innerkits/init_module_engine:libinit_stub_versionscript" ]
deps += [ "//base/startup/init/interfaces/innerkits/init_module_engine:init_module_engine_sources" ]
deps += [ "//base/startup/init/services/modules:static_modules" ]
deps += [ "${FSCRYPT_PATH}/libfscrypt:libfscryptutils_static" ]
cflags = []
...
...
services/init/standard/init_cmds.c
浏览文件 @
e8a8502c
...
...
@@ -44,8 +44,9 @@
#ifdef WITH_SELINUX
#include <policycoreutils.h>
#endif
#include "fscrypt_utils.h"
static
const
char
*
g_fscryptPolicyKey
=
"fscrypt.policy.config"
;
#define FSCRYPT_POLICY_BUF_SIZE (60)
int
GetParamValue
(
const
char
*
symValue
,
unsigned
int
symLen
,
char
*
paramValue
,
unsigned
int
paramLen
)
{
...
...
@@ -412,6 +413,18 @@ static void DoTimerStop(const struct CmdArgs *ctx)
ServiceStopTimer
(
service
);
}
static
bool
InitFscryptPolicy
(
void
)
{
char
policy
[
FSCRYPT_POLICY_BUF_SIZE
];
if
(
LoadFscryptPolicy
(
policy
,
FSCRYPT_POLICY_BUF_SIZE
)
!=
0
)
{
return
false
;
}
if
(
SetFscryptSysparam
(
policy
)
==
0
)
{
return
true
;
}
return
false
;
}
static
void
DoInitGlobalKey
(
const
struct
CmdArgs
*
ctx
)
{
INIT_LOGI
(
"DoInitGlobalKey: start"
);
...
...
@@ -424,6 +437,11 @@ static void DoInitGlobalKey(const struct CmdArgs *ctx)
INIT_LOGE
(
"DoInitGlobalKey: not data partitation"
);
return
;
}
if
(
!
InitFscryptPolicy
())
{
INIT_LOGI
(
"DoInitGlobalKey:init fscrypt failed,not enable fscrypt"
);
return
;
}
char
*
const
argv
[]
=
{
"/system/bin/sdc"
,
"filecrypt"
,
...
...
@@ -442,6 +460,7 @@ static void DoInitMainUser(const struct CmdArgs *ctx)
INIT_LOGE
(
"DoInitMainUser: para invalid"
);
return
;
}
char
*
const
argv
[]
=
{
"/system/bin/sdc"
,
"filecrypt"
,
...
...
@@ -453,23 +472,6 @@ static void DoInitMainUser(const struct CmdArgs *ctx)
INIT_LOGI
(
"DoInitMainUser: end, ret = %d"
,
ret
);
}
int
FileCryptEnable
(
char
*
fileCryptOption
)
{
INIT_LOGI
(
"FileCryptEnable: start"
);
if
(
fileCryptOption
==
NULL
)
{
INIT_LOGE
(
"FileCryptEnable:option null"
);
return
-
EINVAL
;
}
int
ret
=
SystemWriteParam
(
g_fscryptPolicyKey
,
fileCryptOption
);
if
(
ret
!=
0
)
{
INIT_LOGE
(
"FileCryptEnable:set fscrypt config failed"
);
return
ret
;
}
INIT_LOGI
(
"FileCryptEnable:set fscrypt config success, policy:%s"
,
fileCryptOption
);
return
ret
;
}
static
void
DoMkswap
(
const
struct
CmdArgs
*
ctx
)
{
INIT_LOGI
(
"DoMkswap: start"
);
...
...
@@ -595,3 +597,12 @@ void OpenHidebug(const char *name)
}
while
(
0
);
#endif
}
int
SetFileCryptPolicy
(
const
char
*
dir
)
{
if
(
dir
==
NULL
)
{
INIT_LOGE
(
"SetFileCryptPolicy:dir is null"
);
return
-
EINVAL
;
}
return
FscryptPolicyEnable
(
dir
);
}
test/unittest/BUILD.gn
浏览文件 @
e8a8502c
...
...
@@ -30,6 +30,9 @@ config("utest_config") {
ldflags = [ "--coverage" ]
}
FSCRYPT_PATH =
"//foundation/filemanagement/storage_service/services/storage_daemon"
ohos_unittest("init_unittest") {
module_out_path = "startup/init"
sources = [
...
...
@@ -105,6 +108,13 @@ ohos_unittest("init_unittest") {
"//base/startup/init/ueventd/ueventd_socket.c",
]
sources += [
"${FSCRYPT_PATH}/libfscrypt/src/fscrypt_control.c",
"${FSCRYPT_PATH}/libfscrypt/src/fscrypt_utils.c",
"${FSCRYPT_PATH}/libfscrypt/src/key_control.c",
"${FSCRYPT_PATH}/libfscrypt/src/sysparam_static.c",
]
if (defined(build_selinux) && build_selinux) {
sources += [ "//base/startup/init/services/param/adapter/param_selinux.c" ]
}
...
...
@@ -198,6 +208,7 @@ ohos_unittest("init_unittest") {
"//base/security/access_token/interfaces/innerkits/nativetoken/include",
"//base/startup/init/interfaces/innerkits/sandbox/include",
"//base/startup/init/interfaces/innerkits/hals",
"${FSCRYPT_PATH}/include/libfscrypt",
]
deps = [
...
...
test/unittest/init/cmds_unittest.cpp
浏览文件 @
e8a8502c
...
...
@@ -269,8 +269,6 @@ HWTEST_F(CmdsUnitTest, TestGetCmdLinesFromJson, TestSize.Level1)
}
HWTEST_F
(
CmdsUnitTest
,
TestInitCmdFunc
,
TestSize
.
Level1
)
{
FileCryptEnable
((
char
*
)
"test"
);
FileCryptEnable
(
nullptr
);
int
ret
=
GetBootModeFromMisc
();
EXPECT_EQ
(
ret
,
0
);
}
...
...
test/unittest/innerkits/innerkits_unittest.cpp
浏览文件 @
e8a8502c
...
...
@@ -112,7 +112,7 @@ HWTEST_F(InnerkitsUnitTest, GetMountFlags_unitest, TestSize.Level1)
}
const
int
bufferSize
=
512
;
char
fsSpecificOptions
[
bufferSize
]
=
{
0
};
unsigned
long
flags
=
GetMountFlags
(
item
->
mountOptions
,
fsSpecificOptions
,
bufferSize
);
unsigned
long
flags
=
GetMountFlags
(
item
->
mountOptions
,
fsSpecificOptions
,
bufferSize
,
item
->
mountPoint
);
EXPECT_EQ
(
flags
,
static_cast
<
unsigned
long
>
(
MS_NOSUID
|
MS_NODEV
|
MS_NOATIME
));
ReleaseFstab
(
fstab
);
fstab
=
nullptr
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录