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

Add functionality to parse pubkey from Fulcio cert #153

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ oci-distribution = { version = "0.9", default-features = false }
olpc-cjson = "0.1"
open = "3.0.1"
openidconnect = { version = "2.3", default-features = false, features = [ "reqwest" ] }
openssl = "0.10.38"
pem = "1.0.2"
picky = { version = "7.0.0-rc.3", default-features = false, features = [ "x509", "ec" ] }
regex = "1.5.5"
Expand Down Expand Up @@ -57,7 +58,6 @@ anyhow = "1.0.54"
assert-json-diff = "2.0.2"
chrono = "0.4.20"
clap = { version = "4.0.8", features = ["derive"] }
openssl = "0.10.38"
rstest = "0.15.0"
tempfile = "3.3.0"
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }
Expand Down
4 changes: 4 additions & 0 deletions src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,16 @@ pub enum SigstoreError {

#[error(transparent)]
X509ParseError(#[from] x509_parser::nom::Err<x509_parser::error::X509Error>),

#[error(transparent)]
X509Error(#[from] x509_parser::error::X509Error),

#[error(transparent)]
CertError(#[from] picky::x509::certificate::CertError),

#[error(transparent)]
ErrorStack(#[from] openssl::error::ErrorStack),

#[error(transparent)]
Base64DecodeError(#[from] base64::DecodeError),

Expand Down
22 changes: 22 additions & 0 deletions src/fulcio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::crypto::SigningScheme;
use crate::errors::{Result, SigstoreError};
use crate::fulcio::oauth::OauthTokenProvider;
use openidconnect::core::CoreIdToken;
use openssl::x509::X509;
use reqwest::Body;
use serde::ser::SerializeStruct;
use serde::{Serialize, Serializer};
Expand Down Expand Up @@ -78,6 +79,27 @@ impl AsRef<[u8]> for FulcioCert {
}
}

impl FulcioCert {
pub fn new(s: &str) -> FulcioCert {
FulcioCert(String::from(s))
}

pub fn to_inner(&self) -> &str {
&self.0
}

pub fn to_x509(&self) -> Result<X509> {
let x509 = X509::from_pem(self.to_inner().as_bytes())?;
Ok(x509)
}

pub fn extract_pubkey_string(&self) -> Result<String> {
let certificate = self.to_x509()?;
let pub_key_pem = certificate.public_key()?.public_key_to_pem()?;
String::from_utf8(pub_key_pem).map_err(|e| SigstoreError::from(e.utf8_error()))
}
}

impl Display for FulcioCert {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
std::fmt::Display::fmt(&self.0, f)
Expand Down