From 604885d85a9f00ef98ac9022f0c44391dcba7f21 Mon Sep 17 00:00:00 2001 From: renpengfei Date: Thu, 17 Jun 2021 11:00:05 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=88=9D=E5=A7=8B=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .buildscripts/build-and-deploy-snapshot.sh | 10 - .github/workflows/pull_request.yml | 44 -- .github/workflows/push.yml | 20 - .github/workflows/tag.yml | 63 --- .gitignore | 17 +- CHANGELOG.md | 3 + README.OPENSOURCE | 19 + README.md | 534 ++++++++++++++---- app/.gitignore | 1 - app/build.gradle | 46 -- app/checks.gradle | 35 -- app/proguard-rules.pro | 17 - .../SecureStorageBaseTest.kt | 36 -- .../SecureStorageLogicTest.kt | 177 ------ .../securestoragetest/SecureStorageUITest.kt | 81 --- app/src/debug/AndroidManifest.xml | 6 - app/src/main/AndroidManifest.xml | 23 - app/src/main/ic_launcher-web.png | Bin 18876 -> 0 bytes .../android/securestoragetest/MainActivity.kt | 104 ---- app/src/main/res/layout/activity_main.xml | 174 ------ .../res/mipmap-anydpi-v26/ic_launcher.xml | 5 - .../mipmap-anydpi-v26/ic_launcher_round.xml | 5 - .../mipmap-hdpi/ic_launch_secure_storage.png | Bin 1980 -> 0 bytes app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 1501 -> 0 bytes .../res/mipmap-hdpi/ic_launcher_round.png | Bin 3419 -> 0 bytes .../mipmap-mdpi/ic_launch_secure_storage.png | Bin 1195 -> 0 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 1048 -> 0 bytes .../res/mipmap-mdpi/ic_launcher_round.png | Bin 2139 -> 0 bytes .../mipmap-xhdpi/ic_launch_secure_storage.png | Bin 2630 -> 0 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 2032 -> 0 bytes .../res/mipmap-xhdpi/ic_launcher_round.png | Bin 4852 -> 0 bytes .../ic_launch_secure_storage.png | Bin 5282 -> 0 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 3323 -> 0 bytes .../res/mipmap-xxhdpi/ic_launcher_round.png | Bin 7750 -> 0 bytes .../ic_launch_secure_storage.png | Bin 6974 -> 0 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.png | Bin 4590 -> 0 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.png | Bin 11088 -> 0 bytes app/src/main/res/values-w820dp/dimens.xml | 6 - app/src/main/res/values/colors.xml | 6 - app/src/main/res/values/dimens.xml | 5 - .../ic_launch_secure_storage_background.xml | 4 - .../res/values/ic_launcher_background.xml | 4 - app/src/main/res/values/strings.xml | 11 - app/src/main/res/values/styles.xml | 11 - build.gradle | 50 +- config/checkstyle.xml | 134 ----- config/pmd.xml | 77 --- entry/.gitignore | 15 + entry/build.gradle | 27 + entry/src/main/config.json | 48 ++ .../ohos/securestoragetest/MainAbility.java | 35 ++ .../ohos/securestoragetest/MyApplication.java | 32 ++ .../slice/MainAbilitySlice.java | 265 +++++++++ .../main/resources/base/element/color.json | 12 + .../main/resources/base/element/float.json | 40 ++ .../main/resources/base/element/string.json | 24 + .../base/graphic/background_ability_main.xml | 6 + .../resources/base/graphic/button_them.xml | 8 + .../resources/base/layout/ability_main.xml | 206 +++++++ entry/src/main/resources/base/media/icon.png | Bin 0 -> 6790 bytes entry/src/ohosTest/config.json | 41 ++ .../securestoragetest/ExampleOhosTest.java | 154 +++++ .../securestoragetest/ExampleTest.java | 9 + gif/0.gif | Bin 0 -> 3464829 bytes gradle.properties | 15 +- gradle/wrapper/gradle-wrapper.jar | Bin 53636 -> 58694 bytes gradle/wrapper/gradle-wrapper.properties | 2 +- gradlew | 109 ++-- gradlew.bat | 33 +- securestoragelibrary/.gitignore | 14 + securestoragelibrary/build.gradle | 46 +- securestoragelibrary/checks.gradle | 39 -- securestoragelibrary/proguard-rules.pro | 18 +- .../src/main/AndroidManifest.xml | 1 - securestoragelibrary/src/main/config.json | 27 + .../securestoragelibrary/KeystoreTool.java | 273 --------- .../ohos/securestoragelibrary/IoUtils.java | 108 ++++ .../securestoragelibrary/KeystoreTool.java | 147 +++++ .../securestoragelibrary/PRNGFixes.java | 96 ++-- .../securestoragelibrary/PreferenceUtils.java | 88 +++ .../ohos/securestoragelibrary/RsaUtils.java | 179 ++++++ .../SecurePreferences.java | 170 +++--- .../SecureStorageException.java | 3 +- .../src/main/res/values/strings.xml | 5 - .../main/resources/base/element/string.json | 20 + .../securestoragelibrary/ExampleTest.java | 9 + settings.gradle | 2 +- 87 files changed, 2211 insertions(+), 1843 deletions(-) delete mode 100755 .buildscripts/build-and-deploy-snapshot.sh delete mode 100644 .github/workflows/pull_request.yml delete mode 100644 .github/workflows/push.yml delete mode 100644 .github/workflows/tag.yml create mode 100644 CHANGELOG.md create mode 100644 README.OPENSOURCE delete mode 100644 app/.gitignore delete mode 100644 app/build.gradle delete mode 100644 app/checks.gradle delete mode 100644 app/proguard-rules.pro delete mode 100644 app/src/androidTest/java/de/adorsys/android/securestoragetest/SecureStorageBaseTest.kt delete mode 100644 app/src/androidTest/java/de/adorsys/android/securestoragetest/SecureStorageLogicTest.kt delete mode 100644 app/src/androidTest/java/de/adorsys/android/securestoragetest/SecureStorageUITest.kt delete mode 100644 app/src/debug/AndroidManifest.xml delete mode 100644 app/src/main/AndroidManifest.xml delete mode 100644 app/src/main/ic_launcher-web.png delete mode 100644 app/src/main/java/de/adorsys/android/securestoragetest/MainActivity.kt delete mode 100644 app/src/main/res/layout/activity_main.xml delete mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml delete mode 100644 app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml delete mode 100644 app/src/main/res/mipmap-hdpi/ic_launch_secure_storage.png delete mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher.png delete mode 100644 app/src/main/res/mipmap-hdpi/ic_launcher_round.png delete mode 100644 app/src/main/res/mipmap-mdpi/ic_launch_secure_storage.png delete mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher.png delete mode 100644 app/src/main/res/mipmap-mdpi/ic_launcher_round.png delete mode 100644 app/src/main/res/mipmap-xhdpi/ic_launch_secure_storage.png delete mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher.png delete mode 100644 app/src/main/res/mipmap-xhdpi/ic_launcher_round.png delete mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launch_secure_storage.png delete mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher.png delete mode 100644 app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png delete mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launch_secure_storage.png delete mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher.png delete mode 100644 app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png delete mode 100644 app/src/main/res/values-w820dp/dimens.xml delete mode 100644 app/src/main/res/values/colors.xml delete mode 100644 app/src/main/res/values/dimens.xml delete mode 100644 app/src/main/res/values/ic_launch_secure_storage_background.xml delete mode 100644 app/src/main/res/values/ic_launcher_background.xml delete mode 100644 app/src/main/res/values/strings.xml delete mode 100644 app/src/main/res/values/styles.xml delete mode 100644 config/checkstyle.xml delete mode 100644 config/pmd.xml create mode 100644 entry/.gitignore create mode 100644 entry/build.gradle create mode 100644 entry/src/main/config.json create mode 100644 entry/src/main/java/de/adorsys/ohos/securestoragetest/MainAbility.java create mode 100644 entry/src/main/java/de/adorsys/ohos/securestoragetest/MyApplication.java create mode 100644 entry/src/main/java/de/adorsys/ohos/securestoragetest/slice/MainAbilitySlice.java create mode 100644 entry/src/main/resources/base/element/color.json create mode 100644 entry/src/main/resources/base/element/float.json create mode 100644 entry/src/main/resources/base/element/string.json create mode 100644 entry/src/main/resources/base/graphic/background_ability_main.xml create mode 100644 entry/src/main/resources/base/graphic/button_them.xml create mode 100644 entry/src/main/resources/base/layout/ability_main.xml create mode 100644 entry/src/main/resources/base/media/icon.png create mode 100644 entry/src/ohosTest/config.json create mode 100644 entry/src/ohosTest/java/de/adorsys/android/securestoragetest/ExampleOhosTest.java create mode 100644 entry/src/test/java/de/adorsys/android/securestoragetest/ExampleTest.java create mode 100644 gif/0.gif delete mode 100644 securestoragelibrary/checks.gradle delete mode 100644 securestoragelibrary/src/main/AndroidManifest.xml create mode 100644 securestoragelibrary/src/main/config.json delete mode 100644 securestoragelibrary/src/main/java/de/adorsys/android/securestoragelibrary/KeystoreTool.java create mode 100644 securestoragelibrary/src/main/java/de/adorsys/ohos/securestoragelibrary/IoUtils.java create mode 100644 securestoragelibrary/src/main/java/de/adorsys/ohos/securestoragelibrary/KeystoreTool.java rename securestoragelibrary/src/main/java/de/adorsys/{android => ohos}/securestoragelibrary/PRNGFixes.java (79%) create mode 100644 securestoragelibrary/src/main/java/de/adorsys/ohos/securestoragelibrary/PreferenceUtils.java create mode 100644 securestoragelibrary/src/main/java/de/adorsys/ohos/securestoragelibrary/RsaUtils.java rename securestoragelibrary/src/main/java/de/adorsys/{android => ohos}/securestoragelibrary/SecurePreferences.java (61%) rename securestoragelibrary/src/main/java/de/adorsys/{android => ohos}/securestoragelibrary/SecureStorageException.java (97%) delete mode 100644 securestoragelibrary/src/main/res/values/strings.xml create mode 100644 securestoragelibrary/src/main/resources/base/element/string.json create mode 100644 securestoragelibrary/src/test/java/de/adorsys/android/securestoragelibrary/ExampleTest.java diff --git a/.buildscripts/build-and-deploy-snapshot.sh b/.buildscripts/build-and-deploy-snapshot.sh deleted file mode 100755 index e8ca6a1..0000000 --- a/.buildscripts/build-and-deploy-snapshot.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/usr/bin/env bash - -echo -e "\033[0;32m ./gradlew :securestoragelibrary:clean \033[0m" -./gradlew :securestoragelibrary:clean --stacktrace - -echo -e "\033[0;32m ./gradlew :securestoragelibrary:install \033[0m" -./gradlew :securestoragelibrary:build --stacktrace - -echo -e "\033[0;32m ./gradlew :securestoragelibrary:bintrayUpload -PbintrayUser=BINTRAY_USERNAME -PbintrayKey=BINTRAY_API_KEY -PdryRun=false \033[0m" -./gradlew :securestoragelibrary:bintrayUpload -PbintrayUser="$BINTRAY_USERNAME" -PbintrayKey="$BINTRAY_API_KEY" -PdryRun=false --stacktrace \ No newline at end of file diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml deleted file mode 100644 index 2d72ee5..0000000 --- a/.github/workflows/pull_request.yml +++ /dev/null @@ -1,44 +0,0 @@ -name: SecureStorage Pull Request Workflow - -on: - pull_request: - branches-ignore: - - 'gh-pages' - -jobs: - assemble: - name: AssembleDebug SecureStorage - runs-on: macOS-latest - steps: - - name: Checkout - uses: actions/checkout@v1 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: AssembleDebug SecureStorage - run: bash ./gradlew assembleDebug --stacktrace - - test: - needs: assemble - name: Test SecureStorage - runs-on: macOS-latest - strategy: - matrix: - api-level: [21, 22, 23, 25, 29] - target: [default] - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Test SecureStorage - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ matrix.api-level }} - target: ${{ matrix.target }} - arch: x86_64 - profile: Nexus 6 - script: ./gradlew connectedAndroidTest --stacktrace \ No newline at end of file diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml deleted file mode 100644 index 4a25a64..0000000 --- a/.github/workflows/push.yml +++ /dev/null @@ -1,20 +0,0 @@ -name: SecureStorage Push Workflow - -on: - push: - branches-ignore: - - 'gh-pages' - -jobs: - assemble: - name: AssembleDebug SecureStorage - runs-on: macOS-latest - steps: - - name: Checkout - uses: actions/checkout@v1 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: AssembleDebug SecureStorage - run: bash ./gradlew assembleDebug --stacktrace \ No newline at end of file diff --git a/.github/workflows/tag.yml b/.github/workflows/tag.yml deleted file mode 100644 index e8bb075..0000000 --- a/.github/workflows/tag.yml +++ /dev/null @@ -1,63 +0,0 @@ -name: SecureStorage Tag Workflow - -on: - push: - branches: - - master - tags: - - '*' - -jobs: - assemble: - name: AssembleDebug SecureStorage - runs-on: macOS-latest - steps: - - name: Checkout - uses: actions/checkout@v1 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: AssembleDebug SecureStorage - run: bash ./gradlew assembleDebug --stacktrace - - test: - needs: assemble - name: Test SecureStorage - runs-on: macOS-latest - strategy: - matrix: - api-level: [21, 22, 23, 25, 29] - target: [default] - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Test SecureStorage - uses: reactivecircus/android-emulator-runner@v2 - with: - api-level: ${{ matrix.api-level }} - target: ${{ matrix.target }} - arch: x86_64 - profile: Nexus 6 - script: ./gradlew connectedAndroidTest --stacktrace - - publish: - needs: [assemble, test] - name: Publish SecureStorage - runs-on: macOS-latest - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - name: Publish SecureStorage - env: - BINTRAY_API_KEY: ${{ secrets.BINTRAY_API_KEY }} - BINTRAY_USERNAME: andev - run: bash .buildscripts/build-and-deploy-snapshot.sh \ No newline at end of file diff --git a/.gitignore b/.gitignore index 350ff01..0526d3f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,15 @@ *.iml -.gradle -!/gradle/wrapper/gradle-wrapper.jar /local.properties -.idea -!.idea/codeStyleSettings.xml +/.idea +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml .DS_Store -/build \ No newline at end of file +/build +/captures +.externalNativeBuild +.cxx +/.gradle \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..aeb0216 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# 0.0.1-SNAPSHOT + +ohos 第一个版本,完整实现了原库的全部 api \ No newline at end of file diff --git a/README.OPENSOURCE b/README.OPENSOURCE new file mode 100644 index 0000000..31bcf3d --- /dev/null +++ b/README.OPENSOURCE @@ -0,0 +1,19 @@ +[ + + { + + "Name": "secure-storage-android", + + "License": "Apache License", + + "License File": "LICENSE", + + "Version Number": "1.1.0", + + "Upstream URL": "https://github.com/adorsys/secure-storage-android", + + "Description": "Storing Credentials Securely on Android Devices" + + } + +] \ No newline at end of file diff --git a/README.md b/README.md index a5fcb9a..64c86fd 100644 --- a/README.md +++ b/README.md @@ -1,149 +1,453 @@ -# Secure Device Storage - Android +# secure-storage-ohos +### 项目介绍 +- 项目名称:secure-storage-ohos工具类 +- 所属系列:openharmony第三方组件适配移植 +- 功能:RSA非对称加密 +- 项目移植状态:移植完成 +- 调用差异:无 +- 基线版本: Release 0.0.2 +- 开发版本:sdk5,DevEco Studio2.1 Release +- 编程语言:Java -## Storing Credentials Securely on Android Devices +### 效果演示 -[![Actions Status](https://github.com/adorsys/secure-storage-android/workflows/SecureStorage%20Pull%20Request%20Workflow/badge.svg)](https://github.com/adorsys/secure-storage-android/actions) -[![Download](https://api.bintray.com/packages/andev/adorsys/securestoragelibrary/images/download.svg) ](https://bintray.com/andev/adorsys/securestoragelibrary/_latestVersion) -[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Secure%20Storage%20Android-blue.svg?style=flat)](https://android-arsenal.com/details/1/5648) -[![API](https://img.shields.io/badge/API-18%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=18) -[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) -[![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=103)](https://github.com/ellerbrock/open-source-badges/) +![0](/gif/0.gif) + +### 安装教程 +1. 在项目根目录下的build.gradle文件中添加。 +``` +allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } + } +} +``` -### Introduction - -Storing credentials securely on a device is in many occasions necessary. You probably don't want to rely only on the separation of processes of the Android OS but make sure the stored values are also encrypted. -To make that possible we have combined the Android Keystore and the SharedPreferences. The keystore is used for generating cryptographic keys, the values are then encrypted with these keys and subsequently securely stored in the SharedPreferences. +2. 在entry模块下的build.gradle文件中添加依赖。 -The secure part about this solution is that those generated keys are never exposed to the kernel when the device is equipped with a “Trusted Execution Environment”. A so called TEE is a secure area inside the main processor of a smartphone which runs code isolated from other processes. That means even if the device gets compromised or hacked those keys can’t be extracted. Already a lot of modern Android phones out there are equipped with a TEE (mostly because it’s often used to play DRM protected material) and it even is a requirement for Google’s Android Nougat certification — so every phone running Android Nougat and later will come with a TEE installed. +``` +dependencies { + implementation project(path: ':securestoragelibrary') +} +``` -SecureStorage uses its own dedicated private SharedPreferences to prevent conflicts with other possible SharedPreference instances and ensure that the content of the SecureStorage can only be accessed from the app which uses this library. +在sdk5,DevEco Studio2.1 Release下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, 并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下 + +### 使用说明 +secure-storage + +1. 布局文件定义,提供控件:secure-storage + +```xml + + + + + + + + + + + +