@digitalshieldfe/react-native-backup-card-sdk 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -25
- package/android/build.gradle +49 -4
- package/android/consumer-rules.pro +0 -0
- package/android/proguard-rules.pro +21 -0
- package/android/src/main/AndroidManifest.xml +4 -1
- package/android/src/main/java/com/ziancube/backupcardsdk/BackupCardSdk.kt +478 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/GPChannelNatives.java +41 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/listener/ApiAsyncListener.java +13 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/nfc/ApiNfc.java +173 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/nfc/ImplNfc.java +39 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/nfc/NfcComm.java +115 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/utils/ApduParam.java +67 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/utils/CommList.java +41 -0
- package/android/src/main/java/com/ziancube/backupcardsdk/utils/Utils.java +109 -0
- package/android/src/main/jni/CMakeLists.txt +60 -0
- package/android/src/main/jni/GPChannel/include/GPChannelSDK.h +306 -0
- package/android/src/main/jni/GPChannel/include/context/BaseContext.h +56 -0
- package/android/src/main/jni/GPChannel/include/device/ApduBuilder.hpp +72 -0
- package/android/src/main/jni/GPChannel/include/utility/Apdu.hpp +166 -0
- package/android/src/main/jni/GPChannel/include/utility/Debug.hpp +59 -0
- package/android/src/main/jni/GPChannel/include/utility/Singleton.h +34 -0
- package/android/src/main/jni/GPChannel/include/utility/mutex.h +24 -0
- package/android/src/main/jni/GPChannel/include/utility/trim.hpp +155 -0
- package/android/src/main/jni/GPChannel/include/utility/util.h +104 -0
- package/android/src/main/jni/GPChannel/include/utility/xFactory.hpp +26 -0
- package/android/src/main/jni/GPChannel/include/utility/xManager.hpp +84 -0
- package/android/src/main/jni/GPChannel/src/arm64-v8a/libJUB_GPC_APDU_SDK.a +0 -0
- package/android/src/main/jni/GPChannel/src/arm64-v8a/libTrezorCrypto.a +0 -0
- package/android/src/main/jni/GPChannel/src/armeabi-v7a/libJUB_GPC_APDU_SDK.a +0 -0
- package/android/src/main/jni/GPChannel/src/armeabi-v7a/libTrezorCrypto.a +0 -0
- package/android/src/main/jni/GPChannel/src/x86/libJUB_GPC_APDU_SDK.a +0 -0
- package/android/src/main/jni/GPChannel/src/x86/libTrezorCrypto.a +0 -0
- package/android/src/main/jni/src/implJni.cpp +313 -0
- package/android/src/main/jni/src/implJni.h +9 -0
- package/android/src/main/jni/utils/jsoncpp/AUTHORS +111 -0
- package/android/src/main/jni/utils/jsoncpp/CMakeLists.txt +159 -0
- package/android/src/main/jni/utils/jsoncpp/LICENSE +55 -0
- package/android/src/main/jni/utils/jsoncpp/README.md +135 -0
- package/android/src/main/jni/utils/jsoncpp/amalgamate.py +155 -0
- package/android/src/main/jni/utils/jsoncpp/appveyor.yml +22 -0
- package/android/src/main/jni/utils/jsoncpp/dev.makefile +35 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/__init__.py +6 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/agent_vmw7.json +33 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/agent_vmxp.json +26 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/antglob.py +205 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/batchbuild.py +278 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/fixeol.py +70 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/licenseupdater.py +94 -0
- package/android/src/main/jni/utils/jsoncpp/devtools/tarball.py +52 -0
- package/android/src/main/jni/utils/jsoncpp/doxybuild.py +189 -0
- package/android/src/main/jni/utils/jsoncpp/include/CMakeLists.txt +2 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/allocator.h +98 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/assertions.h +54 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/autolink.h +25 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/config.h +187 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/features.h +61 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/forwards.h +37 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/json.h +15 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/reader.h +411 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/value.h +888 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/version.h +20 -0
- package/android/src/main/jni/utils/jsoncpp/include/json/writer.h +357 -0
- package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/jsontest.vcproj +119 -0
- package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/lib_json.vcproj +205 -0
- package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/test_lib_json.vcproj +130 -0
- package/android/src/main/jni/utils/jsoncpp/makerelease.py +390 -0
- package/android/src/main/jni/utils/jsoncpp/meson.build +103 -0
- package/android/src/main/jni/utils/jsoncpp/pkg-config/jsoncpp.pc.in +9 -0
- package/android/src/main/jni/utils/jsoncpp/src/CMakeLists.txt +5 -0
- package/android/src/main/jni/utils/jsoncpp/src/jsontestrunner/CMakeLists.txt +25 -0
- package/android/src/main/jni/utils/jsoncpp/src/jsontestrunner/main.cpp +333 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/CMakeLists.txt +117 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_reader.cpp +2060 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_tool.h +114 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_value.cpp +1661 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_valueiterator.inl +167 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_writer.cpp +1233 -0
- package/android/src/main/jni/utils/jsoncpp/src/lib_json/version.h.in +20 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/CMakeLists.txt +38 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/jsontest.cpp +457 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/jsontest.h +286 -0
- package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/main.cpp +2606 -0
- package/android/src/main/jni/utils/jsoncpp/travis.sh +23 -0
- package/android/src/main/jni/utils/jsoncpp/version +1 -0
- package/android/src/main/jni/utils/jsoncpp/version.in +1 -0
- package/android/src/main/jni/utils/logUtils.cpp +108 -0
- package/android/src/main/jni/utils/logUtils.h +87 -0
- package/android/src/main/jni/utils/mSIGNA/stdutils/uchar_vector.h +614 -0
- package/package.json +2 -3
- package/android/libs/backupcardsdk-1.0.0.aar +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
package com.ziancube.backupcardsdk.listener;
|
|
2
|
+
|
|
3
|
+
import org.json.JSONException;
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Created by lxl on 2019/4/22.
|
|
7
|
+
*/
|
|
8
|
+
public interface ApiAsyncListener<T> {
|
|
9
|
+
|
|
10
|
+
public void onUiChange();
|
|
11
|
+
|
|
12
|
+
public void onResult(int errorCode, T result) throws JSONException;
|
|
13
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
package com.ziancube.backupcardsdk.nfc;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import android.app.Activity;
|
|
5
|
+
import android.app.PendingIntent;
|
|
6
|
+
import android.content.Context;
|
|
7
|
+
import android.content.Intent;
|
|
8
|
+
import android.content.IntentFilter;
|
|
9
|
+
import android.nfc.NfcAdapter;
|
|
10
|
+
import android.nfc.Tag;
|
|
11
|
+
import android.nfc.tech.IsoDep;
|
|
12
|
+
import android.nfc.tech.NfcA;
|
|
13
|
+
import android.os.AsyncTask;
|
|
14
|
+
import android.os.Build;
|
|
15
|
+
import android.util.Log;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
import com.ziancube.backupcardsdk.listener.ApiAsyncListener;
|
|
19
|
+
|
|
20
|
+
import static android.nfc.NfcAdapter.EXTRA_TAG;
|
|
21
|
+
|
|
22
|
+
import org.json.JSONException;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Created by lxl on 2019/4/22.
|
|
26
|
+
*/
|
|
27
|
+
public class ApiNfc {
|
|
28
|
+
private static ApiNfc mApiNfcardOTP;
|
|
29
|
+
private static ImplNfc apiImplNfcardOTP;
|
|
30
|
+
private NfcAdapter nfcAdapter;
|
|
31
|
+
private PendingIntent pendingIntent;
|
|
32
|
+
private static Context apiContext;
|
|
33
|
+
private Activity apiActivity;
|
|
34
|
+
|
|
35
|
+
private IsoDep apiIsodep = null;
|
|
36
|
+
private static String[][] TECHLISTS;
|
|
37
|
+
private static IntentFilter[] TAGFILTERS;
|
|
38
|
+
static {
|
|
39
|
+
try {
|
|
40
|
+
TECHLISTS = new String[][]{{IsoDep.class.getName()},
|
|
41
|
+
{NfcA.class.getName()},};
|
|
42
|
+
|
|
43
|
+
TAGFILTERS = new IntentFilter[]{new IntentFilter(
|
|
44
|
+
NfcAdapter.ACTION_TECH_DISCOVERED, "*/*")};
|
|
45
|
+
} catch (Exception e) {
|
|
46
|
+
e.printStackTrace();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
private ApiNfc(Activity mActivity) {
|
|
51
|
+
apiContext = mActivity;
|
|
52
|
+
apiActivity = mActivity;
|
|
53
|
+
|
|
54
|
+
nfcAdapter = NfcAdapter.getDefaultAdapter(apiActivity);
|
|
55
|
+
int pendingIntentFlags = Build.VERSION.SDK_INT >= Build.VERSION_CODES.S
|
|
56
|
+
? PendingIntent.FLAG_MUTABLE
|
|
57
|
+
: 0;
|
|
58
|
+
pendingIntent = PendingIntent.getActivity(apiActivity, 0, new Intent(
|
|
59
|
+
apiActivity, apiActivity.getClass())
|
|
60
|
+
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), pendingIntentFlags);
|
|
61
|
+
|
|
62
|
+
apiImplNfcardOTP = new ImplNfc(apiContext);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
public synchronized static ApiNfc getInstance(Activity mActivity) {
|
|
66
|
+
if (mApiNfcardOTP == null) {
|
|
67
|
+
mApiNfcardOTP = new ApiNfc(mActivity);
|
|
68
|
+
}
|
|
69
|
+
return mApiNfcardOTP;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public void onPause() {
|
|
73
|
+
if (nfcAdapter != null)
|
|
74
|
+
nfcAdapter.disableForegroundDispatch(apiActivity);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
public void onResume() {
|
|
78
|
+
if (nfcAdapter != null)
|
|
79
|
+
nfcAdapter.enableForegroundDispatch(apiActivity, pendingIntent,
|
|
80
|
+
TAGFILTERS, TECHLISTS);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public int getNfcState() {
|
|
84
|
+
return (nfcAdapter == null) ? -1 : nfcAdapter.isEnabled() ? 1 : 0;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
public String getSdkVersion() {
|
|
88
|
+
return apiImplNfcardOTP.getVersion();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
public int setCardTag(Intent intent) {
|
|
92
|
+
Tag tag = (Tag) intent.getParcelableExtra(EXTRA_TAG);
|
|
93
|
+
if (tag != null) {
|
|
94
|
+
apiIsodep = IsoDep.get(tag);
|
|
95
|
+
apiImplNfcardOTP.ImplsetIsoDepTag(apiIsodep);
|
|
96
|
+
return 0;
|
|
97
|
+
}
|
|
98
|
+
return -1;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
public void transInstructions(byte[] instructions, ApiAsyncListener<String> listener) {
|
|
102
|
+
TransInstructionsTask transInstructionsTask = new TransInstructionsTask(instructions, listener);
|
|
103
|
+
transInstructionsTask.execute();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
static class TransInstructionsTask extends AsyncTask<Void, Void, Integer> {
|
|
107
|
+
private byte[] transInstru;
|
|
108
|
+
private byte[] resultInput = new byte[1024];
|
|
109
|
+
private byte[] result;
|
|
110
|
+
private int[] resultLen = new int[1];
|
|
111
|
+
private ApiAsyncListener<String> mListener;
|
|
112
|
+
|
|
113
|
+
public TransInstructionsTask(byte[] instru, ApiAsyncListener<String> listener) {
|
|
114
|
+
mListener = listener;
|
|
115
|
+
transInstru = instru;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@Override
|
|
119
|
+
protected void onPreExecute() {
|
|
120
|
+
mListener.onUiChange();
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@Override
|
|
124
|
+
protected Integer doInBackground(Void... params) {
|
|
125
|
+
int re;
|
|
126
|
+
re = apiImplNfcardOTP.connect();
|
|
127
|
+
if (re != 0) {
|
|
128
|
+
Log.e("connect error", String.valueOf(re));
|
|
129
|
+
return re;
|
|
130
|
+
}
|
|
131
|
+
re = apiImplNfcardOTP.transInstructions(transInstru, resultInput, resultLen);
|
|
132
|
+
//apiImplNfcardOTP.disConnect();
|
|
133
|
+
return re;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
@Override
|
|
137
|
+
protected void onPostExecute(Integer res) {
|
|
138
|
+
|
|
139
|
+
if (resultLen[0] != 0) {
|
|
140
|
+
result = new byte[resultLen[0]];
|
|
141
|
+
System.arraycopy(resultInput, 0, result, 0, resultLen[0]);
|
|
142
|
+
try {
|
|
143
|
+
mListener.onResult(res.intValue(), Bytes2HexString(result));
|
|
144
|
+
} catch (JSONException e) {
|
|
145
|
+
e.printStackTrace();
|
|
146
|
+
}
|
|
147
|
+
} else {
|
|
148
|
+
try {
|
|
149
|
+
mListener.onResult(res.intValue(), null);
|
|
150
|
+
} catch (JSONException e) {
|
|
151
|
+
e.printStackTrace();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
public static String Bytes2HexString(byte[] b) {
|
|
158
|
+
String ret = "";
|
|
159
|
+
for (int i = 0; i < b.length; i++) {
|
|
160
|
+
String hex = Integer.toHexString(b[i] & 0xFF);
|
|
161
|
+
if (hex.length() == 1) {
|
|
162
|
+
hex = "0".concat(hex) ;
|
|
163
|
+
}
|
|
164
|
+
ret =ret.concat(hex.toUpperCase());
|
|
165
|
+
}
|
|
166
|
+
return ret;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
public void onDestroy() {
|
|
170
|
+
mApiNfcardOTP = null;
|
|
171
|
+
apiContext = null;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
package com.ziancube.backupcardsdk.nfc;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import android.content.Context;
|
|
5
|
+
import android.nfc.tech.IsoDep;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Created by lxl on 2019/4/22.
|
|
9
|
+
*/
|
|
10
|
+
public class ImplNfc {
|
|
11
|
+
private Context implContext;
|
|
12
|
+
private NfcComm implCommunicateWithCard;
|
|
13
|
+
private String ver = "v1.2.2";
|
|
14
|
+
|
|
15
|
+
public ImplNfc(Context mContext) {
|
|
16
|
+
implContext = mContext;
|
|
17
|
+
implCommunicateWithCard = new NfcComm(implContext);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public void ImplsetIsoDepTag(final IsoDep tech) {
|
|
21
|
+
implCommunicateWithCard.setIsoDepTag(tech);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
public String getVersion() {
|
|
25
|
+
return ver;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
public int connect(){
|
|
29
|
+
return implCommunicateWithCard.connect();
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public int transInstructions(byte[] instru, byte[] result, int[] resultLen) {
|
|
33
|
+
return implCommunicateWithCard.transInstructions(instru, result, resultLen);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public int disConnect(){
|
|
37
|
+
return implCommunicateWithCard.disConnect();
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
package com.ziancube.backupcardsdk.nfc;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.nfc.NfcAdapter;
|
|
5
|
+
import android.nfc.tech.IsoDep;
|
|
6
|
+
import android.util.Log;
|
|
7
|
+
|
|
8
|
+
import java.io.IOException;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Created by lxl on 2019/4/22.
|
|
12
|
+
*/
|
|
13
|
+
public final class NfcComm {
|
|
14
|
+
public static final int FT_SUCCESS = 0x00000000;
|
|
15
|
+
public static final int FT_FAIL = 0x00000001;
|
|
16
|
+
public static final int FT_RECV_DATA_SPECIAL = 0x00000002;
|
|
17
|
+
public static final int FT_RECV_LEN_ERROR = 0x00000003;
|
|
18
|
+
public static final int EXCP_COMM_CONNECT = 0x00000010;
|
|
19
|
+
public static final int EXCP_COMM_DISCONNECT = 0x00000011;
|
|
20
|
+
public static final int EXCP_COMM_TRANSCEIVE = 0x00000012;
|
|
21
|
+
public static final int ERROR_NO_TAG = 0x10000000;
|
|
22
|
+
public static final int ERROR_NO_NFC = 0x10000001;
|
|
23
|
+
public static final int ERROR_NFC_DISABLED = 0x10000002;
|
|
24
|
+
public static final int ERROR_RECV_DATA = 0x10000003;
|
|
25
|
+
|
|
26
|
+
private IsoDep nfcTag = null;
|
|
27
|
+
private Context mContext;
|
|
28
|
+
private NfcAdapter nfcAdapter;
|
|
29
|
+
|
|
30
|
+
public NfcComm(Context context) {
|
|
31
|
+
mContext = context;
|
|
32
|
+
nfcAdapter = NfcAdapter.getDefaultAdapter(mContext);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public void setIsoDepTag(IsoDep tag) {
|
|
36
|
+
nfcTag = tag;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public int transInstructions(byte[] instru, byte[] result, int[] resultLen) {
|
|
40
|
+
int res = 0;
|
|
41
|
+
byte[] COMMAND_RECV = new byte[1024];
|
|
42
|
+
int[] COMMAND_RECV_LEN = new int[1];
|
|
43
|
+
byte[] COMMAND = instru;
|
|
44
|
+
res = transceive(COMMAND, COMMAND_RECV, COMMAND_RECV_LEN);
|
|
45
|
+
if (res != 0) {
|
|
46
|
+
return res;
|
|
47
|
+
}
|
|
48
|
+
if (COMMAND_RECV == null || COMMAND_RECV_LEN[0] == 0) {
|
|
49
|
+
res = FT_FAIL;
|
|
50
|
+
return res;
|
|
51
|
+
}
|
|
52
|
+
System.arraycopy(COMMAND_RECV, 0, result, 0, COMMAND_RECV_LEN[0]);
|
|
53
|
+
if (resultLen.length != 0) {
|
|
54
|
+
resultLen[0] = COMMAND_RECV_LEN[0];
|
|
55
|
+
}
|
|
56
|
+
if (COMMAND_RECV_LEN[0] > 1) {
|
|
57
|
+
/*if( ((COMMAND_RECV[0] &0xff) == 0x6C )&& ((COMMAND_RECV[1] &0xff) == 0x8F )){
|
|
58
|
+
res = FT_RECV_DATA_SPECIAL;
|
|
59
|
+
}*/
|
|
60
|
+
}
|
|
61
|
+
return res;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public int connect() {
|
|
65
|
+
if (nfcAdapter == null) {
|
|
66
|
+
return ERROR_NO_NFC;
|
|
67
|
+
} else if (!nfcAdapter.isEnabled()) {
|
|
68
|
+
return ERROR_NFC_DISABLED;
|
|
69
|
+
} else if (nfcTag == null) {
|
|
70
|
+
return ERROR_NO_TAG;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
if (!nfcTag.isConnected()) {
|
|
74
|
+
nfcTag.connect();
|
|
75
|
+
}
|
|
76
|
+
} catch (IOException e) {
|
|
77
|
+
e.printStackTrace();
|
|
78
|
+
return EXCP_COMM_CONNECT;
|
|
79
|
+
}
|
|
80
|
+
return 0;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public int disConnect() {
|
|
84
|
+
if (nfcTag == null) {
|
|
85
|
+
return ERROR_NO_TAG;
|
|
86
|
+
}
|
|
87
|
+
try {
|
|
88
|
+
nfcTag.close();
|
|
89
|
+
} catch (IOException e) {
|
|
90
|
+
e.printStackTrace();
|
|
91
|
+
return EXCP_COMM_DISCONNECT;
|
|
92
|
+
}
|
|
93
|
+
return 0;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
public int transceive(byte[] send, byte[] recv, int[] recvLen) {
|
|
97
|
+
if (nfcTag == null) {
|
|
98
|
+
return ERROR_NO_TAG;
|
|
99
|
+
}
|
|
100
|
+
nfcTag.setTimeout(15000);
|
|
101
|
+
byte[] rsp;
|
|
102
|
+
try {
|
|
103
|
+
rsp = nfcTag.transceive(send);
|
|
104
|
+
} catch (IOException e) {
|
|
105
|
+
Log.e("NfcComm", e.getMessage());
|
|
106
|
+
return EXCP_COMM_TRANSCEIVE;
|
|
107
|
+
}
|
|
108
|
+
if (rsp == null || rsp.length <= 0) {
|
|
109
|
+
return ERROR_RECV_DATA;
|
|
110
|
+
}
|
|
111
|
+
System.arraycopy(rsp, 0, recv, 0, rsp.length);
|
|
112
|
+
recvLen[0] = rsp.length;
|
|
113
|
+
return 0;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
package com.ziancube.backupcardsdk.utils;
|
|
2
|
+
|
|
3
|
+
public class ApduParam {
|
|
4
|
+
private long cla;
|
|
5
|
+
private long ins;
|
|
6
|
+
private long p1;
|
|
7
|
+
private long p2;
|
|
8
|
+
private String data;
|
|
9
|
+
private boolean logToMain;
|
|
10
|
+
private boolean secureChannel;
|
|
11
|
+
private boolean needData;
|
|
12
|
+
private String apdu;
|
|
13
|
+
|
|
14
|
+
public ApduParam(long cla, long ins, long p1, long p2, String data, boolean secureChannel) {
|
|
15
|
+
super();
|
|
16
|
+
this.cla = cla;
|
|
17
|
+
this.ins = ins;
|
|
18
|
+
this.p1 = p1;
|
|
19
|
+
this.p2 = p2;
|
|
20
|
+
this.data = data;
|
|
21
|
+
this.secureChannel = secureChannel;
|
|
22
|
+
this.apdu = "";
|
|
23
|
+
}
|
|
24
|
+
public long getCla() {
|
|
25
|
+
return cla;
|
|
26
|
+
}
|
|
27
|
+
public void setCla(long cla) {
|
|
28
|
+
this.cla = cla;
|
|
29
|
+
}
|
|
30
|
+
public long getIns() {
|
|
31
|
+
return ins;
|
|
32
|
+
}
|
|
33
|
+
public void setIns(long ins) {
|
|
34
|
+
this.ins = ins;
|
|
35
|
+
}
|
|
36
|
+
public long getP1() {
|
|
37
|
+
return p1;
|
|
38
|
+
}
|
|
39
|
+
public void setP1(long p1) {
|
|
40
|
+
this.p1 = p1;
|
|
41
|
+
}
|
|
42
|
+
public long getP2() {
|
|
43
|
+
return p2;
|
|
44
|
+
}
|
|
45
|
+
public void setP2(long p2) {
|
|
46
|
+
this.p2 = p2;
|
|
47
|
+
}
|
|
48
|
+
public String getData() {
|
|
49
|
+
return data;
|
|
50
|
+
}
|
|
51
|
+
public void setData(String data) {
|
|
52
|
+
this.data = data;
|
|
53
|
+
}
|
|
54
|
+
public boolean isSecureChannel() {
|
|
55
|
+
return secureChannel;
|
|
56
|
+
}
|
|
57
|
+
public void setSecureChannel(boolean secureChannel) {
|
|
58
|
+
this.secureChannel = secureChannel;
|
|
59
|
+
}
|
|
60
|
+
public String getApdu() {
|
|
61
|
+
return apdu;
|
|
62
|
+
}
|
|
63
|
+
public void setApdu(String apdu) {
|
|
64
|
+
this.apdu = apdu;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
package com.ziancube.backupcardsdk.utils;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
import java.util.ArrayList;
|
|
5
|
+
import java.util.List;
|
|
6
|
+
|
|
7
|
+
public class CommList {
|
|
8
|
+
|
|
9
|
+
public static final String BOOTLOADER = "00A40400";
|
|
10
|
+
public static final String IMPORT_MNEMONIC = "80CB80005DDFFE5A820257043535353510042BA54A95B4E29E89A10F7BFA6F1166400AE3F096B7B0F46AFECCCB1B9B170CA02342CC4948AD9E9D2259262F28783FBDBE16AF85228F9E0945923A4D65FDF5F549115D06E404AE6880048B745B2ACBFC00";
|
|
11
|
+
public static final String EXPORT_MNEMONIC = "80CB80000BDFFE08820205043535353500";
|
|
12
|
+
public static final String GENERATE_SEED = "80CB80000BDFFE08820305043535353500";
|
|
13
|
+
public static final String CHANGE_PIN = "80CB800010DFFE0D82040A0435353535043535353500";
|
|
14
|
+
public static final String RESET_WALLET = "80CB800005DFFE02820500";
|
|
15
|
+
public static final String GET_AVA_MEMORY = "80CB800005DFFE02814600";
|
|
16
|
+
public static final String VERIFY_PIN = "002001000435353535";
|
|
17
|
+
|
|
18
|
+
public static final String SELECT_BTC = "00A4040010D1560001328300424C44000042544301";
|
|
19
|
+
public static final String BTC_GET_XPUB_KEY = "00E6000011080F6D2F3434272F30272F30272F302F30";
|
|
20
|
+
public static final String BTC_GET_ADDRESS = "00F6000011080F6D2F3434272F30272F30272F302F30";
|
|
21
|
+
public static final List<String> BTC_SIGN = new ArrayList<>();
|
|
22
|
+
|
|
23
|
+
public static final String SELECT_ETH = "00A4040010D1560001328300424C44000045544801";
|
|
24
|
+
public static final String ETH_GET_XPUB_KEY = "00E600011208106D2F3434272F3630272F30272F302F30";
|
|
25
|
+
public static final String ETH_GET_ADDRESS = "00F60000106D2F3434272F3630272F30272F302F3014";
|
|
26
|
+
public static final String ETH_SIGN = "002A01004541010D420502540BE400430304BAF04414EF31DEC147DCDCD64F6A0ABFA7D441B62A216BC9450701C6BF52634000460047106D2F3434272F3630272F30272F302F30480101";
|
|
27
|
+
public static final List<String> ETH_ERC20_SIGN = new ArrayList<>();
|
|
28
|
+
|
|
29
|
+
static {
|
|
30
|
+
BTC_SIGN.add("00F8010013020E10C97B6F367F040000FC28000000000000");
|
|
31
|
+
BTC_SIGN.add("00F80200220F200F6D2F3434272F30272F30272F302F300F6D2F3434272F30272F30272F312F30");
|
|
32
|
+
BTC_SIGN.add("00F80200A30D81A001000000021E89F051847C1691E52C575F392B0C258557B04AFBDB1D7F4FB0B29F0F912E2A0100000000FFFFFFFF83D5C861150ACD9922CD1962DEC00E29B1EC70CB2DBC5B54FE186B84FDFAE40F0000000000FFFFFFFF02FD75A2CF670300001976A91405BBAF8F614D0AC9D8BDA3DB1D3EC53C64159C8588AC288C0F00000000001976A91405BBAF8F614D0AC9D8BDA3DB1D3EC53C64159C8588AC00000000");
|
|
33
|
+
BTC_SIGN.add("00F8030003100100");
|
|
34
|
+
BTC_SIGN.add("002A0000");
|
|
35
|
+
BTC_SIGN.add("00F90000");
|
|
36
|
+
BTC_SIGN.add("00F9010075");
|
|
37
|
+
|
|
38
|
+
ETH_ERC20_SIGN.add("00C700001E00070620414453540014422866A8F0B032C5CF1DFBDEF31A20F4509562B0");
|
|
39
|
+
ETH_ERC20_SIGN.add("00C801008241010C420502540BE40043030249F04414422866A8F0B032C5CF1DFBDEF31A20F4509562B045004644A9059CBB000000000000000000000000EF31DEC147DCDCD64F6A0ABFA7D441B62A216BC9000000000000000000000000000000000000000000000000112210F47DE9811547106D2F3434272F3630272F30272F302F30480101");
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
package com.ziancube.backupcardsdk.utils;
|
|
2
|
+
|
|
3
|
+
import java.math.BigInteger;
|
|
4
|
+
|
|
5
|
+
import static com.ziancube.backupcardsdk.nfc.NfcComm.ERROR_NFC_DISABLED;
|
|
6
|
+
import static com.ziancube.backupcardsdk.nfc.NfcComm.ERROR_NO_NFC;
|
|
7
|
+
import static com.ziancube.backupcardsdk.nfc.NfcComm.ERROR_NO_TAG;
|
|
8
|
+
import static com.ziancube.backupcardsdk.nfc.NfcComm.ERROR_RECV_DATA;
|
|
9
|
+
import static com.ziancube.backupcardsdk.nfc.NfcComm.EXCP_COMM_CONNECT;
|
|
10
|
+
import static com.ziancube.backupcardsdk.nfc.NfcComm.EXCP_COMM_DISCONNECT;
|
|
11
|
+
import static com.ziancube.backupcardsdk.nfc.NfcComm.EXCP_COMM_TRANSCEIVE;
|
|
12
|
+
import static com.ziancube.backupcardsdk.nfc.NfcComm.FT_FAIL;
|
|
13
|
+
import static com.ziancube.backupcardsdk.nfc.NfcComm.FT_RECV_DATA_SPECIAL;
|
|
14
|
+
import static com.ziancube.backupcardsdk.nfc.NfcComm.FT_RECV_LEN_ERROR;
|
|
15
|
+
|
|
16
|
+
public class Utils {
|
|
17
|
+
|
|
18
|
+
public static String bytesToHexString(byte[] bytes) {
|
|
19
|
+
StringBuilder sb = new StringBuilder();
|
|
20
|
+
for (byte b : bytes) {
|
|
21
|
+
sb.append(String.format("%02X", b));
|
|
22
|
+
}
|
|
23
|
+
return sb.toString();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
public static byte[] hexString2Bytes(String hex) {
|
|
27
|
+
return String2Bytes(hex, 16);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private static byte[] String2Bytes(String str, int digit) {
|
|
31
|
+
byte[] bArray = new BigInteger("10".concat(str) , digit).toByteArray();
|
|
32
|
+
byte[] ret = new byte[bArray.length - 1];
|
|
33
|
+
for (int i = 0; i < ret.length; i++) {
|
|
34
|
+
ret[i] = bArray[i + 1];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return ret;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
public static String stringToHexString(String s) {
|
|
42
|
+
String str = "";
|
|
43
|
+
for (int i = 0; i < s.length(); i++) {
|
|
44
|
+
int ch = s.charAt(i);
|
|
45
|
+
String s4 = Integer.toHexString(ch);
|
|
46
|
+
str = str.concat(s4);
|
|
47
|
+
}
|
|
48
|
+
return str;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public static String hexStringToString(String s) {
|
|
52
|
+
StringBuilder sb = new StringBuilder();
|
|
53
|
+
for (int i = 0; i < s.length(); i += 2) {
|
|
54
|
+
String hexPair = s.substring(i, i + 2);
|
|
55
|
+
int charCode = Integer.parseInt(hexPair, 16);
|
|
56
|
+
sb.append((char) charCode);
|
|
57
|
+
}
|
|
58
|
+
return sb.toString();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public static String buildTLV(String tag,String value){
|
|
62
|
+
int len = value.length() / 2;
|
|
63
|
+
String lenHex = String.format("%02X", len);
|
|
64
|
+
return (tag != null ? tag : "") + lenHex + value;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public static String getError(int ret) {
|
|
68
|
+
String msg;
|
|
69
|
+
switch (ret) {
|
|
70
|
+
case 0:
|
|
71
|
+
msg = "success";
|
|
72
|
+
break;
|
|
73
|
+
case FT_FAIL:
|
|
74
|
+
msg = "error: fail";
|
|
75
|
+
break;
|
|
76
|
+
case FT_RECV_DATA_SPECIAL:
|
|
77
|
+
msg = "error: receive data 6c8f";
|
|
78
|
+
break;
|
|
79
|
+
case FT_RECV_LEN_ERROR:
|
|
80
|
+
msg = "error: receive data len error";
|
|
81
|
+
break;
|
|
82
|
+
case EXCP_COMM_CONNECT:
|
|
83
|
+
msg = "error: connect except";
|
|
84
|
+
break;
|
|
85
|
+
case EXCP_COMM_DISCONNECT:
|
|
86
|
+
msg = "error: disconnect except";
|
|
87
|
+
break;
|
|
88
|
+
case EXCP_COMM_TRANSCEIVE:
|
|
89
|
+
msg = "error: transceive except";
|
|
90
|
+
break;
|
|
91
|
+
case ERROR_NO_TAG:
|
|
92
|
+
msg = "error: no tag";
|
|
93
|
+
break;
|
|
94
|
+
case ERROR_NO_NFC:
|
|
95
|
+
msg = "error: no nfc";
|
|
96
|
+
break;
|
|
97
|
+
case ERROR_NFC_DISABLED:
|
|
98
|
+
msg = "error: nfc disabled";
|
|
99
|
+
break;
|
|
100
|
+
case ERROR_RECV_DATA:
|
|
101
|
+
msg = "error: receive data error";
|
|
102
|
+
break;
|
|
103
|
+
default:
|
|
104
|
+
msg = "error : other error";
|
|
105
|
+
break;
|
|
106
|
+
}
|
|
107
|
+
return msg;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
project(gpchannelNDK)
|
|
2
|
+
|
|
3
|
+
cmake_minimum_required(VERSION 3.6.0)
|
|
4
|
+
|
|
5
|
+
message("===============================>>> ndk")
|
|
6
|
+
|
|
7
|
+
# **************************************************************************************************
|
|
8
|
+
# 引入相关头文件
|
|
9
|
+
# 注:因为是分开编译且涉及相互调用,所以需要引入其他库模块中的头文件
|
|
10
|
+
# **************************************************************************************************
|
|
11
|
+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/src)
|
|
12
|
+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/utils)
|
|
13
|
+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/GPChannel/include)
|
|
14
|
+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/utils/jsoncpp/include)
|
|
15
|
+
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/utils/mSIGNA/stdutils)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
# **************************************************************************************************
|
|
19
|
+
# 查找指定目录下的所有源文件,并将其存入指定变量中
|
|
20
|
+
# **************************************************************************************************
|
|
21
|
+
|
|
22
|
+
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/src SRC_LIST)
|
|
23
|
+
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/utils SRC_LIST)
|
|
24
|
+
aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR}/utils/jsoncpp/src/lib_json SRC_LIST)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
# **************************************************************************************************
|
|
28
|
+
# 添加其他预构建库(第三方库)
|
|
29
|
+
# **************************************************************************************************
|
|
30
|
+
|
|
31
|
+
find_library(libLog
|
|
32
|
+
log
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/GPChannel/src/${ANDROID_ABI})
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# **************************************************************************************************
|
|
39
|
+
# 生成动态库
|
|
40
|
+
# **************************************************************************************************
|
|
41
|
+
|
|
42
|
+
add_library(
|
|
43
|
+
gpchannelNDK
|
|
44
|
+
SHARED
|
|
45
|
+
${SRC_LIST}
|
|
46
|
+
)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
# **************************************************************************************************
|
|
51
|
+
# 链接所有相关库
|
|
52
|
+
# 切记链接日志库,否则编译报错 undefined reference to '__android_log_print'
|
|
53
|
+
# **************************************************************************************************
|
|
54
|
+
|
|
55
|
+
target_link_libraries(
|
|
56
|
+
gpchannelNDK
|
|
57
|
+
JUB_GPC_APDU_SDK
|
|
58
|
+
TrezorCrypto
|
|
59
|
+
${libLog}
|
|
60
|
+
)
|