Skip to content

Commit 6dac73b

Browse files
committed
refactor(crypto): CRP-1416: remove obsolete CryptoComponentForNonReplicaProcess trait
1 parent 72f5918 commit 6dac73b

File tree

5 files changed

+25
-165
lines changed

5 files changed

+25
-165
lines changed

rs/crypto/src/lib.rs

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,15 @@ use ic_config::crypto::CryptoConfig;
2626
use ic_crypto_internal_csp::api::CspPublicKeyStore;
2727
use ic_crypto_internal_csp::{CryptoServiceProvider, Csp};
2828
use ic_crypto_internal_logmon::metrics::CryptoMetrics;
29-
use ic_crypto_tls_interfaces::TlsHandshake;
3029
use ic_crypto_utils_basic_sig::conversions::derive_node_id;
3130
use ic_crypto_utils_time::CurrentSystemTimeSource;
32-
use ic_interfaces::crypto::{BasicSigner, KeyManager, ThresholdSigVerifierByPublicKey};
31+
use ic_interfaces::crypto::KeyManager;
3332
use ic_interfaces::time_source::TimeSource;
3433
use ic_interfaces_registry::RegistryClient;
3534
use ic_logger::{new_logger, ReplicaLogger};
3635
use ic_metrics::MetricsRegistry;
3736
use ic_protobuf::registry::crypto::v1::{PublicKey as PublicKeyProto, X509PublicKeyCert};
38-
use ic_types::consensus::CatchUpContentProtobufBytes;
3937
use ic_types::crypto::{CryptoError, CryptoResult, KeyPurpose};
40-
use ic_types::messages::MessageId;
4138
use ic_types::{NodeId, RegistryVersion};
4239
use parking_lot::{RwLock, RwLockReadGuard, RwLockWriteGuard};
4340
use std::fmt;
@@ -51,42 +48,6 @@ pub const THRESHOLD_SIG_DATA_STORE_CAPACITY: usize = ThresholdSigDataStoreImpl::
5148
/// See the Rust documentation of `CryptoComponentImpl`.
5249
pub type CryptoComponent = CryptoComponentImpl<Csp>;
5350

54-
/// A crypto component that offers limited functionality and can be used outside
55-
/// of the replica process.
56-
///
57-
/// This is an intermediate solution before crypto runs in a separate process.
58-
///
59-
/// This should be used whenever crypto is required on a node, but a
60-
/// full-fledged `CryptoComponent` is not available. Example use cases are in
61-
/// separate process such as ic-fe or the orchestrator.
62-
///
63-
/// Do not instantiate a CryptoComponent outside of the replica process, since
64-
/// that may lead to problems with concurrent access to the secret key store.
65-
/// `CryptoComponentForNonReplicaProcess` guarantees that only methods are
66-
/// exposed that don't risk running into such concurrency issues, as they do not
67-
/// modify the secret key store.
68-
pub trait CryptoComponentForNonReplicaProcess:
69-
KeyManager
70-
+ BasicSigner<MessageId>
71-
+ ThresholdSigVerifierByPublicKey<CatchUpContentProtobufBytes>
72-
+ TlsHandshake
73-
+ Send
74-
+ Sync // TODO(CRP-606): add API for authenticating registry queries.
75-
{
76-
}
77-
78-
// Blanket implementation of `CryptoComponentForNonReplicaProcess` for all types
79-
// that fulfill the requirements.
80-
impl<T> CryptoComponentForNonReplicaProcess for T where
81-
T: KeyManager
82-
+ BasicSigner<MessageId>
83-
+ ThresholdSigVerifierByPublicKey<CatchUpContentProtobufBytes>
84-
+ TlsHandshake
85-
+ Send
86-
+ Sync
87-
{
88-
}
89-
9051
/// Allows Internet Computer nodes to perform crypto operations such as
9152
/// distributed key generation, signing, signature verification, and TLS
9253
/// handshakes.
@@ -282,54 +243,6 @@ impl CryptoComponentImpl<Csp> {
282243
}
283244
}
284245

285-
/// Creates a crypto component that offers limited functionality and can be
286-
/// used outside of the replica process.
287-
///
288-
/// Please refer to the trait documentation of
289-
/// `CryptoComponentForNonReplicaProcess` for more details.
290-
///
291-
/// If the `config`'s vault type is `UnixSocket`, a `tokio_runtime_handle`
292-
/// must be provided, which is then used for the `async`hronous
293-
/// communication with the vault via RPC for secret key operations. In most
294-
/// cases, this is done by calling `tokio::runtime::Handle::block_on` and
295-
/// it is the caller's responsibility to ensure that these calls to
296-
/// `block_on` do not panic. This can be achieved, for example, by ensuring
297-
/// that the crypto component's methods are not themselves called from
298-
/// within a call to `block_on` (because calls to `block_on` cannot be
299-
/// nested), or by wrapping them with `tokio::task::block_in_place`
300-
/// and accepting the performance implications.
301-
/// Because the asynchronous communication with the vault happens only for
302-
/// secret key operations, for the `CryptoComponentImpl` the concerned
303-
/// methods are
304-
/// * `KeyManager::check_keys_with_registry`
305-
/// * `BasicSigner::sign_basic`
306-
///
307-
/// The methods of the `TlsHandshake` trait are unaffected by this.
308-
///
309-
/// # NOTE:
310-
/// Callers of this method are strongly encouraged to switch from using
311-
/// `CryptoComponentForNonReplicaProcess`, to using the full crypto component,
312-
/// by calling `new` instead of `new_for_non_replica_process`.
313-
///
314-
/// # Panics
315-
/// Panics if the `config`'s vault type is `UnixSocket` and
316-
/// `tokio_runtime_handle` is `None`.
317-
pub fn new_for_non_replica_process(
318-
config: &CryptoConfig,
319-
tokio_runtime_handle: Option<tokio::runtime::Handle>,
320-
registry_client: Arc<dyn RegistryClient>,
321-
logger: ReplicaLogger,
322-
metrics_registry: Option<&MetricsRegistry>,
323-
) -> impl CryptoComponentForNonReplicaProcess {
324-
CryptoComponentImpl::new(
325-
config,
326-
tokio_runtime_handle,
327-
registry_client,
328-
logger,
329-
metrics_registry,
330-
)
331-
}
332-
333246
/// Returns the `NodeId` of this crypto component.
334247
pub fn get_node_id(&self) -> NodeId {
335248
self.node_id

rs/crypto/tests/integration_test.rs

Lines changed: 0 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use ic_crypto_internal_csp_test_utils::remote_csp_vault::{
99
get_temp_file_path, start_new_remote_csp_vault_server_for_test,
1010
};
1111
use ic_crypto_internal_tls::generate_tls_key_pair_der;
12-
use ic_crypto_node_key_generation::generate_node_keys_once;
13-
use ic_crypto_node_key_validation::ValidNodePublicKeys;
1412
use ic_crypto_temp_crypto::{EcdsaSubnetConfig, NodeKeysToGenerate, TempCryptoComponent};
1513
use ic_crypto_test_utils::files::temp_dir;
1614
use ic_crypto_test_utils_keygen::{add_public_key_to_registry, add_tls_cert_to_registry};
@@ -102,70 +100,6 @@ fn should_not_construct_crypto_component_if_remote_csp_vault_is_missing() {
102100
);
103101
}
104102

105-
#[test]
106-
#[should_panic(expected = "Missing node signing public key")]
107-
fn should_not_construct_crypto_component_for_non_replica_process_without_keys() {
108-
CryptoConfig::run_with_temp_config(|config| {
109-
let registry_client = FakeRegistryClient::new(Arc::new(ProtoRegistryDataProvider::new()));
110-
let _crypto = CryptoComponent::new_for_non_replica_process(
111-
&config,
112-
None,
113-
Arc::new(registry_client),
114-
no_op_logger(),
115-
None,
116-
);
117-
})
118-
}
119-
120-
#[test]
121-
fn should_successfully_construct_crypto_component_for_non_replica_process_with_default_config_and_keys(
122-
) {
123-
CryptoConfig::run_with_temp_config(|config| {
124-
// Create node keys.
125-
let _created_node_pks =
126-
generate_node_keys_once(&config, None).expect("error generating node public keys");
127-
128-
let registry_client = FakeRegistryClient::new(Arc::new(ProtoRegistryDataProvider::new()));
129-
let _crypto = CryptoComponent::new_for_non_replica_process(
130-
&config,
131-
None,
132-
Arc::new(registry_client),
133-
no_op_logger(),
134-
None,
135-
);
136-
})
137-
}
138-
139-
#[test]
140-
fn should_provide_public_keys_via_crypto_for_non_replica_process() {
141-
CryptoConfig::run_with_temp_config(|config| {
142-
// Create node keys.
143-
let created_node_pks =
144-
generate_node_keys_once(&config, None).expect("error generating node public keys");
145-
let node_id = created_node_pks.node_id();
146-
147-
let registry_client = FakeRegistryClient::new(Arc::new(ProtoRegistryDataProvider::new()));
148-
let crypto = CryptoComponent::new_for_non_replica_process(
149-
&config,
150-
None,
151-
Arc::new(registry_client),
152-
no_op_logger(),
153-
None,
154-
);
155-
156-
let retrieved_node_pks = ValidNodePublicKeys::try_from(
157-
crypto
158-
.current_node_public_keys()
159-
.expect("Failed to retrieve node public keys"),
160-
node_id,
161-
ic_types::time::current_time(),
162-
)
163-
.expect("retrieved keys are not valid");
164-
165-
assert_eq!(created_node_pks, retrieved_node_pks);
166-
})
167-
}
168-
169103
// TODO(CRP-430): check/improve the test coverage of SKS checks.
170104

171105
#[test]

rs/orchestrator/src/catch_up_package_provider.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ use crate::error::{OrchestratorError, OrchestratorResult};
3434
use crate::registry_helper::RegistryHelper;
3535
use ic_canister_client::Sender;
3636
use ic_canister_client::{Agent, HttpClient};
37-
use ic_crypto::CryptoComponentForNonReplicaProcess;
37+
use ic_interfaces::crypto::ThresholdSigVerifierByPublicKey;
3838
use ic_logger::{info, warn, ReplicaLogger};
3939
use ic_protobuf::registry::node::v1::NodeRecord;
4040
use ic_protobuf::types::v1 as pb;
@@ -60,7 +60,7 @@ pub(crate) struct CatchUpPackageProvider {
6060
registry: Arc<RegistryHelper>,
6161
cup_dir: PathBuf,
6262
client: HttpClient,
63-
crypto: Arc<dyn CryptoComponentForNonReplicaProcess + Send + Sync>,
63+
crypto: Arc<dyn ThresholdSigVerifierByPublicKey<CatchUpContentProtobufBytes> + Send + Sync>,
6464
logger: ReplicaLogger,
6565
node_id: NodeId,
6666
}
@@ -70,7 +70,7 @@ impl CatchUpPackageProvider {
7070
pub(crate) fn new(
7171
registry: Arc<RegistryHelper>,
7272
cup_dir: PathBuf,
73-
crypto: Arc<dyn CryptoComponentForNonReplicaProcess + Send + Sync>,
73+
crypto: Arc<dyn ThresholdSigVerifierByPublicKey<CatchUpContentProtobufBytes> + Send + Sync>,
7474
logger: ReplicaLogger,
7575
node_id: NodeId,
7676
) -> Self {

rs/orchestrator/src/orchestrator.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::registry_helper::RegistryHelper;
1111
use crate::ssh_access_manager::SshAccessManager;
1212
use crate::upgrade::Upgrade;
1313
use ic_config::metrics::{Config as MetricsConfig, Exporter};
14-
use ic_crypto::{CryptoComponent, CryptoComponentForNonReplicaProcess};
14+
use ic_crypto::CryptoComponent;
1515
use ic_crypto_node_key_generation::{generate_node_keys_once, NodeKeyGenerationError};
1616
use ic_crypto_tls_interfaces::TlsHandshake;
1717
use ic_http_endpoints_metrics::MetricsHttpEndpoint;
@@ -152,7 +152,7 @@ impl Orchestrator {
152152
let crypto_config = config.crypto.clone();
153153
let c_metrics = metrics_registry.clone();
154154
let crypto = tokio::task::spawn_blocking(move || {
155-
Arc::new(CryptoComponent::new_for_non_replica_process(
155+
Arc::new(CryptoComponent::new(
156156
&crypto_config,
157157
Some(tokio::runtime::Handle::current()),
158158
c_registry.get_registry_client(),
@@ -169,7 +169,7 @@ impl Orchestrator {
169169
&slog_logger,
170170
&metrics_registry,
171171
registry.get_registry_client(),
172-
crypto.clone(),
172+
Arc::clone(&crypto) as _,
173173
);
174174
let metrics = Arc::new(metrics);
175175

@@ -184,7 +184,7 @@ impl Orchestrator {
184184
Arc::clone(&registry_client),
185185
Arc::clone(&metrics),
186186
node_id,
187-
Arc::clone(&crypto) as Arc<dyn CryptoComponentForNonReplicaProcess>,
187+
Arc::clone(&crypto) as _,
188188
registry_local_store.clone(),
189189
);
190190

@@ -198,7 +198,7 @@ impl Orchestrator {
198198
let cup_provider = Arc::new(CatchUpPackageProvider::new(
199199
Arc::clone(&registry),
200200
args.cup_dir.clone(),
201-
crypto.clone(),
201+
Arc::clone(&crypto) as _,
202202
logger.clone(),
203203
node_id,
204204
));

rs/orchestrator/src/registration.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use ic_config::{
1414
transport::TransportConfig,
1515
Config,
1616
};
17-
use ic_crypto::CryptoComponentForNonReplicaProcess;
1817
use ic_icos_sev::{get_chip_id, SnpError};
1918
use ic_interfaces::crypto::IDkgKeyRotationResult;
2019
use ic_interfaces_registry::RegistryClient;
@@ -42,14 +41,28 @@ use url::Url;
4241
/// we use a 15% time buffer compensating for a potential delay of the previous node.
4342
const DELAY_COMPENSATION: f64 = 0.85;
4443

44+
pub trait NodeRegistrationCrypto:
45+
ic_interfaces::crypto::KeyManager + ic_interfaces::crypto::BasicSigner<MessageId> + Send + Sync
46+
{
47+
}
48+
49+
// Blanket implementation of `NodeRegistrationCrypto` for all types that fulfill the requirements.
50+
impl<T> NodeRegistrationCrypto for T where
51+
T: ic_interfaces::crypto::KeyManager
52+
+ ic_interfaces::crypto::BasicSigner<MessageId>
53+
+ Send
54+
+ Sync
55+
{
56+
}
57+
4558
/// Subcomponent used to register this node with the provided NNS.
4659
pub(crate) struct NodeRegistration {
4760
log: ReplicaLogger,
4861
node_config: Config,
4962
registry_client: Arc<dyn RegistryClient>,
5063
metrics: Arc<OrchestratorMetrics>,
5164
node_id: NodeId,
52-
key_handler: Arc<dyn CryptoComponentForNonReplicaProcess>,
65+
key_handler: Arc<dyn NodeRegistrationCrypto>,
5366
local_store: Arc<dyn LocalStore>,
5467
signer: Box<dyn Signer>,
5568
}
@@ -63,7 +76,7 @@ impl NodeRegistration {
6376
registry_client: Arc<dyn RegistryClient>,
6477
metrics: Arc<OrchestratorMetrics>,
6578
node_id: NodeId,
66-
key_handler: Arc<dyn CryptoComponentForNonReplicaProcess>,
79+
key_handler: Arc<dyn NodeRegistrationCrypto>,
6780
local_store: Arc<dyn LocalStore>,
6881
) -> Self {
6982
// If we can open a PEM file under the path specified in the replica config,

0 commit comments

Comments
 (0)