Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Write logs to microSD in HSM mode #196

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Sosthene00
Copy link

Hi, I've been experimenting a lot recently with the CC, especially with the HSM mode, and it happened a couple times that the CC "freezes", it just stops responding at some point without any logs or indication of what happened on the screen. I'd let it run for days, so when it happened I would usually figure it out many hours after. At least once it crashed while signing as the screen was reading "Signing..."

I had a look at what it logged on the microSD and I didn't found it to be very helpful for my situation, so I tried to modify it to write more logs that could help me if it crashes again.

I tested my code with the simulator, and it worked, I could register a policy and then it would sign psbts and write logs on the SD card.
But then I tried to flash an actual CC Mk4 with my custom code, and it crashed on startup with the following error
photo_2023-03-13_11-53-07

I tried my code again with the simulator, and it works there. Here's an actual example of the content of a log file I just made like this:

44a119cc5d50ceac Info: Loading the psbt file
44a119cc5d50ceac Info: Beginning formal validation of PSBT
44a119cc5d50ceac Error: FatalPSBTIssueNone of the keys involved in this transaction belong to this Coldcard (need 0F056943, found EF9D9CE6, CE3600EA, FACF6B1F, A3A9EB52, 46D93DA5, 86936C07, D3C3BC8F, 8E236875, 7F7D263A, FCA68DB6, D33C583B, D03AACCA, 5DF7E4B0, FE898C92, 154159B3).

===

I open this PR as a WIP because I think there might be demand for that, especially as more people will run the HSM mode, it's totally hacky right now but if you agree I'd gladly put on some more work because I need it. I'd just be happy to have a little help and not brick a couple more CC just to figure it out 馃槃

@scgbckbone
Copy link
Collaborator

you need to add your new module logging.py to shared/manifest.py (or shared/manifest_mk4). Simulator does not need this as it loads contents directly from shared dir. When building for real thing all modules have to be included in manifest. Your code is failing in flow.py:22 where it attempts to import from hsm.py module. In hsm.py it fails because it cannot find module logging.py as it is not included in manifest.

@Sosthene00
Copy link
Author

Thanks, very helpful! I'll try again and try to come up with something cleaner

@Sosthene00
Copy link
Author

Now it works on the real thing. Here's a summary of the changes made so far:

  • Now AuditLogger is instantiated as soon as we start parsing the psbt file and passed to approve_transaction as an argument. I originally thought I could keep the AuditLogger in the approve_transaction part and just add another one higher in auth.py as to make the less change possible to the way things were, but it appeared that having 2 loggers inside each other writing to the same card was not possible on the real cc (no issue with the simulator though).
  • Instead of having a psbt dir with as many log files as psbt submitted, there's now a log dir with one file for each hsm policy ('00'*32 being no hsm mode) logging each signing attempt.
  • I assumed it was possible to log to card while not being in hsm mode, but maybe it shouldn't be possible idk.
  • I started working on the previous release on top of some unrelated changes I was experimenting with and that were the reason I wanted more detailed logs, so I still need to rebase it on the latest release.

Please let me know if you think this is going in the right direction.

@doc-hex doc-hex added the HSM label Apr 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants