Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
114 commits
Select commit Hold shift + click to select a range
6dccd52
Merge pull request #8 from vacuumlabs/merge_LedgerHQ_changes
relatko Apr 6, 2022
7b115c3
Add containerized build
relatko Apr 9, 2022
6cb7c7b
Make CI more continious
relatko Apr 10, 2022
1117cbb
Start and stop Speculos
relatko Apr 10, 2022
01eda26
Makefile containing JS related goals
relatko Apr 10, 2022
0bf8219
Infrastructure
relatko Jun 3, 2022
7c079db
Speculos tests documentation + .gitignore
relatko Jun 3, 2022
bf361ab
Remove unused files
relatko Jun 18, 2022
569838c
Ass Diffie-Hellman encryption support
relatko Jun 18, 2022
fcc4b96
Merge pull request #9 from vacuumlabs/build_in_container
relatko Jun 18, 2022
62f3f1c
Fix formatting
relatko Jun 20, 2022
7fc2d3d
Introduce NO_PULL option (for build and speculos)
relatko Jun 20, 2022
8efc041
Add sign tx commands integrity checking tools
relatko Jun 20, 2022
0c17bd3
Update github workflows linter to 12
relatko Jun 20, 2022
f1617fb
Refactor tx integrity functions
relatko Jun 20, 2022
dbab988
INIT, APPEND_CONST_DATA, SHOW_MESSAGE, SHOW_MESAGE, FINISH calls
relatko Jun 21, 2022
aec86f7
Counted section internals and unit tests
relatko Jun 21, 2022
8280104
Counted section commands
relatko Jun 22, 2022
0b11271
Storage Commands
relatko Jun 22, 2022
d508b45
Transaction templates
relatko Jun 23, 2022
cc7d25b
Der. path is sent in INIT call instead of FINAL
relatko Jun 24, 2022
1e0b53b
DH commands
relatko Jun 24, 2022
aa81895
DH encryption now encodes the result with base64
relatko Jun 25, 2022
f560dfb
Add Request funds transaction
relatko Jun 26, 2022
b87abed
Integrity check in END DH command + minor chanes
relatko Jun 28, 2022
39c4d04
Add option to skip integrity check in DEVEL mode
relatko Jun 29, 2022
86f2999
Simplifying js parsing
relatko Jun 29, 2022
397daa0
Finish BE->LE transition
relatko Jun 29, 2022
d5b9493
Recordobt transaction
relatko Jun 29, 2022
2a8cb69
New storage compare mode
relatko Jun 30, 2022
2289f87
Refactor contract name and account handling in parser
relatko Jul 1, 2022
540beca
DH decoding internals
relatko Jul 1, 2022
196973b
Remove U2F support according to LedgerHQ commit
relatko Jul 5, 2022
a985bc5
Decoding DH encrypted messages
relatko Jul 6, 2022
281a4ff
Cleanup
relatko Jul 7, 2022
2426707
Addaddress transaction
relatko Jul 7, 2022
28c0949
APPEND_DATA mode for memo hash offline url
relatko Jul 8, 2022
626cc48
Chain code Token code public addr instruction
relatko Jul 10, 2022
37a36cc
Remaddress
relatko Jul 10, 2022
933a3fe
Addnft
relatko Jul 10, 2022
f42e0ed
Remnft
relatko Jul 10, 2022
c273f77
addalladdr, cancelfndreq, rejecthndreq
relatko Jul 10, 2022
95f5c53
addbundles, regaddress, xferaddress, regdomain, renewdomain
relatko Jul 10, 2022
57743f1
Setdomainpub, xferdomain, remallnfts
relatko Jul 11, 2022
b4bec5b
Stakefio, unstakefio, voteproducer, voteproxy
relatko Jul 11, 2022
ad16e50
Add integrity hashes, fix missing tests
relatko Jul 11, 2022
8261a59
Max number of producets in voteproducer to 30
relatko Jul 12, 2022
d8b6a69
NanoX/SP speculos tests + on device tests
relatko Jul 12, 2022
e5609dd
Minor UI improvements
relatko Jul 12, 2022
c1189a8
Merge pull request #17 from vacuumlabs/other_transactions
relatko Jul 12, 2022
61aa75f
Add Speculos tests to CI
relatko Sep 30, 2022
83f49a6
Minor fixes all around
relatko Oct 3, 2022
d32b38b
Merge pull request #18 from vacuumlabs/speculos-to-ci
relatko Oct 3, 2022
ba58b53
Add unit tests to CI
relatko Oct 3, 2022
562e525
Bump version
relatko Oct 3, 2022
a42a138
Merge pull request #19 from vacuumlabs/speculos-to-ci
relatko Oct 3, 2022
320cf6d
Show data POLICY_SHOW_BEFORE_RESPONSE_IF_NONEMPTY
relatko Oct 7, 2022
2e8ed47
Fio request id is not displayed if empty in recordobt
relatko Oct 7, 2022
99a1b13
Merge pull request #20 from vacuumlabs/fixes
relatko Oct 7, 2022
463620f
Rename payee_public_key to other_public_key
relatko Oct 7, 2022
8b14398
Merge pull request #21 from vacuumlabs/fixes
relatko Oct 7, 2022
8c578a2
Minor TS fixes
relatko Oct 7, 2022
9e1e3b5
Merge pull request #22 from vacuumlabs/fixes
relatko Oct 7, 2022
0155d0e
Fix chaincode tokecode serilization + cleanup
relatko Oct 19, 2022
79a4766
Change min public address length in parsing
relatko Oct 19, 2022
714a303
Merge pull request #23 from vacuumlabs/fixes
relatko Oct 19, 2022
21c2117
Fix too too small buffer for tx append
relatko Oct 24, 2022
6af9572
Save some memory in unittests so they pass
relatko Oct 24, 2022
a49e72b
Merge pull request #24 from vacuumlabs/fixes
relatko Oct 24, 2022
48ecf22
Fix code format, force lint with each push
relatko Oct 24, 2022
db167ca
Merge pull request #25 from vacuumlabs/fixes
relatko Oct 24, 2022
24825a9
Fio Oracle transaction
relatko Nov 8, 2022
e12c0c1
Merge pull request #26 from vacuumlabs/fio_oracle
relatko Nov 8, 2022
91c4ded
Bump version
relatko Nov 8, 2022
79dfe80
Merge pull request #27 from vacuumlabs/fio_oracle
relatko Nov 8, 2022
f88f3e4
Change DH texts
relatko Nov 21, 2022
27b2092
Merge pull request #28 from vacuumlabs/fixes2
relatko Nov 21, 2022
31ade88
Modify string in decrypt
relatko Nov 26, 2022
55026fc
Merge pull request #29 from vacuumlabs/fixes2
relatko Nov 28, 2022
86760e8
Extend addnft and remnft token_id parameter
relatko Dec 19, 2022
e0becde
Merge pull request #30 from vacuumlabs/fixes2
relatko Dec 20, 2022
2eae657
Merge pull request #11 from LedgerHQ/develop
sgliner-ledger Jan 2, 2023
a63478d
APDU docs update
relatko Jan 18, 2023
de47ac9
Allowed sequences documentation
relatko Jan 18, 2023
9b282ab
NanoX icon update
relatko Jan 22, 2023
a412d73
Add fuzzing
relatko Jan 23, 2023
7ed0629
Merge branch 'LedgerHQmaster' into documentation_and_cleanup
relatko Jan 23, 2023
46b2edf
Fuzzer modified with very basic new corpus
relatko Jan 23, 2023
cc8ef81
Improve fuzzing
relatko Jan 23, 2023
5b05c9b
Security review documentation and minor fixes
relatko Jan 27, 2023
46b6c6b
Merge pull request #31 from vacuumlabs/documentation_and_cleanup
relatko Jan 27, 2023
43264af
Fix on device get app version test
relatko Jan 27, 2023
a897892
Merge pull request #32 from vacuumlabs/documentation_and_cleanup
relatko Jan 27, 2023
9bf9a7b
Add guidelines enforcer
relatko May 30, 2023
1b228f8
Easy code style fixes
relatko May 30, 2023
76297da
eos_utils guideline_enforcer fix
relatko May 30, 2023
230398e
Fix build
relatko Jun 10, 2023
760ad88
Minor testing fixes
relatko Jun 10, 2023
ab29900
Update speculos container
relatko Jun 10, 2023
9fddc72
Vulnerability fixes
relatko Jul 18, 2023
d4cf90e
Bump containers
relatko Sep 6, 2023
937b5b9
Remove stax from guidelines enforcer, add stax icon
relatko Sep 7, 2023
314618b
Updating deprecated calls
relatko Sep 12, 2023
e167dea
Fix od Speculos NanoX tests
relatko Sep 12, 2023
5d55ca6
Remove exceprions from public and private key code
relatko Sep 30, 2023
a3661c6
Refactor DH crypto functions
relatko Oct 6, 2023
83703bf
Move dependencies to non-throwing crypto modules
relatko Oct 7, 2023
0f87fff
Review changes
relatko Oct 7, 2023
7eb02b9
Consolidate crypto cleanup
relatko Oct 10, 2023
7d38be1
Incorporate review findings
relatko Oct 30, 2023
e722ab0
Merge pull request #34 from vacuumlabs/to_merge_with_LedgerHQ_1_0_5b
relatko Oct 30, 2023
5c1e151
Bump containers, update issues
relatko Oct 30, 2023
28f28c4
Merge pull request #35 from vacuumlabs/to_merge_with_LedgerHQ_1_0_5b
relatko Oct 31, 2023
7df0ae6
Merge branch 'LedgerHQdevelop' into to_merge_with_LedgerHQ_1_0_5
relatko Oct 31, 2023
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
8 changes: 7 additions & 1 deletion src/decodeDH.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,13 @@ void decode_handleAPDU(uint8_t p1,
TRACE("Decoding DH");
ASSERT(ctx->bufferLen <= SIZEOF(ctx->buffer));
TRACE_BUFFER(ctx->buffer, ctx->bufferLen);
ctx->bufferLen = dh_decode(&ctx->pathSpec, &ctx->otherPubKey, ctx->buffer, ctx->bufferLen);
uint16_t err = dh_decode(&ctx->pathSpec, &ctx->otherPubKey, ctx->buffer, &ctx->bufferLen);
if (err != SUCCESS) {
explicit_bzero(ctx->buffer, ctx->bufferLen);
TRACE();
PRINTF("Error: %d\n", err);
THROW(err);
}
ctx->messageDecodedMagic = DECODING_FINISHED_MAGIC;
ctx->bufferSentLen = 0;
TRACE_BUFFER(ctx->buffer, ctx->bufferLen);
Expand Down
547 changes: 327 additions & 220 deletions src/diffieHellman.c

Large diffs are not rendered by default.

185 changes: 134 additions & 51 deletions src/diffieHellman.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,63 +39,146 @@ typedef struct {

// Aes key is secret shared between us and the second party
typedef struct {
uint16_t initialized_magic;
cx_aes_key_t aesKey;
uint8_t km[DH_KM_SIZE];
} dh_aes_key_t;

// You may need to call multiple times if encryption spans multiple APDU's
// You may want to do something like
// APDU1 - dh_init_aes_key, dh_encode_init, dh_encode_append
// APDU2 - dh_init_aes_key, dh_encode_append
// APDU3 - dh_init_aes_key, dh_encode_append, dh_encode_finalize
// Do not forget to guarantee that dh_aes_key_t is zeroes at all times

__noinline_due_to_stack__ void dh_init_aes_key(dh_aes_key_t* dhKey,
const bip44_path_t* pathSpec,
const public_key_t* publicKey);

// Output data are base64 encrypted
__noinline_due_to_stack__ size_t dh_encode_init(dh_context_t* ctx,
const dh_aes_key_t* aes_key,
const uint8_t* iv,
size_t ivSize,
uint8_t* outBuffer,
size_t outSize);

// Output data are base64 encrypted
__noinline_due_to_stack__ size_t dh_encode_append(dh_context_t* ctx,
const dh_aes_key_t* aes_key,
const uint8_t* inBuffer,
size_t inSize,
uint8_t* outBuffer,
size_t outSize);

// Output data are base64 encrypted
__noinline_due_to_stack__ size_t dh_encode_finalize(dh_context_t* ctx,
const dh_aes_key_t* aes_key,
uint8_t* outBuffer,
size_t outSize);

// Convenience function to make all in one step
// Output data are base64 encrypted
__noinline_due_to_stack__ size_t dh_encode(bip44_path_t* pathSpec,
public_key_t* publicKey,
const uint8_t* iv,
size_t ivSize,
const uint8_t* inBuffer,
size_t inSize,
uint8_t* outBuffer,
size_t outSize);

// Inplace decoding function.
// Input data is NOT base64 encrypted
__noinline_due_to_stack__ size_t dh_decode(bip44_path_t* pathSpec,
public_key_t* publicKey,
uint8_t* buffer,
size_t inSize);
/**
* @brief Generates shared secret AES key. Use only in crypto functions to guarantee cleanup.
*
* @param[out] dhKey Resulting AES key.
*
* @param[in] pathSpec Our derivation path.
*
* @param[in] publicKey Their public key.
*
* @return Error code:
* - SUCCESS on success
* - ERR_REJECTED_BY_POLICY
* - ERR_ASSERT for other unexpected errors
*/
__noinline_due_to_stack__ WARN_UNUSED_RESULT uint16_t
dh_init_aes_key(dh_aes_key_t *dhKey, const bip44_path_t *pathSpec, const public_key_t *publicKey);

/**
* @brief Initiates DH+Base64 ecoding.
*
* @param[out] ctx DH encoding context.
*
* @param[in] pathSpec Our derivation path.
*
* @param[in] publicKey Their public key.
*
* @param[in] iv Initiatlization vector.
*
* @param[in] ivSize Size of initialization vector.
*
* @param[out] outBuffer Output buffer, initialization produces cyphertext.
*
* @param[in, out] outSize Size of output buffer. returns the number of new bytes.
*
* @return Error code:
* - SUCCESS on success
* - ERR_REJECTED_BY_POLICY
* - ERR_ASSERT for other unexpected errors
*/
__noinline_due_to_stack__ WARN_UNUSED_RESULT uint16_t dh_encode_init(dh_context_t *ctx,
const bip44_path_t *pathSpec,
const public_key_t *publicKey,
const uint8_t *iv,
uint16_t ivSize,
uint8_t *outBuffer,
uint16_t *outSize);

/**
* @brief Append to DH+Base64 ecoded data.
*
* @param[in, out] ctx DH encoding context.
*
* @param[in] pathSpec Our derivation path.
*
* @param[in] publicKey Their public key.
*
* @param[in] inBuffer Input buffer.
*
* @param[in] inSize Input buffer size.
*
* @param[out] outBuffer Output buffer, initialization produces cyphertext.
*
* @param[in, out] outSize Size of output buffer. returns the number of new bytes.
*
* @return Error code:
* - SUCCESS on success
* - ERR_REJECTED_BY_POLICY
* - ERR_ASSERT for other unexpected errors
*/
__noinline_due_to_stack__ WARN_UNUSED_RESULT uint16_t
dh_encode_append(dh_context_t *ctx,
const bip44_path_t *pathSpec,
const public_key_t *publicKey,
const uint8_t *inBuffer,
uint16_t inSize,
uint8_t *outBuffer,
uint16_t *outSize);

/**
* @brief Finish DH+Base64 encoding.
*
* @param[in] ctx DH encoding context.
*
* @param[in] pathSpec Our derivation path.
*
* @param[in] publicKey Their public key.
*
* @param[out] outBuffer Output buffer, initialization produces cyphertext.
*
* @param[in, out] outSize Size of output buffer. returns the number of new bytes.
*
* @return Error code:
* - SUCCESS on success
* - ERR_REJECTED_BY_POLICY
* - ERR_ASSERT for other unexpected errors
*/
__noinline_due_to_stack__ WARN_UNUSED_RESULT uint16_t
dh_encode_finalize(dh_context_t *ctx,
const bip44_path_t *pathSpec,
const public_key_t *publicKey,
uint8_t *outBuffer,
uint16_t *outSize);

/**
* @brief Inplace DH decoding function. Input data is NOT base64 encrypted
*
* @param[in] pathSpec Our derivation path.
*
* @param[in] publicKey Their public key.
*
* @param[out] buffer Output buffer, initialization produces cyphertext.
*
* @param[in, out] size Size of output buffer. returns the number of new bytes.
*
* @return Error code:
* - SUCCESS on success
* - ERR_REJECTED_BY_POLICY
* - ERR_INVALID_DATA
* - ERR_INVALID_HMAC
* - ERR_ASSERT for other unexpected errors
*/
__noinline_due_to_stack__ WARN_UNUSED_RESULT uint16_t dh_decode(bip44_path_t *pathSpec,
public_key_t *publicKey,
uint8_t *buffer,
uint16_t *size);

#ifdef DEVEL
__noinline_due_to_stack__ WARN_UNUSED_RESULT uint16_t dh_encode(bip44_path_t *pathSpec,
public_key_t *publicKey,
const uint8_t *iv,
uint16_t ivSize,
const uint8_t *inBuffer,
uint16_t inSize,
uint8_t *outBuffer,
uint16_t *outSize);

__noinline_due_to_stack__ void run_diffieHellman_test();
#endif // DEVEL

Expand Down
Loading