Skip to content

Commit a0ebf6b

Browse files
authored
Merge pull request #127 from Xynnn007/refactor-remove-ring
Removed ring dependency
2 parents 7cae68a + 5c14f24 commit a0ebf6b

File tree

25 files changed

+1328
-292
lines changed

25 files changed

+1328
-292
lines changed

Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@ openidconnect = { version = "2.3", default-features = false, features = [ "reqwe
2626
pem = "1.0.2"
2727
picky = { version = "7.0.0-rc.3", default-features = false, features = [ "x509", "ec" ] }
2828
regex = "1.5.5"
29-
ring = "0.16.20"
3029
serde_json = "1.0.79"
3130
serde = { version = "1.0.136", features = ["derive"] }
32-
sha2 = "0.10.2"
31+
sha2 = { version = "0.10.6", features = ["oid"] }
3332
thiserror = "1.0.30"
3433
tokio = { version = "1.17.0", features = ["full"] }
3534
tough = { version = "0.12", features = [ "http" ] }
@@ -44,11 +43,13 @@ pkcs8 = { version = "0.9.0", features = ["pem", "alloc", "pkcs5", "encryption"]
4443
elliptic-curve = { version = "0.12.2", features = [ "arithmetic", "pem" ] }
4544
p256 = "0.11.1"
4645
p384 = "0.11.1"
47-
ecdsa = { version = "0.14.3", features = [ "pkcs8", "digest" ] }
46+
ecdsa = { version = "0.14.3", features = [ "pkcs8", "digest", "der" ] }
4847
digest = "0.10.3"
4948
signature = { version = "1.5.0", features = [ "digest-preview" ] }
5049
ed25519 = { version = "1", features = [ "alloc" ] }
5150
ed25519-dalek-fiat = "0.1.0"
51+
rsa = "0.7.0-rc.1"
52+
pkcs1 = "0.4.0"
5253

5354
[dev-dependencies]
5455
anyhow = "1.0.54"

examples/cosign/verify/main.rs

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use sigstore::cosign::verification_constraint::{
1919
VerificationConstraintVec,
2020
};
2121
use sigstore::cosign::{CosignCapabilities, SignatureLayer};
22-
use sigstore::crypto::SignatureDigestAlgorithm;
22+
use sigstore::crypto::SigningScheme;
2323
use sigstore::errors::SigstoreVerifyConstraintsError;
2424
use sigstore::tuf::SigstoreRepository;
2525
use std::boxed::Box;
@@ -47,9 +47,9 @@ struct Cli {
4747
#[clap(short, long, required(false))]
4848
key: Option<String>,
4949

50-
/// Digest algorithm to use when processing a signature
51-
#[clap(long, default_value = "sha256")]
52-
signature_digest_algorithm: String,
50+
/// Signing scheme when signing and verifying
51+
#[clap(long, required(false))]
52+
signing_scheme: Option<String>,
5353

5454
/// Fetch Rekor and Fulcio data from Sigstore's TUF repository"
5555
#[clap(long)]
@@ -149,11 +149,18 @@ async fn run_app(
149149
}
150150
if let Some(path_to_key) = cli.key.as_ref() {
151151
let key = fs::read(path_to_key).map_err(|e| anyhow!("Cannot read key: {:?}", e))?;
152-
let signature_digest_algorithm =
153-
SignatureDigestAlgorithm::try_from(cli.signature_digest_algorithm.as_str())
154-
.map_err(anyhow::Error::msg)?;
155-
let verifier = PublicKeyVerifier::new(&key, signature_digest_algorithm)
156-
.map_err(|e| anyhow!("Cannot create public key verifier: {}", e))?;
152+
153+
let verifier = match &cli.signing_scheme {
154+
Some(scheme) => {
155+
let signing_scheme =
156+
SigningScheme::try_from(&scheme[..]).map_err(anyhow::Error::msg)?;
157+
PublicKeyVerifier::new(&key, &signing_scheme)
158+
.map_err(|e| anyhow!("Cannot create public key verifier: {}", e))?
159+
}
160+
None => PublicKeyVerifier::try_from(&key)
161+
.map_err(|e| anyhow!("Cannot create public key verifier: {}", e))?,
162+
};
163+
157164
verification_constraints.push(Box::new(verifier));
158165
}
159166

examples/fulcio/cert/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use sigstore::crypto::signing_key::SigningScheme;
1+
use sigstore::crypto::SigningScheme;
22
use sigstore::fulcio::oauth::OauthTokenProvider;
33
use sigstore::fulcio::{FulcioClient, TokenProvider, FULCIO_ROOT};
44
use url::Url;

examples/key_interface/key_pair_gen_and_export/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// limitations under the License.
1515

1616
use anyhow::Result;
17-
use sigstore::crypto::signing_key::SigningScheme;
17+
use sigstore::crypto::SigningScheme;
1818

1919
const PASSWORD: &str = "example password";
2020

examples/key_interface/key_pair_gen_sign_verify/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// limitations under the License.
1515

1616
use anyhow::{anyhow, Result};
17-
use sigstore::crypto::{signing_key::SigningScheme, Signature};
17+
use sigstore::crypto::{Signature, SigningScheme};
1818

1919
const DATA_TO_BE_SIGNED: &str = "this is an example data to be signed";
2020

examples/key_interface/key_pair_import/main.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@
1414
// limitations under the License.
1515

1616
use anyhow::{bail, Result};
17-
use ring::signature::ECDSA_P256_SHA256_ASN1;
1817
use sigstore::crypto::{
1918
signing_key::{ecdsa::ECDSAKeys, SigStoreKeyPair},
20-
CosignVerificationKey, SignatureDigestAlgorithm,
19+
CosignVerificationKey, SigningScheme,
2120
};
2221

2322
const PASSWORD: &str = "password";
@@ -30,13 +29,16 @@ const ECDSA_P256_ASN1_ENCRYPTED_PRIVATE_PEM: &[u8] =
3029
include_bytes!("./ECDSA_P256_ASN1_ENCRYPTED_PRIVATE_PEM.key");
3130

3231
fn main() -> Result<()> {
33-
let _ = CosignVerificationKey::from_pem(
34-
ECDSA_P256_ASN1_PUBLIC_PEM,
35-
SignatureDigestAlgorithm::Sha256,
36-
)?;
32+
let _ = CosignVerificationKey::from_pem(ECDSA_P256_ASN1_PUBLIC_PEM, &SigningScheme::default())?;
33+
println!("Imported PEM encoded public key as CosignVerificationKey using ECDSA_P256_ASN1_PUBLIC_PEM as verification algorithm.");
34+
35+
let _ = CosignVerificationKey::from_der(ECDSA_P256_ASN1_PUBLIC_DER, &SigningScheme::default())?;
36+
println!("Imported DER encoded public key as CosignVerificationKey using ECDSA_P256_ASN1_PUBLIC_PEM as verification algorithm.");
37+
38+
let _ = CosignVerificationKey::try_from_pem(ECDSA_P256_ASN1_PUBLIC_PEM)?;
3739
println!("Imported PEM encoded public key as CosignVerificationKey.");
3840

39-
let _ = CosignVerificationKey::from_der(ECDSA_P256_ASN1_PUBLIC_DER, &ECDSA_P256_SHA256_ASN1)?;
41+
let _ = CosignVerificationKey::try_from_der(ECDSA_P256_ASN1_PUBLIC_DER)?;
4042
println!("Imported DER encoded public key as CosignVerificationKey.");
4143

4244
let _ = SigStoreKeyPair::from_pem(ECDSA_P256_ASN1_PRIVATE_PEM)?;
@@ -69,7 +71,7 @@ fn main() -> Result<()> {
6971
inner.to_sigstore_signer()?;
7072
println!("Converted SigStoreKeyPair to SigStoreSigner.");
7173
}
72-
SigStoreKeyPair::ED25519(_) => bail!("Wrong key pair type."),
74+
_ => bail!("Wrong key pair type."),
7375
}
7476

7577
Ok(())

src/cosign/bundle.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ mod tests {
7070
use serde_json::json;
7171

7272
use crate::cosign::tests::get_rekor_public_key;
73-
use crate::crypto::SignatureDigestAlgorithm;
73+
use crate::crypto::SigningScheme;
7474

7575
fn build_correct_bundle() -> String {
7676
let bundle_json = json!({
@@ -101,11 +101,9 @@ mod tests {
101101
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAENptdY/l3nB0yqkXLBWkZWQwo6+cu
102102
OSWS1X9vPavpiQOoTTGC0xX57OojUadxF1cdQmrsiReWg2Wn4FneJfa8xw==
103103
-----END PUBLIC KEY-----"#;
104-
let not_rekor_pub_key = CosignVerificationKey::from_pem(
105-
public_key.as_bytes(),
106-
SignatureDigestAlgorithm::default(),
107-
)
108-
.expect("Cannot create CosignVerificationKey");
104+
let not_rekor_pub_key =
105+
CosignVerificationKey::from_pem(public_key.as_bytes(), &SigningScheme::default())
106+
.expect("Cannot create CosignVerificationKey");
109107

110108
let bundle_json = build_correct_bundle();
111109
let bundle = Bundle::new_verified(&bundle_json, &not_rekor_pub_key);

src/cosign/client.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,13 @@ impl Client {
137137
mod tests {
138138
use super::*;
139139
use crate::cosign::tests::{get_fulcio_cert_pool, REKOR_PUB_KEY};
140-
use crate::{crypto::SignatureDigestAlgorithm, mock_client::test::MockOciClient};
140+
use crate::crypto::SigningScheme;
141+
use crate::mock_client::test::MockOciClient;
141142

142143
fn build_test_client(mock_client: MockOciClient) -> Client {
143-
let rekor_pub_key = CosignVerificationKey::from_pem(
144-
REKOR_PUB_KEY.as_bytes(),
145-
SignatureDigestAlgorithm::default(),
146-
)
147-
.expect("Cannot create CosignVerificationKey");
144+
let rekor_pub_key =
145+
CosignVerificationKey::from_pem(REKOR_PUB_KEY.as_bytes(), &SigningScheme::default())
146+
.expect("Cannot create CosignVerificationKey");
148147

149148
Client {
150149
registry_client: Box::new(mock_client),

src/cosign/client_builder.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@
1616
use tracing::info;
1717

1818
use super::client::Client;
19-
use crate::crypto::{
20-
certificate_pool::CertificatePool, CosignVerificationKey, SignatureDigestAlgorithm,
21-
};
19+
use crate::crypto::SigningScheme;
20+
use crate::crypto::{certificate_pool::CertificatePool, CosignVerificationKey};
2221
use crate::errors::Result;
2322
use crate::registry::{Certificate, ClientConfig};
2423

@@ -125,7 +124,7 @@ impl ClientBuilder {
125124
}
126125
Some(data) => Some(CosignVerificationKey::from_pem(
127126
data.as_bytes(),
128-
SignatureDigestAlgorithm::default(),
127+
&SigningScheme::default(),
129128
)?),
130129
};
131130

src/cosign/mod.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ mod tests {
150150
AnnotationVerifier, CertSubjectEmailVerifier, VerificationConstraintVec,
151151
};
152152
use crate::crypto::certificate_pool::CertificatePool;
153-
use crate::crypto::{CosignVerificationKey, SignatureDigestAlgorithm};
153+
use crate::crypto::{CosignVerificationKey, SigningScheme};
154154
use crate::simple_signing::Optional;
155155

156156
pub(crate) const REKOR_PUB_KEY: &str = r#"-----BEGIN PUBLIC KEY-----
@@ -201,11 +201,8 @@ TNMea7Ix/stJ5TfcLLeABLE4BNJOsQ4vnBHJ
201201
}
202202

203203
pub(crate) fn get_rekor_public_key() -> CosignVerificationKey {
204-
CosignVerificationKey::from_pem(
205-
REKOR_PUB_KEY.as_bytes(),
206-
SignatureDigestAlgorithm::default(),
207-
)
208-
.expect("Cannot create test REKOR_PUB_KEY")
204+
CosignVerificationKey::from_pem(REKOR_PUB_KEY.as_bytes(), &SigningScheme::default())
205+
.expect("Cannot create test REKOR_PUB_KEY")
209206
}
210207

211208
#[test]

0 commit comments

Comments
 (0)