Skip to content

Commit

Permalink
go/worker/keymanager: Rename error messages and simplify code
Browse files Browse the repository at this point in the history
Renames request not authorized error message and uses
block_on function to simplify the code.
  • Loading branch information
peternose committed Jul 9, 2024
1 parent 48de9d9 commit 8812ba2
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go/worker/keymanager/churp.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ func (w *churpWorker) authorizeNode(ctx context.Context, peerID core.PeerID) err
}
}
}
return fmt.Errorf("request not allowed")
return fmt.Errorf("query not allowed")
default:
return fmt.Errorf("unsupported hardware: %s", rt.TEEHardware)
}
Expand Down
2 changes: 1 addition & 1 deletion go/worker/keymanager/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (w *secretsWorker) authorizeNode(ctx context.Context, peerID core.PeerID, k
}
}
}
return fmt.Errorf("request not allowed")
return fmt.Errorf("query not allowed")
default:
return fmt.Errorf("unsupported hardware: %s", rt.TEEHardware)
}
Expand Down
23 changes: 8 additions & 15 deletions tests/runtimes/simple-keyvalue/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,11 @@ impl Methods {
let key_pair_id = KeyPairId::from(Hash::digest_bytes(key).as_ref());

// Fetch encryption keys.
let result = ctx
let future = ctx
.parent
.key_manager
.get_or_create_keys(key_pair_id, generation);
let key = tokio::runtime::Handle::current()
.block_on(result)
.map_err(|err| err.to_string())?;
let key = block_on(future).map_err(|err| err.to_string())?;

Ok(key.state_key)
}
Expand All @@ -284,10 +282,8 @@ impl Methods {
let key_id = KeyPairId::from(Hash::digest_bytes(key).as_ref());

// Fetch encryption key.
let result = ctx.parent.key_manager.churp_state_key(churp_id, key_id);
let state_key = tokio::runtime::Handle::current()
.block_on(result)
.map_err(|err| err.to_string())?;
let future = ctx.parent.key_manager.churp_state_key(churp_id, key_id);
let state_key = block_on(future).map_err(|err| err.to_string())?;

Ok(state_key)
}
Expand Down Expand Up @@ -433,13 +429,11 @@ impl Methods {
let key_pair_id = KeyPairId::from(hash.as_ref());

// Fetch public key.
let result = ctx
let future = ctx
.parent
.key_manager
.get_public_ephemeral_key(key_pair_id, args.epoch);
let long_term_pk = tokio::runtime::Handle::current()
.block_on(result)
.map_err(|err| err.to_string())?;
let long_term_pk = block_on(future).map_err(|err| err.to_string())?;

// Generate ephemeral key. Not secure, but good enough for testing purposes.
let ephemeral_sk = x25519::PrivateKey::from(hash);
Expand Down Expand Up @@ -473,12 +467,11 @@ impl Methods {
let key_pair_id = KeyPairId::from(hash.as_ref());

// Fetch private key.
let result = ctx
let future = ctx
.parent
.key_manager
.get_or_create_ephemeral_keys(key_pair_id, args.epoch);
let long_term_sk = tokio::runtime::Handle::current()
.block_on(result)
let long_term_sk = block_on(future)
.map_err(|err| format!("private ephemeral key not available: {err}"))?;

// Decode ephemeral_pk || ciphertext.
Expand Down

0 comments on commit 8812ba2

Please sign in to comment.