Skip to main content

sgx_pkix/
x509.rs

1/* Copyright (c) Fortanix, Inc.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6
7use pkix::x509::GenericCertificate;
8use pkix::types::HasOid;
9use pkix::FromDer;
10use sgx_isa::Report;
11
12use super::attestation::{AttestationInlineSgxLocal, reconstruct_sgx_report};
13use super::{Error, Result};
14
15pub fn cert_to_sgx_report(cert: &GenericCertificate) -> Result<Report> {
16    let attestation = cert.tbscert.get_extension(AttestationInlineSgxLocal::oid()).ok_or(Error::MissingAttestation)?;
17    let attestation = AttestationInlineSgxLocal::from_der(&attestation.value).map_err(|_| Error::InvalidAttestation)?;
18    reconstruct_sgx_report(&cert.tbscert.subject, &attestation)
19}