Skip to content

Commit

Permalink
Merge branch 'custom-sign-msg'
Browse files Browse the repository at this point in the history
  • Loading branch information
Toporin committed Nov 12, 2019
2 parents 6e2ad21 + d3a3b04 commit c14be7a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
Binary file modified SatoChip-2.2.2.cap
Binary file not shown.
Binary file modified SatoChip-3.0.3.cap
Binary file not shown.
Binary file modified SatoChip-3.0.4.cap
Binary file not shown.
29 changes: 24 additions & 5 deletions src/org/satochip/applet/CardEdge.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ public class CardEdge extends javacard.framework.Applet implements ExtendedLengt
// 0.7-0.1: add CryptTransaction2FA() to encrypt/decrypt tx messages sent to 2FA device for privacy
// 0.7-0.2: 2FA patch to mitigate replay attack when importing a new seed
// 0.8-0.1: add APDUs to reset the seed/eckey/2FA. 2FA required to sign tx/msg and reset seed/eckey/2FA. 2FA can only be disabled when all privkeys are cleared.
// 0.9-0.1: Message signing for altcoin.
private final static byte PROTOCOL_MAJOR_VERSION = (byte) 0;
private final static byte PROTOCOL_MINOR_VERSION = (byte) 8;
private final static byte PROTOCOL_MINOR_VERSION = (byte) 9;
private final static byte APPLET_MAJOR_VERSION = (byte) 0;
private final static byte APPLET_MINOR_VERSION = (byte) 1;

Expand Down Expand Up @@ -1761,7 +1762,7 @@ private void setBIP32ExtendedPubkey(APDU apdu, byte[] buffer){
* ins: 0x6E
* p1: key number or 0xFF for the last derived Bip32 extended key
* p2: Init-Update-Finalize
* data(init): [ full_msg_size(4b) ]
* data(init): [ full_msg_size(4b) | (option)altcoinSize(1b)-altcoin]
* data(update): [chunk_size(2b) | chunk_data]
* data(finalize): [chunk_size(2b) | chunk_data | (option)HMAC-2FA(20b)]
*
Expand Down Expand Up @@ -1793,9 +1794,27 @@ private void signMessage(APDU apdu, byte[] buffer){
switch(p2){
// initialization
case OP_INIT:
// copy message header to tmp buffer
Util.arrayCopyNonAtomic(BITCOIN_SIGNED_MESSAGE_HEADER, (short)0, recvBuffer, (short)0, (short)BITCOIN_SIGNED_MESSAGE_HEADER.length);
recvOffset= (short)BITCOIN_SIGNED_MESSAGE_HEADER.length;
recvOffset=0;
if (bytesLeft<(short)4){
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);}
else if (bytesLeft==(short)4){
// copy Btc message header to tmp buffer
Util.arrayCopyNonAtomic(BITCOIN_SIGNED_MESSAGE_HEADER, (short)0, recvBuffer, (short)0, (short)BITCOIN_SIGNED_MESSAGE_HEADER.length);
recvOffset= (short)BITCOIN_SIGNED_MESSAGE_HEADER.length;
}
else {
//Altcoin msg header from buffer
offset= (short)ISO7816.OFFSET_CDATA;
offset+=4;
byte altcoinSize= buffer[offset];
offset++;
if (bytesLeft!=(5+altcoinSize))
ISOException.throwIt(ISO7816.SW_WRONG_LENGTH);
recvBuffer[0]= (byte) (altcoinSize+17);
Util.arrayCopyNonAtomic(buffer, offset, recvBuffer, (short)1, (short)altcoinSize);
Util.arrayCopyNonAtomic(BITCOIN_SIGNED_MESSAGE_HEADER, (short)8, recvBuffer, (short)(1+altcoinSize), (short)17); //' Signed Message:\n'
recvOffset= (short) (18+altcoinSize);
}

// buffer data = [4-byte msg_size]
offset= (short)ISO7816.OFFSET_CDATA;
Expand Down

0 comments on commit c14be7a

Please sign in to comment.