Skip to content

Commit

Permalink
Trying a struct for attest response
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Zak <richard@profian.com>
  • Loading branch information
rjzak committed Sep 16, 2022
1 parent e5e544e commit 287405e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ use const_oid::db::rfc5280::{
};
use const_oid::db::rfc5912::ID_EXTENSION_REQ;
use der::asn1::{GeneralizedTime, Ia5StringRef, UIntRef};
use der::{Decode, Encode};
use der::{Decode, Encode, Sequence};
use pkcs8::PrivateKeyInfo;
use x509::ext::pkix::{BasicConstraints, ExtendedKeyUsage, KeyUsage, KeyUsages, SubjectAltName};
use x509::name::RdnSequence;
Expand Down Expand Up @@ -93,6 +93,15 @@ struct State {
san: Option<String>,
}

#[derive(Clone, Debug, Default, Sequence)]
struct Output<'a> {
/// The signing certificate chain back to the root.
pub chain: Vec<Certificate<'a>>,

/// All issued certificates.
pub issued: Vec<Certificate<'a>>,
}

impl State {
pub fn load(
san: Option<String>,
Expand Down Expand Up @@ -274,7 +283,11 @@ async fn attest(
return Err(StatusCode::BAD_REQUEST);
}
};
let mut vec_return: Vec<Vec<u8>> = Vec::new();

let mut response = Output {
chain: vec![issuer.clone()],
issued: Vec::new(),
};

// Decode and verify the certification request.
// let cr = CertReq::from_der(body.as_ref()).or(Err(StatusCode::BAD_REQUEST))?;
Expand Down Expand Up @@ -377,10 +390,9 @@ async fn attest(
let crt = Certificate::from_der(&crt).or(Err(ISE))?;

// Create and return the PkiPath.
let pkipath: Vec<u8> = vec![issuer, crt].to_vec().unwrap();
vec_return.push(pkipath.to_vec().or(Err(ISE))?);
response.issued.push(crt);
}
Ok(vec_return.to_vec().or(Err(ISE))?)
Ok(response.to_vec().or(Err(ISE))?)
}

#[cfg(test)]
Expand Down

0 comments on commit 287405e

Please sign in to comment.