@@ -14,73 +14,72 @@ public class BlindOracleApplet extends SecureApplet{
1414 // commands transmitted over secure channel
1515 // 0x00 - 0x04 are reserved
1616 // key management
17- private static final byte CMD_ROOT = (byte )0x10 ;
17+ protected static final byte CMD_ROOT = (byte )0x10 ;
1818 // bip32 keys - derivation and signing
19- private static final byte CMD_BIP32 = (byte )0x11 ;
19+ protected static final byte CMD_BIP32 = (byte )0x11 ;
2020
2121 /************ key management *********/
2222
2323 // set seed - 64 bytes,
2424 // data format: <64 bytes seed>
25- private static final byte SUBCMD_ROOT_SET_SEED = (byte )0x00 ;
25+ protected static final byte SUBCMD_ROOT_SET_SEED = (byte )0x00 ;
2626 // set xprv - 65 bytes
2727 // data format: <32-byte chain code><00><32-byte prv>
28- private static final byte SUBCMD_ROOT_SET_KEY = (byte )0x01 ;
28+ protected static final byte SUBCMD_ROOT_SET_KEY = (byte )0x01 ;
2929 // generate random key
3030 // WARNING: doesn't return the seed, so it always stays only on this card
3131 // add some backup mechanism in a script to recover if card breaks
3232 // data: ignored
33- private static final byte SUBCMD_ROOT_SET_RANDOM = (byte )0x7D ;
33+ protected static final byte SUBCMD_ROOT_SET_RANDOM = (byte )0x7D ;
3434
3535 /************ master private key management *********/
3636
3737 // returns 65-byte root xpub <chain_code><pubkey>
3838 // data: ignored
39- private static final byte SUBCMD_BIP32_GET_ROOT = (byte )0x00 ;
39+ protected static final byte SUBCMD_BIP32_GET_ROOT = (byte )0x00 ;
4040 // pass array of 4-byte indexes for derivation path
4141 // max derivation len is ~50, should be enough in most cases
4242 // sets result to temporary storage, so you can use it for
4343 // faster signing afterwards
4444 // data: <keyid><4-byte index><4-byte index>...<4-byte index>
4545 // keyid is 00 if derive from root, 01 if derive from current child
4646 // saves derived key as current (id 01)
47- private static final byte SUBCMD_BIP32_GET_DERIVE = (byte )0x01 ;
47+ protected static final byte SUBCMD_BIP32_GET_DERIVE = (byte )0x01 ;
4848 // returns an xpub of the key currently stored in memory
49- private static final byte SUBCMD_BIP32_GET_CURRENT = (byte )0x02 ;
49+ protected static final byte SUBCMD_BIP32_GET_CURRENT = (byte )0x02 ;
5050 // sign using currently derived child key or root key
5151 // data format: <32-byte message hash>00 to use root key
5252 // <32-byte message hash>01 to use current key
53- private static final byte SUBCMD_BIP32_SIGN = (byte )0x03 ;
53+ protected static final byte SUBCMD_BIP32_SIGN = (byte )0x03 ;
5454 // pass 32-byte hash to sign, then key id
5555 // and array of 4-byte indexes for derivation
5656 // key that is signing is not saved as current
5757 // data: <32-byte message hash>00<4-byte index>...<4-byte index> for root
5858 // <32-byte message hash>01<4-byte index>...<4-byte index> for current
59- private static final byte SUBCMD_BIP32_DERIVE_AND_SIGN = (byte )0x04 ;
59+ protected static final byte SUBCMD_BIP32_DERIVE_AND_SIGN = (byte )0x04 ;
6060 // it's not full bip32 key, only chain code and the key
61- private static final short BIP32_LEN = (short )65 ;
62- private static final short CHAINCODE_OFFSET = (short )0 ;
63- private static final short PUBKEY_OFFSET = (short )32 ;
64- private static final short FLAG_OFFSET = (short )32 ;
65- private static final short PRVKEY_OFFSET = (short )33 ;
66- private static final short CHAINCODE_LEN = (short )32 ;
67- private static final short PUBKEY_LEN = (short )33 ;
68- private static final short PRVKEY_LEN = (short )32 ;
69- private static final short SEED_LEN_MIN = (short )16 ;
70- private static final short SEED_LEN_MAX = (short )64 ;
71- private static final short MSG_LEN = (short )32 ;
61+ protected static final short BIP32_LEN = (short )65 ;
62+ protected static final short CHAINCODE_OFFSET = (short )0 ;
63+ protected static final short PUBKEY_OFFSET = (short )32 ;
64+ protected static final short FLAG_OFFSET = (short )32 ;
65+ protected static final short PRVKEY_OFFSET = (short )33 ;
66+ protected static final short CHAINCODE_LEN = (short )32 ;
67+ protected static final short PUBKEY_LEN = (short )33 ;
68+ protected static final short PRVKEY_LEN = (short )32 ;
69+ protected static final short SEED_LEN_MIN = (short )16 ;
70+ protected static final short SEED_LEN_MAX = (short )64 ;
71+ protected static final short MSG_LEN = (short )32 ;
7272 public static final byte [] HDKEY_SEED_KEY = {'B' ,'i' ,'t' ,'c' ,'o' ,'i' ,'n' ,' ' ,'s' ,'e' ,'e' ,'d' };
7373
74- private static final short ERR_INVALID_DATA = (short )0x0700 ;
74+ protected static final short ERR_INVALID_DATA = (short )0x0700 ;
7575
76- private boolean isInitialized = false ;
77- private byte status = (byte )0 ;
76+ protected boolean isInitialized = false ;
7877 // root key
79- private byte [] rootPrv ;
80- private byte [] rootXpub ; // 65 bytes, <chain code><pubkey>
78+ protected byte [] rootPrv ;
79+ protected byte [] rootXpub ; // 65 bytes, <chain code><pubkey>
8180 // child key
82- private byte [] childPrv ;
83- private byte [] childXpub ; // 65 bytes, <chain code><pubkey>
81+ protected byte [] childPrv ;
82+ protected byte [] childXpub ; // 65 bytes, <chain code><pubkey>
8483
8584 // Create an instance of the Applet subclass using its constructor,
8685 // and to register the instance.
@@ -101,18 +100,10 @@ public static void install(byte[] bArray, short bOffset, byte bLength){
101100 */
102101 public BlindOracleApplet (){
103102 super ();
104- try {
105- rootPrv = new byte [PRVKEY_LEN ];
106- rootXpub = new byte [BIP32_LEN ];
107- } catch (Exception e ) {
108- status = (byte )1 ;
109- }
110- try {
111- childPrv = JCSystem .makeTransientByteArray (PRVKEY_LEN , JCSystem .CLEAR_ON_DESELECT );
112- childXpub = JCSystem .makeTransientByteArray (BIP32_LEN , JCSystem .CLEAR_ON_DESELECT );
113- } catch (Exception e ) {
114- status = (byte )2 ;
115- }
103+ rootPrv = new byte [PRVKEY_LEN ];
104+ rootXpub = new byte [BIP32_LEN ];
105+ childPrv = JCSystem .makeTransientByteArray (PRVKEY_LEN , JCSystem .CLEAR_ON_DESELECT );
106+ childXpub = JCSystem .makeTransientByteArray (BIP32_LEN , JCSystem .CLEAR_ON_DESELECT );
116107 }
117108 /**
118109 * Handles secure message (decrypted by SecureChannel)
@@ -125,9 +116,6 @@ protected short processSecureMessage(byte[] buf, short len){
125116 if (isLocked ()){
126117 ISOException .throwIt (ERR_CARD_LOCKED );
127118 }
128- if (status > (byte )0 ){
129- ISOException .throwIt (ERR_INVALID_CMD );
130- }
131119 switch (buf [OFFSET_CMD ]){
132120 case CMD_ROOT :
133121 return processRootCommand (buf , len );
0 commit comments