@digitalshieldfe/react-native-backup-card-sdk 0.1.2 → 0.1.4

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.
Files changed (91) hide show
  1. package/README.md +17 -25
  2. package/android/build.gradle +49 -4
  3. package/android/consumer-rules.pro +0 -0
  4. package/android/proguard-rules.pro +21 -0
  5. package/android/src/main/AndroidManifest.xml +4 -1
  6. package/android/src/main/java/com/ziancube/backupcardsdk/BackupCardSdk.kt +478 -0
  7. package/android/src/main/java/com/ziancube/backupcardsdk/GPChannelNatives.java +41 -0
  8. package/android/src/main/java/com/ziancube/backupcardsdk/listener/ApiAsyncListener.java +13 -0
  9. package/android/src/main/java/com/ziancube/backupcardsdk/nfc/ApiNfc.java +173 -0
  10. package/android/src/main/java/com/ziancube/backupcardsdk/nfc/ImplNfc.java +39 -0
  11. package/android/src/main/java/com/ziancube/backupcardsdk/nfc/NfcComm.java +115 -0
  12. package/android/src/main/java/com/ziancube/backupcardsdk/utils/ApduParam.java +67 -0
  13. package/android/src/main/java/com/ziancube/backupcardsdk/utils/CommList.java +41 -0
  14. package/android/src/main/java/com/ziancube/backupcardsdk/utils/Utils.java +109 -0
  15. package/android/src/main/java/com/ziancube/reactnativebackupcardsdk/BackupCardSdkModule.kt +49 -81
  16. package/android/src/main/jni/CMakeLists.txt +60 -0
  17. package/android/src/main/jni/GPChannel/include/GPChannelSDK.h +306 -0
  18. package/android/src/main/jni/GPChannel/include/context/BaseContext.h +56 -0
  19. package/android/src/main/jni/GPChannel/include/device/ApduBuilder.hpp +72 -0
  20. package/android/src/main/jni/GPChannel/include/utility/Apdu.hpp +166 -0
  21. package/android/src/main/jni/GPChannel/include/utility/Debug.hpp +59 -0
  22. package/android/src/main/jni/GPChannel/include/utility/Singleton.h +34 -0
  23. package/android/src/main/jni/GPChannel/include/utility/mutex.h +24 -0
  24. package/android/src/main/jni/GPChannel/include/utility/trim.hpp +155 -0
  25. package/android/src/main/jni/GPChannel/include/utility/util.h +104 -0
  26. package/android/src/main/jni/GPChannel/include/utility/xFactory.hpp +26 -0
  27. package/android/src/main/jni/GPChannel/include/utility/xManager.hpp +84 -0
  28. package/android/src/main/jni/GPChannel/src/arm64-v8a/libJUB_GPC_APDU_SDK.a +0 -0
  29. package/android/src/main/jni/GPChannel/src/arm64-v8a/libTrezorCrypto.a +0 -0
  30. package/android/src/main/jni/GPChannel/src/armeabi-v7a/libJUB_GPC_APDU_SDK.a +0 -0
  31. package/android/src/main/jni/GPChannel/src/armeabi-v7a/libTrezorCrypto.a +0 -0
  32. package/android/src/main/jni/GPChannel/src/x86/libJUB_GPC_APDU_SDK.a +0 -0
  33. package/android/src/main/jni/GPChannel/src/x86/libTrezorCrypto.a +0 -0
  34. package/android/src/main/jni/src/implJni.cpp +313 -0
  35. package/android/src/main/jni/src/implJni.h +9 -0
  36. package/android/src/main/jni/utils/jsoncpp/AUTHORS +111 -0
  37. package/android/src/main/jni/utils/jsoncpp/CMakeLists.txt +159 -0
  38. package/android/src/main/jni/utils/jsoncpp/LICENSE +55 -0
  39. package/android/src/main/jni/utils/jsoncpp/README.md +135 -0
  40. package/android/src/main/jni/utils/jsoncpp/amalgamate.py +155 -0
  41. package/android/src/main/jni/utils/jsoncpp/appveyor.yml +22 -0
  42. package/android/src/main/jni/utils/jsoncpp/dev.makefile +35 -0
  43. package/android/src/main/jni/utils/jsoncpp/devtools/__init__.py +6 -0
  44. package/android/src/main/jni/utils/jsoncpp/devtools/agent_vmw7.json +33 -0
  45. package/android/src/main/jni/utils/jsoncpp/devtools/agent_vmxp.json +26 -0
  46. package/android/src/main/jni/utils/jsoncpp/devtools/antglob.py +205 -0
  47. package/android/src/main/jni/utils/jsoncpp/devtools/batchbuild.py +278 -0
  48. package/android/src/main/jni/utils/jsoncpp/devtools/fixeol.py +70 -0
  49. package/android/src/main/jni/utils/jsoncpp/devtools/licenseupdater.py +94 -0
  50. package/android/src/main/jni/utils/jsoncpp/devtools/tarball.py +52 -0
  51. package/android/src/main/jni/utils/jsoncpp/doxybuild.py +189 -0
  52. package/android/src/main/jni/utils/jsoncpp/include/CMakeLists.txt +2 -0
  53. package/android/src/main/jni/utils/jsoncpp/include/json/allocator.h +98 -0
  54. package/android/src/main/jni/utils/jsoncpp/include/json/assertions.h +54 -0
  55. package/android/src/main/jni/utils/jsoncpp/include/json/autolink.h +25 -0
  56. package/android/src/main/jni/utils/jsoncpp/include/json/config.h +187 -0
  57. package/android/src/main/jni/utils/jsoncpp/include/json/features.h +61 -0
  58. package/android/src/main/jni/utils/jsoncpp/include/json/forwards.h +37 -0
  59. package/android/src/main/jni/utils/jsoncpp/include/json/json.h +15 -0
  60. package/android/src/main/jni/utils/jsoncpp/include/json/reader.h +411 -0
  61. package/android/src/main/jni/utils/jsoncpp/include/json/value.h +888 -0
  62. package/android/src/main/jni/utils/jsoncpp/include/json/version.h +20 -0
  63. package/android/src/main/jni/utils/jsoncpp/include/json/writer.h +357 -0
  64. package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/jsontest.vcproj +119 -0
  65. package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/lib_json.vcproj +205 -0
  66. package/android/src/main/jni/utils/jsoncpp/makefiles/vs71/test_lib_json.vcproj +130 -0
  67. package/android/src/main/jni/utils/jsoncpp/makerelease.py +390 -0
  68. package/android/src/main/jni/utils/jsoncpp/meson.build +103 -0
  69. package/android/src/main/jni/utils/jsoncpp/pkg-config/jsoncpp.pc.in +9 -0
  70. package/android/src/main/jni/utils/jsoncpp/src/CMakeLists.txt +5 -0
  71. package/android/src/main/jni/utils/jsoncpp/src/jsontestrunner/CMakeLists.txt +25 -0
  72. package/android/src/main/jni/utils/jsoncpp/src/jsontestrunner/main.cpp +333 -0
  73. package/android/src/main/jni/utils/jsoncpp/src/lib_json/CMakeLists.txt +117 -0
  74. package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_reader.cpp +2060 -0
  75. package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_tool.h +114 -0
  76. package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_value.cpp +1661 -0
  77. package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_valueiterator.inl +167 -0
  78. package/android/src/main/jni/utils/jsoncpp/src/lib_json/json_writer.cpp +1233 -0
  79. package/android/src/main/jni/utils/jsoncpp/src/lib_json/version.h.in +20 -0
  80. package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/CMakeLists.txt +38 -0
  81. package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/jsontest.cpp +457 -0
  82. package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/jsontest.h +286 -0
  83. package/android/src/main/jni/utils/jsoncpp/src/test_lib_json/main.cpp +2606 -0
  84. package/android/src/main/jni/utils/jsoncpp/travis.sh +23 -0
  85. package/android/src/main/jni/utils/jsoncpp/version +1 -0
  86. package/android/src/main/jni/utils/jsoncpp/version.in +1 -0
  87. package/android/src/main/jni/utils/logUtils.cpp +108 -0
  88. package/android/src/main/jni/utils/logUtils.h +87 -0
  89. package/android/src/main/jni/utils/mSIGNA/stdutils/uchar_vector.h +614 -0
  90. package/package.json +3 -3
  91. package/android/libs/backupcardsdk-1.0.0.aar +0 -0
@@ -50,8 +50,8 @@ fun ByteArray?.toWritableArrayOrNull(): WritableArray? {
50
50
  class BackupCardSdkModule(val reactContext: ReactApplicationContext) :
51
51
  NativeBackupCardSdkSpec(reactContext) ,LifecycleEventListener
52
52
  {
53
- private var backupCardSdk: BackupCardSdk? = null
54
- private var listenersRegistered = false
53
+ private lateinit var backupCardSdk: BackupCardSdk
54
+ private val tag = "BackupCardSdkModule"
55
55
  private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
56
56
  override fun invalidate() {
57
57
  super.invalidate()
@@ -61,17 +61,18 @@ class BackupCardSdkModule(val reactContext: ReactApplicationContext) :
61
61
  object : BaseActivityEventListener() {
62
62
  override fun onNewIntent(intent: Intent) {
63
63
  super.onNewIntent(intent)
64
- backupCardSdk?.handleIntent(intent)
64
+ backupCardSdk.handleIntent(intent)
65
65
  }
66
66
  }
67
67
 
68
- private fun ensureInitialized(): Boolean {
69
- if (backupCardSdk != null) {
70
- return true
71
- }
68
+ override fun initialize() {
69
+ super.initialize()
72
70
  Utils.init(reactContext)
73
71
  Utils.getActivityLifecycle()
74
- val activity = Utils.getTopActivity() ?: return false
72
+ val activity = Utils.getTopActivity()
73
+ if (activity == null) {
74
+ return
75
+ }
75
76
  val apduLogger =
76
77
  object : ApduLogger {
77
78
  override fun log(message: String, isSent: Boolean, isSuccess: Boolean) {
@@ -97,86 +98,55 @@ class BackupCardSdkModule(val reactContext: ReactApplicationContext) :
97
98
  }
98
99
  }
99
100
  backupCardSdk = BackupCardSdk(activity, apduLogger, nfcTouchListener)
100
- if (!listenersRegistered) {
101
- reactContext.addActivityEventListener(mActivityEventListener)
102
- reactContext.addLifecycleEventListener(this)
103
- listenersRegistered = true
104
- }
105
- return true
106
- }
107
-
108
- private fun requireSdk(promise: Promise): BackupCardSdk? {
109
- if (!ensureInitialized()) {
110
- promise.reject("E_NO_ACTIVITY", "BackupCardSdk requires a foreground Activity")
111
- return null
112
- }
113
- return backupCardSdk
114
- }
115
-
116
- override fun initialize() {
117
- super.initialize()
118
- ensureInitialized()
101
+ reactContext.addActivityEventListener(mActivityEventListener)
102
+ reactContext.addLifecycleEventListener(this)
119
103
  }
120
104
 
121
105
  companion object {
122
106
  const val NAME = NativeBackupCardSdkSpec.NAME
123
107
  }
124
108
 
125
- override fun getCardInfo(promise: Promise) {
126
- val sdk = requireSdk(promise) ?: return
127
- promise.launchSuspend(
128
- block = { sdk.getCardInfo() },
129
- transform = { info -> info?.toWritableMap() }
130
- )
131
- }
109
+ override fun getCardInfo(promise: Promise) =
110
+ promise.launchSuspend(
111
+ block = { backupCardSdk.getCardInfo() },
112
+ transform = { info -> info?.toWritableMap() }
113
+ )
132
114
 
133
- override fun resetCard(promise: Promise) {
134
- val sdk = requireSdk(promise) ?: return
135
- promise.launchSuspend(
136
- block = { sdk.resetCard() },
137
- transform = { result -> result }
138
- )
139
- }
115
+ override fun resetCard(promise: Promise) =
116
+ promise.launchSuspend(
117
+ block = { backupCardSdk.resetCard() },
118
+ transform = { result -> result }
119
+ )
140
120
 
141
- override fun activateCard(pwd: String, promise: Promise) {
142
- val sdk = requireSdk(promise) ?: return
143
- promise.launchSuspend(
144
- block = { sdk.activateCard(pwd) },
145
- transform = { result -> result }
146
- )
147
- }
121
+ override fun activateCard(pwd: String, promise: Promise) =
122
+ promise.launchSuspend(
123
+ block = { backupCardSdk.activateCard(pwd) },
124
+ transform = { result -> result }
125
+ )
148
126
 
149
- override fun changePin(oldPin: String, newPin: String, promise: Promise) {
150
- val sdk = requireSdk(promise) ?: return
151
- promise.launchSuspend(
152
- block = { sdk.changePin(oldPin, newPin) },
153
- transform = { result -> result }
154
- )
155
- }
127
+ override fun changePin(oldPin: String, newPin: String, promise: Promise) =
128
+ promise.launchSuspend(
129
+ block = { backupCardSdk.changePin(oldPin, newPin) },
130
+ transform = { result -> result }
131
+ )
156
132
 
157
- override fun checkSlotEmpty(slotId: Double, pwd: String, promise: Promise) {
158
- val sdk = requireSdk(promise) ?: return
159
- promise.launchSuspend(
160
- block = { sdk.checkSlotEmpty(slotId.toInt(), pwd) },
161
- transform = { result -> result }
162
- )
163
- }
133
+ override fun checkSlotEmpty(slotId: Double, pwd: String, promise: Promise) =
134
+ promise.launchSuspend(
135
+ block = { backupCardSdk.checkSlotEmpty(slotId.toInt(), pwd) },
136
+ transform = { result -> result }
137
+ )
164
138
 
165
- override fun writeSlot(slotIndex: Double, data: ReadableArray, pwd: String, promise: Promise) {
166
- val sdk = requireSdk(promise) ?: return
167
- promise.launchSuspend(
168
- block = { sdk.writeSlot(slotIndex.toInt(), data.toByteArray(), pwd) },
169
- transform = { result -> result }
170
- )
171
- }
139
+ override fun writeSlot(slotIndex: Double, data: ReadableArray, pwd: String, promise: Promise) =
140
+ promise.launchSuspend(
141
+ block = { backupCardSdk.writeSlot(slotIndex.toInt(), data.toByteArray(), pwd) },
142
+ transform = { result -> result }
143
+ )
172
144
 
173
- override fun readSlot(slotIndex: Double, pwd: String, promise: Promise) {
174
- val sdk = requireSdk(promise) ?: return
175
- promise.launchSuspend(
176
- block = { sdk.readSlot(slotIndex.toInt(), pwd) },
177
- transform = { result -> result.toWritableArrayOrNull() }
178
- )
179
- }
145
+ override fun readSlot(slotIndex: Double, pwd: String, promise: Promise) =
146
+ promise.launchSuspend(
147
+ block = { backupCardSdk.readSlot(slotIndex.toInt(), pwd) },
148
+ transform = { result -> result.toWritableArrayOrNull() }
149
+ )
180
150
 
181
151
 
182
152
 
@@ -200,16 +170,14 @@ class BackupCardSdkModule(val reactContext: ReactApplicationContext) :
200
170
  }
201
171
 
202
172
  override fun onHostResume() {
203
- if (ensureInitialized()) {
204
- backupCardSdk?.onActivityResumed()
205
- }
173
+ backupCardSdk.onActivityResumed()
206
174
  }
207
175
 
208
176
  override fun onHostPause() {
209
- backupCardSdk?.onActivityPaused()
177
+ backupCardSdk.onActivityPaused()
210
178
  }
211
179
 
212
180
  override fun onHostDestroy() {
213
- backupCardSdk?.onActivityDestroyed()
181
+ backupCardSdk.onActivityDestroyed()
214
182
  }
215
183
  }
@@ -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
+ )
@@ -0,0 +1,306 @@
1
+ #ifndef JUB_GPC_APDU_SDK_H
2
+ #define JUB_GPC_APDU_SDK_H
3
+ //
4
+ // Generic helper definitions for shared library support
5
+ #include <stdint.h>
6
+
7
+ #if defined _MSC_VER || defined __CYGWIN__
8
+ #define JUB_COINCORE_DLL_IMPORT extern "C" __declspec(dllimport)
9
+ #define JUB_COINCORE_DLL_EXPORT extern "C" __declspec(dllexport)
10
+ #define JUB_COINCORE_DLL_LOCAL
11
+ #else
12
+ #if __GNUC__ >= 4
13
+ #define JUB_COINCORE_DLL_IMPORT __attribute__((visibility("default")))
14
+ #define JUB_COINCORE_DLL_EXPORT __attribute__((visibility("default")))
15
+ #define JUB_COINCORE_DLL_LOCAL __attribute__((visibility("internal")))
16
+ #else
17
+ #define JUB_COINCORE_DLL_IMPORT
18
+ #define JUB_COINCORE_DLL_EXPORT
19
+ #define JUB_COINCORE_DLL_LOCAL
20
+ #endif // #if __GNUC__ >= 4
21
+ #endif // #if defined _MSC_VER || defined __CYGWIN__
22
+
23
+ // Tag to deprecate functions and methods.
24
+ // Gives a compiler warning when they are used.
25
+ #if defined _MSC_VER || defined __CYGWIN__
26
+ #define BC_DEPRECATED __declspec(deprecated)
27
+ #else
28
+ #if __GNUC__ >= 4
29
+ #define JUB_DEPRECATED __attribute__((deprecated))
30
+ #else
31
+ #define JUB_DEPRECATED
32
+ #endif // #if __GNUC__ >= 4
33
+ #endif // #if defined _MSC_VER || defined __CYGWIN__
34
+
35
+ // Avoid namespace conflict between boost::placeholders and std::placeholders.
36
+ #define BOOST_BIND_NO_PLACEHOLDERS
37
+
38
+ // Define so we can have better visibility of lcov exclusion ranges.
39
+ #define LCOV_EXCL_START(text)
40
+ #define LCOV_EXCL_STOP()
41
+
42
+ #if defined(_WIN32)
43
+ #define HID_MODE
44
+ #elif defined(__APPLE__)
45
+ // see https://sourceforge.net/p/predef/mailman/message/34497133/
46
+ #include <TargetConditionals.h>
47
+ #if TARGET_OS_OSX // mac osx
48
+ #define HID_MODE
49
+ #elif TARGET_OS_IOS // ios
50
+ #define BLE_MODE
51
+ #define NFC_MODE
52
+ #endif // #if TARGET_OS_OSX
53
+ #elif defined(__ANDROID__)
54
+ #define BLE_MODE
55
+ #define NFC_MODE
56
+ #else // other
57
+ #define HID_MODE
58
+ #endif // #if defined(_WIN32)
59
+
60
+ #define JUBR_OK 0x00000000UL
61
+
62
+ #define JUBR_ERROR 0x00000001UL
63
+ #define JUBR_HOST_MEMORY 0x00000002UL
64
+ #define JUBR_ARGUMENTS_BAD 0x00000003UL
65
+ #define JUBR_IMPL_NOT_SUPPORT 0x00000004UL
66
+ #define JUBR_MEMORY_NULL_PTR 0x00000005UL
67
+ #define JUBR_CONTEXT_NOT_SATISFIED 0x00000006UL
68
+
69
+ #define JUBR_INVALID_MEMORY_PTR 0x00000008UL
70
+ #define JUBR_REPEAT_MEMORY_PTR 0x00000009UL
71
+ #define JUBR_BUFFER_TOO_SMALL 0x0000000AUL
72
+
73
+ /* === Library typedef: === */
74
+ #ifndef IN
75
+ #define IN
76
+ #endif // #ifndef IN
77
+
78
+ #ifndef OUT
79
+ #define OUT
80
+ #endif // #ifndef OUT
81
+
82
+ #ifndef INOUT
83
+ #define INOUT
84
+ #endif // #ifndef INOUT
85
+
86
+ #define JUB_TRUE 1
87
+ #define JUB_FALSE 0
88
+
89
+ #ifndef JUB_DISABLE_TRUE_FALSE
90
+ #ifndef FALSE
91
+ #define FALSE JUB_FALSE
92
+ #endif // #ifndef FALSE
93
+
94
+ #ifndef TRUE
95
+ #define TRUE JUB_TRUE
96
+ #endif // #ifndef TRUE
97
+ #endif // #ifndef JUB_DISABLE_TRUE_FALSE
98
+
99
+ /* an unsigned 8-bit value */
100
+ typedef unsigned char JUB_BYTE;
101
+
102
+ /* an unsigned 8-bit character */
103
+ typedef JUB_BYTE JUB_UCHAR;
104
+
105
+ /* an unsigned/signed 8-bit character, decide by complie*/
106
+ typedef char JUB_CHAR;
107
+
108
+ /* an 8-bit UTF-8 character */
109
+ typedef JUB_BYTE JUB_UTF8UCHAR;
110
+
111
+ /* a BYTE-sized Boolean flag */
112
+ typedef JUB_BYTE JUB_BBOOL;
113
+
114
+ /* an unsigned value, at least 32 bits long */
115
+ typedef unsigned long int JUB_ULONG;
116
+
117
+ /* a signed value, the same size as a JUB_ULONG */
118
+ typedef signed long int JUB_LONG;
119
+
120
+ typedef JUB_BYTE JUB_UINT8;
121
+
122
+ typedef unsigned int JUB_UINT32;
123
+
124
+ typedef unsigned short JUB_UINT16;
125
+
126
+ /* uint64 */
127
+ typedef unsigned long long JUB_UINT64;
128
+
129
+ /* signed uint64 */
130
+ typedef signed long long JUB_INT64;
131
+
132
+ #define JUB_PTR *
133
+ typedef JUB_CHAR JUB_PTR JUB_CHAR_PTR;
134
+ typedef JUB_CHAR_PTR JUB_PTR JUB_CHAR_PTR_PTR;
135
+ typedef const JUB_CHAR JUB_PTR JUB_CHAR_CPTR;
136
+ typedef const JUB_BYTE JUB_PTR JUB_BYTE_CPTR;
137
+
138
+ typedef JUB_BYTE JUB_PTR JUB_BYTE_PTR;
139
+ typedef const JUB_BYTE JUB_PTR JUB_BYTE_CPTR;
140
+ typedef JUB_UCHAR JUB_PTR JUB_UCHAR_PTR;
141
+ typedef JUB_UTF8UCHAR JUB_PTR JUB_UTF8UCHAR_PTR;
142
+ typedef JUB_ULONG JUB_PTR JUB_ULONG_PTR;
143
+ typedef JUB_UINT16 JUB_PTR JUB_UINT16_PTR;
144
+ typedef JUB_UINT32 JUB_PTR JUB_UINT32_PTR;
145
+ typedef JUB_UINT64 JUB_PTR JUB_UINT64_PTR;
146
+ typedef void JUB_PTR JUB_VOID_PTR;
147
+
148
+ /* Pointer to a JUB_VOID_PTR-- i.e., pointer to pointer to void */
149
+ typedef JUB_VOID_PTR JUB_PTR JUB_VOID_PTR_PTR;
150
+
151
+ typedef JUB_ULONG JUB_RV;
152
+
153
+ #ifdef __cplusplus
154
+ extern "C"
155
+ {
156
+ #endif // #ifdef __cplusplus
157
+
158
+ /**
159
+ * SharedInfo.
160
+ */
161
+ typedef struct JUB_GPC_SCP11_SHAREDINFO
162
+ {
163
+ uint32_t scpID; // SCP identifier and parameters, for SCP11c 0x1107
164
+ uint32_t keyUsage; // Key Usage Qualifier, for SCP11c 0x3C
165
+ uint32_t keyType; // Key Type, for SCP11c, it's 0x88 (AES)
166
+ uint32_t keyLength; // Key Length, 0x10
167
+ JUB_CHAR hostID[33]; // hostID string, max length 32
168
+ } GPC_SCP11_SHAREDINFO;
169
+
170
+ /*****************************************************************************
171
+ * @function name : JUB_FreeMemory
172
+ * @in param : memPtr
173
+ * @out param :
174
+ * @last change :
175
+ *****************************************************************************/
176
+ JUB_RV JUB_FreeMemory(IN JUB_CHAR_CPTR memPtr);
177
+
178
+ /*****************************************************************************
179
+ * @function name : JUB_GPC_TLVDecode
180
+ * @in param : tlv - TLV
181
+ * tag - tag
182
+ * @out param : value - value
183
+ * @last change :
184
+ *****************************************************************************/
185
+ JUB_COINCORE_DLL_EXPORT
186
+ JUB_RV JUB_GPC_TLVDecode(IN JUB_CHAR_CPTR tlv,
187
+ OUT JUB_ULONG_PTR tag,
188
+ OUT JUB_CHAR_PTR_PTR value);
189
+
190
+ /*****************************************************************************
191
+ * @function name : JUB_GPC_Initialize
192
+ * @in param : sharedInfo - SCP11 sharedInfo
193
+ * oce_crt - OCE certificate in hex string
194
+ * e_rk - Ephemeral private key of the OCE used for key agreement in hex string, ecdsa private key, length = 32
195
+ * @out param :
196
+ * @last change :
197
+ *****************************************************************************/
198
+ JUB_COINCORE_DLL_EXPORT
199
+ JUB_RV JUB_GPC_Initialize(IN GPC_SCP11_SHAREDINFO sharedInfo,
200
+ IN JUB_CHAR_CPTR card_group_id,
201
+ IN JUB_CHAR_CPTR oce_crt,
202
+ IN JUB_CHAR_CPTR oce_rk);
203
+
204
+ /*****************************************************************************
205
+ * @function name : JUB_GPC_Finalize
206
+ * @in param :
207
+ * @out param :
208
+ * @last change :
209
+ *****************************************************************************/
210
+ JUB_COINCORE_DLL_EXPORT
211
+ JUB_RV JUB_GPC_Finalize();
212
+
213
+ /*****************************************************************************
214
+ * @function name : JUB_GPC_BuildMutualAuthData
215
+ * @in param :
216
+ * @out param : apduData - APDU data for MutualAuth cmd in hex string
217
+ * @last change :
218
+ * @ condition: JUB_GPC_Initialize() has been called first.
219
+ *****************************************************************************/
220
+ JUB_COINCORE_DLL_EXPORT
221
+ JUB_RV JUB_GPC_BuildMutualAuthData(OUT JUB_CHAR_PTR_PTR apduData);
222
+
223
+ /*****************************************************************************
224
+ * @function name : JUB_GPC_OpenSecureChannel
225
+ * @in param : response - response from Mutual Auth command in hex string
226
+ * @out param :
227
+ * @last change :
228
+ * @ condition: JUB_GPC_Initialize() has been called first.
229
+ *****************************************************************************/
230
+ JUB_COINCORE_DLL_EXPORT
231
+ JUB_RV JUB_GPC_OpenSecureChannel(IN JUB_CHAR_CPTR response);
232
+
233
+ /*****************************************************************************
234
+ * @function name : JUB_GPC_BuildAPDU
235
+ * @in param : cla - Class byte of the command message
236
+ * ins - Instruction byte of the command message
237
+ * p1 - Reference control parameter 1
238
+ * p2 - Reference control parameter 2
239
+ * data - APDU data in hex string
240
+ * @out param : apdu - APDU in plain text
241
+ * @last change :
242
+ *****************************************************************************/
243
+ JUB_COINCORE_DLL_EXPORT
244
+ JUB_RV JUB_GPC_BuildAPDU(IN JUB_ULONG cla, IN JUB_ULONG ins,
245
+ IN JUB_ULONG p1, IN JUB_ULONG p2,
246
+ IN JUB_CHAR_CPTR data,
247
+ OUT JUB_CHAR_PTR_PTR apdu);
248
+
249
+ /*****************************************************************************
250
+ * @function name : JUB_GPC_ParseAPDUResponse
251
+ * @in param : response - command response in hex string
252
+ * @out param : pwRet - APDU response
253
+ * resp - APDU response data
254
+ * @last change :
255
+ *****************************************************************************/
256
+ JUB_COINCORE_DLL_EXPORT
257
+ JUB_RV JUB_GPC_ParseAPDUResponse(IN JUB_CHAR_CPTR response,
258
+ OUT JUB_UINT16_PTR pwRet,
259
+ OUT JUB_CHAR_PTR_PTR resp);
260
+
261
+ /*****************************************************************************
262
+ * @function name : JUB_GPC_BuildSafeAPDU
263
+ * @in param : cla - Class byte of the command message
264
+ * ins - Instruction byte of the command message
265
+ * p1 - Reference control parameter 1
266
+ * p2 - Reference control parameter 2
267
+ * data - APDU data in hex string
268
+ * @out param : safeApdu - APDU in cipher text
269
+ * @last change :
270
+ * @ condition: JUB_GPC_Initialize() has been called first.
271
+ *****************************************************************************/
272
+ JUB_COINCORE_DLL_EXPORT
273
+ JUB_RV JUB_GPC_BuildSafeAPDU(IN JUB_ULONG cla, IN JUB_ULONG ins,
274
+ IN JUB_ULONG p1, IN JUB_ULONG p2,
275
+ IN JUB_CHAR_CPTR data,
276
+ OUT JUB_CHAR_PTR_PTR safeApdu);
277
+
278
+ /*****************************************************************************
279
+ * @function name : JUB_GPC_ParseSafeAPDUResponse
280
+ * @in param : response - command response in hex string
281
+ * @out param : pwRet - APDU response
282
+ * decResp - APDU response data in plain text
283
+ * @last change :
284
+ * @ condition: JUB_GPC_Initialize() has been called first.
285
+ *****************************************************************************/
286
+ JUB_COINCORE_DLL_EXPORT
287
+ JUB_RV JUB_GPC_ParseSafeAPDUResponse(IN JUB_CHAR_CPTR response,
288
+ OUT JUB_UINT16_PTR pwRet,
289
+ OUT JUB_CHAR_PTR_PTR decResp);
290
+
291
+ /*****************************************************************************
292
+ * @function name : JUB_GPC_ParseCertificate
293
+ * @in param : cert - certificate of a device
294
+ * @out param : sn - Certificate Serial Number
295
+ * : subjectID - Subject Identifier in hex
296
+ * @last change :
297
+ *****************************************************************************/
298
+ JUB_COINCORE_DLL_EXPORT
299
+ JUB_RV JUB_GPC_ParseCertificate(IN JUB_CHAR_CPTR cert,
300
+ OUT JUB_CHAR_PTR_PTR sn,
301
+ OUT JUB_CHAR_PTR_PTR subjectID);
302
+
303
+ #ifdef __cplusplus
304
+ }
305
+ #endif // #ifdef __cplusplus
306
+ #endif /* JUB_GPC_APDU_SDK_H */
@@ -0,0 +1,56 @@
1
+ #pragma once
2
+ #ifndef __Context__
3
+ #define __Context__
4
+
5
+ #include "GPChannelSDK.h"
6
+
7
+ #include <string>
8
+ #include <vector>
9
+ #include <iostream>
10
+ #include <memory>
11
+
12
+ #include "scp03/scp03.hpp"
13
+ #include "scp11/scp11c.hpp"
14
+ //#include "utility/Singleton.h"
15
+
16
+
17
+ namespace jub {
18
+ namespace context {
19
+
20
+
21
+ class BaseContext {
22
+ public:
23
+ BaseContext() {
24
+ }
25
+ BaseContext(const scp11_sharedInfo& info,
26
+ const scp11_crt& crt,
27
+ const std::vector<unsigned char>& rk) {
28
+ _scp03.reset();
29
+ _scp11 = scp11c(info, crt, rk);
30
+ }
31
+ virtual ~BaseContext() {
32
+ }
33
+
34
+ void clear() {
35
+ _scp03.reset();
36
+ _scp11.clear();
37
+ }
38
+
39
+ scp03& getSCP03Instance() {
40
+ return _scp03;
41
+ }
42
+ scp11c& getSCP11cInstance() {
43
+ return _scp11;
44
+ }
45
+
46
+ private:
47
+ scp03 _scp03;
48
+ scp11c _scp11;
49
+ }; // class BaseContext end
50
+
51
+
52
+ } // namespace context end
53
+ } // namespace jub end
54
+
55
+
56
+ #endif // #pragma once
@@ -0,0 +1,72 @@
1
+ #ifndef __ApduBuilder__
2
+ #define __ApduBuilder__
3
+
4
+ #include "utility/Apdu.hpp"
5
+
6
+ namespace jub {
7
+
8
+
9
+ class ApduBuilder {
10
+ public:
11
+ /* functions */
12
+ virtual JUB_RV BuildApdu(const APDU *apdu,
13
+ std::vector<JUB_BYTE> &vSafeApdu) = 0;
14
+ virtual JUB_RV BuildSafeApdu(const APDU *apdu, std::vector<JUB_BYTE> &vSafeApdu) = 0;
15
+ virtual JUB_RV ParseSafeApduResp(const JUB_BYTE_PTR respData, const JUB_ULONG respDataLen,
16
+ JUB_BYTE_PTR retData, JUB_ULONG_PTR pretDataLen,
17
+ JUB_UINT16 &wRet) = 0;
18
+
19
+ // do something (for example: encrypt data)
20
+ virtual JUB_RV PackData(std::vector<JUB_BYTE> &vDest,
21
+ const std::vector<JUB_BYTE> &vSrc) = 0;
22
+ // do something (for example: decrypt data)
23
+ virtual JUB_RV UnPackData(std::vector<JUB_BYTE> &vDest,
24
+ const std::vector<JUB_BYTE> &vSrc) = 0;
25
+
26
+ virtual JUB_RV PlusCMAC(const APDU *apdu, APDU *apduSafe) = 0;
27
+ virtual JUB_RV CheckCMAC(const ResponseAPDU &respApdu) = 0;
28
+
29
+ virtual JUB_RV SetSCP03(void *pscp03) = 0;
30
+ virtual JUB_RV SetSCP11(void *pscp11) = 0;
31
+
32
+ protected:
33
+ virtual JUB_RV IncCounter() = 0;
34
+ }; // class ApduBuilder end
35
+
36
+
37
+ class JubApduBuiler
38
+ : public ApduBuilder {
39
+ public:
40
+ /* functions */
41
+ virtual JUB_RV BuildApdu(const APDU *apdu, std::vector<JUB_BYTE> &vApdu);
42
+ virtual JUB_RV ParseApduResp(const JUB_BYTE_PTR respData, const JUB_ULONG respDataLen,
43
+ JUB_BYTE_PTR retData, JUB_ULONG_PTR pretDataLen,
44
+ JUB_UINT16 &wRet);
45
+
46
+ virtual JUB_RV BuildSafeApdu(const APDU *apdu, std::vector<JUB_BYTE> &vSafeApdu);
47
+ virtual JUB_RV ParseSafeApduResp(const JUB_BYTE_PTR respData, const JUB_ULONG respDataLen,
48
+ JUB_BYTE_PTR retData, JUB_ULONG_PTR pretDataLen,
49
+ JUB_UINT16 &wRet);
50
+
51
+ virtual JUB_RV PackData(std::vector<JUB_BYTE> &vDest,
52
+ const std::vector<JUB_BYTE> &vSrc);
53
+ virtual JUB_RV UnPackData(std::vector<JUB_BYTE> &vDest,
54
+ const std::vector<JUB_BYTE> &vSrc);
55
+
56
+ virtual JUB_RV PlusCMAC(const APDU *apdu, APDU *apduSafe);
57
+ virtual JUB_RV CheckCMAC(const ResponseAPDU &respApdu);
58
+
59
+ virtual JUB_RV SetSCP03(void *scp03Ptr);
60
+ virtual JUB_RV SetSCP11(void *scp11Ptr);
61
+
62
+ protected:
63
+ virtual JUB_RV IncCounter() override;
64
+
65
+ private:
66
+ void *_scp03Ptr;
67
+ void *_scp11Ptr;
68
+ }; // class JubApduBuiler end
69
+
70
+
71
+ } // namespace jub end
72
+ #endif // __ApduBuilder__