Skip to main content

sgx storage client

Project description

SGX Storage Client

Overview

A secure Python client for Intel SGX enclave communication implementing DCAP remote attestation and AES-GCM encrypted sessions. Designed for managing sensitive configurations in trusted execution environments.

Features

  • Secure Session Protocol - Ephemeral ECDH key exchange + AES-128-GCM encryption
  • DCAP Remote Attestation - Verify enclave identity through DCAP QVS
  • Complete Management API:
    • Exchange account credentials storage
    • Blockchain address whitelisting
    • Multi-role user access control
    • Network/currency configuration management
  • Production-Ready Security:
    • MRSIGNER-based enclave verification
    • Anti-replay protection with session nonce
    • CMAC-based key derivation (NIST SP 800-108)
    • Hardware-rooted trust chain

Security Notes

  • Ensure private keys are never stored unencrypted or logged.
  • Always validate the enclave’s identity via DCAP unless explicitly testing.
  • Use strong passphrases (≥ 16 characters or ≥ 12 mnemonic words).
  • Consider hardware protection (e.g. TPM, HSM) for production deployment.
  • Ensure TLS is used in transport when communicating with enclaves.

Installation

pip install sgx-storage-client

Components

  • SGX Client (client.py):

    The core interface for communication with the SGX enclave.

  • Attestation Module (attestation.py):

    Provides functionality for remote attestation, ensuring that the enclave is trusted.

  • Key Provider (key_provider.py):

    Contains RawPrivateKeyProvider (or other providers) to manage private key operations securely based on external configuration. You can implement your own key provider by implementing the ECDHProvider methods.

  • Session Handler (session.py):

    Manages secure session establishment, key exchange, and encrypted payload handling.

  • Key Generation (keygen.py):

    Generates high‑entropy, Diceware‑style passphrases and other keys as needed for additional security.

Example usage

Key and passphrase Generation

The keygen.py module provides two main functionalities:

Deterministic Key Pair Generation

You can deterministically generate an EC key pair from a passphrase. This process uses:

  • PBKDF2-HMAC-SHA512 to derive a 64-byte seed from the passphrase.
  • HMAC-SHA512 to compute a scalar from a constant seed and the derived seed.
  • The scalar is then used to build the EC private key on the SECP256R1 curve, and its associated public key is returned as concatenated bytes (X||Y).

Example:

from sgx.keygen import generate_key_pair_from_passphrase

# Generate the key pair deterministically from a passphrase
passphrase = "correct horse battery staple"
public_key_bytes, private_scalar = generate_key_pair_from_passphrase(passphrase)

Diceware‑Style Passphrase Generation

The generate_passphrase function creates high‑entropy passphrases by selecting random words from a supplied wordlist (https://www.eff.org/dice). You can customize options such as the number of words, delimiter, capitalization, and appending a random digit.

Example:

from sgx.keygen import generate_passphrase

#Generate a 7-word passphrase with title-cased words and a trailing digit
passphrase = generate_passphrase(num_words=7)

Sgx client initialization

Variables:

  • MR_SIGNER – Enclave fingerprint (MRSIGNER).
  • DCAP_URL – DCAP attestation service URL.
  • PRIVATE_VALUE – Your private key as an integer.
  • HOST – Enclave server host.
  • PORT – Enclave server port.
  • SP_ID – Service Provider ID (SPID).
from sgx.client import SgxClient
from sgx.attestaion import SGXAttestationVerifier
from sgx.ecdh_provider import RawPrivateKeyProvider

# Initialize the attestation verifier
verifier = SGXAttestationVerifier(
    mr_signer="a1b2c3d4e5f6...", # Trusted enclave fingerprint
    dcap_url="https://qvs.example.com/qvs/attestation/sgx/dcap/v1/report",
    is_debug=False # Default is False, check that the enclave is not in debug mode
)

# Initialize the private key provider
key_provider = RawPrivateKeyProvider(private_value=int('6805925192601811...44757182820103'))


client = SgxClient(
    host="enclave.example.com",
    port=2241,
    spid="11223344556677889900AABBCCDDEEFF",  # 16-byte hex Service Provider ID
    key_provider=key_provider, # Private key for enclave authentication
    attestation_verifier=verifier,  # Optional, use None to skip dcap verification
)

Exchange Account Management

client.get_accounts()

client.add_account(
   name='main-account', 
   exchange='binance', 
   public_key='public-key',
   key='sercret-key', 
   sorting_key=1, 
   additional_data={}
)

client.update_account(
   account_id='1binance', 
   name='secondary-account', 
   public_key='public-key', 
   key='secret-key', 
   sorting_key=1, 
   additional_data={}
)

client.del_account('1binance')

Address Management

client.get_standalone_addresses()

client.add_standalone(
    address='0xC8CD2BE653759aed7B0996315821AAe71e1FEAdF',
    network='ETHEREUM',
    alias='eth-address',
    whitelist=True,
    multisig=False,
    currencies=['ETH', 'USDT'],
    sorting_key=1
)

client.update_standalone(
    address='0xC8CD2BE653759aed7B0996315821AAe71e1FEAdF',
    network='ETHEREUM',
    alias='eth-address-2',
    whitelist=True,
    multisig=False,
    currencies=[],
    sorting_key=1
)

client.del_standalone(address='0xC8CD2BE653759aed7B0996315821AAe71e1FEAdF', network='ETHEREUM')

Whitelist Management

client.get_whitelist()

client.add_whitelist(
    address='0xC8CD2BE653759aed7B0996315821AAe71e1FEAdF',
    network='ETHEREUM',
    alias='trusted-address',
    currencies=[],
    sorting_key=1
)

client.update_whitelist(
   address='0xC8CD2BE653759aed7B0996315821AAe71e1FEAdF',
   network='ETHEREUM',
   alias='trusted-address-2'
)

client.del_whitelist(
    address='0xC8CD2BE653759aed7B0996315821AAe71e1FEAdF',
    network='ETHEREUM',
)

User Management

client.get_users()

client.add_user(
    user='test@gamil.com', 
    role='FULL_ACCESS', 
    sorting_key=2
)

client.update_user(user='test@gamil.com', role='READ_ONLY', sorting_key=2)

client.del_user('test@gamil.com')

client.reset_user_hotp('test@gamil.com')

configurations

client.get_network_coins()

client.get_status()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sgx_storage_client-0.0.5.tar.gz (17.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sgx_storage_client-0.0.5-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file sgx_storage_client-0.0.5.tar.gz.

File metadata

  • Download URL: sgx_storage_client-0.0.5.tar.gz
  • Upload date:
  • Size: 17.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.8

File hashes

Hashes for sgx_storage_client-0.0.5.tar.gz
Algorithm Hash digest
SHA256 15296a3a62fc2a8a8e58d7d6dec8a6664e954b3996adcea5b5b93eecd1a6dcc7
MD5 7d78cdf27e609779f7aac56cc23ef03e
BLAKE2b-256 99945757ef0b95d85e563661fbc1367c71e960b026c8e2cea91c62d54d40c434

See more details on using hashes here.

File details

Details for the file sgx_storage_client-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for sgx_storage_client-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 ec30eecb55d6745c089033bc8b8d69ce6db0ec4c4ab2ecf249b47c21537a1926
MD5 fe07a54f4326db878d110bfd52013ccc
BLAKE2b-256 e2bfcce36c567e85f85319abf8292c6eab35f4723b76ea50dc67d1f94081361c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page