@onekeyfe/react-native-lite-card 6.7.0-6 → 6.7.0-61
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 +134 -43
- package/ReactNativeLiteCard.podspec +31 -2
- package/android/build.gradle +8 -0
- package/android/consumer-rules.pro +4 -0
- package/android/src/main/cpp/CMakeLists.txt +6 -2
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/ReactNativeLiteCardModule.kt +60 -49
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/nfc/gpchannel/GPChannelNatives.kt +7 -7
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/OnekeyLiteCard.kt +117 -39
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/entitys/SendResponse.kt +6 -3
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/CommandGenerator.kt +24 -2
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/Connection.kt +46 -19
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/GPCAPDUGenerator.kt +2 -2
- package/ios/Classes/OKLiteCommand/OKLiteCommandTool.m +38 -1
- package/ios/Classes/OKNFCBridge.mm +24 -1
- package/ios/Classes/OKNFTLite/OKLiteV1.m +20 -10
- package/ios/Classes/OKNFTLite/OKLiteV2.m +13 -5
- package/ios/Classes/OKNFTLite/OKNFCManager.h +2 -2
- package/ios/Classes/OKNFTLite/OKNFCManager.m +110 -18
- package/ios/ReactNativeLiteCard.mm +23 -11
- package/lib/module/index.js +4 -4
- package/lib/typescript/src/NativeReactNativeLiteCard.d.ts +4 -4
- package/lib/typescript/src/index.d.ts +2 -2
- package/package.json +9 -8
- package/sdk/CMakeLists.txt +121 -0
- package/sdk/README.md +190 -0
- package/sdk/android/implJni.cpp +216 -0
- package/sdk/deps/jsoncpp/LICENSE +55 -0
- package/sdk/deps/jsoncpp/include/CMakeLists.txt +2 -0
- package/sdk/deps/jsoncpp/include/json/allocator.h +98 -0
- package/sdk/deps/jsoncpp/include/json/assertions.h +54 -0
- package/sdk/deps/jsoncpp/include/json/autolink.h +25 -0
- package/sdk/deps/jsoncpp/include/json/config.h +187 -0
- package/sdk/deps/jsoncpp/include/json/features.h +61 -0
- package/sdk/deps/jsoncpp/include/json/forwards.h +37 -0
- package/sdk/deps/jsoncpp/include/json/json.h +15 -0
- package/sdk/deps/jsoncpp/include/json/reader.h +411 -0
- package/sdk/deps/jsoncpp/include/json/value.h +888 -0
- package/sdk/deps/jsoncpp/include/json/version.h +20 -0
- package/sdk/deps/jsoncpp/include/json/writer.h +357 -0
- package/sdk/deps/jsoncpp/src/lib_json/CMakeLists.txt +117 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_reader.cpp +2060 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_tool.h +114 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_value.cpp +1661 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_valueiterator.inl +167 -0
- package/sdk/deps/jsoncpp/src/lib_json/json_writer.cpp +1233 -0
- package/sdk/deps/jsoncpp/src/lib_json/version.h.in +20 -0
- package/sdk/deps/trezor-crypto/AUTHORS +2 -0
- package/sdk/deps/trezor-crypto/LICENSE +22 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/TrezorCrypto.h +29 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/address.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/aes.h +224 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/base32.h +49 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/base58.h +58 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bignum.h +169 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip32.h +114 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/bip39.h +66 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake256.h +61 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2b.h +50 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/blake2s.h +49 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/cash_addr.h +109 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-config.h +316 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-sync.h +289 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/ecrypt-types.h +53 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305/poly1305-donna.h +28 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/chacha20poly1305.h +27 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/cmac.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/curves.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ecdsa.h +112 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-32bit.h +87 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/curve25519-donna-helpers.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-blake2b.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-32bit-tables.h +25 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-basepoint-table.h +10 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-impl-base.h +110 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna-portable.h +32 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-donna.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-keccak.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/ed25519-sha3.h +21 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna/modm-donna-32bit.h +87 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519-donna.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ed25519.h +42 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/endian.h +132 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/groestl.h +104 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/hasher.h +90 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/hmac.h +60 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/memzero.h +16 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/base58.h +42 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/monero.h +13 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/range_proof.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/serialize.h +15 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/monero/xmr.h +67 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nano.h +56 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nem.h +199 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/nist256p1.h +35 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/pbkdf2.h +64 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rand.h +44 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rc4.h +37 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/rfc6979.h +40 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripemd160.h +28 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/ripple/base58.h +45 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/schnorr.h +48 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/script.h +30 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/scrypt.h +68 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/secp256k1.h +59 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha2.h +125 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sha3.h +86 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/keypair.h +20 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10.h +85 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/ed25519_ref10_fe_25_5.h +43 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/constants.h +29 -0
- package/sdk/deps/trezor-crypto/include/TrezorCrypto/sodium/private/fe_25_5/fe.h +25 -0
- package/sdk/deps/trezor-crypto/src/address.c +87 -0
- package/sdk/deps/trezor-crypto/src/aes/aes_modes.c +959 -0
- package/sdk/deps/trezor-crypto/src/aes/aescrypt.c +307 -0
- package/sdk/deps/trezor-crypto/src/aes/aeskey.c +560 -0
- package/sdk/deps/trezor-crypto/src/aes/aesopt.h +784 -0
- package/sdk/deps/trezor-crypto/src/aes/aestab.c +418 -0
- package/sdk/deps/trezor-crypto/src/aes/aestab.h +173 -0
- package/sdk/deps/trezor-crypto/src/base32.c +233 -0
- package/sdk/deps/trezor-crypto/src/base58.c +298 -0
- package/sdk/deps/trezor-crypto/src/bignum.c +808 -0
- package/sdk/deps/trezor-crypto/src/bip32.c +852 -0
- package/sdk/deps/trezor-crypto/src/bip39.c +266 -0
- package/sdk/deps/trezor-crypto/src/bip39_english.h +2074 -0
- package/sdk/deps/trezor-crypto/src/blake256.c +235 -0
- package/sdk/deps/trezor-crypto/src/blake2_common.h +39 -0
- package/sdk/deps/trezor-crypto/src/blake2b.c +333 -0
- package/sdk/deps/trezor-crypto/src/blake2s.c +318 -0
- package/sdk/deps/trezor-crypto/src/cash_addr.c +195 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha20poly1305.c +60 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/chacha_merged.c +246 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-machine.h +49 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/ecrypt-portable.h +275 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna-32.h +219 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/poly1305-donna.c +179 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.c +48 -0
- package/sdk/deps/trezor-crypto/src/chacha20poly1305/rfc7539.h +10 -0
- package/sdk/deps/trezor-crypto/src/check_mem.h +30 -0
- package/sdk/deps/trezor-crypto/src/cmac.c +342 -0
- package/sdk/deps/trezor-crypto/src/curves.c +48 -0
- package/sdk/deps/trezor-crypto/src/ecdsa.c +1355 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/README.md +183 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-32bit.c +681 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-helpers.c +66 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.c +67 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/curve25519-donna-scalarmult-base.h +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-blake2b.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-32bit-tables.c +63 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-basepoint-table.c +261 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-donna-impl-base.c +722 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-blake2b.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-keccak.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom-sha3.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-hash-custom.h +23 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-keccak.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519-sha3.c +8 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/ed25519.c +311 -0
- package/sdk/deps/trezor-crypto/src/ed25519-donna/modm-donna-32bit.c +517 -0
- package/sdk/deps/trezor-crypto/src/groestl.c +783 -0
- package/sdk/deps/trezor-crypto/src/groestl_internal.h +419 -0
- package/sdk/deps/trezor-crypto/src/hasher.c +186 -0
- package/sdk/deps/trezor-crypto/src/hmac.c +179 -0
- package/sdk/deps/trezor-crypto/src/memzero.c +6 -0
- package/sdk/deps/trezor-crypto/src/monero/base58.c +245 -0
- package/sdk/deps/trezor-crypto/src/monero/int-util.h +77 -0
- package/sdk/deps/trezor-crypto/src/monero/range_proof.c +115 -0
- package/sdk/deps/trezor-crypto/src/monero/serialize.c +54 -0
- package/sdk/deps/trezor-crypto/src/monero/xmr.c +136 -0
- package/sdk/deps/trezor-crypto/src/nano.c +151 -0
- package/sdk/deps/trezor-crypto/src/nem.c +569 -0
- package/sdk/deps/trezor-crypto/src/nist256p1.c +63 -0
- package/sdk/deps/trezor-crypto/src/nist256p1.table +1664 -0
- package/sdk/deps/trezor-crypto/src/options.h +43 -0
- package/sdk/deps/trezor-crypto/src/pbkdf2.c +177 -0
- package/sdk/deps/trezor-crypto/src/rand.c +51 -0
- package/sdk/deps/trezor-crypto/src/rc4.c +56 -0
- package/sdk/deps/trezor-crypto/src/ripemd160.c +343 -0
- package/sdk/deps/trezor-crypto/src/ripple/base58.c +76 -0
- package/sdk/deps/trezor-crypto/src/schnorr.c +208 -0
- package/sdk/deps/trezor-crypto/src/script.c +64 -0
- package/sdk/deps/trezor-crypto/src/scrypt.c +343 -0
- package/sdk/deps/trezor-crypto/src/secp256k1.c +160 -0
- package/sdk/deps/trezor-crypto/src/secp256k1.table +1664 -0
- package/sdk/deps/trezor-crypto/src/setup.py +38 -0
- package/sdk/deps/trezor-crypto/src/sha2.c +1314 -0
- package/sdk/deps/trezor-crypto/src/sha3.c +395 -0
- package/sdk/deps/trezor-crypto/src/shell.nix +6 -0
- package/sdk/deps/trezor-crypto/src/sodium/keypair.c +63 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10.c +481 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/ed25519_ref10_fe_25_5.c +885 -0
- package/sdk/deps/trezor-crypto/src/sodium/private/fe_25_5/fe.c +237 -0
- package/sdk/gpc/include/scp03/scp03.hpp +80 -0
- package/sdk/gpc/include/scp11/scp11.hpp +492 -0
- package/sdk/gpc/include/scp11/scp11c.hpp +58 -0
- package/sdk/gpc/include/tag.h +68 -0
- package/sdk/gpc/include/tlv.hpp +94 -0
- package/sdk/gpc/include/tlvparse.hpp +24 -0
- package/sdk/gpc/src/scp03.cpp +243 -0
- package/sdk/gpc/src/scp11.cpp +798 -0
- package/sdk/gpc/src/scp11c.cpp +136 -0
- package/sdk/gpc/src/tlv.cpp +159 -0
- package/sdk/gpc/src/tlvparse.c +174 -0
- package/{framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers → sdk/include}/GPChannelSDK.h +0 -0
- package/sdk/include/GPChannelSDKCore.h +10 -0
- package/sdk/include/context/BaseContext.h +56 -0
- package/sdk/include/device/ApduBuilder.hpp +72 -0
- package/sdk/include/mSIGNA/stdutils/uchar_vector.h +36 -0
- package/sdk/include/utility/Apdu.hpp +172 -0
- package/sdk/include/utility/Debug.hpp +3 -0
- package/sdk/include/utility/util.h +104 -0
- package/sdk/scripts/generate-source-id.rb +22 -0
- package/sdk/source-id-manifest.txt +19 -0
- package/sdk/source-id.cmake +31 -0
- package/sdk/src/ApduBuilder.cpp +332 -0
- package/sdk/src/GPChannelSDK.cpp +258 -0
- package/sdk/src/random.c +25 -0
- package/sdk/src/version.c +3 -0
- package/sdk/tests/android/GPChannelProxy.java +55 -0
- package/sdk/tests/android_verify.py +124 -0
- package/sdk/tests/safety.cpp +757 -0
- package/sdk/tests/verify.py +284 -0
- package/src/NativeReactNativeLiteCard.ts +4 -2
- package/src/index.tsx +14 -3
- package/android/src/main/jniLibs/arm64-v8a/libgpchannelNDK.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libgpchannelNDK.so +0 -0
- package/framework/GPChannelSDKCore.xcframework/Info.plist +0 -52
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Info.plist +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
- package/framework/GPChannelSDKCore.xcframework/ios-arm64/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/GPChannelSDKCore +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDK.h +0 -315
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Headers/GPChannelSDKCore.h +0 -19
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Info.plist +0 -0
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/Modules/module.modulemap +0 -7
- package/framework/GPChannelSDKCore.xcframework/ios-arm64_x86_64-simulator/GPChannelSDKCore.framework/_CodeSignature/CodeResources +0 -147
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
|
|
2
|
+
#ifndef __Apdu__
|
|
3
|
+
#define __Apdu__
|
|
4
|
+
|
|
5
|
+
#include "GPChannelSDK.h"
|
|
6
|
+
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace jub {
|
|
10
|
+
|
|
11
|
+
class APDU {
|
|
12
|
+
|
|
13
|
+
public:
|
|
14
|
+
APDU() {
|
|
15
|
+
cla = 0;
|
|
16
|
+
ins = 0;
|
|
17
|
+
p1 = 0;
|
|
18
|
+
p2 = 0;
|
|
19
|
+
lc = 0;
|
|
20
|
+
le = 0;
|
|
21
|
+
data.clear();
|
|
22
|
+
}
|
|
23
|
+
APDU(JUB_ULONG ncla,
|
|
24
|
+
JUB_ULONG nins,
|
|
25
|
+
JUB_ULONG np1,
|
|
26
|
+
JUB_ULONG np2,
|
|
27
|
+
JUB_ULONG nlc,
|
|
28
|
+
const JUB_BYTE* pData = nullptr,
|
|
29
|
+
JUB_ULONG nle = 0) :
|
|
30
|
+
cla(ncla),
|
|
31
|
+
ins(nins),
|
|
32
|
+
p1(np1),
|
|
33
|
+
p2(np2),
|
|
34
|
+
lc(nlc),
|
|
35
|
+
le(nle) {
|
|
36
|
+
if ( 0 != lc
|
|
37
|
+
&& nullptr != pData
|
|
38
|
+
) {
|
|
39
|
+
SetData(pData, lc);
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
data.clear();
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
~APDU() {}
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
JUB_ULONG cla, ins, p1, p2, lc, le;
|
|
49
|
+
std::vector<JUB_BYTE> data;
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
void SetApdu(JUB_ULONG ncla,
|
|
53
|
+
JUB_ULONG nins,
|
|
54
|
+
JUB_ULONG np1,
|
|
55
|
+
JUB_ULONG np2,
|
|
56
|
+
JUB_ULONG nlc,
|
|
57
|
+
JUB_BYTE* pData = nullptr,
|
|
58
|
+
JUB_ULONG nle = 0) {
|
|
59
|
+
cla = ncla;
|
|
60
|
+
ins = nins;
|
|
61
|
+
p1 = np1;
|
|
62
|
+
p2 = np2;
|
|
63
|
+
lc = nlc;
|
|
64
|
+
le = nle;
|
|
65
|
+
if ( 0 != lc
|
|
66
|
+
&& nullptr != pData
|
|
67
|
+
) {
|
|
68
|
+
SetData(pData, lc);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
data.clear();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
void SetData(const JUB_BYTE* pData, JUB_ULONG ulDataSize) {
|
|
75
|
+
// assert(ulDataSize == lc);
|
|
76
|
+
data.clear();
|
|
77
|
+
// data.resize(ulDataSize);
|
|
78
|
+
data.insert(data.begin(), pData, pData + ulDataSize);
|
|
79
|
+
}
|
|
80
|
+
}; // class APDU end
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class ResponseAPDU {
|
|
84
|
+
|
|
85
|
+
public:
|
|
86
|
+
ResponseAPDU() {
|
|
87
|
+
raw.clear();
|
|
88
|
+
clear();
|
|
89
|
+
}
|
|
90
|
+
ResponseAPDU(std::vector<JUB_BYTE> raw)
|
|
91
|
+
: raw(raw) {
|
|
92
|
+
clear();
|
|
93
|
+
}
|
|
94
|
+
ResponseAPDU(JUB_BYTE_PTR ret, JUB_ULONG retLen) {
|
|
95
|
+
raw.insert(raw.end(), ret, ret+retLen);
|
|
96
|
+
clear();
|
|
97
|
+
}
|
|
98
|
+
~ResponseAPDU() {
|
|
99
|
+
raw.clear();
|
|
100
|
+
clear();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
void clear() {
|
|
104
|
+
data.clear();
|
|
105
|
+
cmac.clear();
|
|
106
|
+
SW1 = 0;
|
|
107
|
+
SW2 = 0;
|
|
108
|
+
}
|
|
109
|
+
bool empty() {
|
|
110
|
+
return ( data.empty()
|
|
111
|
+
&& cmac.empty()
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
bool decode(bool hasMac=true) {
|
|
116
|
+
if (raw.empty()) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// The shipped Android and iOS libraries differ on short plain responses.
|
|
121
|
+
#ifdef __ANDROID__
|
|
122
|
+
const int plainMinimum = SW_LEN;
|
|
123
|
+
#else
|
|
124
|
+
const int plainMinimum = CMAC_LEN;
|
|
125
|
+
#endif
|
|
126
|
+
if ( (hasMac ? CMAC_LEN + SW_LEN : plainMinimum) > raw.size()
|
|
127
|
+
&& SW_LEN != raw.size()
|
|
128
|
+
) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
clear();
|
|
133
|
+
|
|
134
|
+
// parse SW
|
|
135
|
+
int swIndex1 = (int)raw.size() - SW_LEN;
|
|
136
|
+
int swIndex2 = (int)raw.size() - 1;
|
|
137
|
+
SW1 = raw[swIndex1];
|
|
138
|
+
SW2 = raw[swIndex2];
|
|
139
|
+
if (SW_LEN == raw.size()) {
|
|
140
|
+
return true;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
int cmacLen = 0;
|
|
144
|
+
if (hasMac) {
|
|
145
|
+
cmacLen = CMAC_LEN;
|
|
146
|
+
}
|
|
147
|
+
int cmacIndex = (int)raw.size() - SW_LEN - cmacLen;
|
|
148
|
+
data.insert(data.end(), raw.begin(), raw.begin()+cmacIndex);
|
|
149
|
+
if (hasMac) {
|
|
150
|
+
cmac.insert(cmac.end(), raw.begin()+cmacIndex, raw.begin()+swIndex1);
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return true;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
public:
|
|
157
|
+
const int CMAC_LEN = 8;
|
|
158
|
+
const int SW_LEN = 2;
|
|
159
|
+
|
|
160
|
+
std::vector<JUB_BYTE> data;
|
|
161
|
+
std::vector<JUB_BYTE> cmac;
|
|
162
|
+
JUB_BYTE SW1;
|
|
163
|
+
JUB_BYTE SW2;
|
|
164
|
+
|
|
165
|
+
private:
|
|
166
|
+
std::vector<JUB_BYTE> raw;
|
|
167
|
+
}; // class ResponseAPDU end
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
} // namespace jub end
|
|
171
|
+
|
|
172
|
+
#endif // __Apdu__
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
#ifndef COINPASS_BIO_UTIL_HPP
|
|
3
|
+
#define COINPASS_BIO_UTIL_HPP
|
|
4
|
+
|
|
5
|
+
#include <assert.h>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <string>
|
|
8
|
+
#include <vector>
|
|
9
|
+
#include <algorithm>
|
|
10
|
+
#include <sstream>
|
|
11
|
+
#include <iostream>
|
|
12
|
+
#include <cstring>
|
|
13
|
+
#include "mSIGNA/stdutils/uchar_vector.h"
|
|
14
|
+
//#include "Data.h"
|
|
15
|
+
|
|
16
|
+
namespace jub {
|
|
17
|
+
|
|
18
|
+
#define JUB_VERIFY_RET(x, r) \
|
|
19
|
+
do { \
|
|
20
|
+
if (!(x)) { \
|
|
21
|
+
return (r); \
|
|
22
|
+
} \
|
|
23
|
+
} while (0)
|
|
24
|
+
|
|
25
|
+
#define JUB_VERIFY_RV(x) \
|
|
26
|
+
do { \
|
|
27
|
+
JUB_RV r = (x); \
|
|
28
|
+
if (JUBR_OK != r) { \
|
|
29
|
+
return r; \
|
|
30
|
+
} \
|
|
31
|
+
} while (0)
|
|
32
|
+
|
|
33
|
+
#define JUB_CHECK_NULL(x) \
|
|
34
|
+
do { \
|
|
35
|
+
if (!x) { \
|
|
36
|
+
assert(false); \
|
|
37
|
+
return JUBR_MEMORY_NULL_PTR; \
|
|
38
|
+
} \
|
|
39
|
+
} while (0)
|
|
40
|
+
|
|
41
|
+
#define JUB_UNREFERENCED_PARAMETER(P) (P)
|
|
42
|
+
|
|
43
|
+
//template <class _Ty, size_t _Size>
|
|
44
|
+
//constexpr size_t array_size(const _Ty (&)[_Size]) noexcept {
|
|
45
|
+
// return (_Size);
|
|
46
|
+
//}
|
|
47
|
+
//
|
|
48
|
+
/*
|
|
49
|
+
* String splitting function
|
|
50
|
+
*/
|
|
51
|
+
//std::vector<std::string> Split(std::string str, std::string pattern);
|
|
52
|
+
/*
|
|
53
|
+
* Merge string function
|
|
54
|
+
*//*
|
|
55
|
+
std::string Join(std::vector<std::string> v, std::string pattern);
|
|
56
|
+
*/
|
|
57
|
+
/*
|
|
58
|
+
* Decimal string conversion -> Hexadecimal string
|
|
59
|
+
*/
|
|
60
|
+
//std::string DecStringToHexString(std::string str);
|
|
61
|
+
//
|
|
62
|
+
//std::string numberToHexString(unsigned int val);
|
|
63
|
+
//
|
|
64
|
+
/*
|
|
65
|
+
* char array<uint8_t, 32> -> Hexadecimal string conversion
|
|
66
|
+
*//*
|
|
67
|
+
std::string CharArray2HexStr(std::array<uint8_t, 32> v);
|
|
68
|
+
*/
|
|
69
|
+
/*
|
|
70
|
+
* Hexadecimal string conversion -> char array<uint8_t, 32>
|
|
71
|
+
*//*
|
|
72
|
+
std::array<uint8_t, 32> HexStr2CharArray(std::string str);
|
|
73
|
+
*/
|
|
74
|
+
/*
|
|
75
|
+
* std::vector<unsigned char> -> Hexadecimal string conversion
|
|
76
|
+
*/
|
|
77
|
+
//std::string CharPtr2HexStr(std::vector<unsigned char> v);
|
|
78
|
+
//
|
|
79
|
+
/*
|
|
80
|
+
* Hexadecimal string conversion -> std::vector<unsigned char>
|
|
81
|
+
*/
|
|
82
|
+
//std::vector<unsigned char> HexStr2CharPtr(std::string str);
|
|
83
|
+
/*
|
|
84
|
+
// Put an array of strings into a vector
|
|
85
|
+
std::vector<std::string> CharPtrArr2StrVector(const char* Arr[]);
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
//#define ETH_PRDFIX "0x"
|
|
89
|
+
/*
|
|
90
|
+
* std::vector<unsigned char> -> Hexadecimal string conversion
|
|
91
|
+
*//*
|
|
92
|
+
std::string ETHCharPtr2HexStr(std::vector<unsigned char> v);
|
|
93
|
+
*/
|
|
94
|
+
/*
|
|
95
|
+
* Hexadecimal string conversion -> std::vector<unsigned char>
|
|
96
|
+
*/
|
|
97
|
+
//std::vector<unsigned char> ETHHexStr2CharPtr(std::string str);
|
|
98
|
+
//
|
|
99
|
+
//TW::Data ToTlv(uint8_t tag, const TW::Data &data);
|
|
100
|
+
//std::vector<TW::Data> ParseTlv(const TW::Data &data);
|
|
101
|
+
//TW::Data Tollv(const std::string& strData);
|
|
102
|
+
} // namespace jub
|
|
103
|
+
|
|
104
|
+
#endif
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# Generate a content identity without incorporating build paths or environment data.
|
|
2
|
+
require 'digest'
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
|
|
5
|
+
package_root = File.expand_path('../..', __dir__)
|
|
6
|
+
manifest = File.join(package_root, 'sdk/source-id-manifest.txt')
|
|
7
|
+
paths = File.readlines(manifest, chomp: true).flat_map do |entry|
|
|
8
|
+
if entry.end_with?('/')
|
|
9
|
+
Dir.glob(File.join(package_root, entry, '**', '*')).select { |path| File.file?(path) }
|
|
10
|
+
.map { |path| path.delete_prefix("#{package_root}/") }
|
|
11
|
+
.select { |path| path.match?(/\.(c|cpp|h|hpp|inc|table|m|mm|swift|kt|java)\z/) }
|
|
12
|
+
.reject { |path| path.split('/').any? { |part| part.start_with?('.') || %w[build generated CMakeFiles node_modules __pycache__].include?(part) } }
|
|
13
|
+
else
|
|
14
|
+
[entry]
|
|
15
|
+
end
|
|
16
|
+
end.uniq.sort
|
|
17
|
+
content = paths.map { |path| "#{path} #{Digest::SHA256.file(File.join(package_root, path)).hexdigest}\n" }.join
|
|
18
|
+
source_id = "source-v1:#{Digest::SHA256.hexdigest(content)}"
|
|
19
|
+
header = "#define GPCHANNEL_NATIVE_SOURCE_ID \"#{source_id}\"\n"
|
|
20
|
+
output = ARGV.fetch(0)
|
|
21
|
+
FileUtils.mkdir_p(File.dirname(output))
|
|
22
|
+
File.write(output, header) unless File.file?(output) && File.read(output) == header
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
sdk/src/
|
|
2
|
+
sdk/include/
|
|
3
|
+
sdk/gpc/
|
|
4
|
+
sdk/deps/trezor-crypto/include/
|
|
5
|
+
sdk/deps/trezor-crypto/src/
|
|
6
|
+
sdk/deps/jsoncpp/include/
|
|
7
|
+
sdk/deps/jsoncpp/src/lib_json/
|
|
8
|
+
sdk/android/
|
|
9
|
+
sdk/CMakeLists.txt
|
|
10
|
+
sdk/source-id.cmake
|
|
11
|
+
sdk/source-id-manifest.txt
|
|
12
|
+
sdk/scripts/generate-source-id.rb
|
|
13
|
+
ReactNativeLiteCard.podspec
|
|
14
|
+
android/src/main/cpp/CMakeLists.txt
|
|
15
|
+
android/build.gradle
|
|
16
|
+
android/consumer-rules.pro
|
|
17
|
+
android/src/main/java/
|
|
18
|
+
android/src/main/assets/config/command.json
|
|
19
|
+
ios/
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Match scripts/generate-source-id.rb using only fixed relative paths and file content.
|
|
2
|
+
get_filename_component(GPCHANNEL_PACKAGE_ROOT "${CMAKE_CURRENT_LIST_DIR}/.." ABSOLUTE)
|
|
3
|
+
set(GPCHANNEL_SOURCE_MANIFEST "${CMAKE_CURRENT_LIST_DIR}/source-id-manifest.txt")
|
|
4
|
+
file(STRINGS "${GPCHANNEL_SOURCE_MANIFEST}" GPCHANNEL_SOURCE_ENTRIES)
|
|
5
|
+
set(GPCHANNEL_SOURCE_PATHS)
|
|
6
|
+
foreach(entry IN LISTS GPCHANNEL_SOURCE_ENTRIES)
|
|
7
|
+
if(entry MATCHES "/$")
|
|
8
|
+
file(GLOB_RECURSE contents CONFIGURE_DEPENDS LIST_DIRECTORIES false
|
|
9
|
+
RELATIVE "${GPCHANNEL_PACKAGE_ROOT}" "${GPCHANNEL_PACKAGE_ROOT}/${entry}*")
|
|
10
|
+
list(FILTER contents INCLUDE REGEX "\\.(c|cpp|h|hpp|inc|table|m|mm|swift|kt|java)$")
|
|
11
|
+
list(FILTER contents EXCLUDE REGEX "(^|/)(\\.[^/]*|build|generated|CMakeFiles|node_modules|__pycache__)(/|$)")
|
|
12
|
+
list(APPEND GPCHANNEL_SOURCE_PATHS ${contents})
|
|
13
|
+
else()
|
|
14
|
+
list(APPEND GPCHANNEL_SOURCE_PATHS "${entry}")
|
|
15
|
+
endif()
|
|
16
|
+
endforeach()
|
|
17
|
+
list(REMOVE_DUPLICATES GPCHANNEL_SOURCE_PATHS)
|
|
18
|
+
list(SORT GPCHANNEL_SOURCE_PATHS)
|
|
19
|
+
set(GPCHANNEL_SOURCE_CONTENT "")
|
|
20
|
+
foreach(path IN LISTS GPCHANNEL_SOURCE_PATHS)
|
|
21
|
+
file(SHA256 "${GPCHANNEL_PACKAGE_ROOT}/${path}" digest)
|
|
22
|
+
string(APPEND GPCHANNEL_SOURCE_CONTENT "${path} ${digest}\n")
|
|
23
|
+
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS "${GPCHANNEL_PACKAGE_ROOT}/${path}")
|
|
24
|
+
endforeach()
|
|
25
|
+
string(SHA256 GPCHANNEL_SOURCE_DIGEST "${GPCHANNEL_SOURCE_CONTENT}")
|
|
26
|
+
set(GPCHANNEL_GENERATED_INCLUDE "${CMAKE_CURRENT_BINARY_DIR}/generated")
|
|
27
|
+
file(MAKE_DIRECTORY "${GPCHANNEL_GENERATED_INCLUDE}")
|
|
28
|
+
file(WRITE "${GPCHANNEL_GENERATED_INCLUDE}/GPChannelSourceId.h.in"
|
|
29
|
+
"#define GPCHANNEL_NATIVE_SOURCE_ID \"source-v1:${GPCHANNEL_SOURCE_DIGEST}\"\n")
|
|
30
|
+
configure_file("${GPCHANNEL_GENERATED_INCLUDE}/GPChannelSourceId.h.in"
|
|
31
|
+
"${GPCHANNEL_GENERATED_INCLUDE}/GPChannelSourceId.h" COPYONLY)
|
|
@@ -0,0 +1,332 @@
|
|
|
1
|
+
#include "device/ApduBuilder.hpp"
|
|
2
|
+
#include "scp03/scp03.hpp"
|
|
3
|
+
#include "scp11/scp11c.hpp"
|
|
4
|
+
#include "utility/util.h"
|
|
5
|
+
|
|
6
|
+
namespace jub {
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
JUB_RV JubApduBuiler::BuildApdu(const APDU *apdu,
|
|
10
|
+
std::vector<JUB_BYTE> &vSafeApdu) {
|
|
11
|
+
// copy header
|
|
12
|
+
vSafeApdu.push_back((JUB_BYTE)apdu->cla);
|
|
13
|
+
vSafeApdu.push_back((JUB_BYTE)apdu->ins);
|
|
14
|
+
vSafeApdu.push_back((JUB_BYTE)apdu->p1);
|
|
15
|
+
vSafeApdu.push_back((JUB_BYTE)apdu->p2);
|
|
16
|
+
|
|
17
|
+
if (0 != apdu->lc) {
|
|
18
|
+
// get lc,data
|
|
19
|
+
if (0xFF < apdu->lc) {
|
|
20
|
+
vSafeApdu.push_back((JUB_BYTE)( (apdu->lc)/0x10000));
|
|
21
|
+
vSafeApdu.push_back((JUB_BYTE)(((apdu->lc)/0x100)%0x100));
|
|
22
|
+
vSafeApdu.push_back((JUB_BYTE)( (apdu->lc)%0x100));
|
|
23
|
+
vSafeApdu.insert(vSafeApdu.end(), apdu->data.begin(),
|
|
24
|
+
apdu->data.begin() + apdu->lc);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
vSafeApdu.push_back((JUB_BYTE)(apdu->lc));
|
|
28
|
+
vSafeApdu.insert(vSafeApdu.end(), apdu->data.begin(),
|
|
29
|
+
apdu->data.begin() + apdu->lc);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (0 != apdu->le) {
|
|
34
|
+
if (0xFF < apdu->le) {
|
|
35
|
+
vSafeApdu.push_back((JUB_BYTE)( (apdu->le)/0x10000));
|
|
36
|
+
vSafeApdu.push_back((JUB_BYTE)(((apdu->le)/0x100)%0x100));
|
|
37
|
+
vSafeApdu.push_back((JUB_BYTE)( (apdu->le)%0x100));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
vSafeApdu.push_back((JUB_BYTE)(apdu->le));
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return JUBR_OK;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// Recovered from the matching vendor binary at address 0x32b74.
|
|
49
|
+
JUB_RV JubApduBuiler::ParseApduResp(const JUB_BYTE_PTR respData,
|
|
50
|
+
const JUB_ULONG respDataLen,
|
|
51
|
+
JUB_BYTE_PTR retData,
|
|
52
|
+
JUB_ULONG_PTR pretDataLen,
|
|
53
|
+
JUB_UINT16& wRet) {
|
|
54
|
+
ResponseAPDU response(respData, respDataLen);
|
|
55
|
+
if (!response.decode(false)) return JUBR_ARGUMENTS_BAD;
|
|
56
|
+
if (pretDataLen) {
|
|
57
|
+
if (*pretDataLen < response.data.size()) return JUBR_BUFFER_TOO_SMALL;
|
|
58
|
+
*pretDataLen = response.data.size();
|
|
59
|
+
std::copy(response.data.begin(), response.data.end(), retData);
|
|
60
|
+
}
|
|
61
|
+
wRet = response.SW1 * 0x100 + response.SW2;
|
|
62
|
+
return JUBR_OK;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
JUB_RV JubApduBuiler::SetSCP03(void *scp03Ptr) {
|
|
66
|
+
_scp03Ptr = scp03Ptr;
|
|
67
|
+
return JUBR_OK;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
JUB_RV JubApduBuiler::SetSCP11(void *scp11Ptr) {
|
|
72
|
+
auto ptr = (scp11*)scp11Ptr;
|
|
73
|
+
if (ptr->empty()) {
|
|
74
|
+
return JUBR_ARGUMENTS_BAD;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
_scp11Ptr = scp11Ptr;
|
|
78
|
+
return JUBR_OK;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
JUB_RV JubApduBuiler::IncCounter() {
|
|
83
|
+
|
|
84
|
+
if (nullptr == _scp03Ptr) {
|
|
85
|
+
return JUBR_ARGUMENTS_BAD;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
((scp03*)_scp03Ptr)->incCounter();
|
|
89
|
+
|
|
90
|
+
return JUBR_OK;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
JUB_RV JubApduBuiler::PackData(std::vector<JUB_BYTE> &vDest,
|
|
95
|
+
const std::vector<JUB_BYTE> &vSrc) {
|
|
96
|
+
|
|
97
|
+
if ( nullptr == _scp03Ptr
|
|
98
|
+
&& nullptr == _scp11Ptr
|
|
99
|
+
) {
|
|
100
|
+
vDest = vSrc;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
auto scp03Ptr = (scp03*)_scp03Ptr;
|
|
104
|
+
auto scp11Ptr = (scp11*)_scp11Ptr;
|
|
105
|
+
|
|
106
|
+
std::vector<unsigned char> encKey = scp11Ptr->sk.s_enc;
|
|
107
|
+
// initial chaining vector
|
|
108
|
+
unsigned char icv[16] = {0x00,};
|
|
109
|
+
int icvLen = sizeof(icv)/sizeof(unsigned char);
|
|
110
|
+
if (!scp03Ptr->icv(encKey.data(), (int)encKey.size(),
|
|
111
|
+
icv, &icvLen)) {
|
|
112
|
+
return JUBR_ERROR;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// encrypt apdu
|
|
116
|
+
unsigned char *enc = nullptr;
|
|
117
|
+
int encLen = 0;
|
|
118
|
+
if (!scp03Ptr->encrypt(encKey.data(), (int)encKey.size(),
|
|
119
|
+
icv, icvLen,
|
|
120
|
+
vSrc.data(), (int)vSrc.size(),
|
|
121
|
+
enc, &encLen)) {
|
|
122
|
+
return JUBR_ERROR;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
enc = new unsigned char[encLen+1];
|
|
126
|
+
memset(enc, 0x00, encLen+1);
|
|
127
|
+
if (!scp03Ptr->encrypt(encKey.data(), (int)encKey.size(),
|
|
128
|
+
icv, icvLen,
|
|
129
|
+
vSrc.data(), (int)vSrc.size(),
|
|
130
|
+
enc, &encLen)) {
|
|
131
|
+
delete [] enc; enc = nullptr;
|
|
132
|
+
return JUBR_ERROR;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
vDest.insert(vDest.end(), enc, enc+encLen);
|
|
136
|
+
delete [] enc; enc = nullptr;
|
|
137
|
+
|
|
138
|
+
return JUBR_OK;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
JUB_RV JubApduBuiler::UnPackData(std::vector<JUB_BYTE> &vDest,
|
|
143
|
+
const std::vector<JUB_BYTE> &vSrc) {
|
|
144
|
+
|
|
145
|
+
if ( nullptr == _scp03Ptr
|
|
146
|
+
&& nullptr == _scp11Ptr
|
|
147
|
+
) {
|
|
148
|
+
vDest = vSrc;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
auto scp03Ptr = (scp03*)_scp03Ptr;
|
|
152
|
+
auto scp11Ptr = (scp11*)_scp11Ptr;
|
|
153
|
+
|
|
154
|
+
// initial chaining vector
|
|
155
|
+
unsigned char icv[16] = {0x00,};
|
|
156
|
+
int icvLen = sizeof(icv)/sizeof(unsigned char);
|
|
157
|
+
if (!scp03Ptr->icv(scp11Ptr->sk.s_enc.data(), (int)scp11Ptr->sk.s_enc.size(),
|
|
158
|
+
icv, &icvLen, false)) {
|
|
159
|
+
return JUBR_ERROR;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// decrypt apdu
|
|
163
|
+
unsigned char *dec = nullptr;
|
|
164
|
+
int decLen = 0;
|
|
165
|
+
if (!scp03Ptr->decrypt(scp11Ptr->sk.s_enc.data(), (int)scp11Ptr->sk.s_enc.size(),
|
|
166
|
+
icv, icvLen,
|
|
167
|
+
vSrc.data(), (int)vSrc.size(),
|
|
168
|
+
dec, &decLen)) {
|
|
169
|
+
return JUBR_ERROR;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
dec = new unsigned char[decLen+1];
|
|
173
|
+
memset(dec, 0x00, decLen+1);
|
|
174
|
+
if (!scp03Ptr->decrypt(scp11Ptr->sk.s_enc.data(), (int)scp11Ptr->sk.s_enc.size(),
|
|
175
|
+
icv, icvLen,
|
|
176
|
+
vSrc.data(), (int)vSrc.size(),
|
|
177
|
+
dec, &decLen)) {
|
|
178
|
+
delete [] dec; dec = nullptr;
|
|
179
|
+
return JUBR_ERROR;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
vDest.insert(vDest.end(), dec, dec+decLen);
|
|
183
|
+
delete [] dec; dec = nullptr;
|
|
184
|
+
|
|
185
|
+
return JUBR_OK;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
JUB_RV JubApduBuiler::PlusCMAC(const APDU *apdu, APDU *apduSafe) {
|
|
190
|
+
|
|
191
|
+
if ( nullptr == _scp03Ptr
|
|
192
|
+
&& nullptr == _scp11Ptr
|
|
193
|
+
) {
|
|
194
|
+
*apduSafe = *apdu;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
auto scp03Ptr = (scp03*)_scp03Ptr;
|
|
198
|
+
auto scp11Ptr = (scp11*)_scp11Ptr;
|
|
199
|
+
|
|
200
|
+
// calculate CMAC
|
|
201
|
+
std::vector<JUB_BYTE> vEnc;
|
|
202
|
+
vEnc.insert(vEnc.end(), apdu->data.begin(), apdu->data.end());
|
|
203
|
+
|
|
204
|
+
std::vector<unsigned char> macChain = scp03Ptr->getMacChain();
|
|
205
|
+
APDU safeApdu(apdu->cla, apdu->ins,
|
|
206
|
+
apdu->p1, apdu->p2, apdu->lc+8);
|
|
207
|
+
safeApdu.cla |= 0x04;
|
|
208
|
+
std::vector<JUB_BYTE> calMAC;
|
|
209
|
+
calMAC.insert(calMAC.end(), macChain.begin(), macChain.end()); // mac_chaining
|
|
210
|
+
calMAC.push_back(safeApdu.cla);
|
|
211
|
+
calMAC.push_back(safeApdu.ins);
|
|
212
|
+
calMAC.push_back(safeApdu.p1);
|
|
213
|
+
calMAC.push_back(safeApdu.p2);
|
|
214
|
+
calMAC.push_back(safeApdu.lc);
|
|
215
|
+
calMAC.insert(calMAC.end(), vEnc.begin(), vEnc.end());
|
|
216
|
+
|
|
217
|
+
unsigned char outmac[16] = {0x00,};
|
|
218
|
+
int outmacLen = sizeof(outmac)/sizeof(unsigned char);
|
|
219
|
+
if (!scp03Ptr->cmac(scp11Ptr->sk.s_mac.data(), (int)scp11Ptr->sk.s_mac.size(),
|
|
220
|
+
calMAC.data(), (int)calMAC.size(),
|
|
221
|
+
outmac, &outmacLen)) {
|
|
222
|
+
return JUBR_ERROR;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
vEnc.insert(vEnc.end(), std::begin(outmac), std::begin(outmac)+8);
|
|
226
|
+
safeApdu.SetData(vEnc.data(), vEnc.size());
|
|
227
|
+
|
|
228
|
+
*apduSafe = safeApdu;
|
|
229
|
+
|
|
230
|
+
// reset mac chain
|
|
231
|
+
macChain.clear();
|
|
232
|
+
macChain.insert(macChain.end(), std::begin(outmac), std::end(outmac));
|
|
233
|
+
scp03Ptr->macChaining(macChain);
|
|
234
|
+
|
|
235
|
+
return JUBR_OK;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
JUB_RV JubApduBuiler::CheckCMAC(const ResponseAPDU &respApdu) {
|
|
240
|
+
|
|
241
|
+
if ( nullptr == _scp03Ptr
|
|
242
|
+
&& nullptr == _scp11Ptr
|
|
243
|
+
) {
|
|
244
|
+
return JUBR_OK;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
auto scp03Ptr = (scp03*)_scp03Ptr;
|
|
248
|
+
auto scp11Ptr = (scp11*)_scp11Ptr;
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
std::vector<unsigned char> macChain = scp03Ptr->getMacChain();
|
|
252
|
+
|
|
253
|
+
std::vector<JUB_BYTE> calMAC;
|
|
254
|
+
calMAC.insert(calMAC.end(), macChain.begin(), macChain.end()); // mac_chaining
|
|
255
|
+
calMAC.insert(calMAC.end(), respApdu.data.begin(), respApdu.data.end());
|
|
256
|
+
calMAC.push_back(respApdu.SW1);
|
|
257
|
+
calMAC.push_back(respApdu.SW2);
|
|
258
|
+
|
|
259
|
+
unsigned char outmac[16] = {0x00,};
|
|
260
|
+
int outmacLen = sizeof(outmac)/sizeof(unsigned char);
|
|
261
|
+
if (!scp03Ptr->cmac(scp11Ptr->sk.s_rmac.data(), (int)scp11Ptr->sk.s_rmac.size(),
|
|
262
|
+
calMAC.data(), (int)calMAC.size(),
|
|
263
|
+
outmac, &outmacLen)) {
|
|
264
|
+
return JUBR_ERROR;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
macChain.clear();
|
|
268
|
+
macChain.insert(macChain.end(), respApdu.cmac.begin(), respApdu.cmac.end());
|
|
269
|
+
|
|
270
|
+
// using c++11 instead of c++14
|
|
271
|
+
// return (std::equal(std::begin(outmac), std::begin(outmac)+respApdu.CMAC_LEN, std::begin(macChain)) ? JUBR_OK : JUBR_ERROR);
|
|
272
|
+
std::vector<unsigned char> vCmac(outmac, outmac + respApdu.CMAC_LEN);
|
|
273
|
+
return (macChain == vCmac ? JUBR_OK : JUBR_ERROR);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
JUB_RV JubApduBuiler::BuildSafeApdu(const APDU *apdu, std::vector<JUB_BYTE> &vSafeApdu) {
|
|
278
|
+
|
|
279
|
+
// encrypt APDU
|
|
280
|
+
std::vector<JUB_BYTE> vEnc;
|
|
281
|
+
JUB_VERIFY_RV(PackData(vEnc, apdu->data));
|
|
282
|
+
|
|
283
|
+
APDU encApdu;
|
|
284
|
+
encApdu.SetApdu(apdu->cla, apdu->ins, apdu->p1, apdu->p2, vEnc.size(), vEnc.data());
|
|
285
|
+
APDU safeApdu;
|
|
286
|
+
JUB_VERIFY_RV(PlusCMAC(&encApdu, &safeApdu));
|
|
287
|
+
|
|
288
|
+
return BuildApdu(&safeApdu, vSafeApdu);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
JUB_RV JubApduBuiler::ParseSafeApduResp(const JUB_BYTE_PTR respData, const JUB_ULONG respDataLen,
|
|
293
|
+
JUB_BYTE_PTR retData, JUB_ULONG_PTR pretDataLen,
|
|
294
|
+
JUB_UINT16 &wRet) {
|
|
295
|
+
|
|
296
|
+
ResponseAPDU respApdu(respData, respDataLen);
|
|
297
|
+
if (!respApdu.decode()) {
|
|
298
|
+
return JUBR_ARGUMENTS_BAD;
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
wRet = respApdu.SW1 * 0x100 + respApdu.SW2;
|
|
302
|
+
#ifndef __ANDROID__
|
|
303
|
+
// The installed Android core authenticates all protected status words.
|
|
304
|
+
if (0x9000 != wRet) {
|
|
305
|
+
IncCounter();
|
|
306
|
+
return JUBR_OK;
|
|
307
|
+
}
|
|
308
|
+
#endif
|
|
309
|
+
|
|
310
|
+
// check cmac
|
|
311
|
+
JUB_VERIFY_RV(CheckCMAC(respApdu));
|
|
312
|
+
|
|
313
|
+
// decrypt
|
|
314
|
+
std::vector<JUB_BYTE> vRecv;
|
|
315
|
+
vRecv.insert(vRecv.end(), respApdu.data.begin(), respApdu.data.end());
|
|
316
|
+
std::vector<JUB_BYTE> vDec;
|
|
317
|
+
JUB_VERIFY_RV(UnPackData(vDec, vRecv));
|
|
318
|
+
|
|
319
|
+
if (nullptr != pretDataLen) {
|
|
320
|
+
if ((*pretDataLen) < vRecv.size()) {
|
|
321
|
+
return JUBR_BUFFER_TOO_SMALL;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
*pretDataLen = vDec.size();
|
|
325
|
+
std::copy(vDec.begin(), vDec.end(), retData);
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
return JUBR_OK;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
} // namespace jub end
|