status-im / status-keycard

Our Javacard Implementation for making secure transactions within Status and Ethereum
Apache License 2.0
213 stars 65 forks source link

Initialization is not as expected #43

Closed antonio-fr closed 5 years ago

antonio-fr commented 5 years ago

I got some Keycard with applet v2.1. I can initialize and use them with WallETH.

Then, I tried to handle them on my own, because for now, there's only Java available. I'm facing a weird behavior with uninitialized keycards : After the SELECT (providing a session card PubKey only), what ever the command sent, the cards answers 0x9000 and no data. It should answer SW_INS_NOT_SUPPORTED = 0x6D00 to any command which is different from 0x80FE. In the case the card is in "secure channel" mode it ca respond with 9000 on every request but it has to be some data in the answer. as in, the card shall answer directly 6D00 for any different command : https://github.com/status-im/status-keycard/blob/master/src/main/java/im/status/keycard/KeycardApplet.java#L324 Maybe, there's an issue in the if else... statements. Does anyone is reproducing the same?

bitgamma commented 5 years ago

I am looking at this right now. The code looks fine at first glance, so I will try to reproduce the issue first

ligi commented 5 years ago

thanks - please also let me know when I did something wrong on the WallETH side there

bitgamma commented 5 years ago

@antonio-fr I think I need some more details, because I cannot reproduce this, I get 6D00 as expected. Did I understand correctly that you are trying to initialize a card which has not yet received the INIT command?

What I did is:

1) Install the applet (so it is not initialized) 2) Send SELECT command - I get the pub key as a response 3) Send random commands (GET STATUS, VERIFY PIN, etc) - I get, correctly, 6D00

If you could send a dump of the command/responses from your tests it'd be useful to find what the problem is about.

BTW beside the Java SDK we also have a Go SDK at https://github.com/status-im/keycard-go

antonio-fr commented 5 years ago

Thanks for your help. I forgot to tell there's also a Go library for the keycard indeed. For my issue, after digging into the debugging of the very low card communication, my own implementation didn't detect any error if SW2 was 00, so for example 6D00 was treated as 9000. Hence it was masking some error as this. Thanks and sorry for the disturbance. At least, that has helped me to figure out what's wrong. I can continue now.

ligi commented 5 years ago

great to hear - please close the issue then

bitgamma commented 5 years ago

great! closing the issue