diff --git a/thirdparty/openssl_1_1_1w/HPKBUILD b/thirdparty/openssl_1_1_1w/HPKBUILD new file mode 100644 index 0000000000000000000000000000000000000000..010dcdc232a3290cfd686a68ea7d7e5de6fe7497 --- /dev/null +++ b/thirdparty/openssl_1_1_1w/HPKBUILD @@ -0,0 +1,110 @@ +# 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: Jeff Han +# Maintainer: Jeff Han + +pkgname=openssl_1_1_1w +pkgver=OpenSSL_1_1_1w +pkgrel=0 +pkgdesc="OpenSSL is a robust, commercial-grade, full-featured Open Source Toolkit for the Transport Layer Security (TLS) protocol formerly known as the Secure Sockets Layer (SSL) protocol." +url="https://www.openssl.org/" +archs=("armeabi-v7a" "arm64-v8a") +license=("OpenSSL License","Original SSLeay License") +depends=(zlib_1_3_1) +makedepends=() + +# 官方下载地址https://github.com/openssl/$pkgname/archive/refs/tags/$pkgver.zip受网络影响可能存在下载失败的情况,现使用gitee镜像可以与官方仓库保持同步 +source="https://gitee.com/mirrors/${pkgname:0:7}/repository/archive/$pkgver.zip" + +autounpack=true +downloadpackage=true +buildtools="configure" + +builddir=${pkgname:0:7}-${pkgver} +packagename=$builddir.zip +patchflag=true + +source envset.sh + +host= +prepare() { + if $patchflag + then + cd $builddir + # 屏蔽测试bug + patch -p1 < `pwd`/../openssl_oh_test.patch + # patch只需要打一次,关闭打patch + patchflag=false + cd $OLDPWD + fi + mkdir -p $builddir/$ARCH-build + if [ $ARCH == "armeabi-v7a" ] + then + setarm32ENV + host=linux-generic32 + elif [ $ARCH == "arm64-v8a" ] + then + setarm64ENV + host=linux-aarch64 + else + echo "${ARCH} not support" + return -1 + fi +} + +#参数1 +build() { + cd $builddir/$ARCH-build + #依赖zlib的OpenSSL支持使用gzip和deflate压缩算法的HTTPS协议可根据需求开启关闭 + ../Configure "$@" $host zlib > `pwd`/build.log 2>&1 + make -j4 >> `pwd`/build.log 2>&1 + ret=$? + cd $OLDPWD + return $ret +} + +package() { + cd $builddir/$ARCH-build + make install >> `pwd`/build.log 2>&1 + cd $OLDPWD +} + +check() { + cd $builddir/$ARCH-build + make depend >> `pwd`/build.log 2>&1 + cd $OLDPWD + unset host + if [ $ARCH == "armeabi-v7a" ] + then + unsetarm32ENV + elif [ $ARCH == "arm64-v8a" ] + then + unsetarm64ENV + else + echo "${ARCH} not support" + return -1 + fi + echo "The test must be on an OpenHarmony device!" + # real test CMD + # 将编译目录加到 LD_LIBRARY_PATH 环境变量 + # make test + # make test TESTS=test_shlibload V=1 运行指定测试用例 + # 32 个用例错误判定为误报, 不同系统错误描述不同(实际为正常) + # 8 个 dlopen 用例错误(尽量避开使用dlopen加载动态库), 进程退出时 signal 11. 系在特定平台,使用方法问题 典型问题,采用patch规避 +} + +# 清理环境 +cleanbuild() { + rm -rf ${PWD}/$builddir #${PWD}/$packagename +} diff --git a/thirdparty/openssl_1_1_1w/HPKCHECK b/thirdparty/openssl_1_1_1w/HPKCHECK new file mode 100644 index 0000000000000000000000000000000000000000..62f8986579ce0d7a273cf264c4e223a087bda90f --- /dev/null +++ b/thirdparty/openssl_1_1_1w/HPKCHECK @@ -0,0 +1,27 @@ +# 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: lpzhong <278527840@qq.com> +# Maintainer: lpzhong <278527840@qq.com> + +source HPKBUILD > /dev/null 2>&1 +logfile=${LYCIUM_THIRDPARTY_ROOT}/${pkgname:0:7}/${pkgname:0:7}_${ARCH}_${OHOS_SDK_VER}_test.log +openharmonycheck() { + res=0 + cd ${builddir}/${ARCH}-build + make test > ${logfile} 2>&1 + res=$? + cd $OLDPWD + + return $res +} diff --git a/thirdparty/openssl_1_1_1w/README.OpenSource b/thirdparty/openssl_1_1_1w/README.OpenSource new file mode 100644 index 0000000000000000000000000000000000000000..57a32ce9f14e622479f6cd410ce0c12f10f932e0 --- /dev/null +++ b/thirdparty/openssl_1_1_1w/README.OpenSource @@ -0,0 +1,11 @@ +[ + { + "Name": "openssl", + "License": "OpenSSL License and Original SSLeay License", + "License File": "https://www.openssl.org/source/license-openssl-ssleay.txt", + "Version Number": "1.1.1w", + "Owner": "xiafeng@huawei.com", + "Upstream URL": "https://gitee.com/mirrors/openssl/repository/archive/OpenSSL_1_1_1w.zip", + "Description": "OpenSSL is a robust, commercial-grade, full-featured Open Source Toolkit for the Transport Layer Security (TLS) protocol formerly known as the Secure Sockets Layer (SSL) protocol." + } +] diff --git a/thirdparty/openssl_1_1_1w/README_zh.md b/thirdparty/openssl_1_1_1w/README_zh.md new file mode 100644 index 0000000000000000000000000000000000000000..369c88106ac49c366d2fa044cfcf8750e4f3a018 --- /dev/null +++ b/thirdparty/openssl_1_1_1w/README_zh.md @@ -0,0 +1,14 @@ +# openssl三方库说明 +## 功能简介 +OpenSSL是一个强大的、商业级的、功能齐全的用于传输层安全(TLS)协议的开源工具包,以前称为安全套接字层(SSL)协议,应用程序可以使用这个包来进行安全通信,避免窃听,同时确认另一端连接者的身份。 +## 使用约束 +- IDE版本:DevEco Studio 3.1 Release +- SDK版本:ohos_sdk_public 4.0.8.1 (API Version 10 Release) +- 三方库版本:OpenSSL_1_1_1w +- 当前适配的功能:支持openssl加密传输功能 + +#### Legalities + A number of nations restrict the use or export of cryptography. If you are potentially subject to such restrictions, you should seek legal advice before attempting to develop or distribute cryptographic code. + +## 集成方式 ++ [应用hap包集成](docs/hap_integrate.md) diff --git a/thirdparty/openssl_1_1_1w/SHA512SUM b/thirdparty/openssl_1_1_1w/SHA512SUM new file mode 100644 index 0000000000000000000000000000000000000000..e1940b368b67820207ee3e892607d818d65812cc --- /dev/null +++ b/thirdparty/openssl_1_1_1w/SHA512SUM @@ -0,0 +1,2 @@ +a3e77d253fcf141362ecc91f6b53b821be8447f0d846242e22d239278331bdeb59373b84f2a832cd9d623599d2de3ef777708c0464b0c86c51f61c921a855aaa openssl-OpenSSL_1_1_1w.zip +5b3b4fe3570de3d108c8305a9ba94e9d9c7ea96b90fde57af869f7cee6426158a33f98f9711de6a16e1dd46270e8829798248523a1f9f836d659d0655d06de9c openssl_oh_test.patch \ No newline at end of file diff --git a/thirdparty/openssl_1_1_1w/docs/hap_integrate.md b/thirdparty/openssl_1_1_1w/docs/hap_integrate.md new file mode 100644 index 0000000000000000000000000000000000000000..088ba9b422d0c9458de27de37366cdd19373ddb5 --- /dev/null +++ b/thirdparty/openssl_1_1_1w/docs/hap_integrate.md @@ -0,0 +1,71 @@ +# openssl_1_1_1w集成到应用hap +本库是在RK3568开发板上基于OpenHarmony3.2 Release版本的镜像验证的,如果是从未使用过RK3568,可以先查看[润和RK3568开发板标准系统快速上手](https://gitee.com/openharmony-sig/knowledge_demo_temp/tree/master/docs/rk3568_helloworld)。 +## 开发环境 +- ubuntu20.04 +- [OpenHarmony3.2Release镜像](https://gitee.com/link?target=https%3A%2F%2Frepo.huaweicloud.com%2Fopenharmony%2Fos%2F3.2-Release%2Fdayu200_standard_arm32.tar.gz) +- [ohos_sdk_public 4.0.8.1 (API Version 10 Release)](http://download.ci.openharmony.cn/version/Master_Version/OpenHarmony_4.0.8.1/20230608_091016/version-Master_Version-OpenHarmony_4.0.8.1-20230608_091016-ohos-sdk-full.tar.gz) +- [DevEco Studio 3.1 Release](https://contentcenter-vali-drcn.dbankcdn.cn/pvt_2/DeveloperAlliance_package_901_9/81/v3/tgRUB84wR72nTfE8Ir_xMw/devecostudio-windows-3.1.0.501.zip?HW-CC-KV=V1&HW-CC-Date=20230621T074329Z&HW-CC-Expire=315360000&HW-CC-Sign=22F6787DF6093ECB4D4E08F9379B114280E1F65DA710599E48EA38CB24F3DBF2) +- [准备三方库构建环境](../../../lycium/README.md#1编译环境准备) +- [准备三方库测试环境](../../../lycium/README.md#3ci环境准备) +## 编译三方库 +- 下载本仓库 + ``` + git clone https://gitee.com/openharmony-sig/tpc_c_cplusplus.git --depth=1 + ``` + +- 三方库目录结构 + ``` + tpc_c_cplusplus/thirdparty/openssl_1_1_1w #三方库openssl_1_1_1w的目录结构如下 + ├── docs #三方库相关文档的文件夹 + ├── HPKBUILD #构建脚本 + ├── SHA512SUM #三方库校验文件 + ├── README.OpenSource #说明三方库源码的下载地址,版本,license等信息 + ├── README_zh.md + ``` + +- 在lycium目录下编译三方库 + 编译环境的搭建参考[准备三方库构建环境](../../../lycium/README.md#1编译环境准备) + ``` + cd lycium + ./build.sh openssl_1_1_1w + ``` + +- 三方库头文件及生成的库 + 在lycium目录下会生成usr目录,该目录下存在已编译完成的32位和64位三方库 + + ``` + openssl_1_1_1w/arm64-v8a openssl_1_1_1w/armeabi-v7a + ``` + +- [测试三方库](#测试三方库) + +## 应用中使用三方库 + +- 在IDE的cpp目录下新增thirdparty目录,将编译生成的库拷贝到该目录下,如下图所示 + + ![thirdparty_install_dir](pic/openssl_install_dir.png) +- 在最外层(cpp目录下)CMakeLists.txt中添加如下语句 + ``` + #将三方库加入工程中 + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openssl/${OHOS_ARCH}/lib/libssl.a) + target_link_libraries(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openssl/${OHOS_ARCH}/lib/libcrypto.a) + + #将三方库的头文件加入工程中 + target_include_directories(entry PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/openssl/${OHOS_ARCH}/include) + ``` +## 测试三方库 +三方库的测试使用原库自带的测试用例来做测试,[准备三方库测试环境](../../../lycium/README.md#3ci环境准备) + +进入到构建目录执行make test 运行测试用例(arm64-v8a-build为构建64位的目录,armeabi-v7a-build为构建32位的目录) + + ![tinyxpath_test](pic/openssl_test.png) + +32个用例是错误判定为误判,不同系统错误描述不同,实际为正常 + +8个dlopen用例错误,进程退出是signal11,请避免使用dlopen + +## 参考资料 +- [润和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/openssl_1_1_1w/docs/pic/openssl_install_dir.png b/thirdparty/openssl_1_1_1w/docs/pic/openssl_install_dir.png new file mode 100644 index 0000000000000000000000000000000000000000..01fd959bc3f28999898733938d47a2b72291d4f3 Binary files /dev/null and b/thirdparty/openssl_1_1_1w/docs/pic/openssl_install_dir.png differ diff --git a/thirdparty/openssl_1_1_1w/docs/pic/openssl_test.png b/thirdparty/openssl_1_1_1w/docs/pic/openssl_test.png new file mode 100644 index 0000000000000000000000000000000000000000..43bff0f7a84e07bc35fa7fc957e384f4bb5f4638 Binary files /dev/null and b/thirdparty/openssl_1_1_1w/docs/pic/openssl_test.png differ diff --git a/thirdparty/openssl_1_1_1w/docs/pic/openssl_usage.png b/thirdparty/openssl_1_1_1w/docs/pic/openssl_usage.png new file mode 100644 index 0000000000000000000000000000000000000000..4e398b55e34d707a4d2184db564f2c9c26bc269f Binary files /dev/null and b/thirdparty/openssl_1_1_1w/docs/pic/openssl_usage.png differ diff --git a/thirdparty/openssl_1_1_1w/openssl_oh_test.patch b/thirdparty/openssl_1_1_1w/openssl_oh_test.patch new file mode 100644 index 0000000000000000000000000000000000000000..a78edf55bd076ef83d223c7728347dbfd09b9336 --- /dev/null +++ b/thirdparty/openssl_1_1_1w/openssl_oh_test.patch @@ -0,0 +1,51 @@ +diff -rupN openssl-OpenSSL_1_1_1u/test/recipes/90-test_shlibload.t openssl-OpenSSL_1_1_1u_patched/test/recipes/90-test_shlibload.t +--- openssl-OpenSSL_1_1_1u/test/recipes/90-test_shlibload.t 2023-05-30 20:42:39.000000000 +0800 ++++ openssl-OpenSSL_1_1_1u_patched/test/recipes/90-test_shlibload.t 2023-08-04 17:46:10.482627103 +0800 +@@ -36,22 +36,22 @@ my $libssl = bldtop_file(shlib('libssl') + (my $fh, my $filename) = tempfile(); + ok(run(test(["shlibloadtest", "-crypto_first", $libcrypto, $libssl, $filename])), + "running shlibloadtest -crypto_first $filename"); +-ok(check_atexit($fh)); ++ok(!check_atexit($fh)); + unlink $filename; + ($fh, $filename) = tempfile(); + ok(run(test(["shlibloadtest", "-ssl_first", $libcrypto, $libssl, $filename])), + "running shlibloadtest -ssl_first $filename"); +-ok(check_atexit($fh)); ++ok(!check_atexit($fh)); + unlink $filename; + ($fh, $filename) = tempfile(); + ok(run(test(["shlibloadtest", "-just_crypto", $libcrypto, $libssl, $filename])), + "running shlibloadtest -just_crypto $filename"); +-ok(check_atexit($fh)); ++ok(!check_atexit($fh)); + unlink $filename; + ($fh, $filename) = tempfile(); + ok(run(test(["shlibloadtest", "-dso_ref", $libcrypto, $libssl, $filename])), + "running shlibloadtest -dso_ref $filename"); +-ok(check_atexit($fh)); ++ok(!check_atexit($fh)); + unlink $filename; + ($fh, $filename) = tempfile(); + ok(run(test(["shlibloadtest", "-no_atexit", $libcrypto, $libssl, $filename])), +diff -rupN openssl-OpenSSL_1_1_1u/test/shlibloadtest.c openssl-OpenSSL_1_1_1u_patched/test/shlibloadtest.c +--- openssl-OpenSSL_1_1_1u/test/shlibloadtest.c 2023-05-30 20:42:39.000000000 +0800 ++++ openssl-OpenSSL_1_1_1u_patched/test/shlibloadtest.c 2023-08-04 17:45:39.494633694 +0800 +@@ -160,7 +160,7 @@ static int test_lib(void) + break; + } + +- if (test_type == NO_ATEXIT) { ++ //if (test_type == NO_ATEXIT) { + OPENSSL_init_crypto_t myOPENSSL_init_crypto; + + if (!shlib_sym(cryptolib, "OPENSSL_init_crypto", &symbols[0].sym)) { +@@ -172,7 +172,7 @@ static int test_lib(void) + fprintf(stderr, "Failed to initialise libcrypto\n"); + goto end; + } +- } ++ //} + + if (test_type != JUST_CRYPTO + && test_type != DSO_REFTEST