androidabe

git clone git://git.codymlewis.com/androidabe.git
Log | Files | Refs | Submodules | README

commit f1f225aa7fafa6e37d101690a3d334e1a4988122
Author: Cody Lewis <cody@codymlewis.com>
Date:   Wed, 20 May 2020 12:08:33 +1000

Initial commit

Diffstat:
A.gitattributes | 3+++
A.gitignore | 15+++++++++++++++
A.gitmodules | 9+++++++++
A.idea/.name | 2++
A.idea/codeStyles/Project.xml | 117+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A.idea/codeStyles/codeStyleConfig.xml | 6++++++
A.idea/gradle.xml | 22++++++++++++++++++++++
A.idea/misc.xml | 10++++++++++
A.idea/runConfigurations.xml | 13+++++++++++++
A.idea/vcs.xml | 10++++++++++
ADockerfile | 44++++++++++++++++++++++++++++++++++++++++++++
AREADME.md | 48++++++++++++++++++++++++++++++++++++++++++++++++
Aabe/.gitignore | 1+
Aabe/build.gradle | 32++++++++++++++++++++++++++++++++
Aabe/consumer-rules.pro | 0
Aabe/proguard-rules.pro | 21+++++++++++++++++++++
Aabe/src/androidTest/java/com/codymlewis/abe/ExampleInstrumentedTest.java | 27+++++++++++++++++++++++++++
Aabe/src/main/AndroidManifest.xml | 2++
Aabe/src/main/assets/d224.param | 14++++++++++++++
Aabe/src/main/cpp/CMakeLists.txt | 21+++++++++++++++++++++
Aabe/src/main/cpp/gmp | 1+
Aabe/src/main/cpp/native-lib.c | 208+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aabe/src/main/cpp/native-lib.h | 128+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aabe/src/main/cpp/openssl | 1+
Aabe/src/main/cpp/pbc | 1+
Aabe/src/main/java/com/codymlewis/abe/Functions.java | 24++++++++++++++++++++++++
Aabe/src/main/java/com/codymlewis/abe/Keychain.java | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aabe/src/main/java/com/codymlewis/abe/Token.java | 120+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aabe/src/test/java/com/codymlewis/abe/ExampleUnitTest.java | 18++++++++++++++++++
Aapp/.gitignore | 1+
Aapp/build.gradle | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aapp/proguard-rules.pro | 21+++++++++++++++++++++
Aapp/src/androidTest/java/com/codymlewis/androidabe/ExampleInstrumentedTest.java | 27+++++++++++++++++++++++++++
Aapp/src/main/AndroidManifest.xml | 22++++++++++++++++++++++
Aapp/src/main/assets/d224.param | 14++++++++++++++
Aapp/src/main/java/com/codymlewis/androidabe/MainActivity.java | 47+++++++++++++++++++++++++++++++++++++++++++++++
Aapp/src/main/res/drawable-v24/ic_launcher_foreground.xml | 31+++++++++++++++++++++++++++++++
Aapp/src/main/res/drawable/ic_launcher_background.xml | 170+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Aapp/src/main/res/layout/activity_main.xml | 21+++++++++++++++++++++
Aapp/src/main/res/mipmap-anydpi-v26/ic_launcher.xml | 6++++++
Aapp/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml | 6++++++
Aapp/src/main/res/mipmap-hdpi/ic_launcher.png | 0
Aapp/src/main/res/mipmap-hdpi/ic_launcher_round.png | 0
Aapp/src/main/res/mipmap-mdpi/ic_launcher.png | 0
Aapp/src/main/res/mipmap-mdpi/ic_launcher_round.png | 0
Aapp/src/main/res/mipmap-xhdpi/ic_launcher.png | 0
Aapp/src/main/res/mipmap-xhdpi/ic_launcher_round.png | 0
Aapp/src/main/res/mipmap-xxhdpi/ic_launcher.png | 0
Aapp/src/main/res/mipmap-xxhdpi/ic_launcher_round.png | 0
Aapp/src/main/res/mipmap-xxxhdpi/ic_launcher.png | 0
Aapp/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png | 0
Aapp/src/main/res/values/colors.xml | 6++++++
Aapp/src/main/res/values/strings.xml | 4++++
Aapp/src/main/res/values/styles.xml | 11+++++++++++
Aapp/src/test/java/com/codymlewis/androidabe/ExampleUnitTest.java | 18++++++++++++++++++
Abuild-and-run.sh | 3+++
Abuild.gradle | 29+++++++++++++++++++++++++++++
Agradle.properties | 20++++++++++++++++++++
Agradle/wrapper/gradle-wrapper.jar | 0
Agradle/wrapper/gradle-wrapper.properties | 6++++++
Agradlew | 172+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Agradlew.bat | 84+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Arun.sh | 25+++++++++++++++++++++++++
Asettings.gradle | 3+++
Asetup.sh | 7+++++++
65 files changed, 1812 insertions(+), 0 deletions(-)

diff --git a/.gitattributes b/.gitattributes @@ -0,0 +1,3 @@ +*.xml binary +*.png binary +*.jar binary diff --git a/.gitignore b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +tags diff --git a/.gitmodules b/.gitmodules @@ -0,0 +1,9 @@ +[submodule "abe/src/main/cpp/openssl"] + path = abe/src/main/cpp/openssl + url = https://github.com/codymlewis/android-openssl.git +[submodule "abe/src/main/cpp/gmp"] + path = abe/src/main/cpp/gmp + url = https://github.com/codymlewis/android-gmp.git +[submodule "abe/src/main/cpp/pbc"] + path = abe/src/main/cpp/pbc + url = https://github.com/codymlewis/android-pbc.git diff --git a/.idea/.name b/.idea/.name @@ -0,0 +1 @@ +Android ABE+ \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml @@ -0,0 +1,116 @@ +<component name="ProjectCodeStyleConfiguration"> + <code_scheme name="Project" version="173"> + <codeStyleSettings language="XML"> + <indentOptions> + <option name="CONTINUATION_INDENT_SIZE" value="4" /> + </indentOptions> + <arrangement> + <rules> + <section> + <rule> + <match> + <AND> + <NAME>xmlns:android</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>xmlns:.*</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + <order>BY_NAME</order> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*:id</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*:name</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>name</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>style</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>^$</XML_NAMESPACE> + </AND> + </match> + <order>BY_NAME</order> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE> + </AND> + </match> + <order>ANDROID_ATTRIBUTE_ORDER</order> + </rule> + </section> + <section> + <rule> + <match> + <AND> + <NAME>.*</NAME> + <XML_ATTRIBUTE /> + <XML_NAMESPACE>.*</XML_NAMESPACE> + </AND> + </match> + <order>BY_NAME</order> + </rule> + </section> + </rules> + </arrangement> + </codeStyleSettings> + </code_scheme> +</component>+ \ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ +<component name="ProjectCodeStyleConfiguration"> + <state> + <option name="PREFERRED_PROJECT_CODE_STYLE" value="Default" /> + </state> +</component>+ \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="GradleMigrationSettings" migrationVersion="1" /> + <component name="GradleSettings"> + <option name="linkedExternalProjectsSettings"> + <GradleProjectSettings> + <option name="testRunner" value="PLATFORM" /> + <option name="distributionType" value="DEFAULT_WRAPPED" /> + <option name="externalProjectPath" value="$PROJECT_DIR$" /> + <option name="modules"> + <set> + <option value="$PROJECT_DIR$" /> + <option value="$PROJECT_DIR$/abe" /> + <option value="$PROJECT_DIR$/app" /> + </set> + </option> + <option name="resolveModulePerSourceSet" value="false" /> + </GradleProjectSettings> + </option> + </component> +</project>+ \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> + <output url="file://$PROJECT_DIR$/build/classes" /> + </component> + <component name="ProjectType"> + <option name="id" value="Android" /> + </component> +</project>+ \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="RunConfigurationProducerService"> + <option name="ignoredProducers"> + <set> + <option value="org.jetbrains.plugins.gradle.execution.test.runner.AllInPackageGradleConfigurationProducer" /> + <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestClassGradleConfigurationProducer" /> + <option value="org.jetbrains.plugins.gradle.execution.test.runner.TestMethodGradleConfigurationProducer" /> + </set> + </option> + </component> +</project>+ \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml @@ -0,0 +1,9 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project version="4"> + <component name="VcsDirectoryMappings"> + <mapping directory="$PROJECT_DIR$" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/app/src/main/cpp/gmp" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/app/src/main/cpp/openssl" vcs="Git" /> + <mapping directory="$PROJECT_DIR$/app/src/main/cpp/pbc" vcs="Git" /> + </component> +</project>+ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile @@ -0,0 +1,44 @@ +FROM alpine:3.7 +MAINTAINER Cody Lewis <cody@codymlewis.com> + +USER root +ENV SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-3859397.zip" \ + ANDROID_HOME="/usr/local/android-sdk" \ + ANDROID_VERSION=29 \ + ANDROID_BUILD_TOOLS_VERSION=29.0.3 \ + ANDROID_NDK_VERSION=21.1.6352462 \ + ANDROID_CMAKE_VERSION=3.10.2.4988404 + +ADD build-and-run.sh /root/build-and-run.sh +RUN chmod +x /root/build-and-run.sh \ + && apk add --no-cache curl unzip openjdk8 git \ + && mkdir "$ANDROID_HOME" .android \ + && cd "$ANDROID_HOME" \ + && curl -o sdk.zip $SDK_URL \ + && unzip sdk.zip \ + && rm sdk.zip \ + && mkdir "$ANDROID_HOME/licenses" || true \ + && echo "24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license" \ + && yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses \ + && $ANDROID_HOME/tools/bin/sdkmanager --update \ + && $ANDROID_HOME/tools/bin/sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \ + "platforms;android-${ANDROID_VERSION}" \ + "platform-tools" \ + "ndk;${ANDROID_NDK_VERSION}" \ + "cmake;${ANDROID_CMAKE_VERSION}" \ + "system-images;android-28;android-wear;x86" \ + "system-images;android-R;google_apis_playstore;x86" \ + && $ANDROID_HOME/tools/bin/avdmanager create avd \ + -n watch -k "system-images;android-28;android-wear;x86" -d 1 \ + -g android-wear \ + && $ANDROID_HOME/tools/bin/avdmanager create avd \ + -n phone -k "system-images;android-R;google_apis_playstore;x86" -d 1 \ + -g google_apis_playstore \ + && git clone https://github.com/codymlewis/androidabe.git && \ + cd androidabe && \ + ./setup.sh + +ENV PATH=$PATH:$ANDROID_HOME/tools/bin:$ANDROID_HOME/platform-tools/bin:$ANDROID_HOME/emulator + + +ENTRYPOINT ["/root/build-and-run.sh"] diff --git a/README.md b/README.md @@ -0,0 +1,48 @@ +# Android ABE +An experimental android application implementing an Attribute Based Encryption +policy. + +## Quick-Start +With docker installed, pull the image with: +```sh +docker pull codymlewis/androidabe:0.0.1 +``` + +Then to run the application in both a wear OS emulator and phone emulator: +```sh +docker run codymlewis/androidabe:0.0.1 +``` +## Building your Own Version +### Requirements +- Android SDK 29 +- Android NDK 21.1.6352462 + +Then either the sdk cmdline-tools for a command line setup, or android studio +for a GUI setup + +### Setup +run the following to get required submodules and clean some possible duplicate +files: +```sh +./setup.sh +``` + +Now you have two options for building and running + +### Command Line +#### Build +Build the apks with: +```sh +./gradlew build +``` + +#### Run +Start up and run the application on a phone and smartwatch emulator with, this +assumes that you have set up a phone emulator named phone, and wear OS emulator +named watch: +```sh +./run.sh +``` + +### Android Studio +Open this root folder from Android Studio, you can then build and run diff --git a/abe/.gitignore b/abe/.gitignore @@ -0,0 +1 @@ +/build diff --git a/abe/build.gradle b/abe/build.gradle @@ -0,0 +1,32 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.3" + + defaultConfig { + minSdkVersion 16 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles 'consumer-rules.pro' + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation 'androidx.appcompat:appcompat:1.1.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' +} diff --git a/abe/consumer-rules.pro b/abe/consumer-rules.pro diff --git a/abe/proguard-rules.pro b/abe/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/abe/src/androidTest/java/com/codymlewis/abe/ExampleInstrumentedTest.java b/abe/src/androidTest/java/com/codymlewis/abe/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.codymlewis.abe; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.codymlewis.abe.test", appContext.getPackageName()); + } +} diff --git a/abe/src/main/AndroidManifest.xml b/abe/src/main/AndroidManifest.xml @@ -0,0 +1,2 @@ +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.codymlewis.abe" /> diff --git a/abe/src/main/assets/d224.param b/abe/src/main/assets/d224.param @@ -0,0 +1,14 @@ +type d +q 15028799613985034465755506450771565229282832217860390155996483840017 +n 15028799613985034465755506450771561352583254744125520639296541195021 +h 1 +r 15028799613985034465755506450771561352583254744125520639296541195021 +a 1871224163624666631860092489128939059944978347142292177323825642096 +b 9795501723343380547144152006776653149306466138012730640114125605701 +k 6 +nk 11522474695025217370062603013790980334538096429455689114222024912184432319228393204650383661781864806076247259556378350541669994344878430136202714945761488385890619925553457668158504202786580559970945936657636855346713598888067516214634859330554634505767198415857150479345944721710356274047707536156296215573412763735135600953865419000398920292535215757291539307525639675204597938919504807427238735811520 +hk 51014915936684265604900487195256160848193571244274648855332475661658304506316301006112887177277345010864012988127829655449256424871024500368597989462373813062189274150916552689262852603254011248502356041206544262755481779137398040376281542938513970473990787064615734720 +coeff0 11975189258259697166257037825227536931446707944682470951111859446192 +coeff1 13433042200347934827742738095249546804006687562088254057411901362771 +coeff2 8327464521117791238079105175448122006759863625508043495770887411614 +nqr 142721363302176037340346936780070353538541593770301992936740616924 diff --git a/abe/src/main/cpp/CMakeLists.txt b/abe/src/main/cpp/CMakeLists.txt @@ -0,0 +1,20 @@ +cmake_minimum_required(VERSION 3.4.1) + +add_library(gmp SHARED IMPORTED) +set_target_properties(gmp PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/gmp/${ANDROID_ABI}/libgmp.so) +add_library(gmpxx SHARED IMPORTED) +set_target_properties(gmpxx PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/gmp/${ANDROID_ABI}/libgmpxx.so) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/gmp/include/) +add_library(pbc SHARED IMPORTED) +set_target_properties(pbc PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/pbc/${ANDROID_ABI}/libpbc.so) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/pbc/include/) + +add_library(opencrypto SHARED IMPORTED) +set_target_properties(opencrypto PROPERTIES IMPORTED_LOCATION ${CMAKE_CURRENT_SOURCE_DIR}/openssl/${ANDROID_ABI}/libcrypto.so) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/openssl/include/) + +add_library(native-lib SHARED native-lib.c) + +find_library(log-lib log) + +target_link_libraries(native-lib gmp gmpxx pbc opencrypto android ${log-lib} )+ \ No newline at end of file diff --git a/abe/src/main/cpp/gmp b/abe/src/main/cpp/gmp @@ -0,0 +1 @@ +Subproject commit 86e513cd55a2a0e6f892cd86117719f23edf62bc diff --git a/abe/src/main/cpp/native-lib.c b/abe/src/main/cpp/native-lib.c @@ -0,0 +1,207 @@ +// +// Created by cody on 5/12/20. +// +#include <jni.h> +#include <pbc.h> +#include <pbc_test.h> +#include <string.h> + +#include <sys/types.h> +#include <malloc.h> + +#include <android/log.h> + +#include <openssl/sha.h> + +#include "native-lib.h" + +jbyteArray buffer_to_jbyteArray(JNIEnv* env, unsigned char* buf, size_t buf_len) +{ + jbyteArray jba = (*env)->NewByteArray(env, buf_len); + jbyte* jbuf = (*env)->GetByteArrayElements(env, jba, NULL); + for (int i = 0; i < buf_len; ++i) { + jbuf[i] = buf[i]; + } + (*env)->SetByteArrayRegion(env, jba, 0, buf_len, jbuf); + (*env)->ReleaseByteArrayElements(env, jba, jbuf, JNI_ABORT); + return jba; + +} + +unsigned char* jbyteArray_to_buffer(JNIEnv* env, jbyteArray jba) +{ + jsize buf_len = (*env)->GetArrayLength(env, jba); + jbyte* jbuf = (*env)->GetByteArrayElements(env, jba, NULL); + unsigned char* buf = malloc(sizeof(unsigned char) * buf_len); + for (size_t i = 0; i < buf_len; ++i) { + buf[i] = jbuf[i]; + } + (*env)->ReleaseByteArrayElements(env, jba, jbuf, JNI_ABORT); + return buf; +} + + +void init_pairing(JNIEnv* env, pairing_t* pairing, jstring params) +{ + const char *s = (*env)->GetStringUTFChars(env, params, NULL); + size_t count = strlen(s) + 1; + pairing_init_set_buf(*pairing, s, count); + (*env)->ReleaseStringUTFChars(env, params, s); +} + +jbyteArray element_to_jbyteArray(JNIEnv* env, pairing_t pairing, element_t element, char* group) +{ + int n; + if (strcmp(group, "G1")) { + n = pairing_length_in_bytes_G1(pairing); + } else if (strcmp(group, "G2")) { + n = pairing_length_in_bytes_G2(pairing); + } else if (strcmp(group, "GT")) { + n = pairing_length_in_bytes_GT(pairing); + } else { + n = pairing_length_in_bytes_Zr(pairing); + } + unsigned char* buf = pbc_malloc(n); + element_to_bytes(buf, element); + jbyteArray result = buffer_to_jbyteArray(env, buf, n); + pbc_free(buf); + return result; +} + +int element_from_jbyteArray(JNIEnv* env, element_t element, jbyteArray jba) +{ + element_from_bytes(element, jbyteArray_to_buffer(env, jba)); + return 1; +} + +int clear_elements(element_t* els, int n) +{ + for (int i = 0; i < n; ++i) { + element_clear(els[i]); + } + return 1; +} + +int hash_1(unsigned char* buf, int len, element_t e) // Remember to init e! +{ + SHA256_CTX c; + SHA256_Init(&c); + SHA256_Update(&c, buf, len); + unsigned char md[SHA256_DIGEST_LENGTH]; + SHA256_Final(md, &c); + element_from_bytes(e, md); + return 1; +} + +int hash_2(unsigned char* buf, int len, element_t e) +{ + element_from_bytes(e, buf); + return 1; +} + +JNIEXPORT jint JNICALL +Java_com_codymlewis_abe_Functions_setup( + JNIEnv* env, + jobject thiz, + jobject keychain) +{ + jclass Keychain = get_Keychain(env); + int k = Keychain_getK(env, Keychain, keychain); + pairing_t pairing; + element_t g; + init_pairing(env, &pairing, Keychain_getGroupData(env, Keychain, keychain)); + element_init_G2(g, pairing); + + element_random(g); + element_pp_t g_pp; + element_pp_init(g_pp, g); + + element_t y[k + 3]; + element_t Y[k + 3]; + jmethodID addSecret = (*env)->GetMethodID(env, Keychain, "addSecret", "([B)V"); + jmethodID addPublic = (*env)->GetMethodID(env, Keychain, "addPublic", "([B)V"); + for (int i = 0; i < k + 3; ++i) { + element_init_Zr(y[i], pairing); + element_random(y[i]); + jbyteArray s = element_to_jbyteArray(env, pairing, y[i], "Zr"); + (*env)->CallVoidMethod(env, keychain, addSecret, s); + element_init_G2(Y[i], pairing); + element_pp_pow_zn(Y[i], y[i], g_pp); + jbyteArray p = element_to_jbyteArray(env, pairing, Y[i], "G2"); + (*env)->CallVoidMethod(env, keychain, addPublic, p); + } + + clear_elements(y, k + 3); + clear_elements(Y, k + 3); + pairing_clear(pairing); + element_pp_clear(g_pp); + element_clear(g); + return 1; +} + + +JNIEXPORT jint JNICALL +Java_com_codymlewis_abe_Functions_issueToken( + JNIEnv* env, + jobject thiz, + jobject keychain, + jobject token) +{ + jclass Keychain = get_Keychain(env); + jclass Token = get_Token(env); + + // Add attributes and ID to keychain + pairing_t pairing; + init_pairing(env, &pairing, Keychain_getGroupData(env, Keychain, keychain)); + element_t h, hbar; + element_init_G1(h, pairing); + element_random(h); + Token_setSigma(env, Token, token, "setSigma1", element_to_jbyteArray(env, pairing, h, "Zr")); + element_init_G1(hbar, pairing); + element_random(hbar); + Token_setSigma(env, Token, token, "setSigmabar1", element_to_jbyteArray(env, pairing, hbar, "Zr")); + + pairing_clear(pairing); + element_clear(h); + element_clear(hbar); + return 1; +} + +JNIEXPORT jint JNICALL +Java_com_codymlewis_abe_Functions_proveKnowledge( + JNIEnv* env, + jobject thiz, + jobject keychain, + jobject token) +{ + jclass Keychain = get_Keychain(env); + jclass Token = get_Token(env); + jmethodID addAdash = get_Token_addAdash_ID(env, Token); + + pairing_t pairing; + init_pairing(env, &pairing, Keychain_getGroupData(env, Keychain, keychain)); + + // Check h is in G_2 + int k = Keychain_getK(env, Keychain, keychain); + element_t Adash[k + 1]; + for (int i = 0; i < k + 1; ++i) { + element_init_Zr(Adash[i], pairing); + element_random(Adash[i]); + Token_addAdash(env, token, addAdash, element_to_jbyteArray(env, pairing, Adash[i], "Zr")); + } + + element_t Tbar; + element_init_G1(Tbar, pairing); + element_t hbar; + element_init_G1(hbar, pairing); + element_from_jbyteArray(env, hbar, Token_getSigma(env, Token, token, "getSigmabar1")); + element_t H_2; + element_init_G1(H_2, pairing); + + pairing_clear(pairing); + element_clear(hbar); + element_clear(Tbar); + element_clear(H_2); + clear_elements(Adash, k + 1); + return 1; +}+ \ No newline at end of file diff --git a/abe/src/main/cpp/native-lib.h b/abe/src/main/cpp/native-lib.h @@ -0,0 +1,128 @@ +// +// Created by cody on 5/18/20. +// + +#ifndef ANDROID_ABE_NATIVE_LIB_H +#define ANDROID_ABE_NATIVE_LIB_H +#include <jni.h> +#include <android/log.h> + + +/** + * Convert a C byte array to a Java byte array + * @param env JNI environment + * @param buf C byte array + * @param buf_len number of bytes in the byte array + * @return Java byte array containing a copy of the C byte array data + */ +jbyteArray buffer_to_jbyteArray(JNIEnv* env, unsigned char* buf, size_t buf_len); + + +/** + * Convert a Java byte array to a C byte array + * @param env JNI environment + * @param jba Java byte array + * @return C byte array containing a copy of the java byte array data + */ +unsigned char* jbyteArray_to_buffer(JNIEnv* env, jbyteArray jba); + +/** + * Read a file asset and generate the pairing + * @param env JNI environment + * @param pairing Pointer to the pairing to put the data in + * @param assetManager AssetManager java object + * @param assetName Name of file to use + */ +void init_pairing(JNIEnv* env, pairing_t* pairing, jstring params); + +/** + * Convert an element to a Java byte array + * @param env JNI environment + * @param pairing PBC pairing struct + * @param element Element to convert + * @param group Name of the group that the element is from + * @return Java byte array of the elements data + */ +jbyteArray element_to_jbyteArray(JNIEnv* env, pairing_t pairing, element_t element, char* group); + +/** + * Convert a Java byte array to an element + * @param env JNI environment + * @param element Element to store the data in + * @param jba Array to convert + * @return 1 on completion + */ +int element_from_jbyteArray(JNIEnv* env, element_t element, jbyteArray jba); + +/** + * Clear a buffer of elements + * @param els Buffer of elements + * @param n Number of elements + * @return 1 on completion + */ +int clear_elements(element_t* els, int n); + +/** + * A normal hash function + * @param buf Buffer to hash + * @param len Number of bytes in the buffer + * @param e Element to put the resulting hash into + * @return 1 on completion + */ +int hash_1(unsigned char* buf, int len, element_t e); + +/** + * Group based hash function, in this case the group is not used so it is simply the identity + * function + * @param buf Buffer to hash + * @param len Number of bytes in the buffer + * @param e Element to put the resulting hash into + * @return 1 on completion + */ +int hash_2(unsigned char* buf, int len, element_t e); + +// Keychain Java related functions +jclass get_Keychain(JNIEnv* env) { + return (*env)->FindClass(env, "com/codymlewis/abe/Keychain"); +} + +int Keychain_getK(JNIEnv* env, jclass Keychain, jobject keychain) { + jmethodID getK = (*env)->GetMethodID(env, Keychain, "getK", "()I"); + return (*env)->CallIntMethod(env, keychain, getK); +} + +jstring Keychain_getGroupData(JNIEnv* env, jclass Keychain, jobject keychain) { + jmethodID getGroupData = (*env)->GetMethodID(env, Keychain, "getGroupData", "()Ljava/lang/String;"); + return (jstring) (*env)->CallObjectMethod(env, keychain, getGroupData); +} + +// Token Java related functions +jclass get_Token(JNIEnv* env) { + return (*env)->FindClass(env, "com/codymlewis/abe/Token"); +} + +void Token_setSigma(JNIEnv* env, jclass Token, jobject token, char* fun_name, jbyteArray jba) { + jmethodID setSigma = (*env)->GetMethodID(env, Token, fun_name, "([B)V"); + (*env)->CallVoidMethod(env, token, setSigma, jba); +} + +jbyteArray Token_getSigma(JNIEnv* env, jclass Token, jobject token, char* fun_name) { + jmethodID getSigma = (*env)->GetMethodID(env, Token, fun_name, "()[B"); + return (jbyteArray) (*env)->CallObjectMethod(env, token, getSigma); +} + +void Token_setN(JNIEnv* env, jclass Token, jobject token, int n) { + jmethodID setN = (*env)->GetMethodID(env, Token, "setN", "(I)V"); + (*env)->CallVoidMethod(env, token, setN, n); +} + +jmethodID get_Token_addAdash_ID(JNIEnv* env, jclass Token) { + return (*env)->GetMethodID(env, Token, "addAdash", "([B)V"); +} + +void Token_addAdash(JNIEnv* env, jobject token, jmethodID addAdash, jbyteArray jba) { + (*env)->CallVoidMethod(env, token, addAdash, jba); +} + + +#endif //ANDROID_ABE_NATIVE_LIB_H diff --git a/abe/src/main/cpp/openssl b/abe/src/main/cpp/openssl @@ -0,0 +1 @@ +Subproject commit cab66b6ff89e56b99651ebfe5d582974a32fa7c2 diff --git a/abe/src/main/cpp/pbc b/abe/src/main/cpp/pbc @@ -0,0 +1 @@ +Subproject commit 17fda209851cd4d55cd0ce4bdc6425d543469f41 diff --git a/abe/src/main/java/com/codymlewis/abe/Functions.java b/abe/src/main/java/com/codymlewis/abe/Functions.java @@ -0,0 +1,24 @@ +package com.codymlewis.abe; + +import android.app.Activity; +import android.content.res.AssetManager; + +import java.io.IOException; +import java.io.InputStream; + +public class Functions { + public static String readParams(Activity a) throws IOException { + InputStream in = a.getAssets().open("d224.param", AssetManager.ACCESS_BUFFER); + byte[] buf = new byte[in.available()]; + in.read(buf); + in.close(); + return new String(buf); + } + + static { + System.loadLibrary("native-lib"); + } + + public static native int setup(Keychain keychain); + public static native int issueToken(Keychain keychain, Token token); +} diff --git a/abe/src/main/java/com/codymlewis/abe/Keychain.java b/abe/src/main/java/com/codymlewis/abe/Keychain.java @@ -0,0 +1,83 @@ +package com.codymlewis.abe; + +import java.util.ArrayList; + +public class Keychain { + private String groupData; + private byte[] x; + private ArrayList<byte[]> y; + private byte[] X; + private ArrayList<byte[]> Y; + private int k; + + public Keychain() { + groupData = ""; + x = null; + y = new ArrayList<>(); + X = null; + Y = new ArrayList<>(); + k = 0; + } + + public Keychain(String groupData, int k) { + this(); + this.groupData = groupData; + this.k = k; + } + + public void setGroupData(String groupData) { + this.groupData = groupData; + } + + public void addSecret(byte[] secret) { + if (x == null) { + x = secret; + } else { + y.add(secret); + } + } + + public void addPublic(byte[] publik) { + if (X == null) { + X = publik; + } else { + Y.add(publik); + } + } + + public void setK(int k) { + this.k = k; + } + + public String getGroupData() { + return groupData; + } + + public byte[] getSecretX() { + return x; + } + + public byte[] getSecretY(int i) { + return y.get(i); + } + + public int lenSecretY() { + return y.size(); + } + + public byte[] getPublicX() { + return X; + } + + public byte[] getPublicY(int i) { + return Y.get(i); + } + + public int lenPublicY() { + return Y.size(); + } + + public int getK() { + return k; + } +} diff --git a/abe/src/main/java/com/codymlewis/abe/Token.java b/abe/src/main/java/com/codymlewis/abe/Token.java @@ -0,0 +1,120 @@ +package com.codymlewis.abe; + +import java.util.ArrayList; +import java.util.Arrays; + +public class Token { + private String userId; + private ArrayList<byte[]> attributes; + private byte[] sigma1; + private byte[] sigma2; + private byte[] sigmabar1; + private byte[] sigmabar2; + private int n; + private byte[] w; + private ArrayList<byte[]> Adash; + + public Token() { + userId = ""; + attributes = new ArrayList<>(); + sigma1 = null; + sigma2 = null; + sigmabar1 = null; + sigmabar2 = null; + n = 0; + w = null; + Adash = new ArrayList<>(); + } + + public Token(String userId, int n) { + this(); + this.userId = userId; + this.n = n; + } + + public void setUserId(String userId) { + this.userId = userId; + } + + public void addAttributes(String[] attributes) { + for (String attribute : attributes) { + this.attributes.add(attribute.getBytes()); + } + } + + public void addAttributes(byte[][] attributes) { + this.attributes.addAll(Arrays.asList(attributes)); + } + + public void setSigma1(byte[] sigma1) { + this.sigma1 = sigma1; + } + + public void setSigma2(byte[] sigma2) { + this.sigma2 = sigma2; + } + + public void setSigmabar1(byte[] sigmabar1) { + this.sigmabar1 = sigmabar1; + } + + public void setSigmabar2(byte[] sigmabar2) { + this.sigmabar2 = sigmabar2; + } + + public void setN(int n) { + this.n = n; + } +// +// public void setW(byte[] w) { +// this.w = w; +// } + + public void addAdash(byte[] adash) { + if (w == null) { + w = adash; + } else { + Adash.add(adash); + } + } + + public String getUserId() { + return userId; + } + + public byte[] getAttribute(int i) { + return attributes.get(i); + } + + public ArrayList<byte[]> getAttributes() { + return attributes; + } + + public byte[] getSigma1() { + return sigma1; + } + + public byte[] getSigma2() { + return sigma2; + } + + public byte[] getSigmabar1() { + return sigmabar1; + } + + public byte[] getSigmabar2() { + return sigmabar2; + } + + public int getN() { + return n; + } + + public byte[] getW() { + return w; + } + + public byte[] getAdash(int i) { + return Adash.get(i); + } +} diff --git a/abe/src/test/java/com/codymlewis/abe/ExampleUnitTest.java b/abe/src/test/java/com/codymlewis/abe/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.codymlewis.abe; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +}+ \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle @@ -0,0 +1,57 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 29 + buildToolsVersion "29.0.3" + ndkVersion "21.1.6352462" + + defaultConfig { + applicationId "com.codymlewis.androidabe" + minSdkVersion 16 + targetSdkVersion 29 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + externalNativeBuild { + cmake { + arguments "-DANDROID_TOOLCHAIN=clang", "-DANDROID_STL=c++_shared" + cFlags "-D__STDC_FORMAT_MACROS" + cppFlags "-fexceptions", "-frtti" + } + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + + externalNativeBuild { + cmake { + path "../abe/src/main/cpp/CMakeLists.txt" + version "3.10.2" + } + } + + sourceSets { + main { + jniLibs.srcDirs '../abe/src/main/cpp/gmp/', '../abe/src/main/cpp/pbc/', '../abe/src/main/cpp/openssl' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + + implementation project(':abe') +} diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/codymlewis/androidabe/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/codymlewis/androidabe/ExampleInstrumentedTest.java @@ -0,0 +1,27 @@ +package com.codymlewis.androidabe; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + + assertEquals("com.codymlewis.androidabe", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="com.codymlewis.androidabe"> + + <application + android:allowBackup="true" + android:icon="@mipmap/ic_launcher" + android:label="@string/app_name" + android:roundIcon="@mipmap/ic_launcher_round" + android:supportsRtl="true" + android:theme="@style/AppTheme"> + <activity android:name=".MainActivity"> + <intent-filter> + <action android:name="android.intent.action.MAIN" /> + + <category android:name="android.intent.category.LAUNCHER" /> + </intent-filter> + </activity> + </application> + +</manifest>+ \ No newline at end of file diff --git a/app/src/main/assets/d224.param b/app/src/main/assets/d224.param @@ -0,0 +1,14 @@ +type d +q 15028799613985034465755506450771565229282832217860390155996483840017 +n 15028799613985034465755506450771561352583254744125520639296541195021 +h 1 +r 15028799613985034465755506450771561352583254744125520639296541195021 +a 1871224163624666631860092489128939059944978347142292177323825642096 +b 9795501723343380547144152006776653149306466138012730640114125605701 +k 6 +nk 11522474695025217370062603013790980334538096429455689114222024912184432319228393204650383661781864806076247259556378350541669994344878430136202714945761488385890619925553457668158504202786580559970945936657636855346713598888067516214634859330554634505767198415857150479345944721710356274047707536156296215573412763735135600953865419000398920292535215757291539307525639675204597938919504807427238735811520 +hk 51014915936684265604900487195256160848193571244274648855332475661658304506316301006112887177277345010864012988127829655449256424871024500368597989462373813062189274150916552689262852603254011248502356041206544262755481779137398040376281542938513970473990787064615734720 +coeff0 11975189258259697166257037825227536931446707944682470951111859446192 +coeff1 13433042200347934827742738095249546804006687562088254057411901362771 +coeff2 8327464521117791238079105175448122006759863625508043495770887411614 +nqr 142721363302176037340346936780070353538541593770301992936740616924 diff --git a/app/src/main/java/com/codymlewis/androidabe/MainActivity.java b/app/src/main/java/com/codymlewis/androidabe/MainActivity.java @@ -0,0 +1,47 @@ +package com.codymlewis.androidabe; + +import androidx.appcompat.app.AppCompatActivity; + +import android.content.res.AssetManager; +import android.os.Bundle; +import android.widget.TextView; + +import com.codymlewis.abe.Functions; +import com.codymlewis.abe.Keychain; +import com.codymlewis.abe.Token; + +import java.io.IOException; +import java.util.Base64; + +public class MainActivity extends AppCompatActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + TextView tv = findViewById(R.id.output_text); + String groupParams = ""; + try { + groupParams = Functions.readParams(this); + } catch (IOException ioe) { + tv.setText(getString(R.string.asset_io_error_message, ioe.getMessage())); + } + System.out.println("Loaded param file"); + Keychain kc = new Keychain(groupParams, 5); + Functions.setup(kc); + String text = String.format("x = %s\n", Base64.getEncoder().encodeToString(kc.getSecretX())); +// for (int i = 0; i < kc.lenSecretY(); ++i) { +// text += String.format("y_%d = %s\n", i, Base64.getEncoder().encodeToString(kc.getSecretY(i))); +// } +// text += String.format("X = %s\n", Base64.getEncoder().encodeToString(kc.getPublicX())); +// for (int i = 0; i < kc.lenPublicY(); ++i) { +// text += String.format("Y_%d = %s\n", i, Base64.getEncoder().encodeToString(kc.getPublicY(i))); +// } + + Token token = new Token("Alice", 5); + Functions.issueToken(kc, token); + text += String.format("sigma1 = %s\n", Base64.getEncoder().encodeToString(token.getSigma1())); + text += String.format("sigmabar1 = %s\n", Base64.getEncoder().encodeToString(token.getSigmabar1())); + tv.setText(text); + } +} diff --git a/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ +<vector xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:aapt="http://schemas.android.com/aapt" + android:width="108dp" + android:height="108dp" + android:viewportWidth="108" + android:viewportHeight="108"> + <path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z"> + <aapt:attr name="android:fillColor"> + <gradient + android:endX="85.84757" + android:endY="92.4963" + android:startX="42.9492" + android:startY="49.59793" + android:type="linear"> + <item + android:color="#44000000" + android:offset="0.0" /> + <item + android:color="#00000000" + android:offset="1.0" /> + </gradient> + </aapt:attr> + </path> + <path + android:fillColor="#FFFFFF" + android:fillType="nonZero" + android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z" + android:strokeWidth="1" + android:strokeColor="#00000000" /> +</vector>+ \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ +<?xml version="1.0" encoding="utf-8"?> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="108dp" + android:height="108dp" + android:viewportWidth="108" + android:viewportHeight="108"> + <path + android:fillColor="#3DDC84" + android:pathData="M0,0h108v108h-108z" /> + <path + android:fillColor="#00000000" + android:pathData="M9,0L9,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,0L19,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M29,0L29,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M39,0L39,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M49,0L49,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M59,0L59,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M69,0L69,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M79,0L79,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M89,0L89,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M99,0L99,108" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,9L108,9" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,19L108,19" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,29L108,29" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,39L108,39" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,49L108,49" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,59L108,59" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,69L108,69" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,79L108,79" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,89L108,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M0,99L108,99" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,29L89,29" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,39L89,39" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,49L89,49" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,59L89,59" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,69L89,69" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M19,79L89,79" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M29,19L29,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M39,19L39,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M49,19L49,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M59,19L59,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M69,19L69,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> + <path + android:fillColor="#00000000" + android:pathData="M79,19L79,89" + android:strokeWidth="0.8" + android:strokeColor="#33FFFFFF" /> +</vector> diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,20 @@ +<?xml version="1.0" encoding="utf-8"?> +<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools" + android:layout_width="match_parent" + android:layout_height="match_parent" + tools:context=".MainActivity"> + + <TextView + android:id="@+id/output_text" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="Hello World!" + android:textSize="12sp" + app:layout_constraintBottom_toBottomOf="parent" + app:layout_constraintLeft_toLeftOf="parent" + app:layout_constraintRight_toRightOf="parent" + app:layout_constraintTop_toTopOf="parent" /> + +</androidx.constraintlayout.widget.ConstraintLayout>+ \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> + <background android:drawable="@drawable/ic_launcher_background" /> + <foreground android:drawable="@drawable/ic_launcher_foreground" /> +</adaptive-icon>+ \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ +<?xml version="1.0" encoding="utf-8"?> +<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android"> + <background android:drawable="@drawable/ic_launcher_background" /> + <foreground android:drawable="@drawable/ic_launcher_foreground" /> +</adaptive-icon>+ \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png Binary files differ. diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png Binary files differ. diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png Binary files differ. diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png Binary files differ. diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png Binary files differ. diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png Binary files differ. diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png Binary files differ. diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png Binary files differ. diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png Binary files differ. diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png Binary files differ. diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <color name="colorPrimary">#0100CE</color> + <color name="colorPrimaryDark">#0100CE</color> + <color name="colorAccent">#03DAC5</color> +</resources> diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ +<resources> + <string name="app_name">Android ABE</string> + <string name="asset_io_error_message">Asset File IO Error: %1$s</string> +</resources> diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ +<resources> + + <!-- Base application theme. --> + <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> + <!-- Customize your theme here. --> + <item name="colorPrimary">@color/colorPrimary</item> + <item name="colorPrimaryDark">@color/colorPrimaryDark</item> + <item name="colorAccent">@color/colorAccent</item> + </style> + +</resources> diff --git a/app/src/test/java/com/codymlewis/androidabe/ExampleUnitTest.java b/app/src/test/java/com/codymlewis/androidabe/ExampleUnitTest.java @@ -0,0 +1,17 @@ +package com.codymlewis.androidabe; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Example local unit test, which will execute on the development machine (host). + * + * @see <a href="http://d.android.com/tools/testing">Testing documentation</a> + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() { + assertEquals(4, 2 + 2); + } +}+ \ No newline at end of file diff --git a/build-and-run.sh b/build-and-run.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +cd androidabe && ./gradlew build && ./run.sh diff --git a/build.gradle b/build.gradle @@ -0,0 +1,29 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + + repositories { + google() + jcenter() + + } + dependencies { + classpath 'com.android.tools.build:gradle:3.6.3' + + + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/gradle.properties b/gradle.properties @@ -0,0 +1,20 @@ +# Project-wide Gradle settings. +# IDE (e.g. Android Studio) users: +# Gradle settings configured through the IDE *will override* +# any settings specified in this file. +# For more details on how to configure your build environment visit +# http://www.gradle.org/docs/current/userguide/build_environment.html +# Specifies the JVM arguments used for the daemon process. +# The setting is particularly useful for tweaking memory settings. +org.gradle.jvmargs=-Xmx1536m +# When configured, Gradle will run in incubating parallel mode. +# This option should only be used with decoupled projects. More details, visit +# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects +# org.gradle.parallel=true +# AndroidX package structure to make it clearer which packages are bundled with the +# Android operating system, and which are packaged with your app's APK +# https://developer.android.com/topic/libraries/support-library/androidx-rn +android.useAndroidX=true +# Automatically convert third-party libraries to use AndroidX +android.enableJetifier=true + diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar Binary files differ. diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Fri May 15 15:24:25 AEST 2020 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip diff --git a/gradlew b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn () { + echo "$*" +} + +die () { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/run.sh b/run.sh @@ -0,0 +1,25 @@ +#!/bin/sh + +emulator="$ANDROID_HOME/emulator/emulator" +adb="$ANDROID_HOME/platform-tools/adb" + +emulate () { + img=$1 + port=$2 + $emulator "$img" -port "$port" & + sleep 5 + case $img in + *Wear*) + app="androidabe" + ;; + *) + app="app" + ;; + esac + $adb -s "emulator-$port" install -t $app/build/outputs/apk/debug/$app-debug.apk + $adb -s "emulator-$port" shell am start com.codymlewis.androidabe/com.codymlewis.androidabe.MainActivity +} + + +emulate "@phone" 5554 +emulate "@watch" 5556 diff --git a/settings.gradle b/settings.gradle @@ -0,0 +1,3 @@ +rootProject.name='Android ABE' +include ':app' +include ':abe' diff --git a/setup.sh b/setup.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +printf "Started setup...\n" && \ +git submodule update --init --recursive && \ +rm abe/src/main/cpp/gmp/README.md && \ +rm abe/src/main/cpp/pbc/README.md && \ +printf "Finished setup, ready to compile.\n"