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

chore: update crypto deps #204

Merged
merged 1 commit into from
Feb 9, 2023
Merged

Conversation

flavio
Copy link
Member

@flavio flavio commented Jan 25, 2023

WARNING: this code currently doesn't compile

Update "tons" of cryptographic libraries:

  • ecdsa
  • ed25519
  • p256
  • p384
  • signature

The majority of these libraries broke their API during the upgrade, hence quite some fixes were needed.

Open issues

The code currently doesn't compile because of these errors:

╰─ cargo check
    Checking sigstore v0.6.0 (/home/flavio/hacking/sigstore/sigstore-rs)
error[E0599]: no method named `verify` found for reference `&ed25519_dalek_fiat::PublicKey` in the current scope
   --> src/crypto/verification_key.rs:314:22
    |
314 |                     .verify(msg, &sig)
    |                      ^^^^^^ method not found in `&ed25519_dalek_fiat::PublicKey`
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
16  | use ed25519_dalek_fiat::Verifier;
    |

error[E0599]: no method named `try_sign` found for struct `ed25519_dalek_fiat::Keypair` in the current scope
   --> src/crypto/signing_key/ed25519.rs:310:48
    |
310 |         let signature = self.key_pair.key_pair.try_sign(msg)?;
    |                                                ^^^^^^^^ method not found in `ed25519_dalek_fiat::Keypair`
    |
   ::: /home/flavio/.cargo/registry/src/github.com-1ecc6299db9ec823/signature-1.6.4/src/signer.rs:24:8
    |
24  |     fn try_sign(&self, msg: &[u8]) -> Result<S, Error>;
    |        -------- the method is available for `ed25519_dalek_fiat::Keypair` here
    |
    = help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
    |
63  | use ed25519_dalek_fiat::Signer;
    |

For more information about this error, try `rustc --explain E0599`.
error: could not compile `sigstore` due to 2 previous errors

The main issue is caused by the ed25519-dalek-fiat crate requiring an older version of the ed25519 crate (this PR switches to v2).

I think we are in trouble, the ed25519-dalek-fiat crate has not been maintained in the last 2 years (no new releases). The company behind it, Novi, ceased to exist on Sept 1, 2022 (note the link is a direct redirect from https://novi.com/).

The ed25519-dalek crate hasn't seen a release in 2 years, but it seems to have some activity on GitHub. Unfortunately, even on the main branch this crate depends on version 1 of ed25519. I've tried to update it, but I ended up in a rabbit hole.

@tarcieri : I see you contributed to ed25519-dalek and you're a maintainer of the majority of these crypto libraries that we're attempting to update. Can you help a bit please?

CC @Xynnn007 who worked on this code

@tarcieri
Copy link
Contributor

Hi there! I can answer some of your questions:

I think we are in trouble, the ed25519-dalek-fiat crate has not been maintained in the last 2 years (no new releases).

The fiat-crypto backend has been upstreamed into curve25519-dalek. Here are instructions for using it with the 4.0.0-release series:

https://github.com/dalek-cryptography/curve25519-dalek/#backends

The ed25519-dalek crate hasn't seen a release in 2 years, but it seems to have some activity on GitHub. Unfortunately, even on the main branch this crate depends on version 1 of ed25519.

The changes you're looking for are on the release/2.0 branch: https://github.com/dalek-cryptography/ed25519-dalek/tree/release/2.0

FWIW, I was able to upgrade the ssh-key crate by pulling curve25519-dalek and ed25519-dalek in via git: https://github.com/RustCrypto/SSH/blob/master/Cargo.toml#L11-L13

Here's a tracking issue to release some prerelease crate versions of curve25519-dalek and ed25519-dalek so you don't need to pull them in via git: dalek-cryptography/ed25519-dalek#274

And here's an overall tracking issue for an ed25519-dalek v2.0 release: dalek-cryptography/ed25519-dalek#245

@flavio
Copy link
Member Author

flavio commented Jan 27, 2023

@tarcieri thanks for the feedback. I tried to switch to the not-yet release of ed25519-dalek but I'm facing some errors.

These are the changes I did to our Cargo.toml:

diff --git a/Cargo.toml b/Cargo.toml
index b725e5dfdc..9f939dbf1e 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -49,7 +49,9 @@ ecdsa = { version = "0.15", features = [ "pkcs8", "digest", "der" ] }
 digest = "0.10.3"
 signature = { version = "2.0" }
 ed25519 = { version = "2", features = [ "alloc" ] }
-ed25519-dalek-fiat = "0.1.0"
+ed25519-dalek = { git = "https://github.com/dalek-cryptography/ed25519-dalek", branch = "release/2.0" }
+
 rsa = "0.8"
 pkcs1 = "0.4.0"
 reqwest = { version = "0.11", default-features = false, features = ["json", "multipart"] }
``

Unfortunately `cargo check` fails immediately because of a dependency/feature issue:

```console
╰─ cargo check
    Updating crates.io index
    Updating git repository `https://github.com/dalek-cryptography/ed25519-dalek`
error: failed to select a version for `curve25519-dalek`.
    ... required by package `ed25519-dalek v1.0.1 (https://github.com/dalek-cryptography/ed25519-dalek?branch=release/2.0#928d6d15)`
    ... which satisfies git dependency `ed25519-dalek` of package `sigstore v0.6.0 (/home/flavio/hacking/sigstore/sigstore-rs)`
versions that meet the requirements `=4.0.0-pre.5` are: 4.0.0-pre.5

the package `ed25519-dalek` depends on `curve25519-dalek`, with features: `precomputed-tables` but `curve25519-dalek` does not have these features.


failed to select a version for `curve25519-dalek` which could resolve this conflict

It looks like ed25519-dalek is requiring some features of curve25519-dalek that do not exist, not even inside of its main branch.

I wonder if I'm doing something stupid, or if that's work a bug opened against ed25519-dalek

@tarcieri
Copy link
Contributor

@flavio that seems like you're pulling curve25519-dalek in via the crate release instead of also via git?

Anyway, there's another forthcoming crate release which should help take care of these problems: dalek-cryptography/curve25519-dalek#501

@tarcieri
Copy link
Contributor

tarcieri commented Feb 5, 2023

@flavio ed25519-dalek v2.0.0-pre.0 has been released: https://crates.io/crates/ed25519-dalek/2.0.0-pre.0

Update tons of cryptographic libraries:

* ecdsa
* ed25519
* p256
* p384
* signature

The majority of these libraries broke their API during the upgrade,
hence quite some fixes were needed.

Signed-off-by: Flavio Castelli <fcastelli@suse.com>
@flavio flavio force-pushed the update-crypto-libs branch from 0d473d4 to 1cf6679 Compare February 7, 2023 08:59
@flavio
Copy link
Member Author

flavio commented Feb 7, 2023

@tarcieri thanks for the update, now everything seems to be working.

I'm changing this PR from draft to "ready to be reviewed".

Please, please.... take a look at that and make sure I didn't do anything stupid 🙏

@flavio flavio marked this pull request as ready for review February 7, 2023 09:00
@Xynnn007
Copy link
Member

Xynnn007 commented Feb 8, 2023

Hi @flavio , great to see the updates for the cryptos! When I was working on replace x509-parser to x509-cert to get rid of ring, it was needed to use new version of rsa. Fortunately, I can rebase this PR later.

@flavio flavio requested a review from Xynnn007 February 8, 2023 15:07
Copy link
Member

@Xynnn007 Xynnn007 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks and sorry for the delay. There are still some another test needs to be added as convert_ed25519_subject_public_key_to_cosign_verification_key, which I will add in another PR.

@flavio flavio merged commit 836f567 into sigstore:main Feb 9, 2023
@flavio flavio deleted the update-crypto-libs branch February 9, 2023 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants