Skip to content

Commit 5f1e3ca

Browse files
committed
chore: address comments
1 parent 682c741 commit 5f1e3ca

File tree

12 files changed

+425
-909
lines changed

12 files changed

+425
-909
lines changed

core/grpc/proto/kms-service-insecure.v1.proto

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,52 @@ package kms_service.v1;
33

44
import "kms.v1.proto";
55

6+
// WARNING: This service is insecure and should not be used in production.
7+
//
8+
// Since this is the insecure endpoint, we do not duplicate
9+
// the documentation. Please see the documentation of the secure endpoint.
10+
// All insecure RPCs (i.e., the ones that have `Insecure` in the prefix)
11+
// have the same semantics as the secure ones.
612
service CoreServiceEndpoint {
7-
// Perform the threshold KMS initialization.
8-
// This call returns an error on the centralized KMS.
913
rpc Init(kms.v1.InitRequest) returns (kms.v1.Empty);
1014

11-
// Start generating preprocessing materials for key generation asynchronously.
12-
// This call returns an error on the centralized KMS.
1315
rpc KeyGenPreproc(kms.v1.KeyGenPreprocRequest) returns (kms.v1.Empty);
1416

15-
// This call returns an error on the centralized KMS.
1617
rpc GetKeyGenPreprocResult(kms.v1.RequestId) returns (kms.v1.KeyGenPreprocResult);
1718

18-
// Generate new keys asynchronously.
1919
rpc KeyGen(kms.v1.KeyGenRequest) returns (kms.v1.Empty);
2020

21-
// Return a URI where they can be accessed.
22-
// The keys at the URI contains signature and authentication information.
23-
// NOTE: Unprivileged and insecure call
2421
rpc GetKeyGenResult(kms.v1.RequestId) returns (kms.v1.KeyGenResult);
2522

26-
// Generate new keys asynchronously.
2723
rpc InsecureKeyGen(kms.v1.KeyGenRequest) returns (kms.v1.Empty);
2824

29-
// Return a URI where they can be accessed.
30-
// The keys at the URI contains signature and authentication information.
31-
// NOTE: Unprivileged and insecure call
3225
rpc GetInsecureKeyGenResult(kms.v1.RequestId) returns (kms.v1.KeyGenResult);
3326

34-
// Perform public decryption of a ciphertext and return the signed plaintext.
3527
rpc PublicDecrypt(kms.v1.PublicDecryptionRequest) returns (kms.v1.Empty);
3628

37-
// Get the public decryption result.
38-
// This query fails if the result is not available yet.
3929
rpc GetPublicDecryptionResult(kms.v1.RequestId) returns (kms.v1.PublicDecryptionResponse);
4030

41-
// Perform user decryption of a ciphertext under a user-specified key and return a signcrypted
42-
// share of the decrypted plaintext.
4331
rpc UserDecrypt(kms.v1.UserDecryptionRequest) returns (kms.v1.Empty);
4432

45-
// Get the user decryption result.
46-
// This query fails if the result is not available yet.
4733
rpc GetUserDecryptionResult(kms.v1.RequestId) returns (kms.v1.UserDecryptionResponse);
4834

49-
// Start the CRS generation protocol asynchronously.
5035
rpc CrsGen(kms.v1.CrsGenRequest) returns (kms.v1.Empty);
5136

52-
// Get a reference to the CRS.
53-
// This query fails if the result is not available yet.
5437
rpc GetCrsGenResult(kms.v1.RequestId) returns (kms.v1.CrsGenResult);
5538

56-
// Start the insecure CRS generation protocol asynchronously.
5739
rpc InsecureCrsGen(kms.v1.CrsGenRequest) returns (kms.v1.Empty);
5840

59-
// Get a reference to the insecure CRS.
60-
// This query fails if the result is not available yet.
6141
rpc GetInsecureCrsGenResult(kms.v1.RequestId) returns (kms.v1.CrsGenResult);
6242

63-
// Create a new KMS context, it may be created without an existing one.
6443
rpc NewKmsContext(kms.v1.NewKmsContextRequest) returns (kms.v1.Empty);
6544

66-
// Destroy an existing KMS context.
6745
rpc DestroyKmsContext(kms.v1.DestroyKmsContextRequest) returns (kms.v1.Empty);
6846

69-
// Create a new custodian context, it may be created without an existing one.
7047
rpc NewCustodianContext(kms.v1.NewCustodianContextRequest) returns (kms.v1.Empty);
7148

72-
// Destroy an existing custodian context.
7349
rpc DestroyCustodianContext(kms.v1.DestroyCustodianContextRequest) returns (kms.v1.Empty);
7450

75-
// Get the public key that a custodian can use to encrypt a backup share
76-
// before sending it to the KMS.
7751
rpc GetOperatorPublicKey(kms.v1.Empty) returns (kms.v1.OperatorPublicKey);
7852

79-
// Restore the contents of the KMS private storage from custodian backup shares.
8053
rpc CustodianBackupRestore(kms.v1.Empty) returns (kms.v1.Empty);
8154
}

core/grpc/proto/kms-service.v1.proto

Lines changed: 307 additions & 26 deletions
Large diffs are not rendered by default.

core/grpc/src/identifiers.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ pub enum IdentifierError {
2424

2525
#[error("Invalid hex format: {0}")]
2626
InvalidHexFormat(#[from] hex::FromHexError),
27+
28+
#[error("Validation failure")]
29+
ValidationFailure,
2730
}
2831

2932
/// KeyId represents a unique identifier for a key in the system
@@ -349,29 +352,23 @@ macro_rules! impl_identifiers {
349352
type Error = IdentifierError;
350353

351354
fn try_from(proto: v1::RequestId) -> Result<Self, Self::Error> {
352-
Self::from_str(&proto.request_id)
355+
let out = Self::from_str(&proto.request_id)?;
356+
if !out.is_valid() {
357+
return Err(Self::Error::ValidationFailure);
358+
}
359+
Ok(out)
353360
}
354361
}
355362

356363
impl<'a> TryFrom<&'a v1::RequestId> for $type {
357364
type Error = IdentifierError;
358365

359366
fn try_from(proto: &'a v1::RequestId) -> Result<Self, Self::Error> {
360-
Self::from_str(&proto.request_id)
361-
}
362-
}
363-
364-
impl TryFrom<Option<v1::RequestId>> for $type {
365-
type Error = IdentifierError;
366-
367-
fn try_from(opt: Option<v1::RequestId>) -> Result<Self, Self::Error> {
368-
match opt {
369-
Some(proto) => $type::try_from(proto),
370-
None => Err(IdentifierError::InvalidLength {
371-
expected: ID_LENGTH,
372-
actual: 0,
373-
}),
367+
let out = Self::from_str(&proto.request_id)?;
368+
if !out.is_valid() {
369+
return Err(Self::Error::ValidationFailure);
374370
}
371+
Ok(out)
375372
}
376373
}
377374
};

core/service/src/client/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ impl Client {
928928

929929
let request_id = parse_optional_proto_request_id(
930930
&key_gen_result.request_id,
931-
RequestIdParsingErr::General("invalid ID while retrieving public key".to_string()),
931+
RequestIdParsingErr::Other("invalid ID while retrieving public key".to_string()),
932932
)
933933
.map_err(|e| anyhow::anyhow!(e.to_string()))?;
934934
tracing::debug!(
@@ -993,7 +993,7 @@ impl Client {
993993
)?;
994994
let request_id = parse_optional_proto_request_id(
995995
&key_gen_result.request_id,
996-
RequestIdParsingErr::General("invalid request ID while retrieving key".to_string()),
996+
RequestIdParsingErr::Other("invalid request ID while retrieving key".to_string()),
997997
)
998998
.map_err(|e| anyhow::anyhow!(e.to_string()))?;
999999
let key: S = self.get_key(&request_id, key_type, storage).await?;
@@ -1052,7 +1052,7 @@ impl Client {
10521052
)?;
10531053
let request_id = parse_optional_proto_request_id(
10541054
&crs_gen_result.request_id,
1055-
RequestIdParsingErr::General("invalid request ID while processing CRS".to_string()),
1055+
RequestIdParsingErr::Other("invalid request ID while processing CRS".to_string()),
10561056
)
10571057
.map_err(|e| anyhow::anyhow!(e.to_string()))?;
10581058
let pp = self.get_crs(&request_id, storage).await?;
@@ -6897,7 +6897,7 @@ pub(crate) mod tests {
68976897
}
68986898

68996899
wait_for_keygen_result(
6900-
req_keygen.request_id.clone().try_into().unwrap(),
6900+
req_keygen.request_id.clone().unwrap().try_into().unwrap(),
69016901
preproc_req_id,
69026902
kms_clients,
69036903
internal_client,

0 commit comments

Comments
 (0)