@onekeyfe/react-native-lite-card 6.7.0-4 → 6.7.0-41
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 +12 -2
- 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 +8 -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,492 @@
|
|
|
1
|
+
//
|
|
2
|
+
// scp11.hpp
|
|
3
|
+
// JubSDK
|
|
4
|
+
//
|
|
5
|
+
// Created by Pan Min on 2020/6/9.
|
|
6
|
+
// Copyright © 2020 JuBiter. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef gpc_scp11_hpp
|
|
10
|
+
#define gpc_scp11_hpp
|
|
11
|
+
|
|
12
|
+
#include <stdio.h>
|
|
13
|
+
#include <string.h>
|
|
14
|
+
#include <memory>
|
|
15
|
+
#include <vector>
|
|
16
|
+
|
|
17
|
+
#include <TrezorCrypto/bip32.h>
|
|
18
|
+
#include <TrezorCrypto/curves.h>
|
|
19
|
+
#include <TrezorCrypto/memzero.h>
|
|
20
|
+
|
|
21
|
+
#include "tlv.hpp"
|
|
22
|
+
#include "tag.h"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
enum GPC_TLV_KEY_USAGE {
|
|
26
|
+
CERT_VERIFY = 0x82, // Digital signature verification (CERT .KA-KLOC.ECDSA)
|
|
27
|
+
CERT_AGGREEMENT = 0x80, // Key agreement (CERT .OCE.ECKA)
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* SharedInfo.
|
|
33
|
+
*/
|
|
34
|
+
typedef struct gpc_scp11_sharedInfo {
|
|
35
|
+
|
|
36
|
+
public:
|
|
37
|
+
gpc_scp11_sharedInfo() {
|
|
38
|
+
clear();
|
|
39
|
+
}
|
|
40
|
+
gpc_scp11_sharedInfo(const std::vector<unsigned char>& keyUsage,
|
|
41
|
+
const std::vector<unsigned char>& keyType,
|
|
42
|
+
const std::vector<unsigned char>& keyLength,
|
|
43
|
+
const std::vector<unsigned char>& hostCardID,
|
|
44
|
+
const std::vector<unsigned char>& cardGroupID) {
|
|
45
|
+
key_usage = tlv_buf(GPC_TLV_SHAREDINFO_KEYUSAGE, keyUsage);
|
|
46
|
+
key_type = tlv_buf(GPC_TLV_SHAREDINFO_KEYTYPE, keyType);
|
|
47
|
+
key_length = tlv_buf(GPC_TLV_SHAREDINFO_KEYLENGTH, keyLength);
|
|
48
|
+
host_cardID = tlv_buf(GPC_TLV_SHAREDINFO_HOSTID, hostCardID);
|
|
49
|
+
card_groupID = tlv_buf(cardGroupID);
|
|
50
|
+
}
|
|
51
|
+
gpc_scp11_sharedInfo(const std::vector<unsigned char>& scpIDParam,
|
|
52
|
+
const std::vector<unsigned char>& keyUsage,
|
|
53
|
+
const std::vector<unsigned char>& keyType,
|
|
54
|
+
const std::vector<unsigned char>& keyLength,
|
|
55
|
+
const std::vector<unsigned char>& hostCardID,
|
|
56
|
+
const std::vector<unsigned char>& cardGroupID) {
|
|
57
|
+
scp_id_param = tlv_buf(GPC_TLV_SHAREDINFO_SCP_ID_PARAM, scpIDParam);
|
|
58
|
+
key_usage = tlv_buf(GPC_TLV_SHAREDINFO_KEYUSAGE, keyUsage);
|
|
59
|
+
key_type = tlv_buf(GPC_TLV_SHAREDINFO_KEYTYPE, keyType);
|
|
60
|
+
key_length = tlv_buf(GPC_TLV_SHAREDINFO_KEYLENGTH, keyLength);
|
|
61
|
+
host_cardID = tlv_buf(GPC_TLV_SHAREDINFO_HOSTID, hostCardID);
|
|
62
|
+
card_groupID = tlv_buf(cardGroupID);
|
|
63
|
+
}
|
|
64
|
+
gpc_scp11_sharedInfo(const gpc_scp11_sharedInfo& sharedInfo) {
|
|
65
|
+
*this = sharedInfo;
|
|
66
|
+
}
|
|
67
|
+
~gpc_scp11_sharedInfo() {
|
|
68
|
+
clear();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
gpc_scp11_sharedInfo& operator=(const gpc_scp11_sharedInfo& rhs) {
|
|
72
|
+
this->scp_id_param = rhs.scp_id_param;
|
|
73
|
+
this->key_usage = rhs.key_usage;
|
|
74
|
+
this->key_type = rhs.key_type;
|
|
75
|
+
this->key_length = rhs.key_length;
|
|
76
|
+
this->host_cardID = rhs.host_cardID;
|
|
77
|
+
this->card_groupID = rhs.card_groupID;
|
|
78
|
+
return *this;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
void clear() {
|
|
82
|
+
scp_id_param.clear();
|
|
83
|
+
key_usage.clear();
|
|
84
|
+
key_type.clear();
|
|
85
|
+
key_length.clear();
|
|
86
|
+
host_cardID.clear();
|
|
87
|
+
}
|
|
88
|
+
bool empty() {
|
|
89
|
+
return (scp_id_param.empty()
|
|
90
|
+
|| key_usage.empty()
|
|
91
|
+
|| key_type.empty()
|
|
92
|
+
|| key_length.empty()
|
|
93
|
+
|| host_cardID.empty()
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
bool hasCardGroupID() {
|
|
98
|
+
return card_groupID.empty();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
std::vector<unsigned char> getCardGroupID() {
|
|
102
|
+
return card_groupID.value;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
std::vector<unsigned char> encodeV(const std::vector<unsigned char>& card_groupID);
|
|
106
|
+
size_t encodeV(const std::vector<unsigned char>& card_groupID, std::vector<unsigned char>& v);
|
|
107
|
+
std::vector<unsigned char> encodeLV();
|
|
108
|
+
size_t encodeLV(std::vector<unsigned char>& lv);
|
|
109
|
+
std::vector<unsigned char> encode();
|
|
110
|
+
size_t encode(std::vector<unsigned char>& code);
|
|
111
|
+
|
|
112
|
+
private:
|
|
113
|
+
tlv_buf scp_id_param;
|
|
114
|
+
tlv_buf key_usage;
|
|
115
|
+
tlv_buf key_type;
|
|
116
|
+
tlv_buf key_length;
|
|
117
|
+
tlv_buf host_cardID;
|
|
118
|
+
tlv_buf card_groupID;
|
|
119
|
+
} scp11_sharedInfo;
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* Data for mutual MUTUAL AUTHENTICATE Command.
|
|
124
|
+
*/
|
|
125
|
+
typedef struct gpc_scp11_mutual_auth {
|
|
126
|
+
|
|
127
|
+
public:
|
|
128
|
+
gpc_scp11_mutual_auth() {
|
|
129
|
+
clear();
|
|
130
|
+
}
|
|
131
|
+
gpc_scp11_mutual_auth(const scp11_sharedInfo* psharedInfo,
|
|
132
|
+
const std::vector<unsigned char>& ePk,
|
|
133
|
+
const std::vector<unsigned char>& sdPK={}) {
|
|
134
|
+
std::vector<unsigned char> vSharedInfo = scp11_sharedInfo(*psharedInfo).encode();
|
|
135
|
+
ka = tlv_buf(GPC_TLV_MA_CR, vSharedInfo);
|
|
136
|
+
e_pk = tlv_buf(GPC_TLV_MA_PK, ePk);
|
|
137
|
+
sd_pk = tlv_buf(GPC_TLV_MA_PK,sdPK);
|
|
138
|
+
}
|
|
139
|
+
~gpc_scp11_mutual_auth() {
|
|
140
|
+
clear();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
void clear() {
|
|
144
|
+
sd_pk.clear();
|
|
145
|
+
ka.clear();
|
|
146
|
+
e_pk.clear();
|
|
147
|
+
}
|
|
148
|
+
bool empty() {
|
|
149
|
+
return ( e_pk.empty()
|
|
150
|
+
|| ka.empty()
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
std::vector<unsigned char> encode();
|
|
155
|
+
size_t encode(std::vector<unsigned char>& code);
|
|
156
|
+
|
|
157
|
+
private:
|
|
158
|
+
tlv_buf ka; // Control Reference Template (Key Agreement)
|
|
159
|
+
tlv_buf e_pk; // ePK.OCE.ECKA
|
|
160
|
+
tlv_buf sd_pk; // PK.SD.ECKA
|
|
161
|
+
} scp11_mutual_auth;
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Public key for an TLV certificate.
|
|
166
|
+
*/
|
|
167
|
+
typedef struct gpc_scp11_pk {
|
|
168
|
+
|
|
169
|
+
public:
|
|
170
|
+
gpc_scp11_pk() {
|
|
171
|
+
clear();
|
|
172
|
+
}
|
|
173
|
+
~gpc_scp11_pk() {
|
|
174
|
+
clear();
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
void clear() {
|
|
178
|
+
q.clear();
|
|
179
|
+
param.clear();
|
|
180
|
+
}
|
|
181
|
+
bool empty() {
|
|
182
|
+
return (param.empty()
|
|
183
|
+
|| q.empty()
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/// Decodes the provided buffer into the certificate.
|
|
188
|
+
virtual bool decode(const std::vector<unsigned char>& data);
|
|
189
|
+
|
|
190
|
+
public:
|
|
191
|
+
tlv_buf q;
|
|
192
|
+
tlv_buf param;
|
|
193
|
+
} scp11_pk;
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Container for an X.509 certificate. The certificate may be chained.
|
|
198
|
+
*/
|
|
199
|
+
typedef struct gpc_scp11_crt {
|
|
200
|
+
|
|
201
|
+
public:
|
|
202
|
+
gpc_scp11_crt() {
|
|
203
|
+
next = nullptr;
|
|
204
|
+
clear();
|
|
205
|
+
}
|
|
206
|
+
gpc_scp11_crt(const std::vector<unsigned char>& data) {
|
|
207
|
+
raw.value.assign(data.begin(), data.end());
|
|
208
|
+
decode(data);
|
|
209
|
+
|
|
210
|
+
next = nullptr;
|
|
211
|
+
}
|
|
212
|
+
~gpc_scp11_crt() {
|
|
213
|
+
clear();
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
void clear() {
|
|
217
|
+
raw.clear();
|
|
218
|
+
tbs.clear();
|
|
219
|
+
|
|
220
|
+
serial.clear();
|
|
221
|
+
cakloc_id.clear();
|
|
222
|
+
|
|
223
|
+
valid_from.clear();
|
|
224
|
+
valid_to.clear();
|
|
225
|
+
|
|
226
|
+
pk.clear();
|
|
227
|
+
|
|
228
|
+
subject_id.clear();
|
|
229
|
+
|
|
230
|
+
key_usage = 0;
|
|
231
|
+
|
|
232
|
+
sig.clear();
|
|
233
|
+
|
|
234
|
+
if (next) {
|
|
235
|
+
delete next; next = nullptr;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
bool empty() {
|
|
239
|
+
return ( raw.empty()
|
|
240
|
+
|| tbs.empty()
|
|
241
|
+
|| serial.empty()
|
|
242
|
+
|| cakloc_id.empty()
|
|
243
|
+
|| valid_from.empty()
|
|
244
|
+
|| valid_to.empty()
|
|
245
|
+
|| pk.empty()
|
|
246
|
+
|| subject_id.empty()
|
|
247
|
+
|| sig.empty()
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
/// Decodes the provided buffer into the certificate.
|
|
252
|
+
virtual bool decode(const std::vector<unsigned char>& data);
|
|
253
|
+
virtual bool decode();
|
|
254
|
+
|
|
255
|
+
public:
|
|
256
|
+
tlv_buf raw; /**< The raw certificate data (TLV). */
|
|
257
|
+
tlv_buf tbs; /**< The raw certificate body (TLV). The part that is To Be Signed. */
|
|
258
|
+
|
|
259
|
+
tlv_buf serial; /**< Unique id for certificate issued by a specific CA. */
|
|
260
|
+
tlv_buf cakloc_id;
|
|
261
|
+
|
|
262
|
+
tlv_buf valid_from; /**< Start time of certificate validity. */
|
|
263
|
+
tlv_buf valid_to; /**< End time of certificate validity. */
|
|
264
|
+
|
|
265
|
+
scp11_pk pk; /**< Container for the public key context. */
|
|
266
|
+
|
|
267
|
+
tlv_buf subject_id; /**< Optional TLV certificate subject unique identifier. */
|
|
268
|
+
|
|
269
|
+
unsigned int key_usage; /**< Optional key usage extension value: See the values in scp11_pk.hpp */
|
|
270
|
+
tlv_buf sig; /**< Signature: hash of the tbs part signed with the private key. */
|
|
271
|
+
struct gpc_scp11_crt *next; /**< Next certificate in the CA-chain. */
|
|
272
|
+
} scp11_crt;
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
typedef enum GPC_SCP11_SESSION {
|
|
276
|
+
KEY_DEK = 0,
|
|
277
|
+
S_ENC,
|
|
278
|
+
S_MAC,
|
|
279
|
+
S_RMAC,
|
|
280
|
+
S_DEK
|
|
281
|
+
} ENUM_SCP11_SESSION;
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
typedef struct gpc_scp11_session_key {
|
|
285
|
+
|
|
286
|
+
public:
|
|
287
|
+
gpc_scp11_session_key() {
|
|
288
|
+
clear();
|
|
289
|
+
}
|
|
290
|
+
gpc_scp11_session_key(const std::vector<unsigned char>& raw)
|
|
291
|
+
: raw (0, raw) {
|
|
292
|
+
clear();
|
|
293
|
+
}
|
|
294
|
+
~gpc_scp11_session_key() {
|
|
295
|
+
clear();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
gpc_scp11_session_key& operator=(const gpc_scp11_session_key& rhs) {
|
|
299
|
+
|
|
300
|
+
this->key_dek = rhs.key_dek;
|
|
301
|
+
this->s_enc = rhs.s_enc;
|
|
302
|
+
this->s_mac = rhs.s_mac;
|
|
303
|
+
this->s_rmac = rhs.s_rmac;
|
|
304
|
+
this->s_dek = rhs.s_dek;
|
|
305
|
+
|
|
306
|
+
return *this;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
void clear() {
|
|
310
|
+
if (!key_dek.empty()) memzero(key_dek.data(), key_dek.size());
|
|
311
|
+
if (!s_enc.empty()) memzero(s_enc.data(), s_enc.size());
|
|
312
|
+
if (!s_mac.empty()) memzero(s_mac.data(), s_mac.size());
|
|
313
|
+
if (!s_rmac.empty()) memzero(s_rmac.data(), s_rmac.size());
|
|
314
|
+
if (!s_dek.empty()) memzero(s_dek.data(), s_dek.size());
|
|
315
|
+
key_dek.clear();
|
|
316
|
+
s_enc.clear();
|
|
317
|
+
s_mac.clear();
|
|
318
|
+
s_rmac.clear();
|
|
319
|
+
s_dek.clear();
|
|
320
|
+
}
|
|
321
|
+
bool empty() {
|
|
322
|
+
return ( raw.empty()
|
|
323
|
+
&& ( key_dek.empty()
|
|
324
|
+
|| s_enc.empty()
|
|
325
|
+
|| s_mac.empty()
|
|
326
|
+
|| s_rmac.empty()
|
|
327
|
+
|| s_dek.empty())
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
static int size() {
|
|
332
|
+
return (KEY_LENGTH*N);
|
|
333
|
+
}
|
|
334
|
+
/// Decodes the provided buffer into the scp11_session_key.
|
|
335
|
+
virtual bool decode(const std::vector<unsigned char>& data,
|
|
336
|
+
const int key_length = KEY_LENGTH);
|
|
337
|
+
virtual bool decode();
|
|
338
|
+
virtual std::vector<unsigned char> encode();
|
|
339
|
+
|
|
340
|
+
private:
|
|
341
|
+
tlv_buf raw;
|
|
342
|
+
|
|
343
|
+
public:
|
|
344
|
+
static int N;
|
|
345
|
+
static int KEY_LENGTH;
|
|
346
|
+
|
|
347
|
+
std::vector<unsigned char> key_dek; // Data Encryption Key
|
|
348
|
+
std::vector<unsigned char> s_enc; // Secure Channel session key for command and response encryption
|
|
349
|
+
std::vector<unsigned char> s_mac; // Message Authentication Code
|
|
350
|
+
std::vector<unsigned char> s_rmac; // Response MAC
|
|
351
|
+
std::vector<unsigned char> s_dek; // Session Data Encryption Key
|
|
352
|
+
} scp11_session_key;
|
|
353
|
+
|
|
354
|
+
|
|
355
|
+
typedef struct gpc_scp11_response_msg {
|
|
356
|
+
|
|
357
|
+
public:
|
|
358
|
+
gpc_scp11_response_msg() {
|
|
359
|
+
clear();
|
|
360
|
+
}
|
|
361
|
+
~gpc_scp11_response_msg() {
|
|
362
|
+
clear();
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
void clear() {
|
|
366
|
+
sd_pk.clear();
|
|
367
|
+
receipt.clear();
|
|
368
|
+
}
|
|
369
|
+
bool empty() {
|
|
370
|
+
return ( receipt.empty()
|
|
371
|
+
|| sd_pk.empty()
|
|
372
|
+
);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
bool decode(const std::vector<unsigned char>& data);
|
|
376
|
+
|
|
377
|
+
public:
|
|
378
|
+
tlv_buf sd_pk; // SCP11c: PK.SD.ECKA
|
|
379
|
+
// SCP11a: ePK.SD.ECKA
|
|
380
|
+
tlv_buf receipt; // Receipt
|
|
381
|
+
} scp11_response_msg;
|
|
382
|
+
|
|
383
|
+
|
|
384
|
+
typedef struct gpc_scp11 {
|
|
385
|
+
|
|
386
|
+
public:
|
|
387
|
+
gpc_scp11() {
|
|
388
|
+
clear();
|
|
389
|
+
curi = (curve_info *)get_curve_by_name(NIST256P1_NAME);
|
|
390
|
+
}
|
|
391
|
+
gpc_scp11(const scp11_sharedInfo& info,
|
|
392
|
+
const scp11_crt& crt,
|
|
393
|
+
const std::vector<unsigned char>& rk) {
|
|
394
|
+
clear();
|
|
395
|
+
oce_crt = crt;
|
|
396
|
+
oce_rk = rk;
|
|
397
|
+
shared_info = info;
|
|
398
|
+
curi = (curve_info *)get_curve_by_name(NIST256P1_NAME);
|
|
399
|
+
}
|
|
400
|
+
~gpc_scp11() {
|
|
401
|
+
clear();
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
public:
|
|
405
|
+
void clear() {
|
|
406
|
+
sd_crt.clear();
|
|
407
|
+
|
|
408
|
+
oce_crt.clear();
|
|
409
|
+
if (!oce_rk.empty()) {
|
|
410
|
+
memzero(oce_rk.data(), oce_rk.size());
|
|
411
|
+
}
|
|
412
|
+
oce_rk.clear();
|
|
413
|
+
|
|
414
|
+
reset();
|
|
415
|
+
}
|
|
416
|
+
bool empty() {
|
|
417
|
+
return (shared_info.empty()
|
|
418
|
+
|| oce_crt.empty()
|
|
419
|
+
|| oce_rk.empty()
|
|
420
|
+
);
|
|
421
|
+
}
|
|
422
|
+
bool isValid() {
|
|
423
|
+
return !empty();
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
bool initialize();
|
|
427
|
+
void setResponseMsg(const scp11_response_msg& msg) {
|
|
428
|
+
receipt_key = msg;
|
|
429
|
+
}
|
|
430
|
+
void setSessionKey(const scp11_session_key &session_key) {
|
|
431
|
+
sk = session_key;
|
|
432
|
+
}
|
|
433
|
+
virtual std::vector<unsigned char> getOCECert() {
|
|
434
|
+
return oce_crt.raw.value;
|
|
435
|
+
}
|
|
436
|
+
virtual std::vector<unsigned char> getMacChain() {
|
|
437
|
+
return receipt_key.receipt.value;
|
|
438
|
+
}
|
|
439
|
+
virtual std::vector<unsigned char> getMutualAuthData() = 0;
|
|
440
|
+
virtual bool generateKeyPair(const char *curve_name,
|
|
441
|
+
unsigned char* e_pk, unsigned char*e_rk);
|
|
442
|
+
virtual bool openSecureChannel(const std::vector<unsigned char>& response) = 0;
|
|
443
|
+
virtual bool isOpen() {
|
|
444
|
+
return !sk.empty();
|
|
445
|
+
}
|
|
446
|
+
virtual void clearSession() {
|
|
447
|
+
receipt_key.clear();
|
|
448
|
+
sk.clear();
|
|
449
|
+
}
|
|
450
|
+
virtual void reset() {
|
|
451
|
+
e_pk.clear();
|
|
452
|
+
if (!e_rk.empty()) {
|
|
453
|
+
memzero(e_rk.data(), e_rk.size());
|
|
454
|
+
}
|
|
455
|
+
e_rk.clear();
|
|
456
|
+
receipt_key.clear();
|
|
457
|
+
sk.clear();
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
protected:
|
|
461
|
+
virtual bool keyDerivation(const scp11_response_msg &response_msg, scp11_session_key &session_key) = 0;
|
|
462
|
+
virtual bool checkReceipt(const scp11_response_msg &response_msg, const std::vector<unsigned char> &key_dek) = 0;
|
|
463
|
+
bool _calcShSss(const unsigned char*pk, const unsigned char*rk,
|
|
464
|
+
unsigned char ShSss[SHA1_DIGEST_LENGTH]);
|
|
465
|
+
bool _calcShSes(const unsigned char*pk, const unsigned char*rk,
|
|
466
|
+
unsigned char ShSes[SHA1_DIGEST_LENGTH]);
|
|
467
|
+
|
|
468
|
+
public:
|
|
469
|
+
scp11_session_key sk;
|
|
470
|
+
|
|
471
|
+
protected:
|
|
472
|
+
curve_info *curi;
|
|
473
|
+
scp11_sharedInfo shared_info;
|
|
474
|
+
|
|
475
|
+
scp11_crt sd_crt;
|
|
476
|
+
|
|
477
|
+
scp11_crt oce_crt;
|
|
478
|
+
std::vector<unsigned char> oce_rk;
|
|
479
|
+
|
|
480
|
+
std::vector<unsigned char> e_pk;
|
|
481
|
+
std::vector<unsigned char> e_rk;
|
|
482
|
+
|
|
483
|
+
scp11_response_msg receipt_key;
|
|
484
|
+
} scp11;
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
int kdf2_sha256(unsigned char *z, unsigned int z_len,
|
|
488
|
+
unsigned char *shareinfo, unsigned int shareinfo_len,
|
|
489
|
+
unsigned char *keyout, unsigned int keyout_len);
|
|
490
|
+
|
|
491
|
+
|
|
492
|
+
#endif /* scp11_hpp */
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
//
|
|
2
|
+
// scp11c.hpp
|
|
3
|
+
// JubSDK
|
|
4
|
+
//
|
|
5
|
+
// Created by Pan Min on 2020/6/9.
|
|
6
|
+
// Copyright © 2020 JuBiter. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef gpc_scp11c_hpp
|
|
10
|
+
#define gpc_scp11c_hpp
|
|
11
|
+
|
|
12
|
+
#include <TrezorCrypto/memzero.h>
|
|
13
|
+
#include "scp11/scp11.hpp"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
typedef struct gpc_scp11c
|
|
17
|
+
: public scp11 {
|
|
18
|
+
|
|
19
|
+
public:
|
|
20
|
+
gpc_scp11c() {
|
|
21
|
+
clear();
|
|
22
|
+
curi = (curve_info *)get_curve_by_name(NIST256P1_NAME);
|
|
23
|
+
}
|
|
24
|
+
gpc_scp11c(const scp11_sharedInfo& info,
|
|
25
|
+
const scp11_crt& crt,
|
|
26
|
+
const std::vector<unsigned char>& rk) {
|
|
27
|
+
clear();
|
|
28
|
+
oce_crt = crt;
|
|
29
|
+
oce_rk = rk;
|
|
30
|
+
shared_info = info;
|
|
31
|
+
curi = (curve_info *)get_curve_by_name(NIST256P1_NAME);
|
|
32
|
+
}
|
|
33
|
+
gpc_scp11c(const scp11_sharedInfo& info,
|
|
34
|
+
const scp11_crt& sd,
|
|
35
|
+
const scp11_crt& crt,
|
|
36
|
+
const std::vector<unsigned char>& rk) {
|
|
37
|
+
clear();
|
|
38
|
+
sd_crt = sd;
|
|
39
|
+
oce_crt = crt;
|
|
40
|
+
oce_rk = rk;
|
|
41
|
+
shared_info = info;
|
|
42
|
+
curi = (curve_info *)get_curve_by_name(NIST256P1_NAME);
|
|
43
|
+
}
|
|
44
|
+
~gpc_scp11c() {
|
|
45
|
+
clear();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
virtual std::vector<unsigned char> getMutualAuthData() override;
|
|
50
|
+
virtual bool openSecureChannel(const std::vector<unsigned char>& response) override;
|
|
51
|
+
|
|
52
|
+
protected:
|
|
53
|
+
virtual bool keyDerivation(const scp11_response_msg &response_msg, scp11_session_key &session_key) override;
|
|
54
|
+
virtual bool checkReceipt(const scp11_response_msg &response_msg, const std::vector<unsigned char> &key_dek) override;
|
|
55
|
+
} scp11c;
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
#endif /* scp11c_hpp */
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
//
|
|
2
|
+
// tag.hpp
|
|
3
|
+
// JubSDK
|
|
4
|
+
//
|
|
5
|
+
// Created by Pan Min on 2020/6/9.
|
|
6
|
+
// Copyright © 2020 JuBiter. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef gpc_tag_h
|
|
10
|
+
#define gpc_tag_h
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* \name TLV Error codes
|
|
15
|
+
* These error codes are OR'ed to X509 error codes for
|
|
16
|
+
* higher error granularity.
|
|
17
|
+
* ASN1 is a standard to specify data structures.
|
|
18
|
+
* \{
|
|
19
|
+
*/
|
|
20
|
+
#define GPC_SCP11_ERR_TLV_OUT_OF_DATA -0x0060 /**< Out of data when parsing an TLV data structure. */
|
|
21
|
+
#define GPC_SCP11_ERR_TLV_UNEXPECTED_TAG -0x0062 /**< ASN1 tag was of an unexpected value. */
|
|
22
|
+
#define GPC_SCP11_ERR_TLV_INVALID_LENGTH -0x0064 /**< Error when trying to determine the length or invalid length. */
|
|
23
|
+
#define GPC_SCP11_ERR_TLV_LENGTH_MISMATCH -0x0066 /**< Actual length differs from expected length. */
|
|
24
|
+
#define GPC_SCP11_ERR_TLV_INVALID_DATA -0x0068 /**< Data is invalid. (not used) */
|
|
25
|
+
#define GPC_SCP11_ERR_TLV_ALLOC_FAILED -0x006A /**< Memory allocation failed */
|
|
26
|
+
#define GPC_SCP11_ERR_TLV_BUF_TOO_SMALL -0x006C /**< Buffer too small when writing TLV data structure. */
|
|
27
|
+
|
|
28
|
+
#define GPC_TLV_BOOLEAN 0x01
|
|
29
|
+
|
|
30
|
+
// SharedInfo
|
|
31
|
+
#define GPC_TLV_SHAREDINFO_SCP_ID_PARAM 0x90
|
|
32
|
+
#define GPC_TLV_SHAREDINFO_KEYUSAGE 0x95
|
|
33
|
+
#define GPC_TLV_SHAREDINFO_KEYTYPE 0x80
|
|
34
|
+
#define GPC_TLV_SHAREDINFO_KEYLENGTH 0x81
|
|
35
|
+
#define GPC_TLV_SHAREDINFO_HOSTID 0x84
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// MUTUAL AUTHENTICATE Data Field
|
|
39
|
+
#define GPC_TLV_MA_CR 0xA6
|
|
40
|
+
#define GPC_TLV_MA_PK 0x5F49
|
|
41
|
+
#define GPC_TLV_MA_RECEIPT 0x86
|
|
42
|
+
|
|
43
|
+
// scp11 crt
|
|
44
|
+
#define GPC_TLV_SCP11CRT 0x7F
|
|
45
|
+
#define GPC_TLV_SCP11CRT_ENTITY 0x7F21
|
|
46
|
+
#define GPC_TLV_SCP11CRT_PUBKEY 0x7F49
|
|
47
|
+
|
|
48
|
+
#define GPC_TLV_SCP11CRT_CAKLOCID 0x42
|
|
49
|
+
#define GPC_TLV_SCP11CRT_DISC_53 0x53
|
|
50
|
+
#define GPC_TLV_SCP11CRT_DISC_73 0x73
|
|
51
|
+
#define GPC_TLV_SCP11CRT_SN 0x93
|
|
52
|
+
#define GPC_TLV_SCP11CRT_KEYUSAGE 0x95
|
|
53
|
+
|
|
54
|
+
#define GPC_TLV_SCP11CRT_ITEM 0x5F
|
|
55
|
+
#define GPC_TLV_SCP11CRT_SUBJECTID 0x5F20
|
|
56
|
+
#define GPC_TLV_SCP11CRT_EXPEDATE 0x5F24
|
|
57
|
+
#define GPC_TLV_SCP11CRT_EFFEDATE 0x5F25
|
|
58
|
+
#define GPC_TLV_SCP11CRT_SIGNATURE 0x5F37
|
|
59
|
+
|
|
60
|
+
#define GPC_TLV_SCP11CRT_BF 0xBF
|
|
61
|
+
#define GPC_TLV_SCP11CRT_BF_RESTR 0xBF20
|
|
62
|
+
#define GPC_TLV_SCP11CRT_BF_ENTITY 0xBF21
|
|
63
|
+
|
|
64
|
+
#define GPC_TLV_PK_Q 0xB0
|
|
65
|
+
#define GPC_TLV_PK_PARAM 0xF0
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
#endif /* gpc_tag_h */
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
//
|
|
2
|
+
// tlv.hpp
|
|
3
|
+
// JubSDK
|
|
4
|
+
//
|
|
5
|
+
// Created by Pan Min on 2020/6/24.
|
|
6
|
+
// Copyright © 2020 JuBiter. All rights reserved.
|
|
7
|
+
//
|
|
8
|
+
|
|
9
|
+
#ifndef tlv_hpp
|
|
10
|
+
#define tlv_hpp
|
|
11
|
+
|
|
12
|
+
#include <stdio.h>
|
|
13
|
+
#include <vector>
|
|
14
|
+
|
|
15
|
+
typedef struct gpc_tlv_buf {
|
|
16
|
+
|
|
17
|
+
public:
|
|
18
|
+
gpc_tlv_buf() {
|
|
19
|
+
clear();
|
|
20
|
+
}
|
|
21
|
+
gpc_tlv_buf(const int t, const unsigned char& v) :
|
|
22
|
+
tag(t) {
|
|
23
|
+
value.push_back(v);
|
|
24
|
+
}
|
|
25
|
+
gpc_tlv_buf(const int t, const std::vector<unsigned char>& v) :
|
|
26
|
+
tag(t),
|
|
27
|
+
value(v) {}
|
|
28
|
+
gpc_tlv_buf(const int t) :
|
|
29
|
+
tag(t),
|
|
30
|
+
value(0) {}
|
|
31
|
+
gpc_tlv_buf(const std::vector<unsigned char>& v) :
|
|
32
|
+
tag(0x00),
|
|
33
|
+
value(v) {}
|
|
34
|
+
~gpc_tlv_buf() {
|
|
35
|
+
clear();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
bool operator==(const std::vector<unsigned char>& rhs) const {
|
|
39
|
+
return (value == rhs);
|
|
40
|
+
}
|
|
41
|
+
bool operator==(const gpc_tlv_buf& rhs) const {
|
|
42
|
+
if (!((*this) == rhs.value)
|
|
43
|
+
|| tag != rhs.tag
|
|
44
|
+
) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
bool operator!=(const std::vector<unsigned char>& rhs) const {
|
|
52
|
+
return !((*this) == rhs);
|
|
53
|
+
}
|
|
54
|
+
bool operator!=(const gpc_tlv_buf& rhs) const {
|
|
55
|
+
return !((*this) == rhs);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
gpc_tlv_buf& operator=(const gpc_tlv_buf& rhs) {
|
|
59
|
+
this->tag = rhs.tag;
|
|
60
|
+
this->value.clear();
|
|
61
|
+
this->value.insert(std::end(this->value), std::begin(rhs.value), std::end(rhs.value));
|
|
62
|
+
return *this;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
void clear() {
|
|
66
|
+
tag = 0;
|
|
67
|
+
value.clear();
|
|
68
|
+
}
|
|
69
|
+
bool empty() {
|
|
70
|
+
return value.empty();
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
std::vector<unsigned char> encodeV();
|
|
74
|
+
size_t encodeV(std::vector<unsigned char>& v);
|
|
75
|
+
// push_back '00' if value is empty.
|
|
76
|
+
std::vector<unsigned char> encodeTBAV();
|
|
77
|
+
// push_back nothing if value is empty.
|
|
78
|
+
std::vector<unsigned char> encodeLV();
|
|
79
|
+
// only for value=0
|
|
80
|
+
std::vector<unsigned char> encodeT();
|
|
81
|
+
size_t encodeLV(std::vector<unsigned char>& lv);
|
|
82
|
+
std::vector<unsigned char> encode();
|
|
83
|
+
size_t encode(std::vector<unsigned char>& code);
|
|
84
|
+
|
|
85
|
+
static size_t decodeLV(const std::vector<unsigned char>& lv, std::vector<unsigned char>& v);
|
|
86
|
+
static size_t decodeTV(const int tag, const std::vector<unsigned char>& tv, std::vector<unsigned char>& v);
|
|
87
|
+
|
|
88
|
+
public:
|
|
89
|
+
int tag; /**< TLV type, e.g. TLV_UTF8_STRING. */
|
|
90
|
+
std::vector<unsigned char> value; /**< TLV data, e.g. in ASCII. */
|
|
91
|
+
} tlv_buf;
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
#endif /* tlv_hpp */
|