@onekeyfe/react-native-lite-card 6.7.0-alpha.449 → 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 +37 -44
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/OnekeyLiteCard.kt +105 -38
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/CommandGenerator.kt +19 -1
- package/android/src/main/java/com/onekeyfe/reactnativelitecard/onekeyLite/nfc/Connection.kt +10 -2
- package/ios/Classes/OKLiteCommand/OKLiteCommandTool.m +34 -0
- package/ios/Classes/OKNFCBridge.mm +23 -0
- package/ios/Classes/OKNFTLite/OKLiteV1.m +13 -6
- package/ios/Classes/OKNFTLite/OKNFCManager.h +2 -2
- package/ios/Classes/OKNFTLite/OKNFCManager.m +84 -12
- package/ios/ReactNativeLiteCard.mm +7 -4
- package/lib/module/index.js +4 -4
- package/lib/typescript/src/NativeReactNativeLiteCard.d.ts +2 -2
- package/lib/typescript/src/index.d.ts +2 -2
- 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 +2 -0
- package/src/index.tsx +14 -3
|
@@ -8,6 +8,28 @@
|
|
|
8
8
|
#import "OKLiteCommandTool.h"
|
|
9
9
|
#import "OKNFCBridge.h"
|
|
10
10
|
#import "OKNFCUtility.h"
|
|
11
|
+
#import "LCLogger.h"
|
|
12
|
+
|
|
13
|
+
static NSString *OKLiteCommandName(OKLiteCommand command) {
|
|
14
|
+
switch (command) {
|
|
15
|
+
case OKLiteCommandSelectSecure: return @"select_secure";
|
|
16
|
+
case OKLiteCommandSelectBackup: return @"select_backup";
|
|
17
|
+
case OKLiteCommandGetCardSN: return @"get_serial";
|
|
18
|
+
case OKLiteCommandGetCardCert: return @"get_certificate";
|
|
19
|
+
case OKLiteCommandGetBackupStatus: return @"get_backup_status";
|
|
20
|
+
case OKLiteCommandGetPINStatus: return @"get_pin_status";
|
|
21
|
+
case OKLiteCommandSetPIN: return @"set_pin";
|
|
22
|
+
case OKLiteCommandChangePIN: return @"change_pin";
|
|
23
|
+
case OKLiteCommandVerifyPIN: return @"verify_pin";
|
|
24
|
+
case OKLiteCommandImportMnemonic: return @"backup_data";
|
|
25
|
+
case OKLiteCommandExportMnemonic: return @"export_data";
|
|
26
|
+
case OKLiteCommandWipeCard: return @"reset_card";
|
|
27
|
+
case OKLiteCommandPinRTL: return @"get_pin_retry_count";
|
|
28
|
+
case OKLiteCommandOpenChannel_1: return @"verify_certificate";
|
|
29
|
+
case OKLiteCommandOpenChannel_2: return @"verify_auth_data";
|
|
30
|
+
}
|
|
31
|
+
return @"unknown";
|
|
32
|
+
}
|
|
11
33
|
|
|
12
34
|
@implementation OKLiteCommandTool
|
|
13
35
|
|
|
@@ -15,8 +37,15 @@
|
|
|
15
37
|
modal:(OKLiteCommandModal *)modal
|
|
16
38
|
completionHandler:(void(^)(NSData *responseData, uint8_t sw1, uint8_t sw2, NSError * _Nullable error, NSString *parseRespon))completionHandler {
|
|
17
39
|
|
|
40
|
+
static NSUInteger nextCommandID = 0;
|
|
41
|
+
NSUInteger commandID;
|
|
42
|
+
@synchronized (OKLiteCommandTool.class) { commandID = ++nextCommandID; }
|
|
43
|
+
NSString *command = OKLiteCommandName(modal.command);
|
|
44
|
+
[LCLogger info:[NSString stringWithFormat:@"commandID=%lu command=%@ stage=send buildSucceeded=%d parseRequested=%d", (unsigned long)commandID, command, apdu != nil, modal.parseResp]];
|
|
18
45
|
id<NFCISO7816Tag> tag = [self.delegate getNFCsessionTag];
|
|
19
46
|
[tag sendCommandAPDU:apdu completionHandler:^(NSData *responseData, uint8_t sw1, uint8_t sw2, NSError *error) {
|
|
47
|
+
uint8_t rawSW1 = sw1;
|
|
48
|
+
uint8_t rawSW2 = sw2;
|
|
20
49
|
NSString *parseRespon = nil;
|
|
21
50
|
if (modal.parseResp) {
|
|
22
51
|
parseRespon = [OKNFCBridge parseSafeAPDUResponse:responseData sw1:sw1 sw2:sw2];
|
|
@@ -25,6 +54,11 @@
|
|
|
25
54
|
}
|
|
26
55
|
}
|
|
27
56
|
|
|
57
|
+
BOOL coreNFCError = [error.domain isEqualToString:NFCErrorDomain];
|
|
58
|
+
[LCLogger info:[NSString stringWithFormat:@"commandID=%lu command=%@ stage=response rawSW1=%u rawSW2=%u effectiveSW1=%u effectiveSW2=%u responseDataBytes=%lu parseRequested=%d parsePresent=%d transportError=%d coreNFCError=%d errorCode=%ld", (unsigned long)commandID, command, rawSW1, rawSW2, sw1, sw2, (unsigned long)responseData.length, modal.parseResp, parseRespon != nil, error != nil, coreNFCError, (long)error.code]];
|
|
59
|
+
if (modal.command == OKLiteCommandGetBackupStatus || modal.command == OKLiteCommandGetPINStatus) {
|
|
60
|
+
[LCLogger info:[NSString stringWithFormat:@"commandID=%lu command=%@ stage=state_read readSucceeded=%d", (unsigned long)commandID, command, error == nil && sw1 == OKNFC_SW1_OK && responseData.length > 0]];
|
|
61
|
+
}
|
|
28
62
|
[OKNFCUtility logAPDU:modal.desc response:responseData sw1:sw1 sw2:sw2 error:error];
|
|
29
63
|
if (completionHandler) {
|
|
30
64
|
completionHandler(responseData,sw1,sw2,error,parseRespon);
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
#if !TARGET_OS_SIMULATOR
|
|
10
10
|
|
|
11
11
|
#import "GPChannelSDK.h"
|
|
12
|
+
#import "GPChannelSDKCore.h"
|
|
12
13
|
#import "OKNFCLiteDefine.h"
|
|
13
14
|
#import "NFCConfig.h"
|
|
14
15
|
|
|
@@ -19,6 +20,22 @@
|
|
|
19
20
|
#import "OKNFCBridge.h"
|
|
20
21
|
#import "LCLogger.h"
|
|
21
22
|
|
|
23
|
+
#if !TARGET_OS_SIMULATOR
|
|
24
|
+
static NSString *sourceIdForLog() {
|
|
25
|
+
NSString *source = [NSString stringWithUTF8String:(const char *)GPChannelSDKCoreVersionString];
|
|
26
|
+
if (source.length != 74 || ![source hasPrefix:@"source-v1:"]) return @"unavailable";
|
|
27
|
+
for (NSUInteger index = 10; index < source.length; ++index) {
|
|
28
|
+
unichar digit = [source characterAtIndex:index];
|
|
29
|
+
if (!((digit >= '0' && digit <= '9') || (digit >= 'a' && digit <= 'f'))) return @"unavailable";
|
|
30
|
+
}
|
|
31
|
+
NSMutableArray<NSString *> *groups = [NSMutableArray array];
|
|
32
|
+
for (NSUInteger offset = 10; offset < source.length; offset += 8) {
|
|
33
|
+
[groups addObject:[source substringWithRange:NSMakeRange(offset, 8)]];
|
|
34
|
+
}
|
|
35
|
+
return [@"source-v1:" stringByAppendingString:[groups componentsJoinedByString:@"-"]];
|
|
36
|
+
}
|
|
37
|
+
#endif
|
|
38
|
+
|
|
22
39
|
@implementation OKNFCBridge
|
|
23
40
|
|
|
24
41
|
#if !TARGET_OS_SIMULATOR
|
|
@@ -39,6 +56,11 @@
|
|
|
39
56
|
} else {
|
|
40
57
|
rv = JUB_GPC_BuildAPDU(cla, ins, p1, p2, c_data, &c_apdu);
|
|
41
58
|
}
|
|
59
|
+
@try {
|
|
60
|
+
[LCLogger info:[NSString stringWithFormat:@"stage=command_build nativeSourceId=%@ safe=%d sdkReturnCode=%lu outputPresent=%d", sourceIdForLog(), encrypt, (unsigned long)rv, c_apdu != nullptr]];
|
|
61
|
+
} @catch (NSException *exception) {
|
|
62
|
+
// Diagnostics must not replace the SDK result.
|
|
63
|
+
}
|
|
42
64
|
|
|
43
65
|
if (JUBR_OK != rv) {
|
|
44
66
|
return nil;
|
|
@@ -64,6 +86,7 @@
|
|
|
64
86
|
JUB_UINT16 wRet = 0;
|
|
65
87
|
JUB_CHAR_PTR pDecResp = nullptr;
|
|
66
88
|
rv = JUB_GPC_ParseSafeAPDUResponse(c_data ,&wRet, &pDecResp);
|
|
89
|
+
[LCLogger info:[NSString stringWithFormat:@"stage=parse_safe_response parseReturnCode=%lu parsedSW=%u parsePresent=%d", (unsigned long)rv, wRet, pDecResp != nullptr]];
|
|
67
90
|
if (JUBR_OK != rv) {
|
|
68
91
|
return nil;
|
|
69
92
|
}
|
|
@@ -98,6 +98,7 @@
|
|
|
98
98
|
|
|
99
99
|
- (BOOL)syncLiteInfo {
|
|
100
100
|
|
|
101
|
+
self.status = OKNFCLiteStatusError;
|
|
101
102
|
OKNFCLiteStatus status = OKNFCLiteStatusError;
|
|
102
103
|
self.pinRTL = 0;
|
|
103
104
|
NSUInteger PinStatus = OKNFC_PIN_ERROR;
|
|
@@ -112,6 +113,11 @@
|
|
|
112
113
|
return NO;
|
|
113
114
|
}
|
|
114
115
|
PinStatus = [self getPINStatus];
|
|
116
|
+
[LCLogger info:[NSString stringWithFormat:@"stage=pin_state_read readSucceeded=%d", PinStatus != OKNFC_PIN_ERROR]];
|
|
117
|
+
if (PinStatus == OKNFC_PIN_ERROR) {
|
|
118
|
+
self.status = OKNFCLiteStatusError;
|
|
119
|
+
return NO;
|
|
120
|
+
}
|
|
115
121
|
status = PinStatus == OKNFC_PIN_UNSET ? OKNFCLiteStatusNewCard : OKNFCLiteStatusActivated;
|
|
116
122
|
self.status = status;
|
|
117
123
|
self.pinRTL = PinStatus == OKNFC_PIN_UNSET ? 10 : PinStatus;
|
|
@@ -489,7 +495,7 @@
|
|
|
489
495
|
[self.commandTool sendCommandWithAPDU:[modal buildAPDU]
|
|
490
496
|
modal:modal
|
|
491
497
|
completionHandler:^(NSData * _Nonnull responseData, uint8_t sw1, uint8_t sw2, NSError * _Nullable error, NSString * _Nonnull parseRespon) {
|
|
492
|
-
if (sw1 != OKNFC_SW1_OK) {
|
|
498
|
+
if (error != nil || sw1 != OKNFC_SW1_OK || responseData.length == 0) {
|
|
493
499
|
[LCLogger error:@"获取 PIN 状态失败"];
|
|
494
500
|
dispatch_semaphore_signal(sema);
|
|
495
501
|
return;
|
|
@@ -501,12 +507,13 @@
|
|
|
501
507
|
return;
|
|
502
508
|
} else {
|
|
503
509
|
OKLiteCommandModal *modal2 = [[OKLiteCommandModal alloc] initWithCommand:OKLiteCommandPinRTL version:self.version];
|
|
504
|
-
[self.commandTool sendCommandWithAPDU:[modal2 buildAPDU] modal:
|
|
505
|
-
if (sw1 == OKNFC_SW1_OK) {
|
|
506
|
-
unsigned int outVal;
|
|
510
|
+
[self.commandTool sendCommandWithAPDU:[modal2 buildAPDU] modal:modal2 completionHandler:^(NSData * _Nonnull responseData, uint8_t sw1, uint8_t sw2, NSError * _Nullable error, NSString * _Nonnull parseRespon) {
|
|
511
|
+
if (error == nil && sw1 == OKNFC_SW1_OK && responseData.length > 0) {
|
|
512
|
+
unsigned int outVal = 0;
|
|
507
513
|
NSScanner* scanner = [NSScanner scannerWithString:responseData.toHexString];
|
|
508
|
-
[scanner scanHexInt:&outVal]
|
|
509
|
-
|
|
514
|
+
if ([scanner scanHexInt:&outVal]) {
|
|
515
|
+
pinStatus = outVal;
|
|
516
|
+
}
|
|
510
517
|
}
|
|
511
518
|
dispatch_semaphore_signal(sema);
|
|
512
519
|
}];
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
|
|
31
31
|
- (void)reset:(ResetCallback)callBack;
|
|
32
32
|
|
|
33
|
-
- (void)setMnemonic:(NSString *)mnemonic withPin:(NSString *)pin overwrite:(BOOL)overwrite complete:(SetMnemonicCallback)complete;
|
|
33
|
+
- (void)setMnemonic:(NSString *)mnemonic withPin:(NSString *)pin overwrite:(BOOL)overwrite expectedSerial:(NSString * _Nullable)expectedSerial complete:(SetMnemonicCallback)complete;
|
|
34
34
|
|
|
35
35
|
- (void)getMnemonicWithPin:(NSString *)pin complete:(GetMnemonicCallback)complete;
|
|
36
36
|
|
|
37
|
-
- (void)changePin:(NSString *)oldPin to:(NSString *)newPin complete:(ChangePinCallback)complete;
|
|
37
|
+
- (void)changePin:(NSString *)oldPin to:(NSString *)newPin expectedSerial:(NSString * _Nullable)expectedSerial complete:(ChangePinCallback)complete;
|
|
38
38
|
|
|
39
39
|
|
|
40
40
|
@end
|
|
@@ -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
|
|
|
@@ -37,6 +56,7 @@
|
|
|
37
56
|
@property (nonatomic, copy) NSString *pin;
|
|
38
57
|
@property (nonatomic, copy) NSString *neoPin;
|
|
39
58
|
@property (nonatomic, copy) NSString *exportMnemonic;
|
|
59
|
+
@property (nonatomic, copy) NSString *expectedSerial;
|
|
40
60
|
@property (nonatomic, assign) BOOL certVerified;
|
|
41
61
|
@property (nonatomic, assign) OKNFCLiteApp selectNFCApp;
|
|
42
62
|
@property (nonatomic, strong) OKLiteV1 *lite;
|
|
@@ -132,6 +152,7 @@
|
|
|
132
152
|
} break;
|
|
133
153
|
case OKNFCLiteSessionTypeSetMnemonic:
|
|
134
154
|
case OKNFCLiteSessionTypeSetMnemonicForce: {
|
|
155
|
+
self.expectedSerial = nil;
|
|
135
156
|
SetMnemonicCallback callback = [self takeCompletionForKey:kSetMnemonicBlock];
|
|
136
157
|
if (callback) {
|
|
137
158
|
callback(self.lite, asCancel ? OKNFCLiteSetMncStatusCancel : OKNFCLiteSetMncStatusError);
|
|
@@ -144,7 +165,11 @@
|
|
|
144
165
|
}
|
|
145
166
|
} break;
|
|
146
167
|
case OKNFCLiteSessionTypeChangePin: {
|
|
147
|
-
ChangePinCallback callback
|
|
168
|
+
ChangePinCallback callback;
|
|
169
|
+
@synchronized (self) {
|
|
170
|
+
self.expectedSerial = nil;
|
|
171
|
+
callback = [self takeCompletionForKey:kChangePinBlock];
|
|
172
|
+
}
|
|
148
173
|
if (callback) {
|
|
149
174
|
callback(self.lite, asCancel ? OKNFCLiteChangePinStatusCancel : OKNFCLiteChangePinStatusError);
|
|
150
175
|
}
|
|
@@ -274,14 +299,23 @@
|
|
|
274
299
|
- (void)setMnemonic:(NSString *)mnemonic
|
|
275
300
|
withPin:(NSString *)pin
|
|
276
301
|
overwrite:(BOOL)overwrite
|
|
302
|
+
expectedSerial:(NSString * _Nullable)expectedSerial
|
|
277
303
|
complete:(SetMnemonicCallback)complete {
|
|
278
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
|
+
}
|
|
279
312
|
if (pin.length != OKNFC_PIN_LENGTH) {
|
|
280
313
|
[self logSessionStage:@"input_rejected" details:@"operation=setMnemonic"];
|
|
281
314
|
return;
|
|
282
315
|
}
|
|
283
316
|
self.pin = pin;
|
|
284
317
|
self.exportMnemonic = mnemonic;
|
|
318
|
+
self.expectedSerial = expectedSerial;
|
|
285
319
|
if(overwrite) {
|
|
286
320
|
// 写入强制覆盖
|
|
287
321
|
self.sessionType = OKNFCLiteSessionTypeSetMnemonicForce;
|
|
@@ -296,9 +330,31 @@
|
|
|
296
330
|
- (void)_setMnemonic:(BOOL)force {
|
|
297
331
|
NSString *mnemonic = self.exportMnemonic;
|
|
298
332
|
NSString *pin = self.pin;
|
|
333
|
+
NSString *expectedSerial = self.expectedSerial;
|
|
334
|
+
self.expectedSerial = nil;
|
|
299
335
|
// Clear sensitive data from properties immediately
|
|
300
336
|
self.exportMnemonic = nil;
|
|
301
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
|
+
}
|
|
348
|
+
if (expectedSerial != nil) {
|
|
349
|
+
BOOL infoValid = [self.lite syncLiteInfo];
|
|
350
|
+
if (!infoValid || ![expectedSerial isEqualToString:self.lite.SN]) {
|
|
351
|
+
[self logSessionStage:infoValid ? @"identity_mismatch" : @"identity_read_failed" details:@"operation=setMnemonic"];
|
|
352
|
+
SetMnemonicCallback callback = [self takeCompletionForKey:kSetMnemonicBlock];
|
|
353
|
+
[self endNFCSessionWithError:YES];
|
|
354
|
+
if (callback) callback(self.lite, infoValid ? OKNFCLiteSetMncStatusSNNotMatch : OKNFCLiteSetMncStatusError);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
302
358
|
__weak typeof(self) weakSelf = self;
|
|
303
359
|
[self.lite setMnemonic:mnemonic withPin:pin overwrite:force complete:^(OKLiteV1 *lite, OKNFCLiteSetMncStatus status) {
|
|
304
360
|
SetMnemonicCallback callback = [weakSelf takeCompletionForKey:kSetMnemonicBlock];
|
|
@@ -336,26 +392,42 @@
|
|
|
336
392
|
|
|
337
393
|
#pragma mark - changePin
|
|
338
394
|
|
|
339
|
-
- (void)changePin:(NSString *)oldPin to:(NSString *)newPin complete:(ChangePinCallback)complete {
|
|
395
|
+
- (void)changePin:(NSString *)oldPin to:(NSString *)newPin expectedSerial:(NSString *)expectedSerial complete:(ChangePinCallback)complete {
|
|
340
396
|
self.pin = oldPin;
|
|
341
397
|
self.neoPin = newPin;
|
|
398
|
+
self.expectedSerial = expectedSerial;
|
|
342
399
|
self.sessionType = OKNFCLiteSessionTypeChangePin;
|
|
343
400
|
[self.completionBlocks setObject:complete forKey:kChangePinBlock];
|
|
344
401
|
[self beginNewNFCSession];
|
|
345
402
|
}
|
|
346
403
|
|
|
347
404
|
- (void)_changePin {
|
|
348
|
-
NSString *oldPin
|
|
349
|
-
NSString *newPin
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
self
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
if (callback)
|
|
357
|
-
|
|
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;
|
|
358
427
|
}
|
|
428
|
+
}
|
|
429
|
+
[self.lite changePin:oldPin to:newPin complete:^(OKLiteV1 *lite, OKNFCLiteChangePinStatus status) {
|
|
430
|
+
callback(lite, status);
|
|
359
431
|
}];
|
|
360
432
|
}
|
|
361
433
|
|
|
@@ -97,12 +97,12 @@ static RCTResponseSenderBlock OKLiteCallbackOnce(NSString *operation, RCTRespons
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
- (void)setMnemonic:(NSString *)mnemonic pwd:(NSString *)pwd overwrite:(BOOL)overwrite callback:(RCTResponseSenderBlock)callBack
|
|
100
|
+
- (void)setMnemonic:(NSString *)mnemonic pwd:(NSString *)pwd overwrite:(BOOL)overwrite expectedSerial:(NSString * _Nullable)expectedSerial callback:(RCTResponseSenderBlock)callBack
|
|
101
101
|
{
|
|
102
102
|
callBack = OKLiteCallbackOnce(@"setMnemonic", callBack);
|
|
103
103
|
if ([ReactNativeLiteCard checkSDKVaild:callBack]) {
|
|
104
104
|
__block OKNFCManager *liteManager = [[OKNFCManager alloc] init];
|
|
105
|
-
[liteManager setMnemonic:mnemonic withPin:pwd overwrite:overwrite complete:^(OKLiteV1 *lite, OKNFCLiteSetMncStatus status) {
|
|
105
|
+
[liteManager setMnemonic:mnemonic withPin:pwd overwrite:overwrite expectedSerial:expectedSerial complete:^(OKLiteV1 *lite, OKNFCLiteSetMncStatus status) {
|
|
106
106
|
NSDictionary *cardInfo = [lite cardInfo];
|
|
107
107
|
switch (status) {
|
|
108
108
|
case OKNFCLiteSetMncStatusSuccess:
|
|
@@ -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
|
@@ -26,9 +26,9 @@ class OnekeyLite {
|
|
|
26
26
|
OKLiteManager.checkNFCPermission(this.convertToPromise(resolve));
|
|
27
27
|
});
|
|
28
28
|
}
|
|
29
|
-
setMnemonic(mnemonic, pwd, overwrite = false) {
|
|
29
|
+
setMnemonic(mnemonic, pwd, overwrite = false, expectedSerial) {
|
|
30
30
|
return new Promise(resolve => {
|
|
31
|
-
OKLiteManager.setMnemonic(mnemonic, pwd, overwrite, this.convertToPromise(resolve));
|
|
31
|
+
OKLiteManager.setMnemonic(mnemonic, pwd, overwrite, expectedSerial ?? null, this.convertToPromise(resolve));
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
getMnemonicWithPin(pwd) {
|
|
@@ -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() {
|
|
@@ -45,9 +45,9 @@ type KeyValuePair = {
|
|
|
45
45
|
export interface Spec extends TurboModule {
|
|
46
46
|
getLiteInfo(callback: (error: CallbackError | null, data: CardInfo | null, cardInfo: CardInfo | null) => void): void;
|
|
47
47
|
checkNFCPermission(callback: (error: CallbackError | null, data: boolean | null, cardInfo: CardInfo | null) => void): void;
|
|
48
|
-
setMnemonic(mnemonic: string, pwd: string, overwrite: boolean, callback: (error: CallbackError | null, data: boolean | null, cardInfo: CardInfo | null) => void): void;
|
|
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;
|
|
@@ -9,9 +9,9 @@ declare class OnekeyLite {
|
|
|
9
9
|
addAccordListener(): import("react-native").EventSubscription;
|
|
10
10
|
getLiteInfo(): Promise<PromiseResult<CardInfo>>;
|
|
11
11
|
checkNFCPermission(): Promise<PromiseResult<boolean>>;
|
|
12
|
-
setMnemonic(mnemonic: string, pwd: string, overwrite?: boolean): Promise<PromiseResult<boolean>>;
|
|
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