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

Already on GitHub? Sign in to your account

feat(crypto): CRP-2420 add new signature verification package initially supporting canister signatures #248

Merged
merged 13 commits into from
Jul 5, 2024

Conversation

przydatek
Copy link
Contributor

@przydatek przydatek commented Jun 20, 2024

Setup ic-signature-verification package, which is intended to be a standalone crate with minimal dependencies
for verifying signatures supported by the Internet Computer.

Add the first utility function to the package, namely verify_canister_sig() for verifying canister signatures.
More comprehensive tests are needed, and they will be added in a follow-up PR.

@przydatek przydatek requested review from a team as code owners June 20, 2024 08:45
@sa-github-api sa-github-api changed the base branch from master to mirroring June 20, 2024 08:47
@przydatek przydatek changed the title Setup the package and add verification of canister signatures feat(crypto) Setup a package for signature verificationn, and add verification of canister signatures Jun 20, 2024
@przydatek przydatek changed the title feat(crypto) Setup a package for signature verificationn, and add verification of canister signatures feat(crypto): CRP-2420 Setup a package for signature verificationn, and add verification of canister signatures Jun 20, 2024
@github-actions github-actions bot added the feat label Jun 20, 2024
@przydatek przydatek requested a review from fspreiss June 20, 2024 09:35
@przydatek
Copy link
Contributor Author

Hi @fspreiss ,
In addition to the more comprehensive tests, there could be (at least) two more extensions/changes (maybe as follow-up PRs, or future work)

  1. Argument types: right now we have mostly &[u8], but maybe we could wrap these e.g. as CanisterSigPublicKeyDer([u8]), or CanisterSignatureCbor([u8]), so that it is not so easy to put the arguments in a wrong order.
  2. The return value is just Result<(), String>, which on one hand is nice because it is simple/generic, but maybe a more elaborate error-enum could be introduced, maybe not for the main function, but for internal reporting between the helpers, and for a potential additional API to be consumed internally by the replica code.

Wdyt?

Copy link
Member

@fspreiss fspreiss left a comment

Choose a reason for hiding this comment

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

Thanks a lot, @przydatek: I didn't check all verification details yet, but this PR looks really good! Above Below you find my comments so far. The code is very concise (partially enabled through the use of ic-certification) and nice to read.

Hi @fspreiss , In addition to the more comprehensive tests, there could be (at least) two more extensions/changes (maybe as follow-up PRs, or future work)

  1. Argument types: right now we have mostly &[u8], but maybe we could wrap these e.g. as CanisterSigPublicKeyDer([u8]), or CanisterSignatureCbor([u8]), so that it is not so easy to put the arguments in a wrong order.

You are right in that having multiple/only &[u8] as parameter types is suboptimal. Introducing newtype wrappers like CanisterSigPublicKeyDer would help, but ideally these types are somewhat smart because being able to instantiate a struct called CanisterSigPublicKeyDer with invalid DER is also suboptimal. The good thing in our situation is that if a caller passes the arguments in the wrong order, nothing bad can happen: the verification will simply fail, which might mean that the &[u8] parameters are good enough. Still, at least for the use of the library in the replica code, dedicated types might help. We can also discuss offline how to proceed here.

  1. The return value is just Result<(), String>, which on one hand is nice because it is simple/generic, but maybe a more elaborate error-enum could be introduced, maybe not for the main function, but for internal reporting between the helpers, and for a potential additional API to be consumed internally by the replica code.

Agreed. String is nice and simple, but indeed we want to use this library later in the CryptoComponent/Replica code (instead of the current canister sig verification code) and for that a proper error type may actually be good to have, at least internally. Anyway, this is also what Roman would recommend.

packages/ic-signature-verification/Cargo.toml Show resolved Hide resolved
packages/ic-ledger-hash-of/CHANGELOG.md Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/Cargo.toml Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
@przydatek przydatek requested review from a team as code owners July 4, 2024 12:20
Copy link
Contributor Author

@przydatek przydatek left a comment

Choose a reason for hiding this comment

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

Thanks, PTAL.

packages/ic-signature-verification/Cargo.toml Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@fspreiss fspreiss left a comment

Choose a reason for hiding this comment

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

I now double-check the verification logic agains the spec, and this looks very good.

packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
.github/CODEOWNERS Show resolved Hide resolved
packages/ic-signature-verification/CHANGELOG.md Outdated Show resolved Hide resolved
packages/ic-signature-verification/Cargo.toml Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor Author

@przydatek przydatek left a comment

Choose a reason for hiding this comment

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

Thanks, PTAL.

.github/CODEOWNERS Show resolved Hide resolved
packages/ic-signature-verification/CHANGELOG.md Outdated Show resolved Hide resolved
packages/ic-signature-verification/Cargo.toml Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Member

@fspreiss fspreiss left a comment

Choose a reason for hiding this comment

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

Thanks for the various changes, @przydatek!

packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
Copy link
Contributor Author

@przydatek przydatek left a comment

Choose a reason for hiding this comment

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

Thanks, will merge once green.

packages/ic-signature-verification/src/lib.rs Outdated Show resolved Hide resolved
@fspreiss fspreiss changed the title feat(crypto): CRP-2420 Setup a package for signature verificationn, and add verification of canister signatures feat(crypto): CRP-2420 add new signature verification package initially supporting canister signatures Jul 5, 2024
@przydatek przydatek added this pull request to the merge queue Jul 5, 2024
Merged via the queue into mirroring with commit fff7154 Jul 5, 2024
20 checks passed
gitlab-dfinity pushed a commit that referenced this pull request Jul 12, 2024
chore(github-sync): PR#248 / feat(crypto): CRP-2420 add new signature verification package initially supporting canister signatures

[GitHub PR 248](#248) (branch: bartosz/ic-sig-verification) 

See merge request dfinity-lab/public/ic!20280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants