forked from Concordium/concordium-ledger-app
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from blooo-io/feat/LDG-535--nano-app-implement…
…-deploy-method Feat/LDG-535--nano-app-implement-deploy-method
- Loading branch information
Showing
22 changed files
with
190 additions
and
2 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
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
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,48 @@ | ||
#include "os.h" | ||
#include "common/ui/display.h" | ||
#include "common/responseCodes.h" | ||
#include "common/sign.h" | ||
#include "common/util.h" | ||
#include "deployModule.h" | ||
|
||
static deployModule_t *ctx_deploy_module = &global.deployModule; | ||
static tx_state_t *tx_state = &global_tx_state; | ||
|
||
#define P1_INITIAL 0x00 | ||
#define P1_SOURCE 0x01 | ||
|
||
void handleDeployModule(uint8_t *cdata, uint8_t p1, uint8_t lc) { | ||
if (p1 == P1_INITIAL) { | ||
cdata += parseKeyDerivationPath(cdata); | ||
cx_sha256_init(&tx_state->hash); | ||
cdata += hashAccountTransactionHeaderAndKind(cdata, DEPLOY_MODULE); | ||
|
||
// hash the version and source length | ||
updateHash((cx_hash_t *) &tx_state->hash, cdata, 8); | ||
ctx_deploy_module->version = U4BE(cdata, 0); | ||
ctx_deploy_module->sourceLength = U4BE(cdata, 4); | ||
ctx_deploy_module->remainingSourceLength = ctx_deploy_module->sourceLength; | ||
// TODO: Format the version | ||
numberToText((uint8_t *) ctx_deploy_module->versionDisplay, | ||
sizeof(ctx_deploy_module->versionDisplay), | ||
ctx_deploy_module->version); | ||
sendSuccessNoIdle(); | ||
} | ||
|
||
else if (p1 == P1_SOURCE && ctx_deploy_module->remainingSourceLength > 0) { | ||
if (ctx_deploy_module->remainingSourceLength < lc) { | ||
THROW(ERROR_INVALID_SOURCE_LENGTH); | ||
} | ||
|
||
updateHash((cx_hash_t *) &tx_state->hash, cdata, lc); | ||
ctx_deploy_module->remainingSourceLength -= lc; | ||
if (ctx_deploy_module->remainingSourceLength > 0) { | ||
sendSuccessNoIdle(); | ||
} else if (ctx_deploy_module->remainingSourceLength == 0) { | ||
uiDeployModuleDisplay(); | ||
} | ||
|
||
} else { | ||
THROW(ERROR_INVALID_STATE); | ||
} | ||
} |
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,25 @@ | ||
#pragma once | ||
|
||
#include <stdint.h> | ||
#include <stdbool.h> | ||
|
||
/** | ||
* Handles the DEPLOY_MODULE instruction, which deploys a module | ||
* | ||
* | ||
*/ | ||
void handleDeployModule(uint8_t *cdata, uint8_t p1, uint8_t p2); | ||
|
||
typedef struct { | ||
uint32_t version; | ||
uint32_t sourceLength; | ||
uint32_t remainingSourceLength; | ||
uint8_t sourceHash[32]; | ||
char sourceHashDisplay[65]; | ||
char versionDisplay[11]; | ||
} deployModule_t; | ||
|
||
// typedef struct { | ||
// uint8_t version[32]; | ||
// uint8_t sourceLength[32]; | ||
// } deployModuleBlob_t; |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,34 @@ | ||
import pytest | ||
|
||
from application_client.boilerplate_command_sender import ( | ||
BoilerplateCommandSender, | ||
Errors, | ||
) | ||
from application_client.boilerplate_response_unpacker import ( | ||
unpack_get_public_key_response, | ||
) | ||
from ragger.bip import calculate_public_key_and_chaincode, CurveChoice | ||
from ragger.error import ExceptionRAPDU | ||
from ragger.navigator import NavInsID, NavIns | ||
from ragger.firmware import Firmware | ||
from utils import navigate_until_text_and_compare, instructions_builder | ||
|
||
|
||
@pytest.mark.active_test_scope | ||
def test_deploy_module( | ||
backend, firmware, navigator, test_name, default_screenshot_path | ||
): | ||
client = BoilerplateCommandSender(backend) | ||
path = "m/1105/0/0/0/0/2/0/0" | ||
header_and_type = bytes.fromhex( | ||
"20a845815bd43a1999e90fbf971537a70392eb38f89e6bd32b3dd70e1a9551d7000000000000000a0000000000000064000000290000000063de5da700" | ||
) | ||
version = 1 | ||
source = b"source" | ||
|
||
with client.deploy_module( | ||
path=path, header_and_type=header_and_type, version=version, source=source | ||
): | ||
navigate_until_text_and_compare( | ||
firmware, navigator, "Sign", default_screenshot_path, test_name | ||
) |