Skip to content

feat:tofu certificate validation#193

Open
lucasdbr05 wants to merge 1 commit intobitcoindevkit:masterfrom
lucasdbr05:feat/TOFU-certificate-validation
Open

feat:tofu certificate validation#193
lucasdbr05 wants to merge 1 commit intobitcoindevkit:masterfrom
lucasdbr05:feat/TOFU-certificate-validation

Conversation

@lucasdbr05
Copy link
Copy Markdown

@lucasdbr05 lucasdbr05 commented Jan 14, 2026

Closes #176

What does this merge request do?

This feature (see the reference issue #176) adds SSL certificate validation based on Trust On First Use (TOFU), storing the certificate on the first connection and verifying its consistency on subsequent connections.
It is implemented via the TofuStore trait, which allows customizable certificate persistence.

  • Introduces a refactored Trust On First Use (TOFU) implementation for SSL certificate verification.
  • Adds the TofuStore trait, allowing library consumers to provide their own certificate persistence mechanism.
  • Updates the Client configuration SSL client initialization flow to accept a TofuStore via ConfigBuilder.
  • Adds examples in examples directory and scripts to demonstrate how TOFU can be integrated and used in practice.

@lucasdbr05 lucasdbr05 changed the title Feat/tofu certificate validation feat:tofu certificate validation Jan 14, 2026
Copy link
Copy Markdown
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took an initial quick look and added some comments (though have yet to do a full review). Though before I proceed, please rewrite the commit history to avoid changing the approach mid-history. Basically, you should try to avoid to touch the same code paths in following commits as far as possible.

Given the code structure and verbosity I'm also suspecting that some form of AI agent was involved here. If this is indeed the case, please note that it is best practice to disclose such use in the PR and commit descriptions.

Comment thread src/tofu/mod.rs
Comment thread src/config.rs Outdated
Comment thread src/raw_client.rs Outdated
Comment thread src/raw_client.rs Outdated
@lucasdbr05
Copy link
Copy Markdown
Author

Took an initial quick look and added some comments (though have yet to do a full review). Though before I proceed, please rewrite the commit history to avoid changing the approach mid-history. Basically, you should try to avoid to touch the same code paths in following commits as far as possible.

Given the code structure and verbosity I'm also suspecting that some form of AI agent was involved here. If this is indeed the case, please note that it is best practice to disclose such use in the PR and commit descriptions.

First of all, thanks for the feedback. When rewriting the history, the best approach would be to avoid keeping commits that record my refactor from persistence-based usage to the trait-based approach, right?

@tnull
Copy link
Copy Markdown
Contributor

tnull commented Jan 15, 2026

When rewriting the history, the best approach would be to avoid keeping commits that record my refactor from persistence-based usage to the trait-based approach, right?

Yes, this would be preferable. Basically, you could just do a git reset and then commit the individual pieces again.

@luisschwab luisschwab self-requested a review January 17, 2026 20:32
@oleonardolima oleonardolima self-requested a review January 19, 2026 17:54
@oleonardolima oleonardolima added the new feature New feature or request label Jan 19, 2026
@oleonardolima oleonardolima moved this to Discussion in BDK Chain Jan 19, 2026
Copy link
Copy Markdown
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with tnull's comments above, you should narrow it down to few commits, for example: feat(tofu): add tofu store mod; feat(client): add new tofu method/feature, docs(example): add new tofu example.

Also, it's best if it's added under a new feature, and by a separate constructor. I don't think many changes to already-existing methods are needed, maybe it's something remaining from previous changes you did.

It's failing in CI, please make sure that everything is building successfully and passing CI too.

Comment thread src/raw_client.rs Outdated
Comment thread src/raw_client.rs Outdated
@lucasdbr05 lucasdbr05 force-pushed the feat/TOFU-certificate-validation branch from 9178ff9 to 42639ae Compare January 21, 2026 04:06
Comment thread src/tofu/mod.rs Outdated
Comment thread src/lib.rs Outdated
Comment thread src/raw_client.rs Outdated
Comment thread src/raw_client.rs Outdated
Comment thread src/raw_client.rs
Comment thread src/raw_client.rs Outdated
Comment thread src/client.rs
@oleonardolima oleonardolima moved this from Discussion to Needs Review in BDK Chain Feb 10, 2026
@oleonardolima oleonardolima added the api API breaking change label Feb 10, 2026
@lucasdbr05 lucasdbr05 force-pushed the feat/TOFU-certificate-validation branch from 42639ae to 3adefc6 Compare February 19, 2026 15:47
@lucasdbr05
Copy link
Copy Markdown
Author

lucasdbr05 commented Feb 19, 2026

@tnull I've squashed the previous commits into a single after the rebase to avoid having changes in the same files spread across diferent commits. However, if you prefer, I can split it in more than one commit.

@luisschwab
Copy link
Copy Markdown
Member

Ok, this is finally in the top of my stack. @lucasdbr05 I'll start reviewing and testing this one.

@lucasdbr05 lucasdbr05 marked this pull request as ready for review March 13, 2026 23:47
Copy link
Copy Markdown
Collaborator

@oleonardolima oleonardolima left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did an initial pass and left a few comments.

Comment thread src/tofu/mod.rs Outdated
Comment thread src/client.rs Outdated
Comment thread src/client.rs Outdated
Comment thread src/client.rs
Comment thread src/lib.rs Outdated
Comment thread src/raw_client.rs Outdated
…ections

Trust On First Use (TOFU) is a security model where a client trusts a certificate upon the first connection and subsequent connections are verified against that initially stored record.

This commit introduces the following features:

- `TofuStore` trait to manage certificates
- Implement TOFU validations both for OpenSSL and Rustls configurations
- Add custom certificate verifier for Rustls
- Support TOFU validation in proxy SSL connections
- Extend enum with error variants specifics to TOFU
- New method to initialize a client with TOFU from config
- Update existing constructors to support the revised SSL backend signatures
- Add some unit tests related to TOFU. The tests cover the following cases: first-use storage and certificate matching/replacement
- Add a TOFU certificates validation example, based on a in-memory store implementation for demonstration purposes

NOTE: Unit tests, supporting mock implementation, and the custom verifier for Rustls were created with AI assistance.
@lucasdbr05 lucasdbr05 force-pushed the feat/TOFU-certificate-validation branch from 3adefc6 to 15eda69 Compare April 16, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api API breaking change new feature New feature or request

Projects

Status: Needs Review

Development

Successfully merging this pull request may close these issues.

feat: check it out and use "TOFU" (trust on first use) for self-signed certificates

4 participants