Skip to content

Commit

Permalink
feature: sign governance vote
Browse files Browse the repository at this point in the history
  • Loading branch information
janmazak committed Nov 30, 2022
1 parent 1763451 commit a4bb662
Show file tree
Hide file tree
Showing 15 changed files with 670 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/deriveNativeScriptHash.c
Expand Up @@ -211,7 +211,7 @@ static void deriveScriptHash_display_ui_runStep()

UI_STEP(DISPLAY_UI_STEP_RESPOND) {
io_send_buf(SUCCESS, NULL, 0);
ui_displayBusy(); // displays dots, called after I/O to avoid freezing
ui_displayBusy(); // displays dots, called only after I/O to avoid freezing
}

UI_STEP_END(DISPLAY_UI_STEP_INVALID);
Expand Down
3 changes: 2 additions & 1 deletion src/getPublicKeys.c
Expand Up @@ -12,6 +12,7 @@ static ins_get_keys_context_t* ctx = &(instructionState.getKeysContext);
// it should be set to this value at the beginning and after a UI state machine is finished
static int UI_STEP_NONE = 0;

// this is supposed to be called at the beginning of each APDU handler
static inline void CHECK_STAGE(get_keys_stage_t expected)
{
TRACE("Checking stage... current one is %d, expected %d", ctx->stage, expected);
Expand Down Expand Up @@ -93,7 +94,7 @@ static void getPublicKeys_respondOneKey_ui_runStep()

io_send_buf(SUCCESS, (uint8_t*) &ctx->extPubKey, SIZEOF(ctx->extPubKey));
ctx->responseReadyMagic = 0; // just for safety
ui_displayBusy(); // displays dots, called after I/O to avoid freezing
ui_displayBusy(); // displays dots, called only after I/O to avoid freezing

ctx->currentPath++;
TRACE("Current path: %u / %u", ctx->currentPath, ctx->numPaths);
Expand Down
2 changes: 2 additions & 0 deletions src/handlers.c
Expand Up @@ -13,6 +13,7 @@
#include "deriveNativeScriptHash.h"
#include "signTx.h"
#include "signOpCert.h"
#include "signGovernanceVote.h"

// The APDU protocol uses a single-byte instruction code (INS) to specify
// which command should be executed. We'll use this code to dispatch on a
Expand All @@ -33,6 +34,7 @@ handler_fn_t* lookupHandler(uint8_t ins)
// 0x2* - signing related
CASE(0x21, signTx_handleAPDU);
CASE(0x22, signOpCert_handleAPDU);
CASE(0x23, signGovernanceVote_handleAPDU);

#ifdef DEVEL
// 0xF* - debug_mode related
Expand Down
10 changes: 5 additions & 5 deletions src/messageSigning.c
Expand Up @@ -62,15 +62,15 @@ static void signRawMessageWithPath(bip44_path_t* pathSpec,
} END_TRY;
}

void getTxWitness(bip44_path_t* pathSpec,
const uint8_t* txHashBuffer, size_t txHashSize,
uint8_t* outBuffer, size_t outSize)
// sign the given hash by the private key derived according to the given path
void getWitness(bip44_path_t* pathSpec,
const uint8_t* hashBuffer, size_t hashSize,
uint8_t* outBuffer, size_t outSize)
{
ASSERT(txHashSize == TX_HASH_LENGTH);
ASSERT(outSize < BUFFER_SIZE_PARANOIA);

#ifndef FUZZING
signRawMessageWithPath(pathSpec, txHashBuffer, txHashSize, outBuffer, outSize);
signRawMessageWithPath(pathSpec, hashBuffer, hashSize, outBuffer, outSize);
#endif
}

Expand Down
6 changes: 3 additions & 3 deletions src/messageSigning.h
Expand Up @@ -3,9 +3,9 @@

#include "bip44.h"

void getTxWitness(bip44_path_t* pathSpec,
const uint8_t* txHashBuffer, size_t txHashSize,
uint8_t* outBuffer, size_t outSize);
void getWitness(bip44_path_t* pathSpec,
const uint8_t* txHashBuffer, size_t txHashSize,
uint8_t* outBuffer, size_t outSize);

void getGovernanceVotingRegistrationSignature(bip44_path_t* pathSpec,
const uint8_t* payloadHashBuffer, size_t payloadHashSize,
Expand Down
25 changes: 25 additions & 0 deletions src/securityPolicy.c
Expand Up @@ -1868,3 +1868,28 @@ security_policy_t policyForSignOpCert(const bip44_path_t* poolColdKeyPathSpec)

DENY(); // should not be reached
}

security_policy_t policyForSignGovernanceVoteInit()
{
PROMPT();
}

security_policy_t policyForSignGovernanceVoteConfirm()
{
PROMPT();
}

security_policy_t policyForSignGovernanceVoteWitness(bip44_path_t* path)
{
switch (bip44_classifyPath(path)) {
case PATH_GOVERNANCE_VOTING_KEY:
WARN_UNLESS(bip44_isPathReasonable(path));
SHOW();
break;


default:
DENY();
break;
}
}
4 changes: 4 additions & 0 deletions src/securityPolicy.h
Expand Up @@ -203,4 +203,8 @@ security_policy_t policyForGovernanceVotingRegistrationNonce();
security_policy_t policyForGovernanceVotingRegistrationVotingPurpose();
security_policy_t policyForGovernanceVotingRegistrationConfirm();

security_policy_t policyForSignGovernanceVoteInit();
security_policy_t policyForSignGovernanceVoteConfirm();
security_policy_t policyForSignGovernanceVoteWitness(bip44_path_t* path);

#endif // H_CARDANO_APP_SECURITY_POLICY

0 comments on commit a4bb662

Please sign in to comment.