Skip to content

Commit

Permalink
sigTst2 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mauricefisher64 committed Nov 11, 2024
1 parent 6028853 commit bfdadc1
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 32 deletions.
1 change: 1 addition & 0 deletions sdk/src/assertions/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub static V2_DEPRECATED_ACTIONS: [&str; 7] = [
/// We use this to allow SourceAgent to be either a string or a ClaimGeneratorInfo
#[derive(Deserialize, Serialize, Clone, Debug, PartialEq, Eq)]
#[serde(untagged)]
#[allow(clippy::large_enum_variant)]
pub enum SoftwareAgent {
String(String),
ClaimGeneratorInfo(ClaimGeneratorInfo),
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/claim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ impl Claim {
let uuid =
Uuid::try_parse(&ug).map_err(|_e| Error::BadParam("invalid Claim GUID".into()))?;
match uuid.get_version() {
Some(v) if v == uuid::Version::Random => (),
Some(uuid::Version::Random) => (),
_ => return Err(Error::BadParam("invalid Claim GUID".into())),
}
let label = if claim_version == 1 {
Expand Down
12 changes: 4 additions & 8 deletions sdk/src/jumbf/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,12 @@ pub(crate) fn manifest_label_to_parts(uri: &str) -> Option<ManifestParts> {
return None;
}

if parts.len() > 3 {
if !parts[3].is_empty() {
vendor = Some(parts[3].to_owned());
}
if parts.len() > 3 && !parts[3].is_empty() {
vendor = Some(parts[3].to_owned());
}

if parts.len() > 4 {
if !parts[4].is_empty() {
version = Some(parts[4].to_owned());
}
if parts.len() > 4 && !parts[4].is_empty() {
version = Some(parts[4].to_owned());
}
}

Expand Down
2 changes: 1 addition & 1 deletion sdk/src/openssl/openssl_trust_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ pub(crate) fn verify_trust(
.set_flags(X509VerifyFlags::NO_CHECK_TIME)
.map_err(Error::OpenSslError)?;
}

builder
.set_param(&verify_param)
.map_err(Error::OpenSslError)?;
Expand Down
45 changes: 24 additions & 21 deletions sdk/src/time_stamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@

use std::ops::Deref;

use asn1_rs::nom::AsBytes;
use async_generic::async_generic;
use bcder::{
decode::{Constructed, SliceSource},
encode::Values,
ConstOid, OctetString,
};
use coset::{sig_structure_data, ProtectedHeader};
use rasn::{AsnType, Decode, Encode};
use serde::{Deserialize, Serialize};
use x509_certificate::DigestAlgorithm::{self};

Expand All @@ -33,8 +35,8 @@ use crate::{
asn1::{
rfc3161::{TimeStampResp, TimeStampToken, TstInfo, OID_CONTENT_TYPE_TST_INFO},
rfc5652::{
CertificateChoices::Certificate, ContentInfo, SignedData, OID_ID_SIGNED_DATA,
OID_MESSAGE_DIGEST, OID_SIGNING_TIME,
CertificateChoices::Certificate, SignedData, OID_ID_SIGNED_DATA, OID_MESSAGE_DIGEST,
OID_SIGNING_TIME,
},
},
error::{Error, Result},
Expand Down Expand Up @@ -444,29 +446,30 @@ fn get_validator_type(sig_alg: &bcder::Oid, hash_alg: &bcder::Oid) -> Option<Str
}
}

#[derive(AsnType, Clone, Debug, Decode, Encode, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct ContentInfo {
pub content_type: rasn::types::ObjectIdentifier,
#[rasn(tag(explicit(0)))]
pub content: rasn::types::Any,
}

// Return timeStampToken used by sigTst2
pub(crate) fn timestamptoken_from_timestamprsp(ts: &[u8]) -> Option<Vec<u8>> {
let ts_resp = get_timestamp_response(ts).ok()?;

let tst = ts_resp.0.time_stamp_token?;
let mut tst_der = Vec::new();
tst.write_encoded(bcder::Mode::Der, &mut tst_der).ok()?;

if let Ok(ts) = Constructed::decode(tst_der.as_ref(), bcder::Mode::Der, |cons| {
cons.take_sequence(|cons| {
let content_type = crate::asn1::rfc5652::ContentType::take_from(cons)?;
let content = cons.take_constructed_if(bcder::Tag::CTX_0, |cons| cons.capture_all())?;

Ok(ContentInfo {
content_type,
content,
})
})
}) {
println!("{:?}", ts);
}
let a: Result<Vec<u32>> = tst
.content_type
.iter()
.map(|v| v.to_u32().ok_or(Error::NotFound))
.collect();

let ci = ContentInfo {
content_type: rasn::types::ObjectIdentifier::new(a.ok()?)?,
content: rasn::types::Any::new(tst.content.as_bytes().to_vec()),
};

Some(tst_der)
rasn::der::encode(&ci).ok()
}

// Returns TimeStamp token info if ts verifies against supplied data
Expand Down Expand Up @@ -784,13 +787,13 @@ pub(crate) fn get_timestamp_signed_data(data: &[u8]) -> Result<Option<SignedData

if let Some(token) = &tst {
if token.content_type == OID_ID_SIGNED_DATA {
return Ok(Some(
Ok(Some(
token
.content
.clone()
.decode(SignedData::take_from)
.map_err(|_err| Error::CoseInvalidTimeStamp)?,
));
))
} else {
Err(Error::CoseInvalidTimeStamp)
}
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/utils/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ pub(crate) fn temp_signer() -> Box<dyn Signer> {
&sign_cert,
&pem_key,
SigningAlg::Ps256,
Some("http://timestamp.digicert.com".into()),
None, // Some("http://timestamp.digicert.com".into()),
)
.expect("get_temp_signer");

Expand Down

0 comments on commit bfdadc1

Please sign in to comment.