Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfehr committed Mar 26, 2023
0 parents commit 4f87157
Show file tree
Hide file tree
Showing 52 changed files with 4,159 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
local.properties
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
47 changes: 47 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
plugins {
id 'com.android.application'
}

android {
namespace 'de.androidcrypto.talktoyourcreditcard'
compileSdk 33

defaultConfig {
applicationId "de.androidcrypto.talktoyourcreditcard"
minSdk 21
targetSdk 33
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'

// parsing BER-TLV encoded data, e.g. a credit card
// source: https://github.com/evsinev/ber-tlv
implementation 'com.payneteasy:ber-tlv:1.0-11'

// pretty printing of card's responses
// source: https://github.com/devnied/EMV-NFC-Paycard-Enrollment
implementation 'com.github.devnied.emvnfccard:library:3.0.1'
}
21 changes: 21 additions & 0 deletions app/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
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.androidcrypto.talktoyourcreditcard;

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("de.androidcrypto.talktoyourcreditcard", appContext.getPackageName());
}
}
29 changes: 29 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<!-- needed for NFC -->
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.VIBRATE" />

<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.TalkToYourCreditCard"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
126 changes: 126 additions & 0 deletions app/src/main/java/de/androidcrypto/talktoyourcreditcard/DOL.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
package de.androidcrypto.talktoyourcreditcard;

/*
* Copyright 2010 sasc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import com.github.devnied.emvnfccard.iso7816emv.TagAndLength;
import com.github.devnied.emvnfccard.utils.TlvUtil;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;


/**
* Data Object List (DOL)
*
* In several instances, the terminal is asked to build a flexible list of data
* elements to be passed to the card under the card‘s direction.
* To minimise processing within the ICC, such a list is not TLV encoded but
* is a single constructed field built by concatenating several data
* elements together. Since the elements of the constructed field are not
* TLV encoded, it is imperative that the ICC knows the format of this field
* when the data is received. This is achieved by including a
* Data Object List (DOL) in the ICC, specifying the format of the data to
* be included in the constructed field.
*
* DOLs currently used in this specification include:
* - the Processing Options Data Object List (PDOL) used with the GET PROCESSING OPTIONS command
* - the Card Risk Management Data Object Lists (CDOL1 and CDOL2) used with the GENERATE APPLICATION CRYPTOGRAM (AC) command
* - the Transaction Certificate Data Object List (TDOL) used to generate a TC Hash Value
* - the Dynamic Data Authentication Data Object List (DDOL) used with the INTERNAL AUTHENTICATE command
*
* ---------------------------------------------------------------------------
*
* In other words, a DOL is sent from the ICC. This DOL contains only Tag ID bytes and length bytes.
* The Terminal constructs the response, which contains only the VALUES for these tags.
*
* //TODO check DOL processing on page 55
*
* @author sasc
*
* Source: https://github.com/sasc999/javaemvreader/blob/master/src/main/java/sasc/emv/DOL.java
*/
public class DOL {

public enum Type{
PDOL("Processing Options Data Object List"),
CDOL1("Card Risk Management Data Object List 1"),
CDOL2("Card Risk Management Data Object List 2"),
TDOL("Transaction Certificate Data Object List"),
//An ICC that supports DDA shall contain a DDOL. The DDOL shall contain only the Unpredictable Number generated by the terminal (tag '9F37', 4 bytes binary).
DDOL("Dynamic Data Authentication Data Object List");

private String description;

private Type(String description){
this.description = description;
}

public String getDescription(){
return description;
}

@Override
public String toString(){
return getDescription();
}
}

private Type type;
private List<TagAndLength> tagAndLengthList = new ArrayList<TagAndLength>();

public DOL(Type type, byte[] data){
//Parse tags and lengths
this.type = type;
this.tagAndLengthList = TlvUtil.parseTagAndLength(data);
}

public List<TagAndLength> getTagAndLengthList(){
return Collections.unmodifiableList(tagAndLengthList);
}

@Override
public String toString(){
StringWriter sw = new StringWriter();
dump(new PrintWriter(sw), 0);
return sw.toString();
}


public void dump(PrintWriter pw, int indent){
pw.println(getSpaces(indent)+type.getDescription());
final int INDENT_SIZE = 2;
String indentStr = getSpaces(indent+INDENT_SIZE);
//String indentStr = Util.getSpaces(indent+Log.INDENT_SIZE);

for(TagAndLength tagAndLength : tagAndLengthList){
int length = tagAndLength.getLength();
pw.println(indentStr+tagAndLength.getTag().getName() + " ("+length+ " "+(length==1?"byte":"bytes")+")");
}
}

public static String getSpaces(int length) {
StringBuilder buf = new StringBuilder(length);
for (int i = 0; i < length; i++) {
buf.append(" ");
}
return buf.toString();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package de.androidcrypto.talktoyourcreditcard;

public class DolTag {

private byte[] tag;
private String tagName;
private byte[] defaultValue;

public DolTag(byte[] tag, String tagName, byte[] defaultValue) {
this.tag = tag;
this.tagName = tagName;
this.defaultValue = defaultValue;
}

public byte[] getTag() {
return tag;
}

public void setTag(byte[] tag) {
this.tag = tag;
}

public String getTagName() {
return tagName;
}

public void setTagName(String tagName) {
this.tagName = tagName;
}

public byte[] getDefaultValue() {
return defaultValue;
}

public void setDefaultValue(byte[] defaultValue) {
this.defaultValue = defaultValue;
}
}
Loading

0 comments on commit 4f87157

Please sign in to comment.