Skip to content

Commit 2851973

Browse files
committed
Add functionality to parse pubkey from Fulcio cert
Signed-off-by: Lily Sturmann <[email protected]>
1 parent 7f8ab57 commit 2851973

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ oci-distribution = { version = "0.9", default-features = false }
2323
olpc-cjson = "0.1"
2424
open = "3.0.1"
2525
openidconnect = { version = "2.3", default-features = false, features = [ "reqwest" ] }
26+
openssl = "0.10.38"
2627
pem = "1.0.2"
2728
picky = { version = "7.0.0-rc.3", default-features = false, features = [ "x509", "ec" ] }
2829
regex = "1.5.5"
@@ -57,7 +58,6 @@ anyhow = "1.0.54"
5758
assert-json-diff = "2.0.2"
5859
chrono = "0.4.20"
5960
clap = { version = "4.0.8", features = ["derive"] }
60-
openssl = "0.10.38"
6161
rstest = "0.15.0"
6262
tempfile = "3.3.0"
6363
tracing-subscriber = { version = "0.3.9", features = ["env-filter"] }

src/errors.rs

+4
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,16 @@ pub enum SigstoreError {
4949

5050
#[error(transparent)]
5151
X509ParseError(#[from] x509_parser::nom::Err<x509_parser::error::X509Error>),
52+
5253
#[error(transparent)]
5354
X509Error(#[from] x509_parser::error::X509Error),
5455

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

59+
#[error(transparent)]
60+
ErrorStack(#[from] openssl::error::ErrorStack),
61+
5862
#[error(transparent)]
5963
Base64DecodeError(#[from] base64::DecodeError),
6064

src/fulcio/mod.rs

+22
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::crypto::SigningScheme;
55
use crate::errors::{Result, SigstoreError};
66
use crate::fulcio::oauth::OauthTokenProvider;
77
use openidconnect::core::CoreIdToken;
8+
use openssl::x509::X509;
89
use reqwest::Body;
910
use serde::ser::SerializeStruct;
1011
use serde::{Serialize, Serializer};
@@ -78,6 +79,27 @@ impl AsRef<[u8]> for FulcioCert {
7879
}
7980
}
8081

82+
impl FulcioCert {
83+
pub fn new(s: &str) -> FulcioCert {
84+
FulcioCert(String::from(s))
85+
}
86+
87+
pub fn to_inner(&self) -> &str {
88+
&self.0
89+
}
90+
91+
pub fn to_x509(&self) -> Result<X509> {
92+
let x509 = X509::from_pem(self.to_inner().as_bytes())?;
93+
Ok(x509)
94+
}
95+
96+
pub fn extract_pubkey_string(&self) -> Result<String> {
97+
let certificate = self.to_x509()?;
98+
let pub_key_pem = certificate.public_key()?.public_key_to_pem()?;
99+
String::from_utf8(pub_key_pem).map_err(|e| SigstoreError::from(e.utf8_error()))
100+
}
101+
}
102+
81103
impl Display for FulcioCert {
82104
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
83105
std::fmt::Display::fmt(&self.0, f)

0 commit comments

Comments
 (0)