Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

distribute AcraWriter Android via maven #310

Merged
merged 1 commit into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ _testmain.go
bin
src/github.com/

.gradle


# iOS and OSX
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ AcraTranslator and AcraServer are fully independent server-side components and c
| ♦️ Ruby | [Installation guide](https://docs.cossacklabs.com/pages/documentation-acra/#building-acrawriter-for-ruby) | [examples/ruby](https://github.com/cossacklabs/acra/tree/master/examples/ruby) | [![Gem](https://img.shields.io/gem/v/acrawriter.svg)](https://rubygems.org/gems/acrawriter) |
| ➕ C++ | [Installation guide](https://docs.cossacklabs.com/pages/documentation-acra/#building-acrawriter-for-c-) | [examples/cpp](https://github.com/cossacklabs/acra/tree/master/examples/cpp) ||
| 📱 Objective-C / Swift (iOS) | [Installation guide](https://docs.cossacklabs.com/pages/documentation-acra/#building-acrawriter-for-ios) | [examples/objc](https://github.com/cossacklabs/acra/tree/master/examples/objc) | [![CocoaPods](https://img.shields.io/cocoapods/v/acrawriter.svg)](https://cocoapods.org/pods/acrawriter) |
| ☎️ Java (Android) | [Installation guide](https://docs.cossacklabs.com/pages/documentation-acra/#building-acrawriter-for-android) | [examples/android_java](https://github.com/cossacklabs/acra/tree/master/examples/android_java) ||
| ☎️ Java (Android) | [Installation guide](https://docs.cossacklabs.com/pages/documentation-acra/#building-acrawriter-for-android) | [examples/android_java](https://github.com/cossacklabs/acra/tree/master/examples/android_java) |[ ![maven](https://api.bintray.com/packages/cossacklabs/maven/acrawriter/images/download.svg) ](https://bintray.com/cossacklabs/maven/acrawriter/_latestVersion)|
| 🐘 PHP | [Installation guide](https://docs.cossacklabs.com/pages/documentation-acra/#building-acrawriter-for-php) | [examples/php](https://github.com/cossacklabs/acra/tree/master/examples/php) ||
| 🍭 Javascript (NodeJS) | [Installation guide](https://docs.cossacklabs.com/pages/documentation-acra/#building-acrawriter-for-nodejs) | [examples/nodejs](https://github.com/cossacklabs/acra/tree/master/examples/nodejs) | [![npm](https://img.shields.io/npm/v/acrawriter.svg)](https://www.npmjs.com/package/acrawriter) |

Expand Down
101 changes: 101 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
apply plugin: 'com.android.library'

buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.0.1'

// Two necessary plugins for uploading .aar to bintray
// from: https://android.jlelse.eu/how-to-distribute-android-library-in-a-convenient-way-d43fb68304a7
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+'
classpath 'com.github.dcendents:android-maven-gradle-plugin:1.+'
}
}

repositories {
google()
jcenter()
maven { url "https://dl.bintray.com/cossacklabs/maven/" }
}

dependencies {
implementation 'com.cossacklabs.com:themis:0.10.+'
}

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 16
}

sourceSets {
main {
java.srcDirs = ['wrappers/java']
manifest.srcFile 'wrappers/java/AndroidManifest.xml'
}
}
}

// distribution

apply plugin: 'com.jfrog.bintray'
apply plugin: 'maven-publish'

publishing {
publications {
Production(MavenPublication) {
artifact("$buildDir/outputs/aar/acra-release.aar")
groupId 'com.cossacklabs.com'
artifactId 'acrawriter'
version '1.0.1'

pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')

// Iterate over the implementation dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.implementation.allDependencies.each {
// Ensure dependencies such as fileTree are not included.
if (it.name != 'unspecified') {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}

bintray {
// Get Bintray credential from environment variable
user = System.getenv('BINTRAY_USER') // Get bintray User
key = System.getenv('BINTRAY_KEY') // Get bintray API Key from https://bintray.com/profile/edit -> APIKey
configurations = ['archives']
pkg {
repo = 'maven'
name = 'acrawriter'
userOrg = 'cossacklabs'
licenses = ['Apache-2.0']
desc = 'AcraWriter library for Android: encrypts data into AcraStructs, allowing Acra to decrypt it.'
websiteUrl = "https://cossacklabs.com/acra/"
vcsUrl = 'https://github.com/cossacklabs/acra.git'
publish = true
version {
name = '1.0.1'
released = new Date()
gpg {
sign = true
passphrase = System.getenv('BINTRAY_GPG_PASSPHRASE')
}
}
}
publications = ['Production']
}
28 changes: 12 additions & 16 deletions examples/android_java/AcraWriterAndroidApp/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 26
buildToolsVersion '26.0.2'
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.cossacklabs.acrawriter_example"
minSdkVersion 16
targetSdkVersion 16
minSdkVersion 25
targetSdkVersion 26
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand All @@ -19,22 +19,18 @@ android {
}
productFlavors {
}

sourceSets {
// acra/wrappers/java
main.java.srcDirs += '../../../../wrappers/java'
androidTest.java.srcDirs += '../../../../wrappers/java'
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
androidTestImplementation 'com.android.support.test:runner:1.0.0'
androidTestImplementation 'com.android.support.test:rules:1.0.0'
androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
androidTestCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:26.+'
compile 'com.android.support.constraint:constraint-layout:1.0.2'
testCompile 'junit:junit:4.12'
debugCompile(name: 'themis-release', ext: 'aar')
androidTestImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
testImplementation 'junit:junit:4.12'

implementation 'com.cossacklabs.com:acrawriter:1.0.+'
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Base64;
import android.util.Log;

import com.cossacklabs.acrawriter.AcraStruct;
import com.cossacklabs.acrawriter.AcraWriter;
Expand All @@ -28,16 +29,39 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Secure cell
try {
generateAndSendAcraStruct();
generateAndSendAcraStructWithZone();
// use to generate AcraStruct and log it
generateAcraStructLocally();

// use with running AcraTranslator
// generateAndSendAcraStruct();
// generateAndSendAcraStructWithZone();

} catch (InvalidArgumentException | NullArgumentException | SecureCellException e) {
e.printStackTrace();
}
}

// Generate storage keys, AcraWriter is using <client_id>_storage.pub public key
// https://github.com/cossacklabs/acra/wiki/AcraConnector-and-AcraWriter#client-side-with-zones
void generateAcraStructLocally() throws SecureCellException, NullArgumentException, InvalidArgumentException {
String message = "local acrastruct";

String acraTranslatorPublicKey = "VUVDMgAAAC240mpnAx8FSrZxhVNPsnhhZFYAm0+ARiRDdXPKAW0vI/2AY0QM";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we use hardcoded public key here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's example that illustrates a typical flow of mobile app: it gets public key from somewhere (via network request) in base64 encoding. to make this example work without inet connection, the key is hardcoded.

I believe for mobile devs it's more useful to see encoding-decoding and to understand that they can get this key from somewhere, than to use local keygen.

PublicKey publicKey = new PublicKey(Base64.decode(acraTranslatorPublicKey.getBytes(), Base64.NO_WRAP));

try {
AcraWriter aw = new AcraWriter();
AcraStruct acraStruct = aw.createAcraStruct(message.getBytes(), publicKey, null);

String encodedString = Base64.encodeToString(acraStruct.toByteArray(), Base64.NO_WRAP);
Log.d("SMC", "acrastruct in base64 = " + encodedString);

} catch (KeyGenerationException | IOException e) {
e.printStackTrace();
}
}

// Generate storage keys, AcraWriter is using <client_id>_storage.pub public key
// https://github.com/cossacklabs/acra/wiki/AcraConnector-and-AcraWriter#client-side-with-zones
void generateAndSendAcraStruct() throws SecureCellException, NullArgumentException, InvalidArgumentException {
Expand Down
5 changes: 4 additions & 1 deletion examples/android_java/AcraWriterAndroidApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
buildscript {
repositories {
jcenter()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'com.android.tools.build:gradle:3.3.0'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -15,9 +16,11 @@ buildscript {
allprojects {
repositories {
jcenter()
google()
flatDir {
dirs 'libs'
}
maven { url "https://dl.bintray.com/cossacklabs/maven/" }
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Sep 04 22:26:50 CEST 2017
#Sun Feb 03 21:16:47 EET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Wed Dec 27 12:10:05 UTC 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip