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

Fix bug in revocation service #229

Merged
merged 1 commit into from
Jul 12, 2021
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
33 changes: 17 additions & 16 deletions src/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ use openssl::pkcs5;
use openssl::pkey::{Id, PKey, PKeyRef, Private, Public};
use openssl::rsa::{Padding, Rsa};
use openssl::sign::{Signer, Verifier};
use std::fs::File;
use openssl::x509::X509;
use std::fs;
use std::io::Read;
use std::string::String;

Expand All @@ -32,21 +33,21 @@ pub(crate) fn do_hmac(
Ok(to_hex_string(hmac))
}

/*
* Input: path to PEM-encoded RSA public key
* Output: OpenSSL RSA key object
*
* Import a PEM-encoded RSA public key and return a callable OpenSSL RSA key
* object.
*/
pub(crate) fn rsa_import_pubkey(
input_key_path: String,
) -> Result<PKey<Public>> {
let mut key_buffer = vec![0; 1];
let mut input_key = File::open(input_key_path)?;
let _ = input_key.read_to_end(&mut key_buffer)?;
PKey::from_rsa(Rsa::public_key_from_pem(&key_buffer)?)
.map_err(Error::Crypto)
// Reads an X509 cert chain (provided by the tenant with the --cert command) and outputs
// its public key.
pub(crate) fn import_x509(input_key_path: String) -> Result<PKey<Public>> {
let contents = fs::read_to_string(&input_key_path[..])?;
let mut cert_chain = X509::stack_from_pem(contents.as_bytes())?;

if cert_chain.len() != 1 {
return Err(Error::Other(
"More than one public key provided in revocation cert"
.to_string(),
));
}

let cert = cert_chain.pop().unwrap(); //#[allow_ci]
cert.public_key().map_err(Error::Crypto)
}

pub(crate) fn rsa_generate(key_size: u32) -> Result<PKey<Private>> {
Expand Down
4 changes: 2 additions & 2 deletions src/revocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,11 @@ pub(crate) async fn run_revocation_service() -> Result<()> {
"Loading the revocation certificate from {}",
revocation_cert_path
);
match crypto::rsa_import_pubkey(revocation_cert_path) {
match crypto::import_x509(revocation_cert_path) {
Ok(v) => v,
Err(e) => {
return Err(Error::Configuration(String::from(
"Can not load pubkey",
"Cannot load pubkey",
)))
}
}
Expand Down