Skip to content

Commit 5547e69

Browse files
authored
Merge pull request #50 from coderofstuff/message-signing-followup
Message signing followup
2 parents d38166b + ba170b7 commit 5547e69

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+208
-610
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ VARIANT_PARAM = COIN
7979
VARIANT_VALUES = KAS
8080

8181
# Enabling DEBUG flag will enable PRINTF and disable optimizations
82-
DEBUG = 1
82+
#DEBUG = 1
8383

8484
########################################
8585
# Application custom permissions #

doc/COMMANDS.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,5 +173,11 @@ Transactions signed with ECDSA are currently not supported.
173173
| 0xB00A | `SW_WRONG_BIP32_COIN_TYPE` | `Coin Type` must be `111111'` |
174174
| 0xB00B | `SW_WRONG_BIP32_TYPE` | `Type` passed is not valid. Must be either `0` for `Receive` or `1` for `Change`|
175175
| 0xB00C | `SW_WRONG_BIP32_PATH_LEN` | Path length must be `5` |
176-
| 0xB00D | `SW_MESSAGE_TOO_LONG` | Message len greater than max |
176+
| 0xB010 | `SW_MESSAGE_PARSING_FAIL` | Unable to parse message data |
177+
| 0xB011 | `SW_MESSAGE_TOO_LONG` | Message len greater than max |
178+
| 0xB012 | `SW_MESSAGE_TOO_SHORT` | Message len is 0 |
179+
| 0xB013 | `SW_MESSAGE_ADDRESS_TYPE_FAIL` | Address type could not be parsed or is not `0`/`1` |
180+
| 0xB014 | `SW_MESSAGE_ADDRESS_INDEX_FAIL` | Address index could not be parsed |
181+
| 0xB015 | `SW_MESSAGE_LEN_PARSING_FAIL` | Message length could not be parsed |
182+
| 0xB016 | `SW_MESSAGE_UNEXPECTED` | Unexpected error while parsing message |
177183
| 0x9000 | `OK` | Success |

fuzzing/fuzz_tx_parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
extern "C" {
3030
#include "buffer.h"
31-
#include "common/format.h"
31+
#include "common/format_local.h"
3232
#include "transaction/deserialize.h"
3333
#include "transaction/types.h"
3434
}

fuzzing/fuzz_txin_parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
extern "C" {
3030
#include "buffer.h"
31-
#include "common/format.h"
31+
#include "common/format_local.h"
3232
#include "transaction/deserialize.h"
3333
#include "transaction/types.h"
3434
}

fuzzing/fuzz_txout_parser.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
extern "C" {
3030
#include "buffer.h"
31-
#include "common/format.h"
31+
#include "common/format_local.h"
3232
#include "transaction/deserialize.h"
3333
#include "transaction/types.h"
3434
}

src/common/format.c

Lines changed: 0 additions & 187 deletions
This file was deleted.

src/common/format.h

Lines changed: 0 additions & 92 deletions
This file was deleted.

src/common/format_local.c

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*****************************************************************************
2+
* MIT License
3+
*
4+
* Copyright (c) 2023 coderofstuff
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*****************************************************************************/
24+
25+
#include <stddef.h> // size_t
26+
#include <stdint.h> // int*_t, uint*_t
27+
#include <string.h> // strncpy, memmove
28+
#include <stdbool.h> // bool
29+
#include <stdio.h> // sprintf, snprintf
30+
#include <ctype.h> // isprint, isspace
31+
32+
#include "./format_local.h"
33+
34+
void format_message_to_sign(char* msg_dest, int msg_dest_len, char* msg_src, int msg_src_len) {
35+
int c;
36+
int dest_idx = 0;
37+
38+
for (int i = 0; i < msg_src_len && dest_idx < msg_dest_len; i++) {
39+
c = msg_src[i];
40+
if (isspace(c)) // to replace all white-space characters as spaces
41+
{
42+
c = ' ';
43+
}
44+
if (isprint(c)) {
45+
sprintf(msg_dest + dest_idx, "%c", (char) c);
46+
dest_idx++;
47+
} else {
48+
int remaining_buffer_length = msg_dest_len - dest_idx - 1;
49+
if (remaining_buffer_length >= 4) // 4 being the fixed length of \x00
50+
{
51+
snprintf(msg_dest + dest_idx, remaining_buffer_length, "\\x%02x", c);
52+
dest_idx += 4;
53+
} else {
54+
// fill the rest of the UI buffer spaces, to consider the buffer full
55+
memset(msg_dest + dest_idx, ' ', remaining_buffer_length);
56+
dest_idx += remaining_buffer_length;
57+
}
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)