From 4a30c4bd083e03587b2818f6e029fa253983fe4c Mon Sep 17 00:00:00 2001 From: xiaoguang Date: Sun, 8 Oct 2023 11:49:47 +0800 Subject: [PATCH 1/5] fix: modify apdu Lc max length --- imkey-core/ikc-common/src/apdu.rs | 6 ++++++ imkey-core/ikc-common/src/constants.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/imkey-core/ikc-common/src/apdu.rs b/imkey-core/ikc-common/src/apdu.rs index 259f433d..6c916d97 100644 --- a/imkey-core/ikc-common/src/apdu.rs +++ b/imkey-core/ikc-common/src/apdu.rs @@ -71,6 +71,9 @@ impl BtcApdu { pub fn btc_sign(index: u8, hash_type: u8, path: &str) -> String { let path_bytes = path.as_bytes(); + if path_bytes.len() as u32 > LC_MAX { + panic!("data to long"); + } let mut apdu = ApduHeader::new(0x80, 0x42, index, hash_type, path_bytes.len() as u8).to_array(); apdu.extend(path_bytes.iter()); @@ -364,6 +367,9 @@ impl BtcForkApdu { pub fn btc_fork_sign(ins: u8, index: u8, hash_type: u8, path: &str) -> String { let path_bytes = path.as_bytes(); + if path_bytes.len() as u32 > LC_MAX { + panic!("data to long"); + } let mut apdu = ApduHeader::new(0x80, ins, index, hash_type, path_bytes.len() as u8).to_array(); apdu.extend(path_bytes.iter()); diff --git a/imkey-core/ikc-common/src/constants.rs b/imkey-core/ikc-common/src/constants.rs index 436f9c8c..a5e08030 100644 --- a/imkey-core/ikc-common/src/constants.rs +++ b/imkey-core/ikc-common/src/constants.rs @@ -14,7 +14,7 @@ pub const TSM_ACTION_COS_UPGRADE: &str = "/seCosUpdate"; pub const TSM_ACTION_COS_CHECK_UPDATE: &str = "/cosCheckUpdate"; //apud related constant -pub const LC_MAX: u32 = 245; +pub const LC_MAX: u32 = 239; pub const ETH_AID: &str = "695F657468"; pub const EOS_AID: &str = "695F656F73"; From 8e79f56b1b9b7d4037f63133f8f3cbb9af43ba47 Mon Sep 17 00:00:00 2001 From: xiaoguang Date: Sun, 8 Oct 2023 11:53:52 +0800 Subject: [PATCH 2/5] chore: modify verson to 2.6.6 --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 57cf282e..338a5b5d 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.6.5 +2.6.6 From d3af144be3e84fd03e9d95bba9570ca26708b4c9 Mon Sep 17 00:00:00 2001 From: xiaoguang Date: Sun, 8 Oct 2023 15:04:52 +0800 Subject: [PATCH 3/5] fix: fix prepare_sign function bug --- imkey-core/ikc-common/src/apdu.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/imkey-core/ikc-common/src/apdu.rs b/imkey-core/ikc-common/src/apdu.rs index 6c916d97..8dffa743 100644 --- a/imkey-core/ikc-common/src/apdu.rs +++ b/imkey-core/ikc-common/src/apdu.rs @@ -448,7 +448,7 @@ impl Apdu { (data.len() as u32 - LC_MAX as u32 * (size - 1 as u32)) as u8, ) } else { - (0x00, 0xF5) + (0x00, 0xEF) }; let apdu_header = ApduHeader::new(0x80, ins, p1, p2, lc); apdu.extend(apdu_header.to_array().iter()); From 6c1e18e8dad6e418217097d003b4f810aea185a6 Mon Sep 17 00:00:00 2001 From: xiaoguang Date: Mon, 9 Oct 2023 11:29:19 +0800 Subject: [PATCH 4/5] fix: modify LC_MAX to 229 --- imkey-core/ikc-common/src/apdu.rs | 2 +- imkey-core/ikc-common/src/constants.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/imkey-core/ikc-common/src/apdu.rs b/imkey-core/ikc-common/src/apdu.rs index 8dffa743..3b6081c5 100644 --- a/imkey-core/ikc-common/src/apdu.rs +++ b/imkey-core/ikc-common/src/apdu.rs @@ -448,7 +448,7 @@ impl Apdu { (data.len() as u32 - LC_MAX as u32 * (size - 1 as u32)) as u8, ) } else { - (0x00, 0xEF) + (0x00, 0xE5) }; let apdu_header = ApduHeader::new(0x80, ins, p1, p2, lc); apdu.extend(apdu_header.to_array().iter()); diff --git a/imkey-core/ikc-common/src/constants.rs b/imkey-core/ikc-common/src/constants.rs index a5e08030..befc359a 100644 --- a/imkey-core/ikc-common/src/constants.rs +++ b/imkey-core/ikc-common/src/constants.rs @@ -14,7 +14,7 @@ pub const TSM_ACTION_COS_UPGRADE: &str = "/seCosUpdate"; pub const TSM_ACTION_COS_CHECK_UPDATE: &str = "/cosCheckUpdate"; //apud related constant -pub const LC_MAX: u32 = 239; +pub const LC_MAX: u32 = 229; pub const ETH_AID: &str = "695F657468"; pub const EOS_AID: &str = "695F656F73"; From fcaa78ebd0ceae6559f12c50443f83ba7075f87e Mon Sep 17 00:00:00 2001 From: xiaoguang Date: Wed, 11 Oct 2023 11:19:58 +0800 Subject: [PATCH 5/5] fix: modify LC_MAX to 217 --- imkey-core/ikc-common/src/apdu.rs | 2 +- imkey-core/ikc-common/src/constants.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/imkey-core/ikc-common/src/apdu.rs b/imkey-core/ikc-common/src/apdu.rs index 3b6081c5..a1bd9a45 100644 --- a/imkey-core/ikc-common/src/apdu.rs +++ b/imkey-core/ikc-common/src/apdu.rs @@ -448,7 +448,7 @@ impl Apdu { (data.len() as u32 - LC_MAX as u32 * (size - 1 as u32)) as u8, ) } else { - (0x00, 0xE5) + (0x00, LC_MAX as u8) }; let apdu_header = ApduHeader::new(0x80, ins, p1, p2, lc); apdu.extend(apdu_header.to_array().iter()); diff --git a/imkey-core/ikc-common/src/constants.rs b/imkey-core/ikc-common/src/constants.rs index befc359a..c61c4f97 100644 --- a/imkey-core/ikc-common/src/constants.rs +++ b/imkey-core/ikc-common/src/constants.rs @@ -14,7 +14,7 @@ pub const TSM_ACTION_COS_UPGRADE: &str = "/seCosUpdate"; pub const TSM_ACTION_COS_CHECK_UPDATE: &str = "/cosCheckUpdate"; //apud related constant -pub const LC_MAX: u32 = 229; +pub const LC_MAX: u32 = 217; pub const ETH_AID: &str = "695F657468"; pub const EOS_AID: &str = "695F656F73";