diff --git a/thirdparty/sqlcipher/HPKBUILD b/thirdparty/sqlcipher/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..1bd363bfcd1dbd396d7e7883e20b0cab6c441d57 --- /dev/null +++ b/thirdparty/sqlcipher/HPKBUILD @@ -0,0 +1,105 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Contributor: OneJUGE +# Maintainer: OneJUGE + +pkgname=sqlcipher +pkgver=v4.5.5 +pkgrel=0 +pkgdesc="SQLCipher is a standalone fork of the SQLite database library that adds 256 bit AES encryption of database files" +url="https://github.com/sqlcipher/sqlcipher" +archs=("armeabi-v7a" "arm64-v8a") +license=("BSD") +depends=("openssl" "tcl") +#安裝tclsh工具 sudo apt install tcl +makedepends=("tclsh") +source="https://github.com/$pkgname/$pkgname/archive/refs/tags/$pkgver.tar.gz" + +downloadpackage=true +autounpack=true +buildtools="configure" + +builddir=$pkgname-${pkgver:1} +packagename=$builddir.tar.gz + +source envset.sh +host= +c_flag= + +prepare() { + mkdir -p $builddir/$ARCH-build + if [ $ARCH == "armeabi-v7a" ] + then + setarm32ENV + host=arm-linux + export LDFLAGS="${OHOS_SDK}/native/llvm/lib/clang/$CLANG_VERSION/lib/arm-linux-ohos/a7_hard_neon-vfpv4/libclang_rt.builtins.a ${LDFLAGS}" + fi + if [ $ARCH == "arm64-v8a" ] + then + setarm64ENV + host=aarch64-linux + export LDFLAGS="${OHOS_SDK}/native/llvm/lib/clang/$CLANG_VERSION/lib/aarch64-linux-ohos/libclang_rt.builtins.a ${LDFLAGS}" + fi +} + +build() { + cd $builddir/$ARCH-build + c_flag=$CFLAGS" -DSQLITE_HAS_CODEC -DSQLCIPHER_TEST -I${LYCIUM_ROOT}/usr/openssl/${ARCH}/include" + PKG_CONFIG_LIBDIR="${pkgconfigpath}" LDFLAGS="-L${LYCIUM_ROOT}/usr/openssl/${ARCH}/lib -lcrypto \ + -I${LYCIUM_ROOT}/usr/tcl/${ARCH}/include -L${LYCIUM_ROOT}/usr/tcl/${ARCH}/lib -ltcl8.6" CFLAGS=$c_flag \ + ../configure "$@" --host=$host --enable-fts5 > $buildlog 2>&1 + $MAKE >> $buildlog 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +package() { + cd $builddir/$ARCH-build + $MAKE install >> $buildlog 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +check() { + cd $builddir/$ARCH-build + $MAKE testfixture >> $buildlog 2>&1 + echo "The test must be on an OpenHarmony device!" + #real test CMD + #cd tpc_c_cplusplus/thirdparty/sqlcipher/sqlcipher-4.5.5/arm64-v8a-build/ + #./testfixture ../test/sqlcipher.test + ret=$? + cd $OLDPWD + return $ret +} + +recoverpkgbuildenv() { + unset host + if [ $ARCH == "armeabi-v7a" ] + then + unsetarm32ENV + elif [ $ARCH == "arm64-v8a" ] + then + unsetarm64ENV + else + echo "${ARCH} not support" + return -1 + fi +} + +# 清理环境 +cleanbuild() { + rm -rf ${PWD}$builddir #${PWD}/$packagename +} diff --git a/thirdparty/sqlcipher/HPKCHECK b/thirdparty/sqlcipher/HPKCHECK new file mode 100755 index 0000000000000000000000000000000000000000..6f37440fda459543d05f373877915240187f3555 --- /dev/null +++ b/thirdparty/sqlcipher/HPKCHECK @@ -0,0 +1,28 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# Contributor: OneJUGE +# Maintainer: OneJUGE + +source HPKBUILD > /dev/null 2>&1 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname}/${pkgname}_${ARCH}_${OHOS_SDK_VER}_test.log + +openharmonycheck() { + res=0 + cd $builddir/${ARCH}-build + ./testfixture ../test/sqlcipher.test > ${logfile} 2>&1 + res=$? + cd $OLDPWD + return $res +} + diff --git a/thirdparty/sqlcipher/OAT.xml b/thirdparty/sqlcipher/OAT.xml new file mode 100644 index 0000000000000000000000000000000000000000..7ae0defe8bdc1153e97cdf116f0a687503d6eced --- /dev/null +++ b/thirdparty/sqlcipher/OAT.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + diff --git a/thirdparty/sqlcipher/README.OpenSource b/thirdparty/sqlcipher/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..f25bf24cfae112549c9da6495d4e3f1146646cf0 --- /dev/null +++ b/thirdparty/sqlcipher/README.OpenSource @@ -0,0 +1,12 @@ +[ + { + "Name": "sqlcipher", + "License": "BSD", + "License File": "LICENSE", + "Version Number": "4.5.5", + "Owner": "wangwenju5@h-partners.com", + "Upstream URL": "https://github.com/sqlcipher/sqlcipher/archive/refs/tags/v4.5.5.tar.gz", + "Description": "SQLCipher is a standalone fork of SQLite that adds 256 bit AES encryption of database files and other security features" + } +] + diff --git a/thirdparty/sqlcipher/README_zh.md b/thirdparty/sqlcipher/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..567c6b6428fa7bdd053755108108a58893e47cd9 --- /dev/null +++ b/thirdparty/sqlcipher/README_zh.md @@ -0,0 +1,12 @@ +# sqlcipher三方库说明 +## 功能简介 +SQLCipher 是 SQLite 的一个独立分支,它增加了数据库文件的 256 位 AES 加密和其他安全功能。 +## 使用约束 +- IDE版本:DevEco Studio 3.1 Release +- SDK版本:ohos_sdk_public 4.0.8.1 (API Version 10 Release) +- 三方库版本:4.5.5 +- 当前适配的功能:SQLite数据库加密 + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) + diff --git a/thirdparty/sqlcipher/SHA512SUM b/thirdparty/sqlcipher/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..f193d646b4db1cb7ad1f4da1a379afa5ba51b4a6 --- /dev/null +++ b/thirdparty/sqlcipher/SHA512SUM @@ -0,0 +1 @@ +034774f8d320a53f08a9735c035bf83f81ef9223780473c39ec07658b80af89dc665599caa3b2662055039fa678c7a29cbf777d046922948e86123e677b823bc sqlcipher-4.5.5.tar.gz diff --git a/thirdparty/sqlcipher/docs/hap_integrate.md b/thirdparty/sqlcipher/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..a8a495ae48f6041eb7b5b68571e79d5a127b8be6 --- /dev/null +++ b/thirdparty/sqlcipher/docs/hap_integrate.md @@ -0,0 +1,102 @@ +# sqlcipher集成到应用hap + +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 + +## 开发环境 + +- [开发环境准备](../../../docs/hap_integrate_environment.md) + +## 编译三方库 + +- 下载本仓库 + + ```shell + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + + ```shell + tpc_c_cplusplus/thirdparty/sqlcipher #三方库sqlcipher的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── HPKCHECK #自动化测试脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md #三方库说明文档 + ├── OAT.xml #开源扫描相关文件 + ``` + +- 在tpc_c_cplusplus/lycium目录下编译三方库 + + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + + ```shell + cd tpc_c_cplusplus/lycium + ./build.sh sqlcipher + ``` + +- 三方库头文件及生成的库 + + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库和头文件 + + ```shell + sqlcipher/arm64-v8a sqlcipher/armeabi-v7a + ``` +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 拷贝动态库到`\\entry\libs\${OHOS_ARCH}\`目录: + 动态库需要在`\\entry\libs\${OHOS_ARCH}\`目录,才能集成到hap包中,所以需要将对应的so文件拷贝到对应CPU架构的目录 +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的库拷贝到该目录下,如下图所示 + +  ![thirdparty_install_dir](pic/sqlcipher_install_dir.png) + +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + ```shell + #将三方库加入工程中 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/libsqlcipher.so.0 + ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/libtcl8.6.so + ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/libcrypto.a + ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/libssl.a + ${CMAKE_CURRENT_SOURCE_DIR}/../../../libs/${OHOS_ARCH}/libsqlcipher.a + ) + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/sqlcipher/${OHOS_ARCH}/include + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/tcl/${OHOS_ARCH}/include + ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openssl/${OHOS_ARCH}/include + ) + + + ``` + +## 测试三方库 + +三方库的测试使用原库自带的测试用例来做测试,[准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + + 进入到构建目录(arm64-v8a-build为构建64位的目录,armeabi-v7a-build为构建32位的目录),执行如下操作步骤: + +- 配置环境变量 + 执行如下命令: + + ```shell + export LD_LIBRARY_PATH=${LYCIUM_ROOT}/usr/openssl/${ARCH}/lib:${LYCIUM_ROOT}/usr/tcl/${ARCH}/lib:${LYCIUM_ROOT}/usr/sqlcipher/${ARCH}/lib:$LD_LIBRARY_PATH + ``` + > 注意:LYCIUM_ROOT代表lycium所在目录的绝对路径;ARCH代表构建架构,64位为arm64-v8a,32位为armeabi-v7a。 + +- 执行测试项: + + ```shell + ./testfixture ../test/sqlcipher.test + ``` +  ![sqlcipher_test](pic/sqlcipher_test.png) + + +## 参考资料 + +- [润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld) +- [OpenHarmony三方库地址](https://gitee.com/openharmony-tpc) +- [OpenHarmony知识体系](https://gitee.com/openharmony-sig/knowledge) +- [通过DevEco Studio开发一个NAPI工程](https://gitee.com/openharmony-sig/knowledge_demo_temp/blob/master/docs/napi_study/docs/hello_napi.md) + diff --git a/thirdparty/sqlcipher/docs/pic/sqlcipher_install_dir.png b/thirdparty/sqlcipher/docs/pic/sqlcipher_install_dir.png new file mode 100644 index 0000000000000000000000000000000000000000..e405fc10dea26ec49fa8da8cadcb432e2a45370d Binary files /dev/null and b/thirdparty/sqlcipher/docs/pic/sqlcipher_install_dir.png differ diff --git a/thirdparty/sqlcipher/docs/pic/sqlcipher_test.png b/thirdparty/sqlcipher/docs/pic/sqlcipher_test.png new file mode 100644 index 0000000000000000000000000000000000000000..fce29b642833a7e7fa059cba68d6ff949cc88027 Binary files /dev/null and b/thirdparty/sqlcipher/docs/pic/sqlcipher_test.png differ