@onekeyfe/react-native-lite-card 6.7.0-alpha.448 → 6.7.0-alpha.464
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 +3 -1
- package/ReactNativeLiteCard.podspec +7 -1
- package/android/build.gradle +1 -0
- package/android/consumer-rules.pro +4 -0
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/ReactNativeLiteCardModule.kt +36 -51
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/OnekeyLiteCard.kt +105 -38
- package/ios/Classes/OKNFCBridge.mm +22 -0
- package/ios/Classes/OKNFTLite/OKNFCManager.h +1 -1
- package/ios/Classes/OKNFTLite/OKNFCManager.m +68 -12
- package/ios/ReactNativeLiteCard.mm +5 -2
- package/lib/module/index.js +2 -2
- package/lib/typescript/src/NativeReactNativeLiteCard.d.ts +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/package.json +1 -1
- package/sdk/CMakeLists.txt +4 -3
- package/sdk/README.md +15 -0
- package/sdk/android/implJni.cpp +39 -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/GPChannelSDK.cpp +7 -1
- package/sdk/src/version.c +2 -1
- package/sdk/tests/android_verify.py +4 -1
- package/sdk/tests/safety.cpp +159 -5
- package/sdk/tests/verify.py +21 -4
- package/src/NativeReactNativeLiteCard.ts +1 -0
- package/src/index.tsx +7 -2
|
@@ -27,6 +27,25 @@
|
|
|
27
27
|
#define kChangePinBlock @"kChangePinBlock"
|
|
28
28
|
#define kResetBlock @"kResetBlock"
|
|
29
29
|
|
|
30
|
+
static NSString *backupInputReason(NSString *input, NSUInteger maxBytes) {
|
|
31
|
+
if (!input) return @"missing";
|
|
32
|
+
if (!input.length) return @"empty";
|
|
33
|
+
if (input.length > maxBytes * 2) return @"too_large";
|
|
34
|
+
for (NSUInteger index = 0; index < input.length; ++index) {
|
|
35
|
+
const unichar digit = [input characterAtIndex:index];
|
|
36
|
+
if (!((digit >= '0' && digit <= '9') || (digit >= 'a' && digit <= 'f') ||
|
|
37
|
+
(digit >= 'A' && digit <= 'F'))) return @"non_hex";
|
|
38
|
+
}
|
|
39
|
+
return @"accepted";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
static void logBackupPreflight(NSString *input, BOOL overwrite, NSString *reason, NSInteger version) {
|
|
43
|
+
@try {
|
|
44
|
+
[LCLogger info:[NSString stringWithFormat:@"operation=setMnemonic stage=input_preflight_%@ inputPresent=%d inputChars=%lu odd=%d versionKnown=%d cardVersion=%ld overwrite=%d reason=%@ accepted=%d", version ? @"detected" : @"entry", input != nil, (unsigned long)input.length, input.length % 2 != 0, version != 0, (long)version, overwrite, reason, [reason isEqualToString:@"accepted"]]];
|
|
45
|
+
} @catch (NSException *exception) {
|
|
46
|
+
// Diagnostics must not alter the input decision or callback.
|
|
47
|
+
}
|
|
48
|
+
}
|
|
30
49
|
|
|
31
50
|
|
|
32
51
|
|
|
@@ -146,7 +165,11 @@
|
|
|
146
165
|
}
|
|
147
166
|
} break;
|
|
148
167
|
case OKNFCLiteSessionTypeChangePin: {
|
|
149
|
-
ChangePinCallback callback
|
|
168
|
+
ChangePinCallback callback;
|
|
169
|
+
@synchronized (self) {
|
|
170
|
+
self.expectedSerial = nil;
|
|
171
|
+
callback = [self takeCompletionForKey:kChangePinBlock];
|
|
172
|
+
}
|
|
150
173
|
if (callback) {
|
|
151
174
|
callback(self.lite, asCancel ? OKNFCLiteChangePinStatusCancel : OKNFCLiteChangePinStatusError);
|
|
152
175
|
}
|
|
@@ -279,6 +302,13 @@
|
|
|
279
302
|
expectedSerial:(NSString * _Nullable)expectedSerial
|
|
280
303
|
complete:(SetMnemonicCallback)complete {
|
|
281
304
|
|
|
305
|
+
NSString *reason = backupInputReason(mnemonic, 65535);
|
|
306
|
+
BOOL accepted = [reason isEqualToString:@"accepted"];
|
|
307
|
+
logBackupPreflight(mnemonic, overwrite, reason, 0);
|
|
308
|
+
if (!accepted) {
|
|
309
|
+
complete(nil, OKNFCLiteSetMncStatusError);
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
282
312
|
if (pin.length != OKNFC_PIN_LENGTH) {
|
|
283
313
|
[self logSessionStage:@"input_rejected" details:@"operation=setMnemonic"];
|
|
284
314
|
return;
|
|
@@ -305,6 +335,16 @@
|
|
|
305
335
|
// Clear sensitive data from properties immediately
|
|
306
336
|
self.exportMnemonic = nil;
|
|
307
337
|
self.pin = nil;
|
|
338
|
+
const NSUInteger maxBytes = self.lite.version == OKNFCLiteVersionV2 ? 65511 : 65535;
|
|
339
|
+
NSString *reason = backupInputReason(mnemonic, maxBytes);
|
|
340
|
+
BOOL accepted = [reason isEqualToString:@"accepted"];
|
|
341
|
+
logBackupPreflight(mnemonic, force, reason, self.lite.version + 1);
|
|
342
|
+
if (!accepted) {
|
|
343
|
+
SetMnemonicCallback callback = [self takeCompletionForKey:kSetMnemonicBlock];
|
|
344
|
+
[self endNFCSessionWithError:YES];
|
|
345
|
+
if (callback) callback(nil, OKNFCLiteSetMncStatusError);
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
308
348
|
if (expectedSerial != nil) {
|
|
309
349
|
BOOL infoValid = [self.lite syncLiteInfo];
|
|
310
350
|
if (!infoValid || ![expectedSerial isEqualToString:self.lite.SN]) {
|
|
@@ -352,26 +392,42 @@
|
|
|
352
392
|
|
|
353
393
|
#pragma mark - changePin
|
|
354
394
|
|
|
355
|
-
- (void)changePin:(NSString *)oldPin to:(NSString *)newPin complete:(ChangePinCallback)complete {
|
|
395
|
+
- (void)changePin:(NSString *)oldPin to:(NSString *)newPin expectedSerial:(NSString *)expectedSerial complete:(ChangePinCallback)complete {
|
|
356
396
|
self.pin = oldPin;
|
|
357
397
|
self.neoPin = newPin;
|
|
398
|
+
self.expectedSerial = expectedSerial;
|
|
358
399
|
self.sessionType = OKNFCLiteSessionTypeChangePin;
|
|
359
400
|
[self.completionBlocks setObject:complete forKey:kChangePinBlock];
|
|
360
401
|
[self beginNewNFCSession];
|
|
361
402
|
}
|
|
362
403
|
|
|
363
404
|
- (void)_changePin {
|
|
364
|
-
NSString *oldPin
|
|
365
|
-
NSString *newPin
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
self
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
if (callback)
|
|
373
|
-
|
|
405
|
+
NSString *oldPin;
|
|
406
|
+
NSString *newPin;
|
|
407
|
+
NSString *expectedSerial;
|
|
408
|
+
ChangePinCallback callback;
|
|
409
|
+
@synchronized (self) {
|
|
410
|
+
// Claim the request and its guard together so cancellation cannot
|
|
411
|
+
// turn a late connection into an unguarded PIN change.
|
|
412
|
+
callback = [self takeCompletionForKey:kChangePinBlock];
|
|
413
|
+
if (!callback) return;
|
|
414
|
+
oldPin = self.pin;
|
|
415
|
+
newPin = self.neoPin;
|
|
416
|
+
expectedSerial = self.expectedSerial;
|
|
417
|
+
self.pin = nil;
|
|
418
|
+
self.neoPin = nil;
|
|
419
|
+
self.expectedSerial = nil;
|
|
420
|
+
}
|
|
421
|
+
if (expectedSerial != nil) {
|
|
422
|
+
BOOL infoValid = [self.lite syncLiteInfo];
|
|
423
|
+
if (!infoValid || !self.lite.SN.length || ![expectedSerial isEqualToString:self.lite.SN]) {
|
|
424
|
+
[self endNFCSessionWithError:YES];
|
|
425
|
+
callback(self.lite, infoValid ? OKNFCLiteChangePinStatusSNNotMatch : OKNFCLiteChangePinStatusError);
|
|
426
|
+
return;
|
|
374
427
|
}
|
|
428
|
+
}
|
|
429
|
+
[self.lite changePin:oldPin to:newPin complete:^(OKLiteV1 *lite, OKNFCLiteChangePinStatus status) {
|
|
430
|
+
callback(lite, status);
|
|
375
431
|
}];
|
|
376
432
|
}
|
|
377
433
|
|
|
@@ -175,17 +175,20 @@ static RCTResponseSenderBlock OKLiteCallbackOnce(NSString *operation, RCTRespons
|
|
|
175
175
|
}
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
- (void)changePin:(NSString *)oldPin newPin:(NSString *)newPin callback:(RCTResponseSenderBlock)callBack
|
|
178
|
+
- (void)changePin:(NSString *)oldPin newPin:(NSString *)newPin expectedSerial:(NSString * _Nullable)expectedSerial callback:(RCTResponseSenderBlock)callBack
|
|
179
179
|
{
|
|
180
180
|
callBack = OKLiteCallbackOnce(@"changePin", callBack);
|
|
181
181
|
if ([ReactNativeLiteCard checkSDKVaild:callBack]) {
|
|
182
182
|
__block OKNFCManager *liteManager = [[OKNFCManager alloc] init];
|
|
183
|
-
[liteManager changePin:oldPin to:newPin complete:^(OKLiteV1 *lite, OKNFCLiteChangePinStatus status) {
|
|
183
|
+
[liteManager changePin:oldPin to:newPin expectedSerial:expectedSerial complete:^(OKLiteV1 *lite, OKNFCLiteChangePinStatus status) {
|
|
184
184
|
NSDictionary *cardInfo = [lite cardInfo];
|
|
185
185
|
switch (status) {
|
|
186
186
|
case OKNFCLiteChangePinStatusSuccess: {
|
|
187
187
|
callBack(@[[NSNull null],@(true),cardInfo]);
|
|
188
188
|
} break;
|
|
189
|
+
case OKNFCLiteChangePinStatusSNNotMatch: {
|
|
190
|
+
callBack(@[@{@"code":@(NFCLiteExceptionsDeviceMismatch),@"message":@""},[NSNull null],[NSNull null]]);
|
|
191
|
+
} break;
|
|
189
192
|
case OKNFCLiteChangePinStatusWiped: {
|
|
190
193
|
callBack(@[@{@"code":@(NFCLiteExceptionsAutoReset),@"message":@""},[NSNull null],[NSNull null]]);
|
|
191
194
|
} break;
|
package/lib/module/index.js
CHANGED
|
@@ -36,9 +36,9 @@ class OnekeyLite {
|
|
|
36
36
|
OKLiteManager.getMnemonicWithPin(pwd, this.convertToPromise(resolve));
|
|
37
37
|
});
|
|
38
38
|
}
|
|
39
|
-
changePin(oldPin, newPin) {
|
|
39
|
+
changePin(oldPin, newPin, expectedSerial) {
|
|
40
40
|
return new Promise(resolve => {
|
|
41
|
-
OKLiteManager.changePin(oldPin, newPin, this.convertToPromise(resolve));
|
|
41
|
+
OKLiteManager.changePin(oldPin, newPin, expectedSerial ?? null, this.convertToPromise(resolve));
|
|
42
42
|
});
|
|
43
43
|
}
|
|
44
44
|
reset() {
|
|
@@ -47,7 +47,7 @@ export interface Spec extends TurboModule {
|
|
|
47
47
|
checkNFCPermission(callback: (error: CallbackError | null, data: boolean | null, cardInfo: CardInfo | null) => void): void;
|
|
48
48
|
setMnemonic(mnemonic: string, pwd: string, overwrite: boolean, expectedSerial: string | null, callback: (error: CallbackError | null, data: boolean | null, cardInfo: CardInfo | null) => void): void;
|
|
49
49
|
getMnemonicWithPin(pwd: string, callback: (error: CallbackError | null, data: string | null, cardInfo: CardInfo | null) => void): void;
|
|
50
|
-
changePin(oldPin: string, newPin: string, callback: (error: CallbackError | null, data: boolean | null, cardInfo: CardInfo | null) => void): void;
|
|
50
|
+
changePin(oldPin: string, newPin: string, expectedSerial: string | null, callback: (error: CallbackError | null, data: boolean | null, cardInfo: CardInfo | null) => void): void;
|
|
51
51
|
reset(callback: (error: CallbackError | null, data: boolean | null, cardInfo: CardInfo | null) => void): void;
|
|
52
52
|
cancel(): void;
|
|
53
53
|
intoSetting(): void;
|
|
@@ -11,7 +11,7 @@ declare class OnekeyLite {
|
|
|
11
11
|
checkNFCPermission(): Promise<PromiseResult<boolean>>;
|
|
12
12
|
setMnemonic(mnemonic: string, pwd: string, overwrite?: boolean, expectedSerial?: string): Promise<PromiseResult<boolean>>;
|
|
13
13
|
getMnemonicWithPin(pwd: string): Promise<PromiseResult<string>>;
|
|
14
|
-
changePin(oldPin: string, newPin: string): Promise<PromiseResult<boolean>>;
|
|
14
|
+
changePin(oldPin: string, newPin: string, expectedSerial?: string): Promise<PromiseResult<boolean>>;
|
|
15
15
|
reset(): Promise<PromiseResult<boolean>>;
|
|
16
16
|
convertToPromise<T>(resolve: (value: PromiseResult<T> | PromiseLike<PromiseResult<T>>) => void): (...result: CallbackResult<T>) => void;
|
|
17
17
|
cancel(): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-lite-card",
|
|
3
|
-
"version": "6.7.0-alpha.
|
|
3
|
+
"version": "6.7.0-alpha.464",
|
|
4
4
|
"description": "OneKey Lite NFC card operations and connection events for React Native",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
package/sdk/CMakeLists.txt
CHANGED
|
@@ -4,6 +4,7 @@ set(CMAKE_C_STANDARD 99)
|
|
|
4
4
|
set(CMAKE_CXX_STANDARD 11)
|
|
5
5
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
6
6
|
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
|
|
7
|
+
include(source-id.cmake)
|
|
7
8
|
|
|
8
9
|
# Restore the original source dependencies without linking a vendor binary.
|
|
9
10
|
set(TREZOR_FILES
|
|
@@ -66,12 +67,12 @@ set(TREZOR_FILES
|
|
|
66
67
|
deps/trezor-crypto/src/cmac.c
|
|
67
68
|
)
|
|
68
69
|
add_library(gpchannel_core STATIC
|
|
69
|
-
src/GPChannelSDK.cpp src/ApduBuilder.cpp src/random.c
|
|
70
|
+
src/GPChannelSDK.cpp src/ApduBuilder.cpp src/random.c src/version.c
|
|
70
71
|
gpc/src/scp03.cpp gpc/src/scp11.cpp gpc/src/scp11c.cpp gpc/src/tlv.cpp
|
|
71
72
|
${TREZOR_FILES})
|
|
72
73
|
target_include_directories(gpchannel_core PUBLIC include
|
|
73
|
-
PRIVATE gpc/include deps/trezor-crypto/include deps/trezor-crypto/src)
|
|
74
|
-
add_library(GPChannelSDKCore SHARED
|
|
74
|
+
PRIVATE gpc/include deps/trezor-crypto/include deps/trezor-crypto/src "${GPCHANNEL_GENERATED_INCLUDE}")
|
|
75
|
+
add_library(GPChannelSDKCore SHARED
|
|
75
76
|
include/GPChannelSDK.h include/GPChannelSDKCore.h)
|
|
76
77
|
target_include_directories(GPChannelSDKCore PUBLIC include)
|
|
77
78
|
set_target_properties(GPChannelSDKCore PROPERTIES LINKER_LANGUAGE CXX)
|
package/sdk/README.md
CHANGED
|
@@ -105,6 +105,15 @@ The API has per-call locking; it does not support concurrent independent session
|
|
|
105
105
|
There is no persistent cache. Returned allocations remain caller-owned across
|
|
106
106
|
finalization and must be freed separately.
|
|
107
107
|
|
|
108
|
+
The existing native `GPChannelSDKCoreVersionString` reports
|
|
109
|
+
`source-v1:<SHA256>` for the package source/configuration manifest in
|
|
110
|
+
`source-id-manifest.txt`. CMake regenerates its private header when those inputs
|
|
111
|
+
change; CocoaPods runs the equivalent Ruby generator before compilation. The
|
|
112
|
+
identity is independent of checkout location, keys, user data and build
|
|
113
|
+
environment. It identifies the selected source snapshot, not the binary hash or
|
|
114
|
+
external toolchains. Command-build diagnostics read that compiled native symbol
|
|
115
|
+
and the actual call's return code without logging command data.
|
|
116
|
+
|
|
108
117
|
## Preserved platform differences
|
|
109
118
|
|
|
110
119
|
These were observed against the installed binaries and retained explicitly:
|
|
@@ -165,6 +174,12 @@ On Linux use the `.so` filename. Omit `--reference` for oracle-only verification
|
|
|
165
174
|
The Python dependency is a test tool, not an application/SDK dependency.
|
|
166
175
|
`tests/safety.cpp` exercises 5000 malformed inputs and allocation/lifecycle checks;
|
|
167
176
|
run it with AddressSanitizer/UBSan compiler and linker flags when supported.
|
|
177
|
+
With host JNI enabled it also captures the actual JNI logger calls, checks the
|
|
178
|
+
metadata allowlist and synthetic sensitive-data absence, and verifies logger
|
|
179
|
+
failure does not change build results. From the package root,
|
|
180
|
+
`node tests/ios-input.cjs` covers the production manager/bridge/LCLogger path and
|
|
181
|
+
`node tests/source-id.cjs` checks source identity generation and incremental
|
|
182
|
+
native rebuilding. These checks do not prove physical NFC or minified app logs.
|
|
168
183
|
|
|
169
184
|
`tests/android/GPChannelProxy.java` and `tests/android_verify.py` run the same oracle
|
|
170
185
|
against real Android ART/JNI and a separately loaded original `.so` in an isolated
|
package/sdk/android/implJni.cpp
CHANGED
|
@@ -3,10 +3,48 @@
|
|
|
3
3
|
#include <atomic>
|
|
4
4
|
#include <string>
|
|
5
5
|
#include "GPChannelSDK.h"
|
|
6
|
+
#include "GPChannelSDKCore.h"
|
|
6
7
|
#include "json/json.h"
|
|
7
8
|
|
|
8
9
|
namespace {
|
|
9
10
|
std::atomic<int> errorCode{0};
|
|
11
|
+
std::string sourceIdForLog() {
|
|
12
|
+
const std::string source(reinterpret_cast<const char*>(GPChannelSDKCoreVersionString));
|
|
13
|
+
if (source.size() != 74 || source.compare(0, 10, "source-v1:") != 0 ||
|
|
14
|
+
source.find_first_not_of("0123456789abcdef", 10) != std::string::npos) return "unavailable";
|
|
15
|
+
std::string display = "source-v1:";
|
|
16
|
+
for (size_t offset = 10; offset < source.size(); offset += 8) {
|
|
17
|
+
if (offset != 10) display += '-';
|
|
18
|
+
display.append(source, offset, 8);
|
|
19
|
+
}
|
|
20
|
+
return display;
|
|
21
|
+
}
|
|
22
|
+
void logBuild(JNIEnv* env, bool safe, JUB_RV code, bool outputPresent) {
|
|
23
|
+
// Preserve caller exceptions; only diagnostics-owned lookup/call failures may be cleared.
|
|
24
|
+
if (env->ExceptionCheck()) return;
|
|
25
|
+
try {
|
|
26
|
+
jclass logger = env->FindClass("com/margelo/nitro/nativelogger/OneKeyLog");
|
|
27
|
+
if (logger) {
|
|
28
|
+
jmethodID info = env->GetStaticMethodID(logger, "info", "(Ljava/lang/String;Ljava/lang/String;)V");
|
|
29
|
+
if (info) {
|
|
30
|
+
const std::string message = std::string("stage=command_build nativeSourceId=") +
|
|
31
|
+
sourceIdForLog() +
|
|
32
|
+
" safe=" + (safe ? "true" : "false") +
|
|
33
|
+
" sdkReturnCode=" + std::to_string(code) +
|
|
34
|
+
" outputPresent=" + (outputPresent ? "true" : "false");
|
|
35
|
+
jstring tag = env->NewStringUTF("LiteCard");
|
|
36
|
+
jstring text = tag && !env->ExceptionCheck() ? env->NewStringUTF(message.c_str()) : nullptr;
|
|
37
|
+
if (tag && text && !env->ExceptionCheck()) env->CallStaticVoidMethod(logger, info, tag, text);
|
|
38
|
+
if (tag) env->DeleteLocalRef(tag);
|
|
39
|
+
if (text) env->DeleteLocalRef(text);
|
|
40
|
+
}
|
|
41
|
+
env->DeleteLocalRef(logger);
|
|
42
|
+
}
|
|
43
|
+
} catch (...) {
|
|
44
|
+
// Diagnostics must not replace the actual command result on allocation failure.
|
|
45
|
+
}
|
|
46
|
+
if (env->ExceptionCheck()) env->ExceptionClear();
|
|
47
|
+
}
|
|
10
48
|
class UtfChars {
|
|
11
49
|
public:
|
|
12
50
|
UtfChars(JNIEnv* env, jstring value) : env(env), value(value),
|
|
@@ -87,6 +125,7 @@ jstring build(JNIEnv* env, bool safe, jlong cla, jlong ins, jlong p1, jlong p2,
|
|
|
87
125
|
Output output;
|
|
88
126
|
auto code = safe ? JUB_GPC_BuildSafeAPDU(cla, ins, p1, p2, text.get(), &output.value)
|
|
89
127
|
: JUB_GPC_BuildAPDU(cla, ins, p1, p2, text.get(), &output.value);
|
|
128
|
+
logBuild(env, safe, code, output.value != nullptr);
|
|
90
129
|
return result(env, code, output);
|
|
91
130
|
} catch (...) {
|
|
92
131
|
errorCode.store(static_cast<int>(JUBR_ERROR));
|
|
@@ -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)
|
package/sdk/src/GPChannelSDK.cpp
CHANGED
|
@@ -67,8 +67,14 @@ JUB_RV build(bool safe, JUB_ULONG cla, JUB_ULONG ins, JUB_ULONG p1,
|
|
|
67
67
|
auto result = configure(builder);
|
|
68
68
|
if (result != JUBR_OK) return result;
|
|
69
69
|
}
|
|
70
|
+
if (!hex) return JUBR_ARGUMENTS_BAD;
|
|
71
|
+
const auto length = strnlen(hex, 65535 * 2 + 1);
|
|
72
|
+
if (length > 65535 * 2) return JUBR_ARGUMENTS_BAD;
|
|
73
|
+
// The vendor treats an odd command as a leading zero nibble, not a trailing one.
|
|
74
|
+
const std::string command = length % 2 ? "0" + std::string(hex, length)
|
|
75
|
+
: std::string(hex, length);
|
|
70
76
|
uchar_vector data;
|
|
71
|
-
if (!decodeHex(
|
|
77
|
+
if (!decodeHex(command.c_str(), data)) return JUBR_ARGUMENTS_BAD;
|
|
72
78
|
// Encryption adds up to one AES block and an eight-byte MAC to Lc.
|
|
73
79
|
if (safe && data.size() > 65511) return JUBR_ARGUMENTS_BAD;
|
|
74
80
|
jub::APDU apdu(cla, ins, p1, p2, data.size(), data.data());
|
package/sdk/src/version.c
CHANGED
|
@@ -74,8 +74,11 @@ class AndroidSDK:
|
|
|
74
74
|
return c.string_at(self.buffers.pop(pointer.value)) if pointer.value else None
|
|
75
75
|
|
|
76
76
|
def build(self, name, data, header=(0x80, 0x20, 0, 0)):
|
|
77
|
+
return self.build_hex(name, data.hex(), header)
|
|
78
|
+
|
|
79
|
+
def build_hex(self, name, text, header=(0x80, 0x20, 0, 0)):
|
|
77
80
|
result = self.request("safe" if name == "BuildSafeAPDU" else "build",
|
|
78
|
-
data=
|
|
81
|
+
data=text, **dict(zip(("cla", "ins", "p1", "p2"), header)))
|
|
79
82
|
return result["code"], result["output"].encode() if result["output"] is not None else None
|
|
80
83
|
|
|
81
84
|
def parse(self, name, data):
|