Back to Diem

Secure Storage

specifications/trusted_computing_base/secure_storage/README.md

latest9.5 KB
Original Source

Secure Storage

Overview

Secure Storage encapsulates a design paradigm for the secure storage of sensitive data for the Diem blockchain. The type of data includes information required for safety and identity within the system, such as cryptographic keys and consensus safety rules.

Properties

  • Persistent - data within storage remains intact across reboots and crashes
  • Tamper resistant - data within storage cannot be subvertly modified through, for example, attempting to change a value or rollback to a previous value
  • Integrity - data within storage remain consistent for their entire life-cycle
  • Authenticated - clients can identify the service and operations occur over a trusted link
  • Access control - the service must allow for distinct personas to access only a subset of the values, such that, two clients cannot access each other's sensitive information
  • Key management - the service supports the ability to generate keys and export either the public or private key and support signing operations without exporting the private key

Design / ecosystem goals

  • Work across cloud providers and on-premise
  • Simple interface,ideally a library or REST / JSON-RPC
  • Minimal third-party dependencies
  • Well-reputed, such that, it is auditiable, open-source, widely trusted

Interface

Secure Storage supports two interfaces:

  • Key/value store (KVStorage) for storing arbitrary data
  • Crypto store (CryptoStorage) for secure generation and handling of cryptographic keys
rust
pub trait KVStorage {
    /// Returns an error if the backend service is not online and available.
    fn available(&self) -> Result<(), Error>;

    /// Retrieves a value from storage and fails if the backend is unavailable or the process has
    /// invalid permissions.
    fn get(&self, key: &str) -> Result<GetResponse, Error>;

    /// Sets a value in storage and fails if the backend is unavailable or the process has
    /// invalid permissions.
    fn set(&mut self, key: &str, value: Value) -> Result<(), Error>;
}

/// A container for a get response that contains relevant metadata and the value stored at the
/// given key.
pub struct GetResponse {
    /// Time since Unix Epoch in seconds.
    pub last_update: u64,
    /// Value stored at the provided key
    pub value: Value,
}

pub enum Value {
    Ed25519PrivateKey(Ed25519PrivateKey),
    Ed25519PublicKey(Ed25519PublicKey),
    HashValue(HashValue),
    String(String),
    Transaction(Transaction),
    U64(u64),
}

pub enum Error {
    EntropyError(String),
    InternalError(String),
    KeyAlreadyExists(String),
    KeyNotSet(String),
    PermissionDenied,
    SerializationError(String),
    UnexpectedValueType,
    KeyVersionNotFound(String),
}
rust
/// CryptoStorage provides an abstraction for secure generation and handling of cryptographic keys.
pub trait CryptoStorage: Send + Sync {
    /// Securely generates a new named Ed25519 private key. The behavior for calling this interface
    /// multiple times with the same name is implementation specific.
    fn create_key(&mut self, name: &str) -> Result<Ed25519PublicKey, Error>;

    /// Returns the Ed25519 private key stored at 'name'.
    fn export_private_key(&self, name: &str) -> Result<Ed25519PrivateKey, Error>;

    /// Returns the Ed25519 private key stored at 'name' and identified by 'version', which is the
    /// corresponding public key. This may fail even if the 'named' key exists but the version is
    /// not present.
    fn export_private_key_for_version(
        &self,
        name: &str,
        version: Ed25519PublicKey,
    ) -> Result<Ed25519PrivateKey, Error>;

    /// Returns the Ed25519 public key stored at 'name'.
    fn get_public_key(&self, name: &str) -> Result<PublicKeyResponse, Error>;

    /// Rotates an Ed25519 private key. Future calls without version to this 'named' key will
    /// return the rotated key instance. The previous key is retained and can be accessed via
    /// the version. At most two versions are expected to be retained.
    fn rotate_key(&mut self, name: &str) -> Result<Ed25519PublicKey, Error>;

    /// Signs the provided message using the 'named' private key.
    fn sign_message(&mut self, name: &str, message: &HashValue) -> Result<Ed25519Signature, Error>;

    /// Signs the provided message using the 'named' and 'versioned' private key. This may fail
    /// even if the 'named' key exists but the version is not present.
    fn sign_message_using_version(
        &mut self,
        name: &str,
        version: Ed25519PublicKey,
        message: &HashValue,
    ) -> Result<Ed25519Signature, Error>;
}

pub struct PublicKeyResponse {
    /// Time since Unix Epoch in seconds.
    pub last_update: u64,
    /// Ed25519PublicKey stored at the provided key
    pub public_key: Ed25519PublicKey,
}

What this is used for

Values

NameTypeInternal name
Validator owner account addressStringowner_account
Validator operator account keyEd25519operator
Validator operator account addressStringoperator_account
Consensus keyEd25519consensus
Execution keyEd25519execution
Validator network keyEd25519validator_network
Fullnode network keyEd25519fullnode_network
Validator network encryption keyStringvalidator_network_key
Epochu64epoch
Last voted roundu64last_voted_round
Preferred roundu64preferred_round
WaypointStringwaypoint

Accessors (Services)

NameDescription
InitializerInitializes the secure storage, both the data and policies
VerifierReads all (non-sensitive) data, displays it and compares to genesis if available
ManagementReads all (non-sensitive) data, and writes some data to support genesis-building process
KeyManagerAutomatically rotates consensus and networking keys
SafetyRulesEnsures consensus safety and has the role of signing all consensus messages
ValidatorNodeRuns the Diem Validator services
FullNodeRuns the Diem Fullnode services

Accessor capabilites

Initializer

ValueCapability
Validator owner account addressCreate
Validator operator account keyCreate
Validator operator account addressCreate
Consensus keyCreate
Execution keyCreate
Validator network keyCreate
Fullnode network keyCreate
Validator network encryption keyCreate
EpochCreate
Last voted roundCreate
Preferred roundCreate
WaypointCreate

Verifier

ValueCapability
Validator owner account addressRead
Validator operator account keyPublic key
Validator operator account addressRead
Consensus keyPublic key
Execution keyPublic key
Validator network keyPublic key
Fullnode network keyPublic key
Validator network encryption keyRead
EpochRead
Last voted roundRead
Preferred roundRead
WaypointRead

Management

ValueCapability
Validator owner account addressRead, Write
Validator operator account keyPublic key, Sign
Validator operator account addressRead, Write
Consensus keyPublic key
Validator network keyPublic key
Fullnode network keyPublic key
Validator network encryption keyRead, Write
WaypointRead, Write

KeyManager

ValueCapability
Validator owner account addressRead
Validator operator account keySign
Consensus keyPublic key, Rotate
Validator network keyPublic key, Rotate
Fullnode network keyPublic key, Rotate
Validator network encryption keyRead, Write

SafetyRules

ValueCapability
Validator owner account addressRead
Consensus keyPrivate Key
Execution keyPublic Key
EpochRead, Write
Last voted roundRead, Write
Preferred roundRead, Write
WaypointRead, Write

ValidatorNode

ValueCapability
Validator owner account addressRead
Execution keyPrivate key
Validator network keyPrivate key
Fullnode network keyPrivate key
Validator network encryption keyRead
WaypointRead

FullNode

ValueCapability
Validator owner account addressRead
Fullnode network keyPrivate key
WaypointRead

Notes: If access is not mentioned, then it is not needed.