10 |
--------------------------------------------------------------------------------
/nfcard/src/androidTest/java/ru/platformasoft/nfcard/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/nfcard-example/src/androidTest/java/platformasoft/ru/nfcardexample/ApplicationTest.java:
--------------------------------------------------------------------------------
1 | package platformasoft.ru.nfcardexample;
2 |
3 | import android.app.Application;
4 | import android.test.ApplicationTestCase;
5 |
6 | /**
7 | * Testing Fundamentals
8 | */
9 | public class ApplicationTest extends ApplicationTestCase {
10 | public ApplicationTest() {
11 | super(Application.class);
12 | }
13 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | #built application files
2 | *.apk
3 | *.ap_
4 |
5 | # files for the dex VM
6 | *.dex
7 |
8 | # Java class files
9 | *.class
10 |
11 | # generated files
12 | bin/
13 | gen/
14 |
15 | # Local configuration file (sdk path, etc)
16 | local.properties
17 |
18 | # Windows thumbnail db
19 | Thumbs.db
20 |
21 | # OSX files
22 | .DS_Store
23 |
24 | # Eclipse project files
25 | .classpath
26 | .project
27 |
28 | # Android Studio
29 | .idea
30 | #.idea/workspace.xml - remove # and delete .idea if it better suit your needs.
31 | .gradle
32 | build/
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/ber/BerValue.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard.ber;
2 |
3 | import java.util.Iterator;
4 |
5 | /**
6 | * Ber value is something that represents value
7 | * Created by Sergey Kapustin on 01.10.2014.
8 | */
9 | public abstract class BerValue {
10 |
11 | /**
12 | * Is ber value primitive?
13 | * @return
14 | */
15 | public abstract boolean isPrimitive();
16 |
17 | /**
18 | * Fetch sub-entities iterator
19 | * @return
20 | */
21 | public abstract Iterator iterator();
22 | }
23 |
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/ber/BerLength.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard.ber;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | /**
7 | * This entity represents length of the BER
8 | * Created by Sergey Kapustin on 01.10.2014.
9 | */
10 | public class BerLength {
11 |
12 | public final int length;
13 |
14 | public BerLength(InputStream input) throws IOException {
15 | length = BerUtils.parseLength(input);
16 | }
17 |
18 | public String toString() {
19 | return "LEN={" + String.valueOf(length) + "}";
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/IsoDepDataFeed.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard;
2 |
3 | import android.nfc.tech.IsoDep;
4 |
5 | import java.io.IOException;
6 |
7 | /**
8 | * Data feed for IsoDep NFC tag
9 | * Created by Sergey Kapustin on 01.10.2014.
10 | */
11 | public class IsoDepDataFeed implements IDataFeed {
12 |
13 | private final IsoDep isoDep;
14 |
15 | public IsoDepDataFeed(IsoDep tag) {
16 | isoDep = tag;
17 | }
18 |
19 | @Override
20 | public byte[] execute(byte[] command) throws IOException {
21 | return isoDep.transceive(command);
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/nfcard/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.library'
2 |
3 | android {
4 | compileSdkVersion 19
5 | buildToolsVersion '20.0.0'
6 | defaultConfig {
7 | applicationId 'ru.platformasoft.nfcard'
8 | minSdkVersion 8
9 | targetSdkVersion 20
10 | versionCode 1
11 | versionName '1.0'
12 | }
13 | buildTypes {
14 | release {
15 | runProguard false
16 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17 | }
18 | }
19 | productFlavors {
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | compile 'com.android.support:appcompat-v7:20.0.0'
26 | }
27 |
--------------------------------------------------------------------------------
/nfcard/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:/Users/admin/android-sdks/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/nfcard-example/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in C:\Users\admin\android-sdks/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
--------------------------------------------------------------------------------
/nfcard-example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 20
5 | buildToolsVersion '20.0.0'
6 |
7 | defaultConfig {
8 | applicationId "platformasoft.ru.nfcardexample"
9 | minSdkVersion 8
10 | targetSdkVersion 20
11 | versionCode 1
12 | versionName "1.0"
13 | }
14 | buildTypes {
15 | release {
16 | runProguard false
17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18 | }
19 | }
20 | }
21 |
22 | dependencies {
23 | compile fileTree(dir: 'libs', include: ['*.jar'])
24 | compile 'com.android.support:appcompat-v7:20.0.0'
25 | compile project(':nfcard')
26 | }
27 |
--------------------------------------------------------------------------------
/nfcard-example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
12 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/TransactionLog.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | /**
7 | * Transaction Log model that is exported to library user
8 | * (single entry)
9 | * Created by Sergey Kapustin on 06.10.2014.
10 | */
11 | public class TransactionLog implements Parcelable {
12 |
13 | /**Currency*/
14 | public String currency;
15 |
16 | /**Transaction authorized amount*/
17 | public float amount;
18 |
19 | /**Readable cryptogram information data*/
20 | public String cryptogramInformationData;
21 |
22 | /**Year of transaction*/
23 | public int year;
24 |
25 | /**Month of transaction*/
26 | public int month;
27 |
28 | /**Day of transaction*/
29 | public int day;
30 |
31 | public TransactionLog() {}
32 |
33 | @Override
34 | public int describeContents() {
35 | return 0;
36 | }
37 |
38 | @Override
39 | public void writeToParcel(Parcel dest, int flags) {
40 | dest.writeString(currency);
41 | dest.writeFloat(amount);
42 | dest.writeString(cryptogramInformationData);
43 | dest.writeInt(year);
44 | dest.writeInt(month);
45 | dest.writeInt(day);
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/ber/BerUtils.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard.ber;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | /**
7 | * Utility class for BER entities
8 | * Created by Sergey Kapustin on 01.10.2014.
9 | */
10 | public class BerUtils {
11 |
12 | public static int parseLength(InputStream input) throws IOException {
13 | int complexTag = 0;
14 | int nextByte = input.read();
15 |
16 | boolean isComplexLength = (nextByte & 0x80) > 0;
17 | if (isComplexLength) {
18 | int bytesCount = nextByte & 0x7f;
19 | for (int i = 0; i < bytesCount; i++) {
20 | complexTag <<= 8;
21 | complexTag |= input.read();
22 | }
23 | return complexTag;
24 | } else {
25 | return nextByte & 0x7f;
26 | }
27 | }
28 |
29 | public static int parseTag(InputStream input, int prefix) throws IOException {
30 | int complexTag = 0;
31 | if (prefix != 0) {
32 | complexTag = prefix;
33 | }
34 | //we need to read subsequent bytes
35 | boolean needReadNextSubsequentByte = true;
36 | while (needReadNextSubsequentByte) {
37 | int nextByte = input.read();
38 | //first bit means if we have subsequent byte(s)
39 | needReadNextSubsequentByte = (nextByte & 0x80) > 0;
40 | int tagPart = nextByte;
41 | complexTag <<= 8;
42 | complexTag |= tagPart;
43 | }
44 | return complexTag;
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/ber/BerObject.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard.ber;
2 |
3 | import java.util.ArrayList;
4 | import java.util.List;
5 |
6 | /**
7 | * Full representation of ber object
8 | * it is TLV stuff
9 | * Created by Sergey Kapustin on 01.10.2014.
10 | */
11 | public class BerObject {
12 |
13 | public BerTag type;
14 | public BerLength length;
15 | public List children;
16 | public String octetStringValue;
17 | public int integerValue;
18 | public byte [] byteArrayValue;
19 |
20 | public BerObject(BerTag type, BerLength length) {
21 | this.type = type;
22 | this.length = length;
23 | this.children = new ArrayList();
24 | this.octetStringValue = null;
25 | this.integerValue = 0;
26 | }
27 |
28 | public void addChild(BerObject child) {
29 | children.add(child);
30 | }
31 |
32 | public void setOctetStringValue(String value) {
33 | octetStringValue = value;
34 | }
35 |
36 | public void setIntegerValue(Integer value) {
37 | integerValue = integerValue;
38 | }
39 |
40 | public void byteArrayValue(byte [] value) {
41 | byteArrayValue = value;
42 | }
43 |
44 | public String toString() {
45 | StringBuffer sb = new StringBuffer();
46 | sb.append(type.toString()).append(" ").append(length.toString()).append('\n');
47 | if (type.isPrimitive) {
48 | sb.append("PRIMITIVE: '").append(octetStringValue).append("' or ").append(integerValue).append('\n');
49 | } else {
50 | for (BerObject child : children) {
51 | sb.append("=============\n");
52 | sb.append(child.toString());
53 | sb.append("=============\n");
54 | }
55 | }
56 | return sb.toString();
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/nfcard-example/src/main/res/layout/row_transaction.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
6 |
7 |
11 |
12 |
19 |
20 |
27 |
28 |
29 |
33 |
34 |
41 |
42 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/nfcard-example/src/main/res/layout/activity_nfcard_sample.xml:
--------------------------------------------------------------------------------
1 |
11 |
12 |
18 |
23 |
24 |
31 |
32 |
33 |
38 |
43 |
44 |
50 |
51 |
52 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/ber/BerTag.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard.ber;
2 |
3 | import java.io.IOException;
4 | import java.io.InputStream;
5 |
6 | /**
7 | * Class that represents BER type
8 | * Created by Sergey Kapustin on 01.10.2014.
9 | */
10 | public class BerTag {
11 |
12 | public static final int TYPE_UNIVERSAL = 0x0;
13 | public static final int TYPE_APPLICATION = 0x1;
14 | public static final int TYPE_CONTEXT = 0x2;
15 | public static final int TYPE_PRIVATE = 0x3;
16 |
17 | public static final int FLAG_IS_PRIMITIVE = 0x0;
18 | public static final int FLAG_IS_CONSTRUCTED = 0x1;
19 |
20 | public static final int FLAG_PRIMITIVE_BOOLEAN = 0x1;
21 | public static final int FLAG_PRIMITIVE_INTEGER = 0x2;
22 | public static final int FLAG_PRIMITIVE_OCTET_STRING = 0x4;
23 | public static final int FLAG_PRIMITIVE_SEQUENCE = 0x10;
24 | public static final int FLAG_NEED_SUBSEQUENT_BYTES = 0x1F;
25 |
26 | public final int objectClass;
27 | public final boolean isPrimitive;
28 | public final int berTag;
29 |
30 | public BerTag(InputStream input) throws IOException {
31 | int tagByte = (int) input.read();
32 |
33 | objectClass = (tagByte & 0xC0) >> 6;
34 | isPrimitive = ((tagByte & 0x20) >> 5) == FLAG_IS_PRIMITIVE ? true: false;
35 | int tag = tagByte;
36 | int tagTitle = tagByte & FLAG_NEED_SUBSEQUENT_BYTES;
37 |
38 | if (tagTitle == FLAG_NEED_SUBSEQUENT_BYTES) {
39 | berTag = BerUtils.parseTag(input, tag);
40 | } else {
41 | berTag = tag;
42 | }
43 | }
44 |
45 | public String toString() {
46 | StringBuffer sb = new StringBuffer();
47 | switch (objectClass) {
48 | case TYPE_UNIVERSAL:
49 | sb.append("[UNIVERSAL]");
50 | break;
51 | case TYPE_APPLICATION:
52 | sb.append("[APPLICATION]");
53 | break;
54 | case TYPE_CONTEXT:
55 | sb.append("[CONTEXT]");
56 | break;
57 | case TYPE_PRIVATE:
58 | sb.append("[PRIVATE]");
59 | break;
60 | }
61 | sb.append(' ');
62 | sb.append(isPrimitive ? "{PRMTV}" : "{CMPLX}");
63 | sb.append(' ');
64 | sb.append(berTag);
65 | return sb.toString();
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/CardData.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 |
6 | import java.util.ArrayList;
7 | import java.util.List;
8 |
9 | /**
10 | * Entity reflects the card data available
11 | * Created by Sergey Kapustin on 06.10.2014.
12 | */
13 | public class CardData implements Parcelable {
14 |
15 | /**
16 | * Track 2 equivalent data
17 | */
18 | public EmvClient.Track2Data track2;
19 |
20 | /**
21 | * Card type (mastercard/visa etc.)
22 | * To be implemented
23 | */
24 | public String cardType = "unknown";
25 |
26 | public List tranactionLog = new ArrayList();
27 |
28 | public CardData(Parcel in) {
29 | track2 = in.readParcelable(ClassLoader.getSystemClassLoader());
30 | cardType = in.readString();
31 | TransactionLog[] logs = (TransactionLog[]) in.readParcelableArray(ClassLoader.getSystemClassLoader());
32 | if (tranactionLog == null) tranactionLog = new ArrayList();
33 | for (int i = 0; i < logs.length; i++) {
34 | tranactionLog.add(logs[i]);
35 | }
36 | }
37 |
38 | @Override
39 | public int describeContents() {
40 | return 0;
41 | }
42 |
43 | @Override
44 | public void writeToParcel(Parcel dest, int flags) {
45 | track2.writeToParcel(dest, flags);
46 | dest.writeString(cardType);
47 | dest.writeParcelableArray((Parcelable[]) tranactionLog.toArray(), flags);
48 | }
49 |
50 | /**
51 | * Builder for card data.
52 | */
53 | public static class Builder {
54 |
55 | private CardData data;
56 |
57 | public Builder() {
58 | data = new CardData();
59 | }
60 |
61 | public Builder setTrack2(EmvClient.Track2Data data) {
62 | this.data.track2 = data;
63 | return this;
64 | }
65 |
66 | public Builder setCardType(String type) {
67 | this.data.cardType = type;
68 | return this;
69 | }
70 |
71 | public Builder addLogEntry(TransactionLog log) {
72 | this.data.tranactionLog.add(log);
73 | return this;
74 | }
75 |
76 | public CardData build() {
77 | return data;
78 | }
79 | }
80 |
81 | public static final Parcelable.Creator CREATOR
82 | = new Parcelable.Creator() {
83 | public CardData createFromParcel(Parcel in) {
84 | return new CardData(in);
85 | }
86 |
87 | public CardData[] newArray(int size) {
88 | return new CardData[size];
89 | }
90 | };
91 |
92 | private CardData() {}
93 | }
94 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | NFCard
2 | ==============
3 |
4 | 
5 |
6 | NFCard is an open-source android library that allows developers to easily scan VISA/MASTERCARD cards via NFC module of android device.
7 | Current version of library allows following:
8 |
9 | 1) Contactless reading PAN of a card that supports PayPass technology
10 |
11 | 2) Contactless reading "Valid Thru" of a card that supports PayPass technology
12 |
13 | 3) Fetching transaction log stored on a card that supports PayPass technology
14 |
15 | Usage is as simple as extending single class that overrides two methods (see usage examples below)
16 |
17 | Integrating library into a project
18 | ==============
19 |
20 | Import the nfcard module into your Android Studio project, and add module dependency to your application module
21 |
22 | How to use
23 | ==============
24 |
25 | 1) Add android.permission.NFC to permissions list required by your application in AndroidManifest.xml
26 |
27 | 2) Create an Activity class that exetends AbstractEmvClientActivity, and implement following methods:
28 |
29 | protected void onCardReadResult(CardData cardData);
30 |
31 | This method is called as soon as card data is available and read via NFC module
32 |
33 | protected void onCardReadError(Exception error);
34 |
35 | This method is called as soon as reading card data is failed for some reason - you may handle the exception here
36 |
37 | 3) Override onCreate method in order to call super.onCreate(Bundle savedState) and call setContentView as usually you do for an activities
38 |
39 | That is. This activity is now NFC-enabled activity that supports credit cards to be read via NFC hardware of the mobile phone. In the case NFC feature is not turned on in settings, the dialog will be shown to the user if he/she wants to enable it in settings.
40 |
41 | Please refer to nfcard-example project for source code of example activity.
42 |
43 | Data Structures
44 | ==============
45 |
46 | Library provides CardData instance in onCardReadResult method, this section covers its content and data that you may use in your application.
47 |
48 | **Track2Data**
49 |
50 | This entity contains track 2 equivalent data of card. Currently it is:
51 |
52 | *String pan* - pan number of card
53 | *int month* - month in "valid thru" section
54 | *int year* - year in "valid thru" section
55 |
56 | **TransactionLog**
57 |
58 | Card data has a list of transaction log entries. Each entry contains data:
59 |
60 | *int year, month, day* - date of transaction
61 |
62 | *String currency* - currency of transaction
63 |
64 | *float amount* - amount of transaction
65 |
66 | *String cryptigramInformationData* - currently it contanis "Transaction Approved", "Transaction Declined" or "Online Authorization Requested"
67 |
68 |
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/TransactionLogFormat.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard;
2 |
3 | import android.util.Pair;
4 |
5 | import java.util.ArrayList;
6 | import java.util.HashMap;
7 | import java.util.Iterator;
8 | import java.util.List;
9 | import java.util.Map;
10 |
11 | /**
12 | * This is entity that describes transaction log format (TAG - LENTGTH)
13 | * Created by Sergey Kapustin on 06.10.2014.
14 | */
15 | public class TransactionLogFormat {
16 |
17 | /**
18 | * ISO 4217 allows us to map currency codes
19 | * TODO: add more currencies into this map
20 | */
21 | public static final Map CURRENCY_ISO_4217_MAP = new HashMap();
22 | static {
23 | CURRENCY_ISO_4217_MAP.put("0643", "RUB");
24 | CURRENCY_ISO_4217_MAP.put("0810", "RUB");
25 | CURRENCY_ISO_4217_MAP.put("0998", "USD");
26 | CURRENCY_ISO_4217_MAP.put("0840", "USD");
27 | CURRENCY_ISO_4217_MAP.put("0997", "USD");
28 | CURRENCY_ISO_4217_MAP.put("0978", "EUR");
29 | }
30 |
31 | /*
32 | Section of tags supported by nfcard, according to EMVCo specifications
33 | */
34 | public static final int TAG_TRANSACTION_DATE = 0x9A;
35 | public static final int TAG_TRANSACTION_CID = 0x9F27;
36 | public static final int TAG_TRANSACTION_AMOUNT = 0x9F02;
37 | public static final int TAG_TRANSACTION_CURRENCY = 0x5F2A;
38 |
39 | /**Usually cards hold no more than this amount of records in log format*/
40 | private static final int EXPECTED_TAG_SEQ_SIZE = 10;
41 |
42 | private List> mTagSequence = new ArrayList>(EXPECTED_TAG_SEQ_SIZE);
43 |
44 | /**
45 | * Add new record to this transaction log format
46 | * @param tag - tag value
47 | * @param len - length of data expected in log transactions
48 | */
49 | public void addRecord(int tag, int len) {
50 | System.err.println("Add tag format: " + tag + " - " + len);
51 | mTagSequence.add(new Pair(tag, len));
52 | }
53 |
54 | /**
55 | * Utility feature that allows to convert currency code into readable format
56 | * @param input
57 | * @return
58 | */
59 | public static final String convertCurrency(String input) {
60 | String mapped = CURRENCY_ISO_4217_MAP.get(input);
61 | if (mapped == null) return input;
62 | return mapped;
63 | }
64 |
65 | /**
66 | * Read fine information from crypto info data
67 | * TODO: add more information (currently data is extracted just from b7 b8
68 | * @param cid - cryptogram information data
69 | * @return human-readable String
70 | */
71 | public static final String convertCryptogramInformation(int cid) {
72 | int b78 = (cid & 0xC0) >> 6;
73 | switch (b78) {
74 | case 0:
75 | return "Transaction Declined";
76 | case 1:
77 | return "Transaction Approved";
78 | case 2:
79 | return "Online Auth Requested";
80 | case 3:
81 | return "AAR";
82 |
83 | }
84 | return String.valueOf(cid) ;
85 | }
86 |
87 | /**
88 | * Tag format iterator
89 | * @return
90 | */
91 | public Iterator> iterator() {
92 | return mTagSequence.iterator();
93 | }
94 | }
95 |
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/ber/BerInputStream.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard.ber;
2 |
3 | import java.io.ByteArrayInputStream;
4 | import java.io.IOException;
5 | import java.io.InputStream;
6 |
7 | /**
8 | * Decorator for input stream that fetches us BER entities
9 | * Created by Sergey Kapustin on 01.10.2014.
10 | */
11 | public class BerInputStream extends InputStream {
12 |
13 | private InputStream source;
14 |
15 | @Override
16 | public int available() throws IOException {
17 |
18 | return source.available();
19 | }
20 |
21 | @Override
22 | public void close() throws IOException {
23 | source.close();
24 | }
25 |
26 | @Override
27 | public void mark(int readlimit) {
28 | source.mark(readlimit);
29 | }
30 |
31 | @Override
32 | public boolean markSupported() {
33 | return source.markSupported();
34 | }
35 |
36 | @Override
37 | public int read() throws IOException {
38 | return source.read();
39 | }
40 |
41 | @Override
42 | public int read(byte[] buffer) throws IOException {
43 | return source.read(buffer);
44 | }
45 |
46 | @Override
47 | public int read(byte[] buffer, int byteOffset, int byteCount) throws IOException {
48 | return source.read(buffer, byteOffset, byteCount);
49 | }
50 |
51 | @Override
52 | public void reset() throws IOException {
53 | source.reset();
54 | }
55 |
56 | @Override
57 | public long skip(long byteCount) throws IOException {
58 | return source.skip(byteCount);
59 | }
60 |
61 | public BerInputStream(InputStream source) {
62 | this.source = source;
63 | }
64 |
65 | public BerTag readBerType() throws IOException {
66 | return new BerTag(source);
67 | }
68 |
69 | public BerLength readBerLength() throws IOException {
70 | return new BerLength(source);
71 | }
72 |
73 | public BerObject readBerObject() throws IOException {
74 | BerTag type = readBerType();
75 | BerLength length = readBerLength();
76 | // Log.d("BIS", "TYPE READ:" + type);
77 | // Log.d("BIS", "LEN READ: " + length.toString());
78 | BerObject result = new BerObject(type, length);
79 | //now we need to read the length bytes and do something with it
80 | byte [] valueBuffer = new byte[length.length];
81 | read(valueBuffer, 0, valueBuffer.length);//fill in the value
82 | //now it depends on the type
83 | if (type.isPrimitive) {
84 | switch (type.berTag) {
85 | case BerTag.FLAG_PRIMITIVE_INTEGER:
86 | case BerTag.FLAG_PRIMITIVE_BOOLEAN:
87 | case 7:
88 | //it is integer
89 | result.integerValue = 0;
90 | for (int i = valueBuffer.length - 1; i>=0; i--) {
91 | result.integerValue <<= 8;
92 | result.integerValue |= valueBuffer[i];
93 | }
94 | break;
95 | case BerTag.FLAG_PRIMITIVE_OCTET_STRING:
96 | result.octetStringValue = new String(valueBuffer);
97 | break;
98 | default:
99 | //well, this is sequence!
100 | result.octetStringValue = new String(valueBuffer);
101 | break;
102 | // default:
103 | // throw new IOException("Unknown primitive object class: " + type.objectClass);
104 |
105 | }
106 | //remember bytes, we might need them.
107 | result.byteArrayValue = valueBuffer;
108 | } else {
109 | //it is non-primitive, it should be a complex stuff
110 | BerInputStream subStream = new BerInputStream(new ByteArrayInputStream(valueBuffer));
111 | while (subStream.available() > 0) {
112 | result.addChild(subStream.readBerObject());
113 | }
114 | }
115 | return result;
116 | }
117 | }
118 |
--------------------------------------------------------------------------------
/nfcard-example/src/main/java/platformasoft/ru/nfcardexample/NfcardSampleActivity.java:
--------------------------------------------------------------------------------
1 | package platformasoft.ru.nfcardexample;
2 |
3 | import android.os.Bundle;
4 | import android.util.Log;
5 | import android.view.Menu;
6 | import android.view.MenuItem;
7 | import android.view.View;
8 | import android.view.ViewGroup;
9 | import android.widget.BaseAdapter;
10 | import android.widget.ListView;
11 | import android.widget.TextView;
12 |
13 | import ru.platformasoft.nfcard.CardData;
14 | import ru.platformasoft.nfcard.EmvClient;
15 | import ru.platformasoft.nfcard.TransactionLog;
16 | import ru.platformasoft.nfcard.android.AbstractEmvClientActivity;
17 |
18 | /**
19 | * Sample nfcard usage activity:
20 | * reads card track2 and transaction log and displays it
21 | */
22 | public class NfcardSampleActivity extends AbstractEmvClientActivity {
23 |
24 | private TextView mCardValidThru;
25 | private TextView mCardPan;
26 | private ListView mTransactionLog;
27 |
28 | private CardData mCardData;
29 |
30 | private TransactionLogAdapter mLogAdapter;
31 |
32 |
33 | private class TransactionLogAdapter extends BaseAdapter {
34 |
35 | @Override
36 | public int getCount() {
37 | return mCardData.tranactionLog.size();
38 | }
39 |
40 | @Override
41 | public Object getItem(int i) {
42 | return mCardData.tranactionLog.get(i);
43 | }
44 |
45 | @Override
46 | public long getItemId(int i) {
47 | return i;
48 | }
49 |
50 | @Override
51 | public View getView(int i, View convertView, ViewGroup viewGroup) {
52 | if (convertView == null) {
53 | convertView = getLayoutInflater().inflate(R.layout.row_transaction, null);
54 | }
55 |
56 | TransactionLog log = mCardData.tranactionLog.get(i);
57 |
58 | TextView tvDate = (TextView) convertView.findViewById(R.id.value_transaction_date);
59 | TextView tvAmount = (TextView) convertView.findViewById(R.id.value_amount);
60 | TextView tvType = (TextView) convertView.findViewById(R.id.value_transaction_type);
61 | TextView tvCurrency = (TextView) convertView.findViewById(R.id.value_currency);
62 |
63 | tvDate.setText(log.day + "." + log.month + "." + log.year);
64 | tvAmount.setText(String.valueOf(log.amount));
65 | tvCurrency.setText(log.currency);
66 | tvType.setText(log.cryptogramInformationData);
67 |
68 | return convertView;
69 | }
70 | }
71 |
72 | @Override
73 | protected void onCreate(Bundle savedInstanceState) {
74 | super.onCreate(savedInstanceState);
75 | setContentView(R.layout.activity_nfcard_sample);
76 |
77 | mCardValidThru = (TextView) findViewById(R.id.value_card_valid_thru);
78 | mCardPan = (TextView) findViewById(R.id.value_card_pan);
79 | mTransactionLog = (ListView) findViewById(R.id.transaction_log);
80 | }
81 |
82 | @Override
83 | protected void onCardReadResult(CardData cardData) {
84 | EmvClient.Track2Data track2 = cardData.track2;
85 | if (track2 != null) {
86 | mCardValidThru.setText(track2.month + "/" + track2.year);
87 | mCardPan.setText(track2.pan);
88 | }
89 |
90 | mCardData = cardData;
91 | Log.d("nfc", "Total record logs: " + mCardData.tranactionLog.size());
92 | mLogAdapter = new TransactionLogAdapter();
93 | mTransactionLog.setAdapter(mLogAdapter);
94 | }
95 |
96 | @Override
97 | protected void onCardReadError(Exception error) {
98 | error.printStackTrace();
99 | }
100 |
101 | @Override
102 | public boolean onCreateOptionsMenu(Menu menu) {
103 | // Inflate the menu; this adds items to the action bar if it is present.
104 | getMenuInflater().inflate(R.menu.nfcard_sample, menu);
105 | return true;
106 | }
107 |
108 | @Override
109 | public boolean onOptionsItemSelected(MenuItem item) {
110 | // Handle action bar item clicks here. The action bar will
111 | // automatically handle clicks on the Home/Up button, so long
112 | // as you specify a parent activity in AndroidManifest.xml.
113 | int id = item.getItemId();
114 | if (id == R.id.action_settings) {
115 | return true;
116 | }
117 | return super.onOptionsItemSelected(item);
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/nfcard-example/nfcard_example.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/nfcard/nfcard.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/android/AbstractEmvClientActivity.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard.android;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.app.PendingIntent;
6 | import android.content.Context;
7 | import android.content.DialogInterface;
8 | import android.content.Intent;
9 | import android.content.IntentFilter;
10 | import android.content.pm.PackageManager;
11 | import android.nfc.NfcAdapter;
12 | import android.nfc.Tag;
13 | import android.nfc.tech.IsoDep;
14 | import android.nfc.tech.MifareClassic;
15 | import android.nfc.tech.MifareUltralight;
16 | import android.nfc.tech.NdefFormatable;
17 | import android.nfc.tech.NfcA;
18 | import android.nfc.tech.NfcB;
19 | import android.nfc.tech.NfcF;
20 | import android.nfc.tech.NfcV;
21 | import android.os.Build;
22 | import android.os.Bundle;
23 |
24 | import ru.platformasoft.nfcard.CardData;
25 | import ru.platformasoft.nfcard.EmvClient;
26 | import ru.platformasoft.nfcard.IsoDepDataFeed;
27 | import ru.platformasoft.nfcard.R;
28 |
29 | /**
30 | * Abstract activity that uses EMV client to fetch card data via NFC
31 | * Created by Sergey Kapustin on 06.10.2014.
32 | */
33 | public abstract class AbstractEmvClientActivity extends Activity {
34 |
35 | protected NfcAdapter mAdapter;
36 | private IntentFilter[] mFilters;
37 |
38 | /**
39 | * This utility method may be used to find out if NFC feature is even
40 | * provided by hardware
41 | *
42 | * @param ctx = any context
43 | * @return true, if NFC feature is supported by mobile phone hardware
44 | */
45 | public static boolean isNfcFeatureAvailable(Context ctx) {
46 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.GINGERBREAD) return false;
47 | return ctx.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC);
48 | }
49 |
50 | @Override
51 | protected void onCreate(Bundle savedInstanceState) {
52 | super.onCreate(savedInstanceState);
53 |
54 | /*
55 | Initialize intent filter for foreground dispatch
56 | */
57 | IntentFilter filterTagDiscover = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
58 | IntentFilter filterTechDiscover = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
59 |
60 | mFilters = new IntentFilter[]{filterTagDiscover, filterTechDiscover};
61 | }
62 |
63 | @Override
64 | public void onResume() {
65 | super.onResume();
66 |
67 | mAdapter = NfcAdapter.getDefaultAdapter(this);
68 |
69 | if (!mAdapter.isEnabled()) {
70 | /*
71 | In case NFC adapter is not enabled on the device, ask user if he/she wants to
72 | enable it in settings
73 | */
74 | AlertDialog.Builder builder = new AlertDialog.Builder(AbstractEmvClientActivity.this);
75 | builder.setTitle(R.string.nfc_ask_turn_on);
76 | builder.setMessage(R.string.nfc_ask_message);
77 | builder.setPositiveButton(R.string.nfc_ask_yes, new DialogInterface.OnClickListener() {
78 | @Override
79 | public void onClick(DialogInterface dialog, int which) {
80 | startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
81 | dialog.dismiss();
82 | }
83 | });
84 | builder.setNegativeButton(R.string.nfc_ask_no, new DialogInterface.OnClickListener() {
85 | @Override
86 | public void onClick(DialogInterface dialog, int which) {
87 | dialog.dismiss();
88 | AbstractEmvClientActivity.this.finish();
89 | }
90 | });
91 | builder.show();
92 | }
93 |
94 | //Enable the foregrund dispatch for NFC events
95 |
96 | PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
97 | new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
98 | mAdapter.enableForegroundDispatch(this, pendingIntent, mFilters,
99 | new String[][]{{NfcF.class.getName(),
100 | MifareClassic.class.getName(),
101 | MifareUltralight.class.getName(),
102 | IsoDep.class.getName(),
103 | NfcA.class.getName(),
104 | NfcB.class.getName(),
105 | NfcV.class.getName(),
106 | NdefFormatable.class.getName()}});
107 | }
108 |
109 | @Override
110 | public void onNewIntent(Intent intent) {
111 | //ACTION_TECH_DISCOVERED, ACTION_TAG_DISCOVERED mean target case of use: we discovered NFC source
112 | if (intent.getAction().equals(NfcAdapter.ACTION_TECH_DISCOVERED) || intent.getAction()
113 | .equals(NfcAdapter.ACTION_TAG_DISCOVERED)) {
114 | /*
115 | * nfc tech discovered action. try read data from a card and post
116 | * the results
117 | */
118 | Tag tagFromIntent = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
119 | // MifareClassic isoDep = MifareClassic.get(tagFromIntent);
120 | IsoDep isoDep = IsoDep.get(tagFromIntent);
121 | isoDep.setTimeout(5000);
122 |
123 | try {
124 | //connect to NFC data feed
125 | isoDep.connect();
126 |
127 | //initialize data feed, and EMV client
128 | EmvClient client = new EmvClient(new IsoDepDataFeed(isoDep));
129 |
130 | //read the card data
131 | CardData cardDataResult = client.readCardData();
132 |
133 | if (cardDataResult != null) {
134 | //notify successors about card data read
135 | onCardReadResult(cardDataResult);
136 | } else {
137 | //looks, like client gave us no card data, take it as an error
138 | throw new NullPointerException("No card data available");
139 | }
140 | } catch (Exception e) {
141 | //in case card read error, notify successors about it
142 | onCardReadError(e);
143 | } finally {
144 | //Finally, consume iso dep connection
145 | try {
146 | isoDep.close();
147 | } catch (Exception e) {
148 | e.printStackTrace();
149 | }
150 | }
151 | }
152 | }
153 |
154 | /**
155 | * This one is called as soon as card data is read through the nfc data feed
156 | *
157 | * @param cardData - incoming card data
158 | */
159 | protected abstract void onCardReadResult(CardData cardData);
160 |
161 | /**
162 | * This one is called if no card data is available through the nfc data feed
163 | *
164 | * @param error
165 | */
166 | protected abstract void onCardReadError(Exception error);
167 | }
168 |
--------------------------------------------------------------------------------
/nfcard-example/nfcard-example.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
--------------------------------------------------------------------------------
/nfcard/src/main/java/ru/platformasoft/nfcard/EmvClient.java:
--------------------------------------------------------------------------------
1 | package ru.platformasoft.nfcard;
2 |
3 | import android.os.Parcel;
4 | import android.os.Parcelable;
5 | import android.util.Pair;
6 |
7 | import java.io.ByteArrayInputStream;
8 | import java.io.ByteArrayOutputStream;
9 | import java.io.IOException;
10 | import java.util.ArrayList;
11 | import java.util.Iterator;
12 | import java.util.List;
13 |
14 | import ru.platformasoft.nfcard.ber.BerInputStream;
15 | import ru.platformasoft.nfcard.ber.BerObject;
16 | import ru.platformasoft.nfcard.ber.BerTag;
17 |
18 | /**
19 | * EMV client allows us to execute some commands on a card
20 | * Current implementation allows to fetch CardData to the library user
21 | * Created by Sergey Kapustin on 01.10.2014.
22 | */
23 | public class EmvClient {
24 |
25 | private static final byte[] PDOL_RELATED_STANDARD_TAG = {(byte)(0x83 & 0xFF), 0x00};
26 | private static final byte[] LOG_DATA_FORMAT = {(byte) (0x9f & 0xff), (byte) (0x4f & 0xff)};
27 |
28 | private IDataFeed mDataFeed;
29 |
30 | private TransactionLogFormat mLogFormat;
31 |
32 | private static final char[] hexCode = "0123456789ABCDEF".toCharArray();
33 |
34 | public static String printHexBinary(byte[] data) {
35 | if (data == null)
36 | return "NULL";
37 | StringBuilder r = new StringBuilder(data.length * 2);
38 | for (byte b : data) {
39 | r.append(hexCode[(b >> 4) & 0xF]);
40 | r.append(hexCode[(b & 0xF)]);
41 | }
42 | return r.toString();
43 | }
44 |
45 | //GPO record descriptor data
46 | private static class GpoDescriptor {
47 | public byte sfi;
48 | public byte recMin;
49 | public byte recMax;
50 |
51 | public GpoDescriptor(byte sfi, byte recMin, byte recMax) {
52 | this.sfi = sfi;
53 | this.recMin = recMin;
54 | this.recMax = recMax;
55 | }
56 |
57 | public String toString() {
58 | StringBuffer sb = new StringBuffer("GPO DESCRIPTOR: ");
59 | sb.append(sfi).append(' ').append(recMin).append(" - ").append(recMax);
60 | return sb.toString();
61 | }
62 |
63 | }
64 |
65 | public static class Track2Data implements Parcelable {
66 | public String pan;
67 | public int month;
68 | public int year;
69 |
70 | public Track2Data() {}
71 |
72 | public Track2Data(Parcel in) {
73 | pan= in.readString();
74 | month = in.readInt();
75 | year = in.readInt();
76 | }
77 |
78 | @Override
79 | public int describeContents() {
80 | return 0;
81 | }
82 |
83 | @Override
84 | public void writeToParcel(Parcel dest, int flags) {
85 | dest.writeString(pan);
86 | dest.writeInt(month);
87 | dest.writeInt(year);
88 | }
89 |
90 | public static final Parcelable.Creator CREATOR
91 | = new Parcelable.Creator() {
92 | public Track2Data createFromParcel(Parcel in) {
93 | return new Track2Data(in);
94 | }
95 |
96 | public Track2Data[] newArray(int size) {
97 | return new Track2Data[size];
98 | }
99 | };
100 | }
101 |
102 | public EmvClient(IDataFeed feed) {
103 | mDataFeed = feed;
104 | }
105 |
106 | private byte [] createApduCommand(int cla, int ins, int p1, int p2, byte [] data, int expectedLength) {
107 | ByteArrayOutputStream baos = new ByteArrayOutputStream();
108 | baos.write(cla);
109 | baos.write(ins);
110 | baos.write(p1);
111 | baos.write(p2);
112 | if (data != null) {
113 | baos.write(data.length);
114 | baos.write(data, 0, data.length);
115 | }
116 | baos.write(expectedLength);
117 | return baos.toByteArray();
118 | }
119 |
120 | private BerObject executeRawCommand(byte [] command) throws IOException {
121 | byte [] apduResponse = mDataFeed.execute(command);
122 |
123 | //check SW1 SW2
124 | if (apduResponse[apduResponse.length - 2] != (byte)(0x90 & 0xFF)) throw new IOException("Invalid Response");
125 | if (apduResponse[apduResponse.length - 1] != 0) throw new IOException("Invalid Response");
126 |
127 | BerInputStream bis = new BerInputStream(new ByteArrayInputStream(apduResponse));
128 | BerObject ber = bis.readBerObject();
129 | return ber;
130 | }
131 |
132 | private byte [] rawExecuteRawCommand(byte [] command) throws IOException {
133 | byte [] apduResponse = mDataFeed.execute(command);
134 |
135 | //check SW1 SW2
136 | if (apduResponse[apduResponse.length - 2] != (byte)(0x90 & 0xFF)) throw new IOException("Invalid Response");
137 | if (apduResponse[apduResponse.length - 1] != 0) throw new IOException("Invalid Response");
138 |
139 | return apduResponse;
140 | }
141 |
142 | private BerObject selectFile(String filename) throws IOException {
143 | return executeRawCommand(createApduCommand(0x00, 0xa4, 0x04, 0x00, filename.getBytes(), 0x00));
144 | }
145 |
146 | private BerObject selectApplication(byte [] applicationIdentifier) throws IOException {
147 | return executeRawCommand(createApduCommand(0x00,0xa4,0x04,0x00,applicationIdentifier, 0x00));
148 | }
149 |
150 | private BerObject getProcessingOptions() throws IOException {
151 | return executeRawCommand(createApduCommand(0x80, 0xa8, 0x00, 0x00, PDOL_RELATED_STANDARD_TAG, 0x00));
152 | }
153 |
154 | private byte [] readGpoData(GpoDescriptor gpo, byte rec) throws IOException {
155 | return rawExecuteRawCommand(createApduCommand(0x00, 0xb2, rec, ((gpo.sfi << 3) | 0x4), null, 0x00));
156 | }
157 |
158 | private BerObject readGpoRecord(GpoDescriptor gpo, byte rec) throws IOException {
159 | return executeRawCommand(createApduCommand(0x00, 0xb2, rec, ((gpo.sfi << 3) | 0x4), null, 0x00));
160 | }
161 |
162 | private BerObject getData(byte [] format) throws IOException {
163 | return executeRawCommand(createApduCommand(0x80, 0xca, format[0], format[1], null, 0x00));
164 | }
165 |
166 | private TransactionLog parseTransactionRecord(byte [] data) throws IOException {
167 | if (mLogFormat == null) throw new IllegalStateException("No log format known exists");
168 | TransactionLog log = new TransactionLog();
169 | ByteArrayInputStream bais = new ByteArrayInputStream(data);
170 | Iterator> iterator = mLogFormat.iterator();
171 |
172 | int index = 0;
173 |
174 | while (iterator.hasNext()) {
175 | Pair nextTag = iterator.next();
176 |
177 | byte [] chunk = new byte[nextTag.second];
178 | bais.read(chunk);
179 |
180 | int tagInt = nextTag.first;
181 | switch (tagInt) {
182 | case TransactionLogFormat.TAG_TRANSACTION_AMOUNT:
183 | String str = printHexBinary(chunk);
184 | log.amount = Long.parseLong(str) / 100f;
185 | break;
186 | case TransactionLogFormat.TAG_TRANSACTION_CID:
187 | log.cryptogramInformationData = TransactionLogFormat.convertCryptogramInformation(chunk[0]);
188 | break;
189 | case TransactionLogFormat.TAG_TRANSACTION_CURRENCY:
190 | log.currency = TransactionLogFormat.convertCurrency(printHexBinary(chunk));
191 | break;
192 | case TransactionLogFormat.TAG_TRANSACTION_DATE:
193 | str = printHexBinary(chunk);
194 | log.year = Integer.parseInt(str.substring(0,2));
195 | log.month = Integer.parseInt(str.substring(2,4));
196 | log.day = Integer.parseInt(str.substring(4,6));
197 | break;
198 | }
199 | }
200 |
201 | return log;
202 | }
203 |
204 | private TransactionLogFormat getTransactionLogFormat(BerObject logFormat) throws IOException {
205 | byte [] data = logFormat.byteArrayValue;
206 | BerInputStream bis = new BerInputStream(new ByteArrayInputStream(data));
207 |
208 | TransactionLogFormat result = new TransactionLogFormat();
209 |
210 | while (bis.available() > 0) {
211 | BerTag tag = bis.readBerType();
212 | int len = bis.read();
213 |
214 | result.addRecord(tag.berTag, len);
215 | }
216 |
217 | return result;
218 | }
219 |
220 | private Track2Data findTrack2Data(BerObject emvTag) {
221 | if (emvTag.type.berTag != 0x70) throw new IllegalArgumentException("No EMV Proprietary Template Specified as Argument");
222 |
223 | for (BerObject child : emvTag.children) {
224 | if (child.type.berTag == 0x57) {
225 | //it is Track 2 equivalent data
226 | byte [] track2 = child.byteArrayValue;
227 | String track2String = printHexBinary(track2);
228 |
229 | int splitIndex = track2String.indexOf('D');
230 | if (splitIndex < 0) break;//Invalid pan
231 |
232 | Track2Data result = new Track2Data();
233 | result.pan = track2String.substring(0, splitIndex);
234 | result.year = Integer.parseInt(track2String.substring(splitIndex + 1, splitIndex + 3));
235 | result.month = Integer.parseInt(track2String.substring(splitIndex + 3, splitIndex + 5));
236 |
237 | return result;
238 | }
239 | }
240 |
241 | // no track2 found, return null
242 | return null;
243 | }
244 |
245 | private void fillGpoDescriptors(byte [] afl, List list) {
246 | if (afl.length % 4 != 0) throw new IllegalArgumentException("Invalid AFL value");
247 | int gpoCount = afl.length / 4;
248 | for (int i = 0; i < gpoCount; i++) {
249 | int offset = i * 4;
250 | list.add(new GpoDescriptor((byte) (afl[offset] >> 3), afl[offset + 1], afl[offset + 2]));
251 | }
252 | }
253 |
254 | //fetch AFL record from Response Message Template Format 2 (e.g. such a message is responded by GET PROCESSING OPTIONS
255 | private byte[] getAfl(BerObject responseMessageTemplateFormat2) throws IOException {
256 | if (responseMessageTemplateFormat2.type.berTag != 0x77) throw new IllegalArgumentException("Object is not Response Message Template Format 2");
257 | for (BerObject afl : responseMessageTemplateFormat2.children) {
258 | if (afl.type.berTag == 0x94) {
259 | //it is afl!
260 | return afl.byteArrayValue;
261 | }
262 | }
263 | throw new IllegalArgumentException("No AFL Found!");
264 | }
265 |
266 | //get the access to SFI record that holds transaction log
267 | private byte [] getLogEntry(BerObject fciTempalte) {
268 | for (BerObject fciProprietaryTemplateCandidate : fciTempalte.children) {
269 | if (fciProprietaryTemplateCandidate.type.berTag == 0xa5) {
270 | for (BerObject fciIssuerData : fciProprietaryTemplateCandidate.children) {
271 | if (fciIssuerData.type.berTag == 0xbf0c) {
272 | //find log entry
273 | for (BerObject logEntry : fciIssuerData.children) {
274 | if (logEntry.type.berTag == 0x9f4d) {
275 | //it is log entry
276 | return logEntry.byteArrayValue;
277 | }
278 | }
279 | throw new IllegalArgumentException("No Log Entry Found");
280 | }
281 | }
282 | throw new IllegalArgumentException("No FCI Issuer Discretionary Data found");
283 | }
284 | }
285 | throw new IllegalArgumentException("No FCI Proprietary Template Was Found");
286 | }
287 |
288 | //get application identifier from file control information
289 | private byte[] getApplicationIdentifier(BerObject fileControlInformation) {
290 | if (fileControlInformation.type.berTag != 0x6f) throw new IllegalArgumentException("Ber Object is not FCI Template");
291 | for (BerObject fciProprietaryTemplateCandidate : fileControlInformation.children) {
292 | if (fciProprietaryTemplateCandidate.type.berTag == 0xa5) {
293 | //it is FCI proprietary template
294 | BerObject fciIssuerData = fciProprietaryTemplateCandidate.children.get(0);
295 | if (fciIssuerData.type.berTag != 0xbf0c) throw new IllegalArgumentException("No FCI Issuer Discretionary Data found");
296 | BerObject applicationTemplate = fciIssuerData.children.get(0);
297 | if (applicationTemplate.type.berTag != 0x61) throw new IllegalArgumentException("No Application template found");
298 | for (BerObject aidCandidate : applicationTemplate.children) {
299 | if (aidCandidate.type.berTag == 0x4f) {
300 | //wow, it is AID!
301 | return aidCandidate.byteArrayValue;
302 | }
303 | }
304 | throw new IllegalArgumentException("No AID found");
305 | }
306 | }
307 | throw new IllegalArgumentException("No FCI Proprietary Template record is found");
308 | }
309 |
310 | public CardData readCardData() throws IOException {
311 |
312 | CardData.Builder builder = new CardData.Builder();
313 |
314 | /*
315 | Firse of all, select 2.PAY.SYS.DDF01 file
316 | */
317 | BerObject selectFileResult = selectFile("2PAY.SYS.DDF01");
318 |
319 | /*
320 | Now, extract application id, and select this application from response
321 | */
322 | byte [] applicationId = getApplicationIdentifier(selectFileResult);
323 | BerObject selectApplicationResult = selectApplication(applicationId);
324 |
325 | try {
326 | byte [] logEntry = getLogEntry(selectApplicationResult);
327 | byte sfiNumber = logEntry[0];
328 | byte sfiNumberOfRecords = logEntry[1];
329 |
330 | //read the log format
331 | BerObject logFormat = getData(LOG_DATA_FORMAT);
332 | mLogFormat = getTransactionLogFormat(logFormat);
333 |
334 | GpoDescriptor d = new GpoDescriptor(sfiNumber, (byte) 0, sfiNumberOfRecords);
335 | for (byte b = 1; b < sfiNumberOfRecords; b++) {
336 | byte [] data = readGpoData(d, b);
337 | TransactionLog transactionLog = parseTransactionRecord(data);
338 | builder.addLogEntry(transactionLog);
339 | }
340 | } catch (IOException e) {
341 | e.printStackTrace();
342 | }
343 |
344 | /*
345 | Then get processing options
346 | */
347 | BerObject gpoResult = getProcessingOptions();
348 | byte [] afl = getAfl(gpoResult);
349 |
350 | List gpos = new ArrayList();
351 | fillGpoDescriptors(afl, gpos);
352 |
353 | List suspects = new ArrayList(5);
354 |
355 | for (GpoDescriptor descriptor : gpos) {
356 | for (int i = descriptor.recMax; i <= descriptor.recMax; i++) {
357 | BerObject gpoRecord = readGpoRecord(descriptor, (byte) i);
358 | if (gpoRecord.type.berTag == 0x70) {
359 | //this is EMV Proprietary Template
360 | Track2Data track2 = findTrack2Data(gpoRecord);
361 | if (track2 != null) suspects.add(track2);
362 | }
363 | }
364 | }
365 |
366 | if (!suspects.isEmpty()) {
367 | builder.setTrack2(suspects.get(0));
368 | }
369 |
370 | return builder.build();
371 | }
372 |
373 | }
374 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 2, June 1991
3 |
4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
5 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
6 | Everyone is permitted to copy and distribute verbatim copies
7 | of this license document, but changing it is not allowed.
8 |
9 | Preamble
10 |
11 | The licenses for most software are designed to take away your
12 | freedom to share and change it. By contrast, the GNU General Public
13 | License is intended to guarantee your freedom to share and change free
14 | software--to make sure the software is free for all its users. This
15 | General Public License applies to most of the Free Software
16 | Foundation's software and to any other program whose authors commit to
17 | using it. (Some other Free Software Foundation software is covered by
18 | the GNU Lesser General Public License instead.) You can apply it to
19 | your programs, too.
20 |
21 | When we speak of free software, we are referring to freedom, not
22 | price. Our General Public Licenses are designed to make sure that you
23 | have the freedom to distribute copies of free software (and charge for
24 | this service if you wish), that you receive source code or can get it
25 | if you want it, that you can change the software or use pieces of it
26 | in new free programs; and that you know you can do these things.
27 |
28 | To protect your rights, we need to make restrictions that forbid
29 | anyone to deny you these rights or to ask you to surrender the rights.
30 | These restrictions translate to certain responsibilities for you if you
31 | distribute copies of the software, or if you modify it.
32 |
33 | For example, if you distribute copies of such a program, whether
34 | gratis or for a fee, you must give the recipients all the rights that
35 | you have. You must make sure that they, too, receive or can get the
36 | source code. And you must show them these terms so they know their
37 | rights.
38 |
39 | We protect your rights with two steps: (1) copyright the software, and
40 | (2) offer you this license which gives you legal permission to copy,
41 | distribute and/or modify the software.
42 |
43 | Also, for each author's protection and ours, we want to make certain
44 | that everyone understands that there is no warranty for this free
45 | software. If the software is modified by someone else and passed on, we
46 | want its recipients to know that what they have is not the original, so
47 | that any problems introduced by others will not reflect on the original
48 | authors' reputations.
49 |
50 | Finally, any free program is threatened constantly by software
51 | patents. We wish to avoid the danger that redistributors of a free
52 | program will individually obtain patent licenses, in effect making the
53 | program proprietary. To prevent this, we have made it clear that any
54 | patent must be licensed for everyone's free use or not licensed at all.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | GNU GENERAL PUBLIC LICENSE
60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61 |
62 | 0. This License applies to any program or other work which contains
63 | a notice placed by the copyright holder saying it may be distributed
64 | under the terms of this General Public License. The "Program", below,
65 | refers to any such program or work, and a "work based on the Program"
66 | means either the Program or any derivative work under copyright law:
67 | that is to say, a work containing the Program or a portion of it,
68 | either verbatim or with modifications and/or translated into another
69 | language. (Hereinafter, translation is included without limitation in
70 | the term "modification".) Each licensee is addressed as "you".
71 |
72 | Activities other than copying, distribution and modification are not
73 | covered by this License; they are outside its scope. The act of
74 | running the Program is not restricted, and the output from the Program
75 | is covered only if its contents constitute a work based on the
76 | Program (independent of having been made by running the Program).
77 | Whether that is true depends on what the Program does.
78 |
79 | 1. You may copy and distribute verbatim copies of the Program's
80 | source code as you receive it, in any medium, provided that you
81 | conspicuously and appropriately publish on each copy an appropriate
82 | copyright notice and disclaimer of warranty; keep intact all the
83 | notices that refer to this License and to the absence of any warranty;
84 | and give any other recipients of the Program a copy of this License
85 | along with the Program.
86 |
87 | You may charge a fee for the physical act of transferring a copy, and
88 | you may at your option offer warranty protection in exchange for a fee.
89 |
90 | 2. You may modify your copy or copies of the Program or any portion
91 | of it, thus forming a work based on the Program, and copy and
92 | distribute such modifications or work under the terms of Section 1
93 | above, provided that you also meet all of these conditions:
94 |
95 | a) You must cause the modified files to carry prominent notices
96 | stating that you changed the files and the date of any change.
97 |
98 | b) You must cause any work that you distribute or publish, that in
99 | whole or in part contains or is derived from the Program or any
100 | part thereof, to be licensed as a whole at no charge to all third
101 | parties under the terms of this License.
102 |
103 | c) If the modified program normally reads commands interactively
104 | when run, you must cause it, when started running for such
105 | interactive use in the most ordinary way, to print or display an
106 | announcement including an appropriate copyright notice and a
107 | notice that there is no warranty (or else, saying that you provide
108 | a warranty) and that users may redistribute the program under
109 | these conditions, and telling the user how to view a copy of this
110 | License. (Exception: if the Program itself is interactive but
111 | does not normally print such an announcement, your work based on
112 | the Program is not required to print an announcement.)
113 |
114 | These requirements apply to the modified work as a whole. If
115 | identifiable sections of that work are not derived from the Program,
116 | and can be reasonably considered independent and separate works in
117 | themselves, then this License, and its terms, do not apply to those
118 | sections when you distribute them as separate works. But when you
119 | distribute the same sections as part of a whole which is a work based
120 | on the Program, the distribution of the whole must be on the terms of
121 | this License, whose permissions for other licensees extend to the
122 | entire whole, and thus to each and every part regardless of who wrote it.
123 |
124 | Thus, it is not the intent of this section to claim rights or contest
125 | your rights to work written entirely by you; rather, the intent is to
126 | exercise the right to control the distribution of derivative or
127 | collective works based on the Program.
128 |
129 | In addition, mere aggregation of another work not based on the Program
130 | with the Program (or with a work based on the Program) on a volume of
131 | a storage or distribution medium does not bring the other work under
132 | the scope of this License.
133 |
134 | 3. You may copy and distribute the Program (or a work based on it,
135 | under Section 2) in object code or executable form under the terms of
136 | Sections 1 and 2 above provided that you also do one of the following:
137 |
138 | a) Accompany it with the complete corresponding machine-readable
139 | source code, which must be distributed under the terms of Sections
140 | 1 and 2 above on a medium customarily used for software interchange; or,
141 |
142 | b) Accompany it with a written offer, valid for at least three
143 | years, to give any third party, for a charge no more than your
144 | cost of physically performing source distribution, a complete
145 | machine-readable copy of the corresponding source code, to be
146 | distributed under the terms of Sections 1 and 2 above on a medium
147 | customarily used for software interchange; or,
148 |
149 | c) Accompany it with the information you received as to the offer
150 | to distribute corresponding source code. (This alternative is
151 | allowed only for noncommercial distribution and only if you
152 | received the program in object code or executable form with such
153 | an offer, in accord with Subsection b above.)
154 |
155 | The source code for a work means the preferred form of the work for
156 | making modifications to it. For an executable work, complete source
157 | code means all the source code for all modules it contains, plus any
158 | associated interface definition files, plus the scripts used to
159 | control compilation and installation of the executable. However, as a
160 | special exception, the source code distributed need not include
161 | anything that is normally distributed (in either source or binary
162 | form) with the major components (compiler, kernel, and so on) of the
163 | operating system on which the executable runs, unless that component
164 | itself accompanies the executable.
165 |
166 | If distribution of executable or object code is made by offering
167 | access to copy from a designated place, then offering equivalent
168 | access to copy the source code from the same place counts as
169 | distribution of the source code, even though third parties are not
170 | compelled to copy the source along with the object code.
171 |
172 | 4. You may not copy, modify, sublicense, or distribute the Program
173 | except as expressly provided under this License. Any attempt
174 | otherwise to copy, modify, sublicense or distribute the Program is
175 | void, and will automatically terminate your rights under this License.
176 | However, parties who have received copies, or rights, from you under
177 | this License will not have their licenses terminated so long as such
178 | parties remain in full compliance.
179 |
180 | 5. You are not required to accept this License, since you have not
181 | signed it. However, nothing else grants you permission to modify or
182 | distribute the Program or its derivative works. These actions are
183 | prohibited by law if you do not accept this License. Therefore, by
184 | modifying or distributing the Program (or any work based on the
185 | Program), you indicate your acceptance of this License to do so, and
186 | all its terms and conditions for copying, distributing or modifying
187 | the Program or works based on it.
188 |
189 | 6. Each time you redistribute the Program (or any work based on the
190 | Program), the recipient automatically receives a license from the
191 | original licensor to copy, distribute or modify the Program subject to
192 | these terms and conditions. You may not impose any further
193 | restrictions on the recipients' exercise of the rights granted herein.
194 | You are not responsible for enforcing compliance by third parties to
195 | this License.
196 |
197 | 7. If, as a consequence of a court judgment or allegation of patent
198 | infringement or for any other reason (not limited to patent issues),
199 | conditions are imposed on you (whether by court order, agreement or
200 | otherwise) that contradict the conditions of this License, they do not
201 | excuse you from the conditions of this License. If you cannot
202 | distribute so as to satisfy simultaneously your obligations under this
203 | License and any other pertinent obligations, then as a consequence you
204 | may not distribute the Program at all. For example, if a patent
205 | license would not permit royalty-free redistribution of the Program by
206 | all those who receive copies directly or indirectly through you, then
207 | the only way you could satisfy both it and this License would be to
208 | refrain entirely from distribution of the Program.
209 |
210 | If any portion of this section is held invalid or unenforceable under
211 | any particular circumstance, the balance of the section is intended to
212 | apply and the section as a whole is intended to apply in other
213 | circumstances.
214 |
215 | It is not the purpose of this section to induce you to infringe any
216 | patents or other property right claims or to contest validity of any
217 | such claims; this section has the sole purpose of protecting the
218 | integrity of the free software distribution system, which is
219 | implemented by public license practices. Many people have made
220 | generous contributions to the wide range of software distributed
221 | through that system in reliance on consistent application of that
222 | system; it is up to the author/donor to decide if he or she is willing
223 | to distribute software through any other system and a licensee cannot
224 | impose that choice.
225 |
226 | This section is intended to make thoroughly clear what is believed to
227 | be a consequence of the rest of this License.
228 |
229 | 8. If the distribution and/or use of the Program is restricted in
230 | certain countries either by patents or by copyrighted interfaces, the
231 | original copyright holder who places the Program under this License
232 | may add an explicit geographical distribution limitation excluding
233 | those countries, so that distribution is permitted only in or among
234 | countries not thus excluded. In such case, this License incorporates
235 | the limitation as if written in the body of this License.
236 |
237 | 9. The Free Software Foundation may publish revised and/or new versions
238 | of the General Public License from time to time. Such new versions will
239 | be similar in spirit to the present version, but may differ in detail to
240 | address new problems or concerns.
241 |
242 | Each version is given a distinguishing version number. If the Program
243 | specifies a version number of this License which applies to it and "any
244 | later version", you have the option of following the terms and conditions
245 | either of that version or of any later version published by the Free
246 | Software Foundation. If the Program does not specify a version number of
247 | this License, you may choose any version ever published by the Free Software
248 | Foundation.
249 |
250 | 10. If you wish to incorporate parts of the Program into other free
251 | programs whose distribution conditions are different, write to the author
252 | to ask for permission. For software which is copyrighted by the Free
253 | Software Foundation, write to the Free Software Foundation; we sometimes
254 | make exceptions for this. Our decision will be guided by the two goals
255 | of preserving the free status of all derivatives of our free software and
256 | of promoting the sharing and reuse of software generally.
257 |
258 | NO WARRANTY
259 |
260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
268 | REPAIR OR CORRECTION.
269 |
270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
278 | POSSIBILITY OF SUCH DAMAGES.
279 |
280 | END OF TERMS AND CONDITIONS
281 |
282 | How to Apply These Terms to Your New Programs
283 |
284 | If you develop a new program, and you want it to be of the greatest
285 | possible use to the public, the best way to achieve this is to make it
286 | free software which everyone can redistribute and change under these terms.
287 |
288 | To do so, attach the following notices to the program. It is safest
289 | to attach them to the start of each source file to most effectively
290 | convey the exclusion of warranty; and each file should have at least
291 | the "copyright" line and a pointer to where the full notice is found.
292 |
293 | {description}
294 | Copyright (C) {year} {fullname}
295 |
296 | This program is free software; you can redistribute it and/or modify
297 | it under the terms of the GNU General Public License as published by
298 | the Free Software Foundation; either version 2 of the License, or
299 | (at your option) any later version.
300 |
301 | This program is distributed in the hope that it will be useful,
302 | but WITHOUT ANY WARRANTY; without even the implied warranty of
303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
304 | GNU General Public License for more details.
305 |
306 | You should have received a copy of the GNU General Public License along
307 | with this program; if not, write to the Free Software Foundation, Inc.,
308 | 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
309 |
310 | Also add information on how to contact you by electronic and paper mail.
311 |
312 | If the program is interactive, make it output a short notice like this
313 | when it starts in an interactive mode:
314 |
315 | Gnomovision version 69, Copyright (C) year name of author
316 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
317 | This is free software, and you are welcome to redistribute it
318 | under certain conditions; type `show c' for details.
319 |
320 | The hypothetical commands `show w' and `show c' should show the appropriate
321 | parts of the General Public License. Of course, the commands you use may
322 | be called something other than `show w' and `show c'; they could even be
323 | mouse-clicks or menu items--whatever suits your program.
324 |
325 | You should also get your employer (if you work as a programmer) or your
326 | school, if any, to sign a "copyright disclaimer" for the program, if
327 | necessary. Here is a sample; alter the names:
328 |
329 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program
330 | `Gnomovision' (which makes passes at compilers) written by James Hacker.
331 |
332 | {signature of Ty Coon}, 1 April 1989
333 | Ty Coon, President of Vice
334 |
335 | This General Public License does not permit incorporating your program into
336 | proprietary programs. If your program is a subroutine library, you may
337 | consider it more useful to permit linking proprietary applications with the
338 | library. If this is what you want to do, use the GNU Lesser General
339 | Public License instead of this License.
340 |
341 |
--------------------------------------------------------------------------------