Skip to content

Commit

Permalink
keymanger-runtime: replace with test/simple-keymanager
Browse files Browse the repository at this point in the history
Common keymanager initalization code is extracted into the `keymanager-lib`
crate. This enables for the actual key manager implementation to only
provide a set of key manager policy signers.

Aditionally the `keymanager-runtime` crate is removed and replaced with
a test `simple-keymanager` runtime that is used in E2E tests.
  • Loading branch information
ptrus committed Apr 14, 2020
1 parent edb76f1 commit f55cdff
Show file tree
Hide file tree
Showing 31 changed files with 116 additions and 135 deletions.
6 changes: 3 additions & 3 deletions .buildkite/code.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,15 @@ steps:
# .buildkite/rust/test_runtime_and_gateway.sh and .buildkite/scripts/download_utils.sh.
- label: Build key manager runtime
command:
- .buildkite/rust/build_runtime.sh keymanager-runtime
- .buildkite/rust/build_runtime.sh tests/runtimes/simple-keymanager
- .buildkite/rust/build_runtime.sh tests/runtimes/simple-keyvalue

# Upload the built artifacts.
- cd /var/tmp/artifacts/sgx/x86_64-fortanix-unknown-sgx/debug
- buildkite-agent artifact upload oasis-core-keymanager-runtime.sgxs
- buildkite-agent artifact upload simple-keymanager.sgxs
- buildkite-agent artifact upload simple-keyvalue.sgxs
- cd /var/tmp/artifacts/default/debug
- buildkite-agent artifact upload oasis-core-keymanager-runtime
- buildkite-agent artifact upload simple-keymanager
- buildkite-agent artifact upload simple-keyvalue
agents:
buildkite_agent_size: large
Expand Down
6 changes: 3 additions & 3 deletions .buildkite/longtests.pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,15 @@ steps:

- label: Build key manager runtime
command:
- .buildkite/rust/build_runtime.sh keymanager-runtime
- .buildkite/rust/build_runtime.sh tests/runtimes/simple-keymanager
- .buildkite/rust/build_runtime.sh tests/runtimes/simple-keyvalue

# Upload the built artifacts.
- cd /var/tmp/artifacts/sgx/x86_64-fortanix-unknown-sgx/debug
- buildkite-agent artifact upload oasis-core-keymanager-runtime.sgxs
- buildkite-agent artifact upload simple-keymanager.sgxs
- buildkite-agent artifact upload simple-keyvalue.sgxs
- cd /var/tmp/artifacts/default/debug
- buildkite-agent artifact upload oasis-core-keymanager-runtime
- buildkite-agent artifact upload simple-keymanager
- buildkite-agent artifact upload simple-keyvalue
agents:
buildkite_agent_size: large
Expand Down
6 changes: 3 additions & 3 deletions .buildkite/scripts/download_e2e_test_artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ download_artifact oasis-test-runner.test go/oasis-test-runner 755
download_artifact oasis-remote-signer go/oasis-remote-signer 755
download_artifact oasis-core-runtime-loader target/default/debug 755

# Key manager runtime.
download_artifact oasis-core-keymanager-runtime.sgxs target/sgx/x86_64-fortanix-unknown-sgx/debug 755
download_artifact oasis-core-keymanager-runtime target/default/debug 755
# Simple Key manager runtime.
download_artifact simple-keymanager.sgxs target/sgx/x86_64-fortanix-unknown-sgx/debug 755
download_artifact simple-keymanager target/default/debug 755

# Test simple-keyvalue runtime and clients.
download_artifact test-long-term-client target/default/debug 755
Expand Down
7 changes: 7 additions & 0 deletions .changelog/2837.internal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
keymanger-runtime: replace with test/simple-keymanager

Common keymanager initalization code is extracted into the keymanager-lib
crate. This enables for the actual key manager implementation to only
provide a set of key manager policy signers.
Aditionally the `keymanager-runtime` crate is removed and replaced with
a test `simple-keymanager` runtime that is used in E2E tests.
43 changes: 13 additions & 30 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ members = [
"keymanager-client",
"keymanager-api-common",
"keymanager-lib",
"keymanager-runtime",
"tools",

# Test runtimes.
"tests/runtimes/simple-keyvalue",
"tests/runtimes/simple-keymanager",
# Test clients.
"tests/clients/simple-keyvalue",
"tests/clients/simple-keyvalue-enc",
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
include common.mk

# List of runtimes to build.
RUNTIMES := keymanager-runtime \
tests/runtimes/simple-keyvalue
RUNTIMES := tests/runtimes/simple-keyvalue \
tests/runtimes/simple-keymanager

# Set all target as the default target.
all: build
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ runtime, do:
--net.node.binary go/oasis-node/oasis-node \
--net.runtime.binary target/default/debug/simple-keyvalue \
--net.runtime.loader target/default/debug/oasis-core-runtime-loader \
--net.keymanager.binary target/default/debug/oasis-core-keymanager-runtime
--net.keymanager.binary target/default/debug/simple-keymanager
```

Wait for the network to start, there should be messages about nodes being
Expand Down Expand Up @@ -361,7 +361,7 @@ except the `oasis-net-runner` invocation:
--net.node.binary go/oasis-node/oasis-node \
--net.runtime.binary target/sgx/x86_64-fortanix-unknown-sgx/debug/simple-keyvalue.sgxs \
--net.runtime.loader target/default/debug/oasis-core-runtime-loader \
--net.keymanager.binary target/sgx/x86_64-fortanix-unknown-sgx/debug/oasis-core-keymanager-runtime.sgxs
--net.keymanager.binary target/sgx/x86_64-fortanix-unknown-sgx/debug/simple-keymanager.sgxs
```
<!-- markdownlint-enable line-length -->

Expand Down Expand Up @@ -408,8 +408,9 @@ For even more output, check the other `*.log` files.
* `client`: Client library for talking with the runtimes.
* `docker`: Docker environment definitions.
* `go`: Oasis node.
* `keymanager-api-common`: Common keymanager code shared between client and lib.
* `keymanager-client`: Client crate for the key manager.
* `keymanager-runtime`: (INSECURE) key manager implementation.
* `keymanager-lib`: Keymanager library crate.
* `runtime`: The runtime library that simplifies writing SGX and non-SGX
runtimes.
* `runtime-loader`: The SGX and non-SGX runtime loader process.
Expand Down
2 changes: 0 additions & 2 deletions docker/deployment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@ LABEL com.oasislabs.oasis-core-build-image-tag="${OASIS_CORE_BUILD_IMAGE_TAG}"

COPY go/oasis-node/oasis-node /oasis/bin/oasis-node
COPY target/release/oasis-core-runtime-loader /oasis/bin/
COPY target/release/oasis-core-keymanager-runtime /oasis/lib/
COPY target/x86_64-fortanix-unknown-sgx/release/oasis-core-keymanager-runtime.sgxs /oasis/lib/

ENV PATH "/oasis/bin:${PATH}"
2 changes: 0 additions & 2 deletions docker/deployment/build_context.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,4 @@ popd
tar -czf "$dst" \
go/oasis-node/oasis-node \
target/release/oasis-core-runtime-loader \
target/release/oasis-core-keymanager-runtime \
target/x86_64-fortanix-unknown-sgx/release/oasis-core-keymanager-runtime.sgxs \
docker/deployment/Dockerfile
2 changes: 1 addition & 1 deletion go/oasis-net-runner/fixtures/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func init() {
Flags.String(cfgRuntimeBinary, "simple-keyvalue", "path to the runtime binary")
Flags.String(cfgRuntimeGenesisState, "", "path to the runtime genesis state")
Flags.String(cfgRuntimeLoader, "oasis-core-runtime-loader", "path to the runtime loader")
Flags.String(cfgKeymanagerBinary, "oasis-core-keymanager-runtime", "path to the keymanager runtime")
Flags.String(cfgKeymanagerBinary, "simple-keymanager", "path to the keymanager runtime")
Flags.String(cfgTEEHardware, "", "TEE hardware to use")
Flags.Bool(cfgEpochtimeMock, false, "use mock epochtime")
Flags.Uint64(cfgHaltEpoch, math.MaxUint64, "halt epoch height")
Expand Down
2 changes: 1 addition & 1 deletion go/oasis-test-runner/scenario/e2e/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func resolveRuntimeBinary(runtimeBinary string) (string, error) {
}

func resolveDefaultKeyManagerBinary() (string, error) {
return resolveRuntimeBinary("oasis-core-keymanager-runtime")
return resolveRuntimeBinary("simple-keymanager")
}

func startClient(env *env.Env, net *oasis.Network, binary string, clientArgs []string) (*exec.Cmd, error) {
Expand Down
3 changes: 2 additions & 1 deletion keymanager-api-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ authors = ["Oasis Labs Inc. <[email protected]>"]
edition = "2018"

[dependencies]
base64 = "0.10.1"
oasis-core-runtime = { path = "../runtime" }

base64 = "0.10.1"
serde = "1.0.71"
serde_derive = "1.0"
serde_bytes = "~0.10"
Expand Down
10 changes: 9 additions & 1 deletion keymanager-api-common/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use oasis_core_runtime::{
runtime::RuntimeId,
sgx::avr::EnclaveIdentity,
},
impl_bytes,
impl_bytes, runtime_api,
};

impl_bytes!(ContractId, 32, "A 256-bit contract identifier.");
Expand Down Expand Up @@ -248,3 +248,11 @@ impl Default for TrustedPolicySigners {
}
}
}

runtime_api! {
pub fn get_or_create_keys(RequestIds) -> ContractKey;

pub fn get_public_key(RequestIds) -> Option<SignedPublicKey>;

pub fn replicate_master_secret(ReplicateRequest) -> ReplicateResponse;
}
2 changes: 1 addition & 1 deletion keymanager-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
oasis-core-client = { path = "../client" }
oasis-core-runtime = { path = "../runtime" }
oasis-core-keymanager-api = { path = "../keymanager-runtime/api" }
oasis-core-keymanager-api-common = { path = "../keymanager-api-common" }
failure = "0.1.5"
futures = "0.1.25"
io-context = "0.2.0"
Expand Down
5 changes: 3 additions & 2 deletions keymanager-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::iter::FromIterator;
use oasis_core_runtime::{common::cbor, protocol::ProtocolError, types::Body};

use oasis_core_client::{create_rpc_api_client, BoxFuture, RpcClient};
use oasis_core_keymanager_api::*;
use oasis_core_keymanager_api_common::*;
use oasis_core_runtime::{
common::{runtime::RuntimeId, sgx::avr::EnclaveIdentity},
protocol::Protocol,
Expand Down Expand Up @@ -92,9 +92,10 @@ impl RemoteClient {
protocol: Arc<Protocol>,
rak: Arc<RAK>,
keys_cache_sizes: usize,
signers: TrustedPolicySigners,
) -> Self {
#[cfg(target_env = "sgx")]
init_trusted_policy_signers();
set_trusted_policy_signers(signers);

#[cfg(target_env = "sgx")]
let enclaves: Option<HashSet<EnclaveIdentity>> = match protocol
Expand Down
4 changes: 2 additions & 2 deletions keymanager-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::Arc;

use io_context::Context;
use oasis_core_client::BoxFuture;
use oasis_core_keymanager_api;
use oasis_core_keymanager_api_common;

/// Key manager client interface.
pub trait KeyManagerClient: Send + Sync {
Expand Down Expand Up @@ -57,4 +57,4 @@ impl<T: ?Sized + KeyManagerClient> KeyManagerClient for Arc<T> {
}

// Re-exports.
pub use self::{client::RemoteClient, oasis_core_keymanager_api::*};
pub use self::{client::RemoteClient, oasis_core_keymanager_api_common::*};
2 changes: 1 addition & 1 deletion keymanager-client/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{collections::HashMap, sync::Mutex};
use futures::{future, Future};
use io_context::Context;
use oasis_core_client::BoxFuture;
use oasis_core_keymanager_api::*;
use oasis_core_keymanager_api_common::*;
use oasis_core_runtime::common::crypto::signature::Signature;

use super::KeyManagerClient;
Expand Down
1 change: 1 addition & 0 deletions keymanager-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ edition = "2018"
oasis-core-runtime = { path = "../runtime" }
oasis-core-keymanager-api-common = { path = "../keymanager-api-common" }
oasis-core-keymanager-client = { path = "../keymanager-client" }

failure = "0.1.5"
lazy_static = "1.3.0"
lru = "0.1.17"
Expand Down
28 changes: 13 additions & 15 deletions keymanager-runtime/src/main.rs → keymanager-lib/src/keymanager.rs
Original file line number Diff line number Diff line change
@@ -1,38 +1,37 @@
use std::sync::Arc;

mod methods;

use failure::Fallible;

use oasis_core_keymanager_api::*;
use oasis_core_keymanager_api_common::*;
use oasis_core_runtime::{
common::version::Version,
dispatcher::Initializer,
rak::RAK,
register_runtime_rpc_methods,
rpc::{
dispatcher::{Method as RpcMethod, MethodDescriptor as RpcMethodDescriptor},
Context as RpcContext,
},
version_from_cargo, Protocol, RpcDemux, RpcDispatcher, TxnDispatcher,
Protocol, RpcDemux, RpcDispatcher, TxnDispatcher,
};

use oasis_core_keymanager_lib::{context, kdf::Kdf, policy::Policy};
use crate::{context, kdf::Kdf, policy::Policy};

/// Initialize the Kdf.
fn init_kdf(req: &InitRequest, ctx: &mut RpcContext) -> Fallible<SignedInitResponse> {
let policy_checksum = Policy::global().init(ctx, &req.policy)?;
Kdf::global().init(&req, ctx, policy_checksum)
}

fn main() {
/// Initialize a keymanager with trusted policy signers.
pub fn new_keymanager(signers: TrustedPolicySigners) -> Box<dyn Initializer> {
// Initializer.
let init = |protocol: &Arc<Protocol>,
_rak: &Arc<RAK>,
_rpc_demux: &mut RpcDemux,
rpc: &mut RpcDispatcher|
-> Option<Box<dyn TxnDispatcher>> {
let init = move |protocol: &Arc<Protocol>,
_rak: &Arc<RAK>,
_rpc_demux: &mut RpcDemux,
rpc: &mut RpcDispatcher|
-> Option<Box<dyn TxnDispatcher>> {
// Initialize the set of trusted policy signers.
init_trusted_policy_signers();
set_trusted_policy_signers(signers.clone());

// Register RPC methods exposed via EnclaveRPC to remote clients.
{
Expand Down Expand Up @@ -65,6 +64,5 @@ fn main() {
None
};

// Start the runtime.
oasis_core_runtime::start_runtime(Box::new(init), version_from_cargo!());
Box::new(init)
}
2 changes: 2 additions & 0 deletions keymanager-lib/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod context;
pub mod kdf;
pub mod keymanager;
mod methods;
pub mod policy;
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//! Methods exported to remote clients via EnclaveRPC.
use failure::Fallible;
use oasis_core_keymanager_api::*;
use oasis_core_keymanager_api_common::*;
use oasis_core_runtime::rpc::Context as RpcContext;

use oasis_core_keymanager_lib::{kdf::Kdf, policy::Policy};
use crate::{kdf::Kdf, policy::Policy};

/// See `Kdf::get_or_create_keys`.
pub fn get_or_create_keys(req: &RequestIds, ctx: &mut RpcContext) -> Fallible<ContractKey> {
Expand Down
Loading

0 comments on commit f55cdff

Please sign in to comment.