Skip to content

Commit

Permalink
adding OtpRequest interjection
Browse files Browse the repository at this point in the history
  • Loading branch information
someone42 committed Nov 13, 2013
1 parent 15e9d05 commit c5e9226
Show file tree
Hide file tree
Showing 15 changed files with 441 additions and 103 deletions.
9 changes: 9 additions & 0 deletions avr/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ static const char str_MISCSTR_PARAM_TOO_LARGE[] PROGMEM = "Parameter too large";
static const char str_MISCSTR_PERMISSION_DENIED_HOST[] PROGMEM = "Host cancelled action";
/** String specifying that an unexpected message was received. */
static const char str_MISCSTR_UNEXPECTED_PACKET[] PROGMEM = "Unexpected packet";
/** String specifying that the submitted one-time password (OTP) did not match
* the generated OTP. */
static const char str_MISCSTR_OTP_MISMATCH[] PROGMEM = "OTP mismatch";
/** String for #WALLET_FULL wallet error. */
static const char str_WALLET_FULL[] PROGMEM = "Wallet has run out of space";
/** String for #WALLET_EMPTY wallet error. */
Expand Down Expand Up @@ -113,6 +116,9 @@ char getString(StringSet set, uint8_t spec, uint16_t pos)
case MISCSTR_UNEXPECTED_PACKET:
return (char)pgm_read_byte(&(str_MISCSTR_UNEXPECTED_PACKET[pos]));
break;
case MISCSTR_OTP_MISMATCH:
return (char)pgm_read_byte(&(str_MISCSTR_OTP_MISMATCH[pos]));
break;
default:
return (char)pgm_read_byte(&(str_UNKNOWN[pos]));
break;
Expand Down Expand Up @@ -231,6 +237,9 @@ uint16_t getStringLength(StringSet set, uint8_t spec)
case MISCSTR_UNEXPECTED_PACKET:
return (uint16_t)(sizeof(str_MISCSTR_UNEXPECTED_PACKET) - 1);
break;
case MISCSTR_OTP_MISMATCH:
return (uint16_t)(sizeof(str_MISCSTR_OTP_MISMATCH) - 1);
break;
default:
return (uint16_t)(sizeof(str_UNKNOWN) - 1);
break;
Expand Down
16 changes: 15 additions & 1 deletion hwinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ typedef enum MiscStringsEnum
/** Text explaining that the operation was denied by the host. */
MISCSTR_PERMISSION_DENIED_HOST = 5,
/** Text explaining that an unexpected packet was received. */
MISCSTR_UNEXPECTED_PACKET = 6
MISCSTR_UNEXPECTED_PACKET = 6,
/** Text explaining that the submitted one-time password (OTP) did not
* match the generated OTP. */
MISCSTR_OTP_MISMATCH = 7
} MiscStrings;

/** Obtain one character from one of the device's strings.
Expand Down Expand Up @@ -180,6 +183,17 @@ extern void displayAddress(char *address, uint8_t num_sigs, uint8_t num_pubkeys)
* \return false if the user accepted, true if the user denied.
*/
extern bool userDenied(AskUserCommand command);
/** Display a short (maximum 8 characters) one-time password for the user to
* see. This one-time password is used to reduce the chance of a user
* accidentally doing something stupid.
* \param command The action to ask the user about. See #AskUserCommandEnum.
* \param otp The one-time password to display. This will be a
* null-terminated string.
*/
extern void displayOTP(AskUserCommand command, char *otp);
/** Clear the OTP (one-time password) shown by displayOTP() from the
* display. */
extern void clearOTP(void);

/** Fill buffer with 32 random bytes from a hardware random number generator.
* \param buffer The buffer to fill. This should have enough space for 32
Expand Down
9 changes: 9 additions & 0 deletions lpc11uxx/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ static const char str_MISCSTR_PARAM_TOO_LARGE[] = "Parameter too large";
static const char str_MISCSTR_PERMISSION_DENIED_HOST[] = "Host cancelled action";
/** String specifying that an unexpected message was received. */
static const char str_MISCSTR_UNEXPECTED_PACKET[] = "Unexpected packet";
/** String specifying that the submitted one-time password (OTP) did not match
* the generated OTP. */
static const char str_MISCSTR_OTP_MISMATCH[] = "OTP mismatch";
/** String for #WALLET_FULL wallet error. */
static const char str_WALLET_FULL[] = "Wallet has run out of space";
/** String for #WALLET_EMPTY wallet error. */
Expand Down Expand Up @@ -109,6 +112,9 @@ char getString(StringSet set, uint8_t spec, uint16_t pos)
case MISCSTR_UNEXPECTED_PACKET:
str = str_MISCSTR_UNEXPECTED_PACKET;
break;
case MISCSTR_OTP_MISMATCH:
str = str_MISCSTR_OTP_MISMATCH;
break;
default:
str = str_UNKNOWN;
break;
Expand Down Expand Up @@ -228,6 +234,9 @@ uint16_t getStringLength(StringSet set, uint8_t spec)
case MISCSTR_UNEXPECTED_PACKET:
return (uint16_t)(sizeof(str_MISCSTR_UNEXPECTED_PACKET) - 1);
break;
case MISCSTR_OTP_MISMATCH:
return (uint16_t)(sizeof(str_MISCSTR_OTP_MISMATCH) - 1);
break;
default:
return (uint16_t)(sizeof(str_UNKNOWN) - 1);
break;
Expand Down
19 changes: 16 additions & 3 deletions messages.pb.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb constant definitions */
/* Generated by nanopb-0.2.0 at Sun Apr 14 15:32:23 2013. */
/* Generated by nanopb-0.2.0 at Wed May 01 22:50:59 2013. */

#include "messages.pb.h"

Expand Down Expand Up @@ -54,6 +54,19 @@ const pb_field_t PinCancel_fields[1] = {
PB_LAST_FIELD
};

const pb_field_t OtpRequest_fields[1] = {
PB_LAST_FIELD
};

const pb_field_t OtpAck_fields[2] = {
PB_FIELD( 1, STRING , REQUIRED, STATIC, OtpAck, otp, otp, 0),
PB_LAST_FIELD
};

const pb_field_t OtpCancel_fields[1] = {
PB_LAST_FIELD
};

const pb_field_t NewWallet_fields[5] = {
PB_FIELD( 1, UINT32 , OPTIONAL, STATIC, NewWallet, wallet_number, wallet_number, &NewWallet_wallet_number_default),
PB_FIELD( 2, BYTES , OPTIONAL, CALLBACK, NewWallet, password, wallet_number, 0),
Expand Down Expand Up @@ -183,10 +196,10 @@ const pb_field_t MasterPublicKey_fields[3] = {

/* Check that field information fits in pb_field_t */
#if !defined(PB_FIELD_16BIT) && !defined(PB_FIELD_32BIT)
STATIC_ASSERT((pb_membersize(Wallets, wallet_info) < 256 && pb_membersize(RestoreWallet, new_wallet) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_Ping_PingResponse_Success_Failure_ButtonRequest_ButtonAck_ButtonCancel_PinRequest_PinAck_PinCancel_NewWallet_NewAddress_Address_GetNumberOfAddresses_NumberOfAddresses_GetAddressAndPublicKey_SignTransaction_Signature_LoadWallet_UnloadWallet_FormatWalletArea_ChangeEncryptionKey_ChangeWalletName_ListWallets_WalletInfo_Wallets_BackupWallet_RestoreWallet_GetDeviceUUID_DeviceUUID_GetEntropy_Entropy_GetMasterPublicKey_MasterPublicKey)
STATIC_ASSERT((pb_membersize(Wallets, wallet_info) < 256 && pb_membersize(RestoreWallet, new_wallet) < 256), YOU_MUST_DEFINE_PB_FIELD_16BIT_FOR_MESSAGES_Ping_PingResponse_Success_Failure_ButtonRequest_ButtonAck_ButtonCancel_PinRequest_PinAck_PinCancel_OtpRequest_OtpAck_OtpCancel_NewWallet_NewAddress_Address_GetNumberOfAddresses_NumberOfAddresses_GetAddressAndPublicKey_SignTransaction_Signature_LoadWallet_UnloadWallet_FormatWalletArea_ChangeEncryptionKey_ChangeWalletName_ListWallets_WalletInfo_Wallets_BackupWallet_RestoreWallet_GetDeviceUUID_DeviceUUID_GetEntropy_Entropy_GetMasterPublicKey_MasterPublicKey)
#endif

#if !defined(PB_FIELD_32BIT)
STATIC_ASSERT((pb_membersize(Wallets, wallet_info) < 65536 && pb_membersize(RestoreWallet, new_wallet) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_Ping_PingResponse_Success_Failure_ButtonRequest_ButtonAck_ButtonCancel_PinRequest_PinAck_PinCancel_NewWallet_NewAddress_Address_GetNumberOfAddresses_NumberOfAddresses_GetAddressAndPublicKey_SignTransaction_Signature_LoadWallet_UnloadWallet_FormatWalletArea_ChangeEncryptionKey_ChangeWalletName_ListWallets_WalletInfo_Wallets_BackupWallet_RestoreWallet_GetDeviceUUID_DeviceUUID_GetEntropy_Entropy_GetMasterPublicKey_MasterPublicKey)
STATIC_ASSERT((pb_membersize(Wallets, wallet_info) < 65536 && pb_membersize(RestoreWallet, new_wallet) < 65536), YOU_MUST_DEFINE_PB_FIELD_32BIT_FOR_MESSAGES_Ping_PingResponse_Success_Failure_ButtonRequest_ButtonAck_ButtonCancel_PinRequest_PinAck_PinCancel_OtpRequest_OtpAck_OtpCancel_NewWallet_NewAddress_Address_GetNumberOfAddresses_NumberOfAddresses_GetAddressAndPublicKey_SignTransaction_Signature_LoadWallet_UnloadWallet_FormatWalletArea_ChangeEncryptionKey_ChangeWalletName_ListWallets_WalletInfo_Wallets_BackupWallet_RestoreWallet_GetDeviceUUID_DeviceUUID_GetEntropy_Entropy_GetMasterPublicKey_MasterPublicKey)
#endif

17 changes: 16 additions & 1 deletion messages.pb.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* Automatically generated nanopb header */
/* Generated by nanopb-0.2.0 at Sun Apr 14 15:32:23 2013. */
/* Generated by nanopb-0.2.0 at Wed May 01 22:50:59 2013. */

#ifndef _PB_MESSAGES_PB_H_
#define _PB_MESSAGES_PB_H_
Expand Down Expand Up @@ -43,6 +43,14 @@ typedef struct _NewAddress {
uint8_t dummy_field;
} NewAddress;

typedef struct _OtpCancel {
uint8_t dummy_field;
} OtpCancel;

typedef struct _OtpRequest {
uint8_t dummy_field;
} OtpRequest;

typedef struct _PinCancel {
uint8_t dummy_field;
} PinCancel;
Expand Down Expand Up @@ -170,6 +178,10 @@ typedef struct _NumberOfAddresses {
uint32_t number_of_addresses;
} NumberOfAddresses;

typedef struct _OtpAck {
char otp[16];
} OtpAck;

typedef struct _PinAck {
pb_callback_t password;
} PinAck;
Expand Down Expand Up @@ -246,6 +258,9 @@ extern const pb_field_t ButtonCancel_fields[1];
extern const pb_field_t PinRequest_fields[1];
extern const pb_field_t PinAck_fields[2];
extern const pb_field_t PinCancel_fields[1];
extern const pb_field_t OtpRequest_fields[1];
extern const pb_field_t OtpAck_fields[2];
extern const pb_field_t OtpCancel_fields[1];
extern const pb_field_t NewWallet_fields[5];
extern const pb_field_t NewAddress_fields[1];
extern const pb_field_t Address_fields[4];
Expand Down
13 changes: 13 additions & 0 deletions messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ message PinCancel
{
}

message OtpRequest
{
}

message OtpAck
{
required string otp = 1 [(nanopb).max_size = 16];
}

message OtpCancel
{
}

// Responses: Success or Failure
// Response interjections: ButtonRequest
// wallet_name is stored purely for the convenience of the host. It should be
Expand Down
9 changes: 9 additions & 0 deletions pic32/strings.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ static const char str_MISCSTR_PARAM_TOO_LARGE[] = "Parameter too large";
static const char str_MISCSTR_PERMISSION_DENIED_HOST[] = "Host cancelled action";
/** String specifying that an unexpected message was received. */
static const char str_MISCSTR_UNEXPECTED_PACKET[] = "Unexpected packet";
/** String specifying that the submitted one-time password (OTP) did not match
* the generated OTP. */
static const char str_MISCSTR_OTP_MISMATCH[] = "OTP mismatch";
/** String for #WALLET_FULL wallet error. */
static const char str_WALLET_FULL[] = "Wallet has run out of space";
/** String for #WALLET_EMPTY wallet error. */
Expand Down Expand Up @@ -109,6 +112,9 @@ char getString(StringSet set, uint8_t spec, uint16_t pos)
case MISCSTR_UNEXPECTED_PACKET:
str = str_MISCSTR_UNEXPECTED_PACKET;
break;
case MISCSTR_OTP_MISMATCH:
str = str_MISCSTR_OTP_MISMATCH;
break;
default:
str = str_UNKNOWN;
break;
Expand Down Expand Up @@ -228,6 +234,9 @@ uint16_t getStringLength(StringSet set, uint8_t spec)
case MISCSTR_UNEXPECTED_PACKET:
return (uint16_t)(sizeof(str_MISCSTR_UNEXPECTED_PACKET) - 1);
break;
case MISCSTR_OTP_MISMATCH:
return (uint16_t)(sizeof(str_MISCSTR_OTP_MISMATCH) - 1);
break;
default:
return (uint16_t)(sizeof(str_UNKNOWN) - 1);
break;
Expand Down
6 changes: 6 additions & 0 deletions pic32/testers/hwb_tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,12 @@ static char *packetCommandToText(int command)
return "PinAck";
case 0x55:
return "PinCancel";
case 0x56:
return "OtpRequest";
case 0x57:
return "OtpAck";
case 0x58:
return "OtpCancel";
default:
return "unknown";
}
Expand Down
Binary file added pic32/testers/otp_ack.bin
Binary file not shown.
Binary file added pic32/testers/otp_cancel.bin
Binary file not shown.
Loading

0 comments on commit c5e9226

Please sign in to comment.