Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide the ability to specify the header x5c #13

Merged
merged 2 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/crypto/tpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,33 @@ where
KeyAlgorithm::Rsa2048 => header.alg = JwaAlg::RS256,
}

header.kid = Some(self.kid.clone());
// Only set the kid if we don't have an x509 cert for the x5c
match self.id_key {
IdentityKey::SoftEcdsa256 {
pkey: _,
x509: Some(x509),
}
| IdentityKey::SoftRsa2048 {
pkey: _,
x509: Some(x509),
} => {
header.x5c = Some(vec![general_purpose::STANDARD.encode(
match x509.to_der() {
Ok(der) => der,
Err(ossl_err) => {
error!(?ossl_err);
return Err(JwtError::OpenSSLError);
}
},
)])
}
_ => {
// Only set the kid if it wasn't set previously with JwsBuilder.set_x5c()
if let None = header.x5c {
header.kid = Some(self.kid.clone());
}
}
}

// if were were asked to ember the jwk, do so now.
/*
Expand Down
10 changes: 10 additions & 0 deletions src/jws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ impl JwsBuilder {
self
}

/// Set the chain of certificates
pub fn set_x5c(mut self, x5c: Option<Vec<Vec<u8>>>) -> Self {
self.header.x5c = x5c.map(|v| {
v.into_iter()
.map(|c| general_purpose::STANDARD.encode(c))
.collect()
});
self
}

/// Finalise this builder
pub fn build(self) -> Jws {
let JwsBuilder { header, payload } = self;
Expand Down
Loading