Skip to content

Commit

Permalink
Extract library (#1)
Browse files Browse the repository at this point in the history
* Use gradle 3.2.1

* Use gradle 4.10.2

* Cleanup - this is not needed

* Cleanup

* Cleanup

* Leverage SystemClock

* Cleanup

* Separate the Application specific code

* Extract library

* Do not bleed out BouncyCastle into library API

Also change the logging as we do not have the byte[]->hex method from spongycastle anymore
  • Loading branch information
ligi authored and bitgamma committed Oct 27, 2018
1 parent 60f1315 commit 8950e15
Show file tree
Hide file tree
Showing 44 changed files with 241 additions and 199 deletions.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.0'
classpath 'com.android.tools.build:gradle:3.2.1'


// NOTE: Do not place your application dependencies here; they belong
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions app/build.gradle → demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "im.status.hardwallet_lite_android"
applicationId "im.status.hardwallet_lite_android.demo"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
Expand All @@ -19,11 +19,11 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.madgag.spongycastle:core:1.58.0.0'
implementation 'com.madgag.spongycastle:prov:1.58.0.0'

implementation project(':lib')

testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="im.status.hardwallet_lite_android">

<uses-permission android:name="android.permission.NFC" />
<uses-feature android:name="android.hardware.nfc.hce" android:required="true" />
package="im.status.hardwallet_lite_android.demo">

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package im.status.hardwallet_lite_android.app;

import android.nfc.NfcAdapter;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import im.status.hardwallet_lite_android.demo.R;
import im.status.hardwallet_lite_android.io.APDUResponse;
import im.status.hardwallet_lite_android.io.CardChannel;
import im.status.hardwallet_lite_android.io.CardManager;
import im.status.hardwallet_lite_android.io.OnCardConnectedListener;
import im.status.hardwallet_lite_android.wallet.WalletAppletCommandSet;

public class MainActivity extends AppCompatActivity {

private static final String TAG = "MainActivity";

private NfcAdapter nfcAdapter;
private CardManager cardManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
cardManager = new CardManager();

cardManager.setOnCardConnectedListener(new OnCardConnectedListener() {
@Override
public void onConnected(CardChannel cardChannel) {
try {

Log.i(TAG, "onCardConnected()");

// Applet-specific code
WalletAppletCommandSet cmdSet = new WalletAppletCommandSet(cardChannel);

// First thing to do is selecting the applet on the card.
cmdSet.select().checkOK();

Log.i(TAG, "Applet is installed on the connected card.");

// In real projects, the pairing key should be saved and used for all new sessions.
cmdSet.autoPair("WalletAppletTest");

Log.i(TAG, "Pairing with card is done.");

// Opening a Secure Channel is needed for all other applet commands
cmdSet.autoOpenSecureChannel();

Log.i(TAG, "Secure channel opened.");

// We send a GET STATUS command, which does not require PIN authentication
APDUResponse resp = cmdSet.getStatus(WalletAppletCommandSet.GET_STATUS_P1_APPLICATION).checkOK();

Log.i(TAG, "Got status (response length=" + resp.getData().length + ")." );

// PIN authentication allows execution of privileged commands
cmdSet.verifyPIN("000000").checkOK();

Log.i(TAG, "Pin Verified.");

// Cleanup, in a real application you would not unpair and instead keep the pairing key for successive interactions.
// We also remove all other pairings so that we do not fill all slots with failing runs. Again in real application
// this would be a very bad idea to do.
cmdSet.unpairOthers();
cmdSet.autoUnpair();

Log.i(TAG, "Unpaired.");

} catch (Exception e) {
Log.e(TAG, e.getMessage());
}

}
});
cardManager.start();
}

@Override
public void onResume() {
super.onResume();
if (nfcAdapter != null) {
nfcAdapter.enableReaderMode(this, this.cardManager, NfcAdapter.FLAG_READER_NFC_A | NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK, null);
}
}

@Override
public void onPause() {
super.onPause();
if (nfcAdapter != null) {
nfcAdapter.disableReaderMode(this);
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Tue Oct 23 10:14:17 CEST 2018
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
Empty file modified gradlew
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions lib/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
26 changes: 26 additions & 0 deletions lib/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
}

task androidSourcesJar(type: Jar) {
from android.sourceSets.main.java.source
classifier = 'sources'
}

artifacts {
archives androidSourcesJar
}

}

dependencies {
implementation 'com.madgag.spongycastle:core:1.58.0.0'
implementation 'com.madgag.spongycastle:prov:1.58.0.0'
}
21 changes: 21 additions & 0 deletions lib/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit 8950e15

Please sign in to comment.