Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

WIP: Write logs to microSD in HSM mode #196

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Sosthene00 wants to merge 7 commits into Coldcard:master
base: master
Choose a base branch
Loading
from Sosthene00:feature/logging

Conversation

@Sosthene00
Copy link

@Sosthene00 Sosthene00 commented Mar 13, 2023

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 😄

slvrfn reacted with thumbs up emoji
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 reacted with thumbs up emoji

Copy link
Author

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /