Skip to content

Commit eb731be

Browse files
authored
Merge pull request #896 from fortanix/gilang/bug-invalid-serializing-pckcrl
Mistakenly serializing `VerificationType` field preventing deserialization to work correctly (e.g., `PckCrl`)
2 parents c39fbd6 + 568a872 commit eb731be

File tree

6 files changed

+27
-14
lines changed

6 files changed

+27
-14
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

intel-sgx/pcs/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pcs"
3-
version = "0.8.0"
3+
version = "0.8.1"
44
authors = ["Fortanix, Inc."]
55
license = "MPL-2.0"
66
edition = "2018"

intel-sgx/pcs/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,14 +208,14 @@ impl TryFrom<&str> for DcapArtifactIssuer {
208208

209209
/// A trait type to define a bound of a type that signifies a Verified or Unverified
210210
/// instance of a type.
211-
pub trait VerificationType : Serialize { }
211+
pub trait VerificationType { }
212212

213-
#[derive(Clone, Serialize, Debug, Eq, PartialEq)]
213+
#[derive(Clone, Debug, Eq, PartialEq)]
214214
pub struct Verified;
215215

216216
impl VerificationType for Verified {}
217217

218-
#[derive(Clone, Serialize, Debug, Eq, PartialEq)]
218+
#[derive(Clone, Debug, Eq, PartialEq)]
219219
pub struct Unverified;
220220

221221
impl VerificationType for Unverified {}

intel-sgx/pcs/src/pckcrl.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@ use crate::{DcapArtifactIssuer, Error, Unverified, VerificationType, Verified};
2626
pub struct PckCrl<V: VerificationType = Verified> {
2727
crl: String,
2828
ca_chain: Vec<String>,
29-
type_: V,
29+
#[serde(skip_serializing)]
30+
_type: V,
3031
}
3132

3233
impl PckCrl<Unverified> {
3334
pub fn new(crl: String, ca_chain: Vec<String>) -> Result<PckCrl<Unverified>, Error> {
34-
let crl = PckCrl { crl, ca_chain, type_: Unverified };
35+
let crl = PckCrl { crl, ca_chain, _type: Unverified };
3536
Ok(crl)
3637
}
3738

@@ -70,7 +71,7 @@ impl PckCrl<Unverified> {
7071
self.ca()?;
7172

7273
let PckCrl { crl, ca_chain, .. } = self;
73-
Ok(PckCrl::<Verified>{ crl, ca_chain, type_: Verified})
74+
Ok(PckCrl::<Verified>{ crl, ca_chain, _type: Verified})
7475
}
7576

7677
pub fn read_from_file(input_dir: &str, ca: DcapArtifactIssuer) -> Result<Self, Error> {
@@ -158,6 +159,16 @@ mod tests {
158159
crl.verify(&root_cas).unwrap();
159160
}
160161

162+
#[cfg(all(not(target_env = "sgx"), feature = "verify"))]
163+
#[test]
164+
fn serialize_deserialize_pck_crl() {
165+
let crl = PckCrl::read_from_file("./tests/data/", DcapArtifactIssuer::PCKProcessorCA).unwrap();
166+
167+
let serialized_bytes = serde_json::ser::to_vec(&crl).unwrap();
168+
let crt_deserialized: PckCrl<crate::Unverified> = serde_json::de::from_slice(&serialized_bytes[..]).unwrap();
169+
assert_eq!(crt_deserialized, crl);
170+
}
171+
161172
#[cfg(all(not(target_env = "sgx"), feature = "verify"))]
162173
#[test]
163174
fn read_platform_pck_crl() {

intel-sgx/pcs/src/pckcrt.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ impl PckCerts {
505505
pub struct PckCert<V: VerificationType = Verified> {
506506
cert: String,
507507
ca_chain: Vec<String>,
508-
type_: V,
508+
#[serde(skip_serializing)]
509+
_type: V,
509510
}
510511

511512
impl PckCert<Unverified> {
@@ -527,7 +528,7 @@ impl PckCert<Unverified> {
527528
PckCert {
528529
cert,
529530
ca_chain,
530-
type_: Unverified
531+
_type: Unverified
531532
}
532533
}
533534

@@ -558,7 +559,7 @@ impl PckCert<Unverified> {
558559
Ok(PckCert {
559560
cert: self.cert,
560561
ca_chain: self.ca_chain,
561-
type_: Verified,
562+
_type: Verified,
562563
})
563564
}
564565

intel-sgx/pcs/src/qe_identity.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ pub struct QeIdentity<V: VerificationType = Verified> {
118118
mrsigner: [u8; 32],
119119
isvprodid: u16,
120120
tcb_levels: Vec<TcbLevel>,
121-
type_: V,
121+
#[serde(skip_serializing)]
122+
_type: V,
122123
}
123124

124125
impl QeIdentity {
@@ -348,7 +349,7 @@ impl QeIdentitySigned {
348349
mrsigner,
349350
isvprodid,
350351
tcb_levels,
351-
type_: _
352+
_type: _
352353
} = serde_json::from_str(&self.raw_enclave_identity).map_err(|e| Error::ParseError(e))?;
353354

354355
if version != 2 {
@@ -381,7 +382,7 @@ impl QeIdentitySigned {
381382
mrsigner,
382383
isvprodid,
383384
tcb_levels,
384-
type_: Verified,
385+
_type: Verified,
385386
})
386387
}
387388
}

0 commit comments

Comments
 (0)