Skip to content

Commit

Permalink
update pem
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklan committed Jun 2, 2023
1 parent 962f520 commit 6cab6d1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
7 changes: 4 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ k8s-openapi = { version = "0.14.0", features = ["v1_23"] }
lazy_static = "^1.4"
os_pipe = "^1.0"
p12 = "^0.6"
pem = "^1.0"
pem = "^2.0"
regex = "^1.3"
rustls = { version = "0.20", features = ["dangerous_configuration"] }
rustyline = "^10.0"
Expand Down
10 changes: 5 additions & 5 deletions src/k8s.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,26 @@ fn pkcs1to8(pkcs1: &[u8]) -> Vec<u8> {
fn get_id_from_pkcs12(key: Vec<u8>, cert: Vec<u8>) -> Result<Identity, ClickError> {
let key_pem = pem::parse(key)?;

let key_der = match key_pem.tag.as_str() {
let key_der = match key_pem.tag() {
"RSA PRIVATE KEY" => {
// pkcs#1 pem, need to convert to pkcs#8
pkcs1to8(&key_pem.contents)
pkcs1to8(key_pem.contents())
}
"PRIVATE KEY" => {
// pkcs#8 pem, use as is
key_pem.contents
key_pem.contents().to_vec()
}
_ => {
return Err(ClickError::ConfigFileError(format!(
"Unknown key type: {}",
key_pem.tag
key_pem.tag()
)));
}
};

let cert_pem = pem::parse(cert)?;

let pfx = p12::PFX::new(&cert_pem.contents, &key_der, None, "", "")
let pfx = p12::PFX::new(cert_pem.contents(), &key_der, None, "", "")
.ok_or_else(|| ClickError::ConfigFileError("Could not parse pkcs12 data".to_string()))?;

let pkcs12der = pfx.to_der();
Expand Down

0 comments on commit 6cab6d1

Please sign in to comment.