Skip to content

Commit

Permalink
Merge pull request #50 from coderofstuff/message-signing-followup
Browse files Browse the repository at this point in the history
Message signing followup
  • Loading branch information
coderofstuff authored Sep 16, 2023
2 parents d38166b + ba170b7 commit 5547e69
Show file tree
Hide file tree
Showing 79 changed files with 208 additions and 610 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ VARIANT_PARAM = COIN
VARIANT_VALUES = KAS

# Enabling DEBUG flag will enable PRINTF and disable optimizations
DEBUG = 1
#DEBUG = 1

########################################
# Application custom permissions #
Expand Down
8 changes: 7 additions & 1 deletion doc/COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,11 @@ Transactions signed with ECDSA are currently not supported.
| 0xB00A | `SW_WRONG_BIP32_COIN_TYPE` | `Coin Type` must be `111111'` |
| 0xB00B | `SW_WRONG_BIP32_TYPE` | `Type` passed is not valid. Must be either `0` for `Receive` or `1` for `Change`|
| 0xB00C | `SW_WRONG_BIP32_PATH_LEN` | Path length must be `5` |
| 0xB00D | `SW_MESSAGE_TOO_LONG` | Message len greater than max |
| 0xB010 | `SW_MESSAGE_PARSING_FAIL` | Unable to parse message data |
| 0xB011 | `SW_MESSAGE_TOO_LONG` | Message len greater than max |
| 0xB012 | `SW_MESSAGE_TOO_SHORT` | Message len is 0 |
| 0xB013 | `SW_MESSAGE_ADDRESS_TYPE_FAIL` | Address type could not be parsed or is not `0`/`1` |
| 0xB014 | `SW_MESSAGE_ADDRESS_INDEX_FAIL` | Address index could not be parsed |
| 0xB015 | `SW_MESSAGE_LEN_PARSING_FAIL` | Message length could not be parsed |
| 0xB016 | `SW_MESSAGE_UNEXPECTED` | Unexpected error while parsing message |
| 0x9000 | `OK` | Success |
2 changes: 1 addition & 1 deletion fuzzing/fuzz_tx_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

extern "C" {
#include "buffer.h"
#include "common/format.h"
#include "common/format_local.h"
#include "transaction/deserialize.h"
#include "transaction/types.h"
}
Expand Down
2 changes: 1 addition & 1 deletion fuzzing/fuzz_txin_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

extern "C" {
#include "buffer.h"
#include "common/format.h"
#include "common/format_local.h"
#include "transaction/deserialize.h"
#include "transaction/types.h"
}
Expand Down
2 changes: 1 addition & 1 deletion fuzzing/fuzz_txout_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

extern "C" {
#include "buffer.h"
#include "common/format.h"
#include "common/format_local.h"
#include "transaction/deserialize.h"
#include "transaction/types.h"
}
Expand Down
187 changes: 0 additions & 187 deletions src/common/format.c

This file was deleted.

92 changes: 0 additions & 92 deletions src/common/format.h

This file was deleted.

60 changes: 60 additions & 0 deletions src/common/format_local.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*****************************************************************************
* MIT License
*
* Copyright (c) 2023 coderofstuff
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*****************************************************************************/

#include <stddef.h> // size_t
#include <stdint.h> // int*_t, uint*_t
#include <string.h> // strncpy, memmove
#include <stdbool.h> // bool
#include <stdio.h> // sprintf, snprintf
#include <ctype.h> // isprint, isspace

#include "./format_local.h"

void format_message_to_sign(char* msg_dest, int msg_dest_len, char* msg_src, int msg_src_len) {
int c;
int dest_idx = 0;

for (int i = 0; i < msg_src_len && dest_idx < msg_dest_len; i++) {
c = msg_src[i];
if (isspace(c)) // to replace all white-space characters as spaces
{
c = ' ';
}
if (isprint(c)) {
sprintf(msg_dest + dest_idx, "%c", (char) c);
dest_idx++;
} else {
int remaining_buffer_length = msg_dest_len - dest_idx - 1;
if (remaining_buffer_length >= 4) // 4 being the fixed length of \x00
{
snprintf(msg_dest + dest_idx, remaining_buffer_length, "\\x%02x", c);
dest_idx += 4;
} else {
// fill the rest of the UI buffer spaces, to consider the buffer full
memset(msg_dest + dest_idx, ' ', remaining_buffer_length);
dest_idx += remaining_buffer_length;
}
}
}
}
Loading

0 comments on commit 5547e69

Please sign in to comment.