Skip to content

Commit

Permalink
Merge branch 'main' into wasm32-wasi_0.41.0
Browse files Browse the repository at this point in the history
  • Loading branch information
cdmurph32 authored Feb 5, 2025
2 parents 2e4e51e + 4cb20e3 commit a5edd28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions internal/crypto/src/cose/sign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
// specific language governing permissions and limitations under
// each license.

use asn1_rs::FromDer;
use async_generic::async_generic;
use ciborium::value::Value;
use coset::{
Expand All @@ -19,6 +20,7 @@ use coset::{
TaggedCborSerializable,
};
use serde_bytes::ByteBuf;
use x509_parser::prelude::X509Certificate;

use super::cert_chain_from_sign1;
use crate::{
Expand Down Expand Up @@ -161,7 +163,13 @@ pub fn sign_v1(
"bad certificate chain".to_string(),
))?;

let curve = ec_curve_from_public_key_der(signing_cert).ok_or(
let (_, cert) = X509Certificate::from_der(signing_cert).map_err(|_e| {
CoseError::CborGenerationError("incorrect EC signature format".to_string())
})?;

let certificate_public_key = cert.public_key();

let curve = ec_curve_from_public_key_der(certificate_public_key.raw).ok_or(
CoseError::CborGenerationError("incorrect EC signature format".to_string()),
)?;

Expand Down Expand Up @@ -235,7 +243,13 @@ pub fn sign_v2(
"bad certificate chain".to_string(),
))?;

let curve = ec_curve_from_public_key_der(signing_cert).ok_or(
let (_, cert) = X509Certificate::from_der(signing_cert).map_err(|_e| {
CoseError::CborGenerationError("incorrect EC signature format".to_string())
})?;

let certificate_public_key = cert.public_key();

let curve = ec_curve_from_public_key_der(certificate_public_key.raw).ok_or(
CoseError::CborGenerationError("incorrect EC signature format".to_string()),
)?;

Expand Down
1 change: 1 addition & 0 deletions internal/crypto/src/ec_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pub(crate) fn der_to_p1363(data: &[u8], sig_len: usize) -> Result<Vec<u8>, RawSi
}

// Returns supported EcdsaCurve for given public key.
#[allow(dead_code)]
pub(crate) fn ec_curve_from_public_key_der(public_key: &[u8]) -> Option<EcdsaCurve> {
let (_, pk) = SubjectPublicKeyInfo::from_der(public_key).ok()?;

Expand Down

0 comments on commit a5edd28

Please sign in to comment.