@onekeyfe/react-native-lite-card 6.7.0-alpha.409 → 6.7.0-alpha.412
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 +9 -1
- package/ReactNativeLiteCard.podspec +25 -2
- package/android/build.gradle +7 -0
- package/android/src/main/cpp/CMakeLists.txt +6 -2
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/nfc/gpchannel/GPChannelNatives.kt +7 -7
- 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 +5 -1
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/Connection.kt +21 -7
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/GPCAPDUGenerator.kt +2 -2
- package/ios/Classes/OKLiteCommand/OKLiteCommandTool.m +4 -1
- package/ios/Classes/OKNFCBridge.mm +1 -1
- package/ios/Classes/OKNFTLite/OKLiteV1.m +6 -3
- package/ios/Classes/OKNFTLite/OKLiteV2.m +13 -5
- package/package.json +2 -2
- package/sdk/CMakeLists.txt +120 -0
- package/sdk/README.md +175 -0
- package/sdk/android/implJni.cpp +177 -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/src/ApduBuilder.cpp +332 -0
- package/sdk/src/GPChannelSDK.cpp +252 -0
- package/sdk/src/random.c +25 -0
- package/sdk/src/version.c +2 -0
- package/sdk/tests/android/GPChannelProxy.java +55 -0
- package/sdk/tests/android_verify.py +121 -0
- package/sdk/tests/safety.cpp +603 -0
- package/sdk/tests/verify.py +267 -0
- 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,136 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
//
|
|
4
|
+
// scp11c.cpp
|
|
5
|
+
// JubSDK
|
|
6
|
+
//
|
|
7
|
+
// Created by Pan Min on 2020/6/9.
|
|
8
|
+
// Copyright © 2020 JuBiter. All rights reserved.
|
|
9
|
+
//
|
|
10
|
+
|
|
11
|
+
#include "utility/Debug.hpp"
|
|
12
|
+
#include "mSIGNA/stdutils/uchar_vector.h"
|
|
13
|
+
|
|
14
|
+
#include <TrezorCrypto/aes.h>
|
|
15
|
+
#include <TrezorCrypto/cmac.h>
|
|
16
|
+
#include "scp11/scp11c.hpp"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
std::vector<unsigned char> scp11c::getMutualAuthData() {
|
|
20
|
+
|
|
21
|
+
// 6.5 MUTUAL AUTHENTICATE Command
|
|
22
|
+
// Table 6-17: MUTUAL AUTHENTICATE Data Field
|
|
23
|
+
scp11_mutual_auth ma(&shared_info,
|
|
24
|
+
e_pk);
|
|
25
|
+
return ma.encode();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
bool scp11c::keyDerivation(const scp11_response_msg &response_msg, scp11_session_key& session_key) {
|
|
30
|
+
|
|
31
|
+
// OCE calculates ShSss from PK.SD.ECKA and SK.OCE.ECKA
|
|
32
|
+
unsigned char ShSss[SHA1_DIGEST_LENGTH] = {0x00,};
|
|
33
|
+
if (!_calcShSss(response_msg.sd_pk.value.data(),
|
|
34
|
+
oce_rk.data(),
|
|
35
|
+
ShSss)) {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// OCE calculates ShSes from PK.SD.ECKA and eSK.OCE.ECKASD
|
|
40
|
+
unsigned char ShSes[SHA1_DIGEST_LENGTH] = {0x00,};
|
|
41
|
+
if (!_calcShSes(response_msg.sd_pk.value.data(),
|
|
42
|
+
e_rk.data(),
|
|
43
|
+
ShSes)) {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// OCE derives AES sessionkeys from ShSes and ShSss
|
|
48
|
+
unsigned char z[SHA1_DIGEST_LENGTH*2] = {0x00,};
|
|
49
|
+
unsigned int zLen = sizeof(z)/sizeof(unsigned char);
|
|
50
|
+
memcpy(z, ShSes, SHA1_DIGEST_LENGTH);
|
|
51
|
+
memcpy(z + SHA1_DIGEST_LENGTH, ShSss, SHA1_DIGEST_LENGTH);
|
|
52
|
+
|
|
53
|
+
// Card Group ID is the content of tag '5F20' (subject identifier) in CERT.SD.ECKA.
|
|
54
|
+
std::vector<unsigned char> cardGroupID;
|
|
55
|
+
if (!sd_crt.empty()) {
|
|
56
|
+
cardGroupID = sd_crt.subject_id.value;
|
|
57
|
+
}
|
|
58
|
+
else if (!shared_info.hasCardGroupID()) {
|
|
59
|
+
cardGroupID = shared_info.getCardGroupID();
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
std::vector<unsigned char> shared = scp11_sharedInfo(shared_info).encodeV(cardGroupID);
|
|
65
|
+
unsigned int shared_info_len = (unsigned int)shared.size();
|
|
66
|
+
if (0 == shared_info_len) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
DEBUG_LOG("scp11c::keyDerivation::scp11_sharedInfo[%d]: %s\n", shared.size(), uchar_vector(shared).getHex().c_str());
|
|
71
|
+
|
|
72
|
+
unsigned int outKeyLen = scp11_session_key::size();
|
|
73
|
+
unsigned char *outKey = new unsigned char[outKeyLen+1];
|
|
74
|
+
memset(outKey, 0x00, outKeyLen+1);
|
|
75
|
+
outKeyLen = kdf2_sha256(z, zLen,
|
|
76
|
+
shared.data(), (int)shared.size(),
|
|
77
|
+
outKey, outKeyLen);
|
|
78
|
+
|
|
79
|
+
std::vector<unsigned char> session;
|
|
80
|
+
session.insert(session.begin(), outKey, outKey+outKeyLen);
|
|
81
|
+
delete [] outKey; outKey = nullptr;
|
|
82
|
+
|
|
83
|
+
DEBUG_LOG("scp11c::keyDerivation::session[%d]: %s\n", session.size(), uchar_vector(session).getHex().c_str());
|
|
84
|
+
|
|
85
|
+
return session_key.decode(session, scp11_session_key::KEY_LENGTH);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
bool scp11c::checkReceipt(const scp11_response_msg &response_msg, const std::vector<unsigned char> &key_dek) {
|
|
90
|
+
|
|
91
|
+
scp11_mutual_auth ma(&shared_info,
|
|
92
|
+
e_pk,
|
|
93
|
+
response_msg.sd_pk.value);
|
|
94
|
+
std::vector<unsigned char> receiptInputData = ma.encode();
|
|
95
|
+
DEBUG_LOG("scp11c::checkReceipt::receiptInputData[%d]: %s\n", receiptInputData.size(), uchar_vector(receiptInputData).getHex().c_str());
|
|
96
|
+
|
|
97
|
+
// check if receipt == mac
|
|
98
|
+
unsigned char outmac[16] = {0x00,};
|
|
99
|
+
int outmacLen = sizeof(outmac)/sizeof(unsigned char);
|
|
100
|
+
std::vector<unsigned char> key(key_dek);
|
|
101
|
+
AES_CMAC(key.data(), receiptInputData.data(), (int)receiptInputData.size(),
|
|
102
|
+
outmac);
|
|
103
|
+
|
|
104
|
+
DEBUG_LOG("scp11c::checkReceipt::receipt[%d]: %s\n", response_msg.receipt.value.size(), uchar_vector(response_msg.receipt.value).getHex().c_str());
|
|
105
|
+
DEBUG_LOG("scp11c::checkReceipt::outmac[%d]: %s\n", outmacLen, uchar_vector(outmac, outmacLen).getHex().c_str());
|
|
106
|
+
|
|
107
|
+
// using c++11 instead of c++14
|
|
108
|
+
// return std::equal(std::begin(response_msg.receipt.value), std::end(response_msg.receipt.value),
|
|
109
|
+
// std::begin(outmac));
|
|
110
|
+
std::vector<unsigned char> vOutmac(outmac, outmac + sizeof(outmac)/sizeof(unsigned char));
|
|
111
|
+
return (response_msg.receipt.value == vOutmac);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
bool scp11c::openSecureChannel(const std::vector<unsigned char>& response) {
|
|
116
|
+
|
|
117
|
+
scp11_response_msg response_msg;
|
|
118
|
+
if (!response_msg.decode(response)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
scp11_session_key session_key;
|
|
123
|
+
if (!keyDerivation(response_msg, session_key)) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// check the receipt
|
|
128
|
+
if (!checkReceipt(response_msg, session_key.key_dek)) {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
setSessionKey(session_key);
|
|
133
|
+
setResponseMsg(response_msg);
|
|
134
|
+
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
//
|
|
2
|
+
// tlv.cpp
|
|
3
|
+
// JubSDK
|
|
4
|
+
//
|
|
5
|
+
// Created by Pan Min on 2020/6/24.
|
|
6
|
+
// Copyright © 2020 JuBiter. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#include <stdio.h>
|
|
10
|
+
#include "tlv.hpp"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/// struct gpc_tlv_buf
|
|
14
|
+
std::vector<unsigned char> tlv_buf::encode() {
|
|
15
|
+
|
|
16
|
+
std::vector<unsigned char> out;
|
|
17
|
+
|
|
18
|
+
if ( 0 == tag
|
|
19
|
+
&& value.empty()
|
|
20
|
+
) {
|
|
21
|
+
return out;
|
|
22
|
+
}
|
|
23
|
+
if (tag&0xFF00) {
|
|
24
|
+
out.push_back((tag&0xFF00)>>8);
|
|
25
|
+
out.push_back( tag&0x00FF);
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
out.push_back(tag);
|
|
29
|
+
}
|
|
30
|
+
out.push_back(value.size());
|
|
31
|
+
out.insert(out.end(), value.begin(), value.end());
|
|
32
|
+
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
size_t tlv_buf::encode(std::vector<unsigned char>& code) {
|
|
38
|
+
|
|
39
|
+
code = encode();
|
|
40
|
+
return code.size();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
// push_back '00' if value is empty.
|
|
45
|
+
std::vector<unsigned char> tlv_buf::encodeTBAV() {
|
|
46
|
+
|
|
47
|
+
std::vector<unsigned char> out;
|
|
48
|
+
|
|
49
|
+
if (value.empty()) {
|
|
50
|
+
out.push_back(value.size());
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
out.push_back(value.size());
|
|
54
|
+
out.insert(out.end(), value.begin(), value.end());
|
|
55
|
+
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
// push_back nothing if value is empty.
|
|
61
|
+
std::vector<unsigned char> tlv_buf::encodeLV() {
|
|
62
|
+
|
|
63
|
+
std::vector<unsigned char> out;
|
|
64
|
+
|
|
65
|
+
if (value.empty()) {
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
out.push_back(value.size());
|
|
69
|
+
out.insert(out.end(), value.begin(), value.end());
|
|
70
|
+
|
|
71
|
+
return out;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
size_t tlv_buf::encodeLV(std::vector<unsigned char>& lv) {
|
|
76
|
+
|
|
77
|
+
lv = encodeLV();
|
|
78
|
+
return lv.size();
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
// only for value=0
|
|
83
|
+
std::vector<unsigned char> tlv_buf::encodeT() {
|
|
84
|
+
|
|
85
|
+
std::vector<unsigned char> out;
|
|
86
|
+
|
|
87
|
+
if (tag&0xFF00) {
|
|
88
|
+
out.push_back((tag&0xFF00)>>8);
|
|
89
|
+
out.push_back( tag&0x00FF);
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
out.push_back(tag);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
std::vector<unsigned char> tlv_buf::encodeV() {
|
|
100
|
+
|
|
101
|
+
std::vector<unsigned char> out;
|
|
102
|
+
|
|
103
|
+
if (value.empty()) {
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
out.insert(out.end(), value.begin(), value.end());
|
|
107
|
+
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
size_t tlv_buf::encodeV(std::vector<unsigned char>& v) {
|
|
113
|
+
|
|
114
|
+
v = encodeV();
|
|
115
|
+
return v.size();
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
size_t tlv_buf::decodeLV(const std::vector<unsigned char>& lv, std::vector<unsigned char>& v) {
|
|
120
|
+
|
|
121
|
+
if (lv.empty() || lv.size() != (static_cast<size_t>(lv[0]) + 1)) {
|
|
122
|
+
return 0;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
v.insert(v.end(), lv.begin()+1, lv.end());
|
|
126
|
+
|
|
127
|
+
return v.size();
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
size_t tlv_buf::decodeTV(const int tag, const std::vector<unsigned char>& tv,
|
|
132
|
+
std::vector<unsigned char>& v) {
|
|
133
|
+
|
|
134
|
+
std::vector<unsigned char> vTag;
|
|
135
|
+
|
|
136
|
+
if (tag&0xFF00) {
|
|
137
|
+
vTag.push_back((tag&0xFF00)>>8);
|
|
138
|
+
vTag.push_back( tag&0x00FF);
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
vTag.push_back(tag);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (tv.size() < vTag.size()) {
|
|
145
|
+
return 0;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// using c++11 instead of c++14
|
|
149
|
+
// if (!std::equal(tv.begin(), tv.begin()+vTag.size(), std::begin(vTag))) {
|
|
150
|
+
std::vector<unsigned char> vTv(tv.begin(), tv.begin()+vTag.size());
|
|
151
|
+
if (vTv != vTag) {
|
|
152
|
+
return 0;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
v.clear();
|
|
156
|
+
v.insert(v.end(), tv.begin()+vTag.size(), tv.end());
|
|
157
|
+
|
|
158
|
+
return (tv.size()-vTag.size());
|
|
159
|
+
}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Generic TLV parsing
|
|
3
|
+
*
|
|
4
|
+
* Copyright (C) 2018-2020, JuBiter Limited, All Rights Reserved
|
|
5
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
8
|
+
* not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
15
|
+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*
|
|
19
|
+
* This file is part of JuBiter2.0 (http://www.jubiterwallet.com)
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#ifndef GPC_TLV_PARSE_C
|
|
23
|
+
#define GPC_TLV_PARSE_C
|
|
24
|
+
|
|
25
|
+
#include <stdio.h>
|
|
26
|
+
#include <string.h>
|
|
27
|
+
#include "tag.h"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
/*
|
|
31
|
+
* TLV decoding routines
|
|
32
|
+
*/
|
|
33
|
+
int gpc_tlv_get_tag( unsigned char **p,
|
|
34
|
+
const unsigned char *end,
|
|
35
|
+
unsigned short *tag,
|
|
36
|
+
size_t *len )
|
|
37
|
+
{
|
|
38
|
+
if (!p || !*p || !end || !tag || !len || *len < 2) {
|
|
39
|
+
return GPC_SCP11_ERR_TLV_OUT_OF_DATA;
|
|
40
|
+
}
|
|
41
|
+
const size_t available = *len;
|
|
42
|
+
const unsigned char first = **p;
|
|
43
|
+
size_t header = ((first == 0x5f || first == 0x7f || first == 0xbf) ? 3 : 2);
|
|
44
|
+
if (available < header) return GPC_SCP11_ERR_TLV_OUT_OF_DATA;
|
|
45
|
+
if ((first == 0x7f || first == 0xbf) && (*p)[1] == 0x21) {
|
|
46
|
+
if ((*p)[2] == 0x81) header = 4;
|
|
47
|
+
else if ((*p)[2] == 0x82) header = 5;
|
|
48
|
+
else return GPC_SCP11_ERR_TLV_OUT_OF_DATA;
|
|
49
|
+
}
|
|
50
|
+
if (available < header) return GPC_SCP11_ERR_TLV_OUT_OF_DATA;
|
|
51
|
+
unsigned short _tag = **p;
|
|
52
|
+
unsigned char subTag = (*(*p+1));
|
|
53
|
+
size_t length = (*(*p+1));
|
|
54
|
+
switch( _tag ) {
|
|
55
|
+
case GPC_TLV_SCP11CRT:
|
|
56
|
+
{
|
|
57
|
+
length = (*(*p+2));
|
|
58
|
+
_tag = (GPC_TLV_SCP11CRT <<8) + subTag;
|
|
59
|
+
switch (subTag) {
|
|
60
|
+
case (GPC_TLV_SCP11CRT_ENTITY & 0x00FF): // '7F21' - Table 6-12: Certificate Format
|
|
61
|
+
{
|
|
62
|
+
switch (length) {
|
|
63
|
+
case 0x82:
|
|
64
|
+
{
|
|
65
|
+
length = (*(*p+3)) << 8;
|
|
66
|
+
length |= (*(*p+4)) & 0xFF;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case 0x81:
|
|
70
|
+
{
|
|
71
|
+
length = (*(*p+3));
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
default:
|
|
75
|
+
return( GPC_SCP11_ERR_TLV_OUT_OF_DATA );
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
*tag = _tag;
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
case (GPC_TLV_SCP11CRT_PUBKEY & 0x00FF): // '7F49' - Public Key
|
|
82
|
+
{
|
|
83
|
+
*tag = _tag;
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
default:
|
|
87
|
+
return( GPC_SCP11_ERR_TLV_OUT_OF_DATA );
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
}
|
|
91
|
+
case GPC_TLV_MA_RECEIPT:
|
|
92
|
+
case GPC_TLV_PK_Q:
|
|
93
|
+
case GPC_TLV_PK_PARAM:
|
|
94
|
+
case GPC_TLV_SCP11CRT_CAKLOCID: // '42' - CA-KLOC (or KA-KLOC) Identifier
|
|
95
|
+
case GPC_TLV_SCP11CRT_DISC_53: // '53' - Discretionary Data
|
|
96
|
+
case GPC_TLV_SCP11CRT_DISC_73: // '73' - Discretionary Data
|
|
97
|
+
case GPC_TLV_SCP11CRT_SN: // '93' - Certificate Serial Number
|
|
98
|
+
case GPC_TLV_SCP11CRT_KEYUSAGE: // '95' - Key Usage:
|
|
99
|
+
// '82': Digital signature verification (CERT .KA-KLOC.ECDSA)
|
|
100
|
+
// '00 80': Key agreement (CERT .OCE.ECKA)
|
|
101
|
+
{
|
|
102
|
+
*tag = _tag;
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
case GPC_TLV_SCP11CRT_ITEM:
|
|
106
|
+
{
|
|
107
|
+
length = (*(*p+2));
|
|
108
|
+
_tag = (GPC_TLV_SCP11CRT_ITEM <<8) + subTag;
|
|
109
|
+
switch (subTag) {
|
|
110
|
+
case (GPC_TLV_SCP11CRT_SUBJECTID & 0x00FF): // '5F20' - Subject Identifier
|
|
111
|
+
case (GPC_TLV_SCP11CRT_EXPEDATE & 0x00FF): // '5F24' - Expiration Date (YYYYMMDD, BCD M format)
|
|
112
|
+
case (GPC_TLV_SCP11CRT_EFFEDATE & 0x00FF): // '5F25' - Effective Date (YYYYMMDD, O BCD format)
|
|
113
|
+
case (GPC_TLV_SCP11CRT_SIGNATURE & 0x00FF): // '5F37' - Signature
|
|
114
|
+
case (GPC_TLV_MA_PK & 0x00FF): // '5F49' - ePK.OCE.ECKA
|
|
115
|
+
{
|
|
116
|
+
*tag = _tag;
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
default:
|
|
120
|
+
return( GPC_SCP11_ERR_TLV_OUT_OF_DATA );
|
|
121
|
+
}
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
case GPC_TLV_SCP11CRT_BF:
|
|
125
|
+
{
|
|
126
|
+
length = (*(*p+2));
|
|
127
|
+
_tag = (GPC_TLV_SCP11CRT_BF <<8) + subTag;
|
|
128
|
+
switch (subTag) {
|
|
129
|
+
case (GPC_TLV_SCP11CRT_BF_RESTR & 0x00FF): // 'BF20' - Restrictions under SCP11c
|
|
130
|
+
{
|
|
131
|
+
*tag = _tag;
|
|
132
|
+
break;
|
|
133
|
+
}
|
|
134
|
+
case (GPC_TLV_SCP11CRT_BF_ENTITY & 0x00FF): // 'BF21' - SCP11 certificate store
|
|
135
|
+
{
|
|
136
|
+
switch (length) {
|
|
137
|
+
case 0x82:
|
|
138
|
+
{
|
|
139
|
+
length = (*(*p+3)) << 8;
|
|
140
|
+
length |= (*(*p+4)) & 0xFF;
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
case 0x81:
|
|
144
|
+
{
|
|
145
|
+
length = (*(*p+3));
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
default:
|
|
149
|
+
return( GPC_SCP11_ERR_TLV_OUT_OF_DATA );
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
*tag = _tag;
|
|
153
|
+
break;
|
|
154
|
+
}
|
|
155
|
+
default:
|
|
156
|
+
return( GPC_SCP11_ERR_TLV_OUT_OF_DATA );
|
|
157
|
+
}
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
default:
|
|
161
|
+
return( GPC_SCP11_ERR_TLV_OUT_OF_DATA );
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (length > available - header) {
|
|
165
|
+
return( GPC_SCP11_ERR_TLV_OUT_OF_DATA );
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
*len = length;
|
|
169
|
+
|
|
170
|
+
return( 0 );
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
#endif /* GPC_TLV_PARSE_C */
|
|
File without changes
|
|
@@ -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 = nullptr;
|
|
67
|
+
void *_scp11Ptr = nullptr;
|
|
68
|
+
}; // class JubApduBuiler end
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
} // namespace jub end
|
|
72
|
+
#endif // __ApduBuilder__
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// Recovered subset used by GPChannel; hexadecimal data has no wallet semantics.
|
|
2
|
+
#pragma once
|
|
3
|
+
#include <cstddef>
|
|
4
|
+
#include <stdexcept>
|
|
5
|
+
#include <string>
|
|
6
|
+
#include <vector>
|
|
7
|
+
|
|
8
|
+
class uchar_vector : public std::vector<unsigned char> {
|
|
9
|
+
public:
|
|
10
|
+
using std::vector<unsigned char>::vector;
|
|
11
|
+
uchar_vector(const std::vector<unsigned char>& bytes)
|
|
12
|
+
: std::vector<unsigned char>(bytes) {}
|
|
13
|
+
explicit uchar_vector(const std::string& hex) {
|
|
14
|
+
if (hex.size() % 2) throw std::invalid_argument("Odd hexadecimal length");
|
|
15
|
+
reserve(hex.size() / 2);
|
|
16
|
+
for (size_t i = 0; i < hex.size(); i += 2) {
|
|
17
|
+
push_back(static_cast<unsigned char>((nibble(hex[i]) << 4) | nibble(hex[i + 1])));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
std::string getHex(bool upper = false) const {
|
|
21
|
+
const char* digits = upper ? "0123456789ABCDEF" : "0123456789abcdef";
|
|
22
|
+
std::string hex(size() * 2, '0');
|
|
23
|
+
for (size_t i = 0; i < size(); ++i) {
|
|
24
|
+
hex[i * 2] = digits[(*this)[i] >> 4];
|
|
25
|
+
hex[i * 2 + 1] = digits[(*this)[i] & 15];
|
|
26
|
+
}
|
|
27
|
+
return hex;
|
|
28
|
+
}
|
|
29
|
+
private:
|
|
30
|
+
static unsigned char nibble(char c) {
|
|
31
|
+
if (c >= '0' && c <= '9') return c - '0';
|
|
32
|
+
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
|
33
|
+
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
|
34
|
+
throw std::invalid_argument("Invalid hexadecimal character");
|
|
35
|
+
}
|
|
36
|
+
};
|