Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update docs. #42

Merged
merged 1 commit into from
May 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ ColumnLimit: 100
PointerAlignment: Right
AlignAfterOpenBracket: Align
AlignConsecutiveMacros: true
AllowAllParametersOfDeclarationOnNextLine: false
SortIncludes: false
SpaceAfterCStyleCast: true
AllowShortCaseLabelsOnASingleLine: false
AllowAllArgumentsOnNextLine: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortFunctionsOnASingleLine: None
BinPackArguments: false
BinPackParameters: false
---

2 changes: 1 addition & 1 deletion .clusterfuzzlite/project.yaml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
language: c
language: c++
16 changes: 8 additions & 8 deletions docs/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
| `SIGN_TX` | 0x04 | Sign the raw transaction |
| `GET_APP_CONFIGURATION` | 0x06 | Get application configuration information |
| `SIGN_HASH` | 0x08 | Sign the hash |
| `INS_SIGN_SOROBAN_AUTHORATION` | 0x0A | Sign the Soroban Authoration |
| `SIGN_SOROBAN_AUTHORATION` | 0x0A | Sign the Soroban Authoration |

## GET_PUBLIC_KEY

Expand Down Expand Up @@ -50,7 +50,7 @@

| Response length (bytes) | SW | RData |
| ----------------------- | ------ | ---------------------------------------------------------------------------- |
| 4 | 0x9000 | `HASH_SIGNING_ENABLED (1)` \|\| `MAJOR (1)` \|\| `MINOR (1)` \|\| `PATCH (1)` \|\| `RAW_TX_MAX_SIZE (2)` |
| 4 | 0x9000 | `HASH_SIGNING_ENABLED (1)` \|\| `MAJOR (1)` \|\| `MINOR (1)` \|\| `PATCH (1)` \|\| `RAW_DATA_MAX_SIZE (2)` |

## SIGN_HASH

Expand All @@ -66,7 +66,7 @@
| ----------------------- | ------ | ---------------- |
| 64 | 0x9000 | `signature (64)` |

## INS_SIGN_SOROBAN_AUTHORATION
## SIGN_SOROBAN_AUTHORATION

### Command

Expand All @@ -85,7 +85,7 @@

| SW | SW name | Description |
| ------ | ------------------------------------- | ------------------------------------------------------- |
| 0x6125 | `SW_TX_FORMATTING_FAIL` | Failed to format transaction data |
| 0x6125 | `SW_FORMATTING_FAIL` | Failed to format the data |
| 0x6985 | `SW_DENY` | Rejected by user |
| 0x6A87 | `SW_WRONG_DATA_LENGTH` | `Lc` or minimum APDU lenght is incorrect |
| 0x6B00 | `SW_WRONG_P1P2` | Either `P1` or `P2` is incorrect |
Expand All @@ -94,10 +94,10 @@
| 0x6E00 | `SW_CLA_NOT_SUPPORTED` | Bad `CLA` used for this application |
| 0xB002 | `SW_DISPLAY_ADDRESS_FAIL` | Failed to display address |
| 0xB003 | `SW_DISPLAY_TRANSACTION_HASH_FAIL` | Failed to display transaction hash |
| 0xB004 | `SW_WRONG_TX_LENGTH` | Wrong raw transaction length |
| 0xB005 | `SW_TX_PARSING_FAIL` | Failed to parse raw transaction |
| 0xB006 | `SW_TX_HASH_FAIL` | Failed to compute hash digest of raw transaction |
| 0xB004 | `SW_DATA_TOO_LARGE` | The data is too large to be processed |
| 0xB005 | `SW_DATA_PARSING_FAIL` | Failed to parse raw data |
| 0xB006 | `SW_DATA_HASH_FAIL` | Failed to compute hash digest of raw data |
| 0xB007 | `SW_BAD_STATE` | Security issue with bad state |
| 0xB008 | `SW_SIGNATURE_FAIL` | Signature of raw transaction or transaction hash failed |
| 0xB008 | `SW_SIGNATURE_FAIL` | Generating signature failed |
| 0xB009 | `SW_SWAP_CHECKING_FAIL` | Failed to check swap params (maybe the data is invalid) |
| 0x9000 | `SW_OK` | Success |
6 changes: 3 additions & 3 deletions src/apdu/dispatcher.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ int apdu_dispatcher(const command_t *cmd) {
}

if (G_called_from_swap) {
if (cmd->ins != GET_PUBLIC_KEY && cmd->ins != SIGN_TX) {
if (cmd->ins != INS_GET_PUBLIC_KEY && cmd->ins != INS_SIGN_TX) {
PRINTF("Only GET_PUBLIC_KEY and SIGN_TX can be called during swap\n");
return io_send_sw(SW_INS_NOT_SUPPORTED);
}
Expand All @@ -54,7 +54,7 @@ int apdu_dispatcher(const command_t *cmd) {
return io_send_sw(SW_WRONG_P1P2);
}
return handler_get_app_configuration();
case GET_PUBLIC_KEY:
case INS_GET_PUBLIC_KEY:
if (cmd->p1 != 0 || cmd->p2 > 1) {
return io_send_sw(SW_WRONG_P1P2);
}
Expand All @@ -81,7 +81,7 @@ int apdu_dispatcher(const command_t *cmd) {
buf.size = cmd->lc;
buf.offset = 0;
return handler_sign_hash(&buf);
case SIGN_TX:
case INS_SIGN_TX:
if ((cmd->p1 != P1_FIRST && cmd->p1 != P1_MORE) ||
(cmd->p2 != P2_LAST && cmd->p2 != P2_MORE)) {
return io_send_sw(SW_WRONG_P1P2);
Expand Down
4 changes: 2 additions & 2 deletions src/constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#define DETAIL_VALUE_MAX_LENGTH 105

#ifdef TARGET_NANOS
#define RAW_TX_MAX_SIZE 1536
#define RAW_DATA_MAX_SIZE 1536
#else
#define RAW_TX_MAX_SIZE 10240
#define RAW_DATA_MAX_SIZE 10240
#endif
8 changes: 4 additions & 4 deletions src/handler/get_app_configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ int handler_get_app_configuration() {
"MINOR version must be between 0 and 255!");
_Static_assert(PATCH_VERSION >= 0 && PATCH_VERSION <= UINT8_MAX,
"PATCH version must be between 0 and 255!");
_Static_assert(RAW_TX_MAX_SIZE >= 0 && RAW_TX_MAX_SIZE <= UINT16_MAX,
"RAW_TX_MAX_SIZE must be between 0 and 65535!");
_Static_assert(RAW_DATA_MAX_SIZE >= 0 && RAW_DATA_MAX_SIZE <= UINT16_MAX,
"RAW_DATA_MAX_SIZE must be between 0 and 65535!");

uint8_t config[] = {HAS_SETTING(S_HASH_SIGNING_ENABLED),
MAJOR_VERSION,
MINOR_VERSION,
PATCH_VERSION,
RAW_TX_MAX_SIZE >> 8,
RAW_TX_MAX_SIZE & 0xFF};
RAW_DATA_MAX_SIZE >> 8,
RAW_DATA_MAX_SIZE & 0xFF};

return io_send_response_pointer(config, sizeof(config), SW_OK);
}
8 changes: 4 additions & 4 deletions src/handler/sign_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ int handler_sign_auth(buffer_t *cdata, bool is_first_chunk, bool more) {
explicit_bzero(&G_context, sizeof(G_context));
}

if (G_context.raw_size + cdata->size > RAW_TX_MAX_SIZE) {
return io_send_sw(SW_WRONG_TX_LENGTH);
if (G_context.raw_size + cdata->size > RAW_DATA_MAX_SIZE) {
return io_send_sw(SW_DATA_TOO_LARGE);
}

if (is_first_chunk) {
Expand Down Expand Up @@ -74,7 +74,7 @@ int handler_sign_auth(buffer_t *cdata, bool is_first_chunk, bool more) {
if (!parse_soroban_authorization_envelope(G_context.raw,
G_context.raw_size,
&G_context.envelope)) {
return io_send_sw(SW_TX_PARSING_FAIL);
return io_send_sw(SW_DATA_PARSING_FAIL);
}

G_context.state = STATE_PARSED;
Expand All @@ -89,7 +89,7 @@ int handler_sign_auth(buffer_t *cdata, bool is_first_chunk, bool more) {
}

if (cx_hash_sha256(G_context.raw, G_context.raw_size, G_context.hash, HASH_SIZE) != HASH_SIZE) {
return io_send_sw(SW_TX_HASH_FAIL);
return io_send_sw(SW_DATA_HASH_FAIL);
}

return ui_display_auth();
Expand Down
10 changes: 5 additions & 5 deletions src/handler/sign_tx.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ int handler_sign_tx(buffer_t *cdata, bool is_first_chunk, bool more) {
explicit_bzero(&G_context, sizeof(G_context));
}

if (G_context.raw_size + cdata->size > RAW_TX_MAX_SIZE) {
return io_send_sw(SW_WRONG_TX_LENGTH);
if (G_context.raw_size + cdata->size > RAW_DATA_MAX_SIZE) {
return io_send_sw(SW_DATA_TOO_LARGE);
}

if (is_first_chunk) {
Expand Down Expand Up @@ -72,7 +72,7 @@ int handler_sign_tx(buffer_t *cdata, bool is_first_chunk, bool more) {
}

if (!parse_transaction_envelope(G_context.raw, G_context.raw_size, &G_context.envelope)) {
return io_send_sw(SW_TX_PARSING_FAIL);
return io_send_sw(SW_DATA_PARSING_FAIL);
}

G_context.state = STATE_PARSED;
Expand All @@ -97,7 +97,7 @@ int handler_sign_tx(buffer_t *cdata, bool is_first_chunk, bool more) {

if (cx_hash_sha256(G_context.raw, G_context.raw_size, G_context.hash, HASH_SIZE) !=
HASH_SIZE) {
return io_send_sw(SW_TX_HASH_FAIL);
return io_send_sw(SW_DATA_HASH_FAIL);
}

if (crypto_sign_message(G_context.hash,
Expand All @@ -124,7 +124,7 @@ int handler_sign_tx(buffer_t *cdata, bool is_first_chunk, bool more) {

if (cx_hash_sha256(G_context.raw, G_context.raw_size, G_context.hash, HASH_SIZE) !=
HASH_SIZE) {
return io_send_sw(SW_TX_HASH_FAIL);
return io_send_sw(SW_DATA_HASH_FAIL);
}
return ui_display_transaction();
}
Expand Down
13 changes: 6 additions & 7 deletions src/sw.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@
*/
#define SW_DISPLAY_TRANSACTION_HASH_FAIL 0xB003
/**
* Status word for wrong transaction length.
* When the data requested by the user is too large, this exception will be thrown.
* Status word for the data is too large to be processed.
*/
#define SW_WRONG_TX_LENGTH 0xB004
#define SW_DATA_TOO_LARGE 0xB004
/**
* Status word for fail of transaction parsing.
* Status word for fail of data parsing.
*/
#define SW_TX_PARSING_FAIL 0xB005
#define SW_DATA_PARSING_FAIL 0xB005
/**
* Status word for fail of transaction hash.
* Status word for fail of data hash.
*/
#define SW_TX_HASH_FAIL 0xB006
#define SW_DATA_HASH_FAIL 0xB006
/**
* Status word for bad state.
*/
Expand Down
6 changes: 3 additions & 3 deletions src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
* Enumeration with expected INS of APDU commands.
*/
typedef enum {
GET_PUBLIC_KEY = 0x02, // public key of corresponding BIP32 path
SIGN_TX = 0x04, // sign transaction with BIP32 path
INS_GET_PUBLIC_KEY = 0x02, // public key of corresponding BIP32 path
INS_SIGN_TX = 0x04, // sign transaction with BIP32 path
INS_GET_APP_CONFIGURATION = 0x06, // app configuration of the application
INS_SIGN_HASH = 0x08, // sign transaction in hash mode
INS_SIGN_SOROBAN_AUTHORATION = 0x0a, // sign soroban authoration
Expand Down Expand Up @@ -48,7 +48,7 @@ enum e_state {
*/
typedef struct {
envelope_t envelope;
uint8_t raw[RAW_TX_MAX_SIZE];
uint8_t raw[RAW_DATA_MAX_SIZE];
uint32_t raw_size;
uint8_t raw_public_key[RAW_ED25519_PUBLIC_KEY_SIZE]; // BIP32 path public key
uint8_t hash[HASH_SIZE]; // tx hash
Expand Down
Loading