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

Remove bcder #839

Merged
merged 49 commits into from
Jul 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
7babd74
Enable manual invocation of the e2e test.
ximon18 May 25, 2022
745dc98
Set up (failing) test for migration from 0.9.x to 0.10.0
Jun 2, 2022
2813e2a
Use updated rpki-rs with BGPSec signing support.
Jun 2, 2022
36d783a
Start implementing issuing BGPSec certificates (incomplete, #827)
Jun 9, 2022
194bc5f
Schedule "RenewObjectsIfNeeded" at startup. #833
Jun 10, 2022
427d6e9
Update readme and version for release 0.9.6
Jun 10, 2022
95e6681
Clarify need to upgrade to 0.9.6.
Jun 10, 2022
e71ed67
Continue implementing issuing BGPSec certificates (incomplete, #827)
Jun 15, 2022
a1bc56f
Merge branch 'main' into dev
Jun 15, 2022
080a52a
Merge branch 'dev' into sign-bgpsec
Jun 15, 2022
05a866d
Support signing BGPSec certificates through CLI/API. (#827)
Jun 16, 2022
3e64ed5
Use rpki-rs 0.15.0 with all features (hsm in particular).
Jun 17, 2022
6bbbee4
Depend on merged rpki-rs 0.15.0-dev
Jun 17, 2022
6c5b54a
Fix more errors with all features enabled
Jun 17, 2022
ed67c49
Remove the direct dependency on bcder #822.
Jun 20, 2022
5b719a7
Merge branch 'sign-bgpsec' into migrate_0_10_0
Jun 23, 2022
a7027d3
Use IdCertInfo internally, use IdCert for API.
Jun 27, 2022
ded38c1
Support migrating the RepositoryAccess component of the publication s…
Jun 28, 2022
bd04c33
Some quick clippy fixes
Jun 28, 2022
a6853fe
Migrate CAs
Jun 28, 2022
44d0d32
Use internal type for certitificates in stored structure and history.…
Jun 30, 2022
00cb5c9
Migrate CaObjects structure.
Jul 1, 2022
4a537a8
Fix certificate names.
Jul 1, 2022
ea0d1f0
Fix tests for all-features.
Jul 1, 2022
2218d8a
Only store the essence of manifests.
Jul 1, 2022
b62c079
Depend on branch for rpki rs PR
Jul 3, 2022
24903f6
Don't reissue mft only on signing cert uri change. (see #840)
Jul 3, 2022
3710094
Track object set revision in one place.
Jul 4, 2022
a4cc5f1
Introduce PublishedItem
Jul 4, 2022
34e6c7e
Do not depend on Crl object type when publishing.
Jul 4, 2022
0a1cec9
Do not store ROA objects in history.
Jul 4, 2022
f024738
Do not store ASPA objects in history
Jul 5, 2022
4793b6a
Remove unused RevokedObject - handled elsewhere.
Jul 5, 2022
8567ee9
Fix lifetime annotations
Jul 5, 2022
46c62c2
No longer store certificates in object set for publication.
Jul 5, 2022
0f734ad
Do not store full BgpSecCertInfo in current object set
Jul 5, 2022
835414b
No longer rely on Cert in TaCertDetails.
Jul 6, 2022
21c8ce4
Depend on merged rpki-rs
Jul 6, 2022
c43760c
Remove dead code
Jul 6, 2022
f634141
Ignore test until #821 gets done.
Jul 6, 2022
1800674
Merge branch 'dev' into migrate_0_10_0
Jul 7, 2022
d024e25
Clean up use statement
Jul 7, 2022
e951f07
Enable rc feature to allow serde of ObjectName with no-default-features
Jul 7, 2022
36e3b33
Test and fix RPKI keyroll over (RFC 6489) issues (#749)
Jul 11, 2022
02f78c6
Merge branch 'migrate_0_10_0' into remove-bcder
Jul 11, 2022
b061be0
Clean up unused (commented out) code
Jul 11, 2022
84add6d
Update to using updated rpki-rs implementation.
Jul 11, 2022
9e50591
Merge branch 'dev' into remove-bcder
Jul 18, 2022
cb73f63
Fix merge error
Jul 18, 2022
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
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ build = "build.rs"
backoff = { version = "0.3.0", optional = true }
base64 = "^0.13"
basic-cookies = { version = "^0.1", optional = true }
bcder = "0.6.1"
bytes = "1"
chrono = { version = "^0.4", features = ["serde"] }
clap = "^2.33"
Expand Down
10 changes: 3 additions & 7 deletions src/commons/crypto/error.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use std::fmt;
use std::fmt::Display;

use bcder::decode;

#[derive(Debug)]
pub enum Error {
KeyError(String),
SigningError(String),
KeyNotFound,
SignerError(String),
DecodeError(decode::Error),
DecodeError(String),
}

impl fmt::Display for Error {
Expand All @@ -36,10 +34,8 @@ impl Error {
pub fn signer(e: impl Display) -> Self {
Error::SignerError(e.to_string())
}
}

impl From<decode::Error> for Error {
fn from(e: decode::Error) -> Self {
Error::DecodeError(e)
pub fn decode(e: impl Display) -> Self {
Error::DecodeError(e.to_string())
}
}
2 changes: 1 addition & 1 deletion src/commons/crypto/signing/dispatch/krillsigner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl KrillSigner {
.map_err(crypto::Error::signing)?;

// Decode the encoded CSR again to get a typed RpkiCaCsr
Ok(RpkiCaCsr::decode(signed_and_encoded_csr.as_slice())?)
RpkiCaCsr::decode(signed_and_encoded_csr.as_slice()).map_err(crypto::Error::signing)
}

pub fn sign_cert(&self, tbs: TbsCert, key_id: &KeyIdentifier) -> CryptoResult<Cert> {
Expand Down
70 changes: 27 additions & 43 deletions src/commons/crypto/signing/signers/kmip/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{
};

use backoff::ExponentialBackoff;
use bcder::encode::{PrimitiveContent, Values};
use bytes::Bytes;
use kmip::{
client::{Client, ClientCertificate},
Expand All @@ -35,7 +34,6 @@ use crate::commons::{
signers::{
kmip::connpool::ConnectionManager,
probe::{ProbeError, ProbeStatus, StatefulProbe},
util,
},
SignerError, SignerHandle,
},
Expand Down Expand Up @@ -718,8 +716,7 @@ impl KmipSigner {
Ok(public_key)
}

/// Get the RSA public bytes for the given KMIP server public key.
fn get_rsa_public_key_bytes(&self, public_key_id: &str) -> Result<Bytes, SignerError> {
pub(super) fn get_public_key_from_id(&self, public_key_id: &str) -> Result<PublicKey, SignerError> {
let response_payload = self.with_conn("get key", |conn| conn.get_key(public_key_id))?;

if response_payload.object_type != ObjectType::PublicKey {
Expand All @@ -737,56 +734,43 @@ impl KmipSigner {
}
};

let rsa_public_key_bytes = match key_material {
KeyMaterial::Bytes(bytes) => bytes::Bytes::from(bytes),
match key_material {
KeyMaterial::Bytes(bytes) => {
PublicKey::rsa_from_bits_bytes(bytes::Bytes::from(bytes)).map_err(|e| {
SignerError::KmipError(format!(
"Failed to construct RSA Public for key with ID '{}'. Error: {}",
public_key_id, e
))
})
}
KeyMaterial::TransparentRSAPublicKey(pub_key) => {
util::rsa_public_key_bytes_from_parts(&pub_key.modulus, &pub_key.public_exponent)?
PublicKey::rsa_from_components(&pub_key.modulus, &pub_key.public_exponent).map_err(|e| {
SignerError::KmipError(format!(
"Failed to construct RSA Public for key with ID '{}'. Error: {}",
public_key_id, e
))
})
}
KeyMaterial::TransparentRSAPrivateKey(priv_key) => {
if let Some(public_exponent) = priv_key.public_exponent {
util::rsa_public_key_bytes_from_parts(&priv_key.modulus, &public_exponent)?
PublicKey::rsa_from_components(&priv_key.modulus, &public_exponent).map_err(|e| {
SignerError::KmipError(format!(
"Failed to construct RSA Public for key with ID '{}'. Error: {}",
public_key_id, e
))
})
} else {
return Err(SignerError::KmipError(format!(
Err(SignerError::KmipError(format!(
"Failed to get key material: missing exponent in transparent RSA private key returned by KMIP Get operation for public key with ID '{}'",
public_key_id)));
public_key_id)))
}
}
_ => {
return Err(SignerError::KmipError(format!(
Err(SignerError::KmipError(format!(
"Failed to get key material: unsupported key material type {:?} returned by KMIP Get operation for public key with ID '{}'",
key_material, public_key_id)));
key_material, public_key_id)))
}
};

Ok(rsa_public_key_bytes)
}

pub(super) fn get_public_key_from_id(&self, public_key_id: &str) -> Result<PublicKey, SignerError> {
let rsa_public_key_bytes = self.get_rsa_public_key_bytes(public_key_id)?;

let subject_public_key = bcder::BitString::new(0, rsa_public_key_bytes);

let subject_public_key_info =
bcder::encode::sequence((PublicKeyFormat::Rsa.encode(), subject_public_key.encode()));

let mut subject_public_key_info_source: Vec<u8> = Vec::new();
subject_public_key_info
.write_encoded(bcder::Mode::Der, &mut subject_public_key_info_source)
.map_err(|err| {
SignerError::KmipError(format!(
"Failed to create DER encoded SubjectPublicKeyInfo from constituent parts: {}",
err
))
})?;

let public_key = PublicKey::decode(subject_public_key_info_source.as_slice()).map_err(|err| {
SignerError::KmipError(format!(
"Failed to create public key from the DER encoded SubjectPublicKeyInfo: {}",
err
))
})?;

Ok(public_key)
}
}

pub(super) fn sign_with_key<Alg: SignatureAlgorithm>(
Expand Down
3 changes: 0 additions & 3 deletions src/commons/crypto/signing/signers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ pub mod pkcs11;

pub mod softsigner;

#[cfg(feature = "hsm")]
pub mod util;

#[cfg(feature = "hsm")]
pub mod probe;

Expand Down
57 changes: 19 additions & 38 deletions src/commons/crypto/signing/signers/pkcs11/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::{

use backoff::ExponentialBackoff;

use bcder::encode::{PrimitiveContent, Values};
use bytes::Bytes;
use cryptoki::{
context::Info,
Expand All @@ -35,7 +34,6 @@ use crate::commons::crypto::{
session::Pkcs11Session,
},
probe::{ProbeError, ProbeStatus, StatefulProbe},
util,
},
SignerError, SignerHandle,
};
Expand Down Expand Up @@ -722,50 +720,33 @@ impl Pkcs11Signer {
Ok((public_key, pub_handle, priv_handle, hex::encode(cka_id)))
}

fn get_rsa_public_key_bytes(&self, pub_handle: ObjectHandle) -> Result<Bytes, SignerError> {
pub(super) fn get_public_key_from_handle(&self, pub_handle: ObjectHandle) -> Result<PublicKey, SignerError> {
let res = self.with_conn("get key pair parts", |conn| {
conn.get_attributes(pub_handle, &[AttributeType::Modulus, AttributeType::PublicExponent])
})?;

if res.len() == 2 {
if let (Attribute::Modulus(m), Attribute::PublicExponent(e)) = (&res[0], &res[1]) {
return util::rsa_public_key_bytes_from_parts(m, e);
PublicKey::rsa_from_components(m, e).map_err(|e| {
SignerError::Pkcs11Error(format!(
"Failed to construct RSA Public for key '{:?}'. Error: {}",
pub_handle, e
))
})
} else {
Err(SignerError::Pkcs11Error(format!(
"Unable to obtain modulus and public exponent for key {:?}. Got two different attribute types: {} and {}",
pub_handle,
res[0].attribute_type(),
res[1].attribute_type(),
)))
}
} else {
Err(SignerError::Pkcs11Error(format!(
"Unable to obtain modulus and public exponent attributes for key {:?}",
pub_handle
)))
}

Err(SignerError::Pkcs11Error(format!(
"Unable to obtain modulus and public exponent for key {:?}",
pub_handle
)))
}

// TODO: This is almost identical to the equivalent fn in KmipSigner. Factor out the common code.
pub(super) fn get_public_key_from_handle(&self, pub_handle: ObjectHandle) -> Result<PublicKey, SignerError> {
let rsa_public_key_bytes = self.get_rsa_public_key_bytes(pub_handle)?;

let subject_public_key = bcder::BitString::new(0, rsa_public_key_bytes);

let subject_public_key_info =
bcder::encode::sequence((PublicKeyFormat::Rsa.encode(), subject_public_key.encode()));

let mut subject_public_key_info_source: Vec<u8> = Vec::new();
subject_public_key_info
.write_encoded(bcder::Mode::Der, &mut subject_public_key_info_source)
.map_err(|err| {
SignerError::Pkcs11Error(format!(
"Failed to create DER encoded SubjectPublicKeyInfo from constituent parts: {}",
err
))
})?;

let public_key = PublicKey::decode(subject_public_key_info_source.as_slice()).map_err(|err| {
SignerError::Pkcs11Error(format!(
"Failed to create public key from the DER encoded SubjectPublicKeyInfo: {}",
err
))
})?;

Ok(public_key)
}

pub(super) fn sign_with_key<Alg: SignatureAlgorithm>(
Expand Down
17 changes: 0 additions & 17 deletions src/commons/crypto/signing/signers/util.rs

This file was deleted.

2 changes: 1 addition & 1 deletion src/daemon/ca/publishing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ impl ResourceClassObjects {

fn reissue(&mut self, timing: &IssuanceTimingConfig, signer: &KrillSigner) -> KrillResult<()> {
match self.keys.borrow_mut() {
ResourceClassKeyState::Current(state) => state.current_set.reissue(timing, signer),
ResourceClassKeyState::Current(state) => state.current_set.reissue_set(timing, signer),
ResourceClassKeyState::Staging(state) => {
state.staging_set.reissue_set(timing, signer)?;
state.current_set.reissue(timing, signer)
Expand Down
11 changes: 7 additions & 4 deletions src/daemon/http/tls_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//! in case they are not provided
use std::{fmt, path::Path, path::PathBuf};

use bcder::decode;
use bytes::Bytes;

use openssl::{
Expand Down Expand Up @@ -129,8 +128,8 @@ impl HttpsSigner {
.public_key_to_der()
.map_err(Error::OpenSslError)?,
);
let pk = PublicKey::decode(&mut b).map_err(Error::DecodeError)?;
Ok(pk)

PublicKey::decode(&mut b).map_err(Error::decode)
}

// See OpenSslSigner::sign_with_key for reference.
Expand Down Expand Up @@ -173,7 +172,7 @@ impl HttpsSigner {
pub enum Error {
IoError(KrillIoError),
OpenSslError(openssl::error::ErrorStack),
DecodeError(decode::Error),
DecodeError(String),
BuildError,
EmptyCertStack,
Pkcs12(String),
Expand All @@ -185,6 +184,10 @@ impl Error {
pub fn signer(e: impl fmt::Display) -> Self {
Error::SignerError(e.to_string())
}

pub fn decode(e: impl fmt::Display) -> Self {
Error::DecodeError(e.to_string())
}
}

impl fmt::Display for Error {
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#![allow(clippy::upper_case_acronyms)]
extern crate base64;
extern crate bcder;
// #[macro_use]
extern crate bytes;
extern crate chrono;
extern crate clap;
Expand Down