-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
234 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/******************************************************************************* | ||
* (c) 2018 - 2024 Zondax AG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
********************************************************************************/ | ||
|
||
#include "apdu_handler_legacy.h" | ||
|
||
#include "actions.h" | ||
#include "addr.h" | ||
#include "view_internal.h" | ||
|
||
void legacy_extractHDPath(uint32_t rx, uint32_t offset) { | ||
if (rx < LEGACY_OFFSET_HDPATH_LEN) { | ||
THROW(APDU_CODE_WRONG_LENGTH); | ||
} | ||
|
||
uint8_t hdPathQty = G_io_apdu_buffer[LEGACY_OFFSET_HDPATH_LEN]; | ||
uint8_t hdPathLen = hdPathQty * sizeof(uint32_t); | ||
|
||
if ( rx - offset != hdPathLen) { | ||
THROW(APDU_CODE_WRONG_LENGTH); | ||
} | ||
|
||
memcpy(hdPath, G_io_apdu_buffer + offset, hdPathLen); | ||
|
||
const bool mainnet = hdPath[0] == HDPATH_0_DEFAULT && hdPath[1] == HDPATH_1_DEFAULT; | ||
|
||
if (!mainnet) { | ||
THROW(APDU_CODE_DATA_INVALID); | ||
} | ||
} | ||
|
||
void legacy_handleGetAddr(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx, const uint8_t requireConfirmation) { | ||
legacy_extractHDPath(rx, LEGACY_OFFSET_HDPATH_DATA); | ||
|
||
zxerr_t zxerr = app_fill_address(); | ||
if (zxerr != zxerr_ok) { | ||
*tx = 0; | ||
THROW(APDU_CODE_DATA_INVALID); | ||
} | ||
if (requireConfirmation) { | ||
view_review_init(addr_getItem, addr_getNumItems, app_reply_address); | ||
view_review_show(REVIEW_ADDRESS); | ||
*flags |= IO_ASYNCH_REPLY; | ||
return; | ||
} | ||
|
||
// Add the pubkey length to the beginning of the buffer | ||
MEMMOVE(G_io_apdu_buffer + 1, G_io_apdu_buffer, action_addrResponseLen); | ||
G_io_apdu_buffer[0] = action_addrResponseLen; | ||
|
||
*tx = action_addrResponseLen + 1; | ||
THROW(APDU_CODE_OK); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/******************************************************************************* | ||
* (c) 2018 - 2024 Zondax AG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
********************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
#include <stdint.h> | ||
|
||
#define LEGACY_OFFSET_HDPATH_LEN 5 | ||
#define LEGACY_OFFSET_HDPATH_DATA 6 | ||
|
||
void legacy_handleGetAddr(volatile uint32_t *flags, volatile uint32_t *tx, uint32_t rx, const uint8_t requireConfirmation); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/** ****************************************************************************** | ||
* (c) 2018 - 2024 Zondax AG | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
******************************************************************************* */ | ||
|
||
import Zemu, { ButtonKind, zondaxMainmenuNavigation, isTouchDevice } from '@zondax/zemu' | ||
import Kda from "hw-app-kda"; | ||
import { PATH, defaultOptions, models, simpleTxNormal } from './common' | ||
import { blake2bFinal, blake2bInit, blake2bUpdate } from 'blakejs' | ||
|
||
import { HASH_TEST_CASES } from './testscases/hash' | ||
import { TRANSACTIONS_TEST_CASES } from './testscases/transactions' | ||
|
||
// @ts-expect-error | ||
import ed25519 from 'ed25519-supercop' | ||
|
||
jest.setTimeout(60000) | ||
|
||
|
||
describe.each(HASH_TEST_CASES)('Hash transactions', function (data) { | ||
test.only.each(models)('sign', async function (m) { | ||
const sim = new Zemu(m.path) | ||
try { | ||
await sim.start({ ...defaultOptions, model: m.name }) | ||
const app = new Kda(sim.getTransport()); | ||
|
||
const responseAddr = await app.getPublicKey(data.path) | ||
const pubKey = responseAddr.publicKey | ||
console.log(pubKey) | ||
|
||
// do not wait here... we need to navigate | ||
// const signatureRequest = app.signHash(data.path, data.hash) | ||
|
||
// // Wait until we are not in the main menu | ||
// await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) | ||
// await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_${data.name}`) | ||
|
||
// const signatureResponse = await signatureRequest | ||
// console.log(signatureResponse) | ||
|
||
// const rawHash = | ||
// typeof data.hash == 'string' | ||
// ? data.hash.length == 64 | ||
// ? Buffer.from(data.hash, 'hex') | ||
// : Buffer.from(data.hash, 'base64') | ||
// : Buffer.from(data.hash) | ||
// // Now verify the signature | ||
// const valid = ed25519.verify(signatureResponse.signature, rawHash, pubKey) | ||
// expect(valid).toEqual(true) | ||
} finally { | ||
await sim.close() | ||
} | ||
}) | ||
}) | ||
|
||
describe.each(TRANSACTIONS_TEST_CASES)('Tx transactions', function (data) { | ||
test.concurrent.each(models)('sign', async function (m) { | ||
const sim = new Zemu(m.path) | ||
try { | ||
await sim.start({ ...defaultOptions, model: m.name }) | ||
const app = new Kda(sim.getTransport()); | ||
|
||
const responseAddr = await app.getAddressAndPubKey(data.path) | ||
const pubKey = responseAddr.pubkey | ||
|
||
// do not wait here... we need to navigate | ||
const signatureRequest = app.signTransferTx(data.path, data) | ||
|
||
// // Wait until we are not in the main menu | ||
// await sim.waitUntilScreenIsNot(sim.getMainMenuSnapshot()) | ||
// await sim.compareSnapshotsAndApprove('.', `${m.prefix.toLowerCase()}-sign_${data.name}`) | ||
|
||
// const signatureResponse = await signatureRequest | ||
// console.log(signatureResponse) | ||
|
||
// const rawHash = | ||
// typeof data.hash == 'string' | ||
// ? data.hash.length == 64 | ||
// ? Buffer.from(data.hash, 'hex') | ||
// : Buffer.from(data.hash, 'base64') | ||
// : Buffer.from(data.hash) | ||
// // Now verify the signature | ||
// const valid = ed25519.verify(signatureResponse.signature, rawHash, pubKey) | ||
// expect(valid).toEqual(true) | ||
} finally { | ||
await sim.close() | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module 'hw-app-kda'; |
3d92edf
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cpp-Linter Report⚠️
Some files did not pass the configured checks!
clang-format reports: 6 file(s) not formatted
Have any feedback or feature suggestions? Share it here.