Giter Club home page Giter Club logo

kmyth's Introduction

Kmyth

Kmyth provides a simple mechanism for interacting with the TPM. The three core components are:

  • kmyth-seal: A tool that encrypts a file and protects the encryption key by sealing it to the TPM
  • kmyth-unseal: A tool that reads a file (.ski) that has been kmyth-sealed and produces the original content
  • kmyth-getkey: A tool that demonstrates the programatic api of kmyth-seal and kmyth-unseal by protecting a certificate private key used in a TLS connection

In addition Kmyth provides a simple API which allows developers to use the TPM without having to become experts in the underlying TPM libraries.


Table of Contents


Building and Installation

For build and installation instructions see the INSTALL file.


Usage

kmyth-seal / kmyth-reseal

This tool will kmyth-seal a file using the TPM 2.0. In TPM parlance, 'sealing' typically refers to encrypting the file using a key known only to that TPM (i.e., binding that data to a specific TPM) and imposing system state criteria (i.e., Platform Configuration Register or PCR constraints) on the decryption of that data. While kmyth-seal utilizes the TPM's capability to 'seal' and/or 'bind' under the hood, it references the entire process used to create a .ski file result. This includes:

  • generation and use of a wrapping key to symmetrically encrypt the input data
  • use of the TPM to derive the Kmyth SRK as a primary key
  • use of the TPM to create a Kmyth SK that is sealed to the SRK with an authorization policy
  • use of the TPM to seal the symmetric wrapping key to the SK and an authorization policy
  • compilation of the encrypted secret being protected (e.g., CAPK), TPM sealed storage key, TPM sealed symmetric key, and the symmetric cipher specification into a .ski file to facilitate the ability to later kmyth-unseal it
WARNING:

Because the TPM is used to encrypt the symmetric key that encrypts your data, the encrypted data can only be decrypted using the same machine (and the same TPM) with which it was encrypted. If the data is moved to a different machine, if the PCRs used to encrypt it change, or if the TPM is reset, the data will be permanently lost.

usage: ./bin/kmyth-seal [options] 
     : ./bin/kmyth-reseal [options] 

options are: 

 -a or --auth_string     String used to create 'authVal' digest. Defaults to empty string (all-zero digest).
 -i or --input           Path to file containing the data to be sealed.
 -o or --output          Destination path for the sealed file. Defaults to <filename>.ski in the CWD.
 -f or --force           Force the overwrite of an existing .ski file when using default output.
 -p or --pcrs_list       List of TPM platform configuration registers (PCRs) to apply to authorization policy.
                         Defaults to no PCRs specified. Encapsulate in quotes (e.g. "0, 1, 2").
 -c or --cipher          Specifies the cipher type to use. Defaults to 'AES/GCM/NoPadding/256'
 -g or --get_exp_policy  Retrieves the PolicyPCR digest associated with the current value of pcr registers
 -e or --expected_policy Specifies an alternative digest value that can satisfy the authorization policy.
 -l or --list_ciphers    Lists all valid ciphers and exits.
 -w or --owner_auth      TPM 2.0 storage (owner) hierarchy authorization. Defaults to emptyAuth to match TPM default.
 -v or --verbose         Enable detailed logging.
 -h or --help            Help (displays this usage).

*kmyth-reseal is a specialization of kmyth-seal where the -g / --get_exp_policy option is forced but otherwise all the options are available. One may think of 'kmyth-reseal ..' as identical functionality as 'kmyth-seal -g ..'. Use of the -g flag within kmyth-reseal while allowed, is superfluous.

kmyth-unseal

This tool will kmyth-unseal a file using the TPM 2.0. In TPM parlance, 'unsealing' typically refers to decrypting 'sealed' input data using a key known only to that TPM (i.e., the encrypted input is 'bound' to a specific TPM) while imposing system state criteria (i.e., Platform Configuration Register or PCR constraints) on the ability to decrypt. While kmyth-unseal utilizes the TPM's capability to 'unseal' under the hood, it references the entire process used to recover Kmyth protected secret data (e.g., a CAPK) from a .ski file input. This includes:

  • recovery of data contained in the input .ski file
  • use of the TPM and its Kmyth SRK to recover the Kmyth SK
  • loading the recovered Kmyth SK into the TPM
  • use of the TPM and loaded Kmyth SK to recover the symmetric wrapping key
  • use of the symmetric wrapping key and the cipher specification to recover the 'kmyth-sealed' secret
  • providing the recovered result to the user in the required format (e.g., a file)
    usage: ./bin/kmyth-unseal [options]
    
    options are: 
    
     -a or --auth_string   String used to create 'authVal' digest. Defaults to empty string (all-zero digest).
     -i or --input         Path to file containing data the to be unsealed
     -o or --output        Destination path for unsealed file. This or -s must be specified. Will not overwrite any
                           existing files unless the 'force' option is selected.
     -s or --stdout        Output unencrypted result to stdout instead of file.
     -w or --owner_auth    TPM 2.0 storage (owner) hierarchy authorization. Defaults to emptyAuth to match TPM default.
     -v or --verbose       Enable detailed logging.
     -h or --help          Help (displays this usage).

kmyth-getkey

This tool is used specifically for obtaining a key from a remote server.

Preliminaries

In order to use kmyth-getkey some preliminary setup is required.

  • You must have a key server listening for connections.

  • The client running kmyth-getkey must have a private key sealed using kmyth-seal along with a corresponding certificate.

  • The key server must be able to authenticate the client's certificate.

    usage: ./bin/kmyth-getkey [options]
    
    options are:
    
    Client Information --
      -i or --input         Path to file containing the kmyth-sealed client's certificate private key.
      -l or --client        Path to file containing the client's certificate.
    
    Server Information --
      -t or --type          Type of key server backend (e.g., 'kmip', 'simple').
      -s or --server        Path to file containing the certificate
                            for the CA that issued the server cert.
      -c or --conn_addr     The ip_address:port for the TLS connection.
      -m or --message       An optional message to send the key server.
    
    Output Parameters --
      -o or --output        Output file path to write the key. If none is selected, key will be sent to stdout.
    
    Sealed Key Parameters --
      -a or --auth_string   String used to create 'authVal' digest. Defaults to empty string (all-zero digest)
      -w or --owner_auth    TPM 2.0 storage (owner) hierarchy authorization. Defaults to emptyAuth to match TPM default.
    
    Misc --
      -v or --verbose       Detailed logging mode to help with debugging.
      -h or --help          Help (displays this usage).

Notes

General TPM 2.0

  • TPM 2.0 Software Stack (TSS2)

    • The Feature API (FAPI) provides the highest-level of abstraction and was the last layer implemented (tss2-fapi).

    • The Enhanced System API (ESAPI) is the next layer down. While less abstract than the FAPI, it hides much of the session management overhead and provides cryptographic function support. Our development efforts preceded the initial release of an implementation of this layer (tss2-esys).

    • The System API (SAPI) provides the developer functionality that maps to the TPM 2.0 commands. The Kmyth TPM 2.0 code is currently based primarily on this layer (tss2-sys) of the TSS2 library.

    • The TPM Command Transmission Interface (TCTI) represents the layer where the actual TPM commands and responses are exchanged. In the TSS2 library, this layer is implemented by the tss2-tcti component.

    • TSS 2.0 Marshalling/Unmarshalling functionality is used to convert back and forth between C structures in the SAPI layer and the canonicalized commands/responses found in the TCTI layer. In the TSS2 library, these features are implemented by the tss2-mu component.

    • The TPM Access Broker (TAB) layer controls multi-process synchronization for the TPM. The Resource Manager (RM) swaps TPM sessions and objects in and out of very limited TPM memory, as needed. An open source implementation of these two layers is provided by the TPM2 Access Broker & Resource Manager Daemon (tss2-abrmd).

    • At the bottom of the software stack, the TPM device driver handles the physical transmission of data to and from the TPM. This is totally abstracted from our Kmyth code, however.

TPM 2.0 Simulator

Default (typical) TPM 2.0 simulator settings:

  • hostname : 127.0.0.1 (localhost)

  • port : 2321 (TPM command)

TPM 2.0 Tools (Intel)

  • the tpm2-abrmd binary is used to start the TPM Access Broker (TAB) and Resource Manager (RM) daemon.

  • The tpm2_takeownership binary can be used to set (change) the TPM's owner (storage) and endorsement hierarchy passwords (empty string by default), as well as the lockout authorization value.

TPM 2.0 Resource Manager (Intel)

  • Can be run on either emulator or device.

  • Must be run in root if running on device.

  • Must be in white list group or root to run.

  • To white list a group do the following:

    • In /etc/dbus-1/system.d/tpm2-abrmd.conf add:
          <policy group="[insert name of group here]">
          <allow own="com.intel.tss2.Tabrmd">
          </policy>
    
    • Then reset connection (e.g., dzdo pkill -HUP dbus-daemon)
  • Valgrind gives glib errors when connecting to resource manager. These are known errors present in the glib code. To supress only these errors do the following:

    • Create a file, say libgio.supp, with the following text:
          {
            ignore_libglib_stuff
            Memcheck:Leak
            ...
            obj:*/libglib-2.0.so.*
          }
          {
            ignore_lib_gobject_stuff
            Memcheck:Leak
            ...
            obj:*/libgobject-2.0.so.*
          }
    
    • Then run valgrind with option --suppressions=libgio.supp

TPM_SU options:

TPM_SU_CLEAR:

  • On TPM2_Shutdown() it indicates that the TPM should prepare for loss of power and save state required for an orderly startup TPM Reset.

  • On TPM2_Startup() it indicates that the TPM should perform Reset or Restart.

TPM_SU_STATE:

  • On TPM2_Shutdown(), it indicates that the TPM should prepare for loss of power and save state required for an orderly startup (TPM Restart or Resume).

  • On TPM2_Startup(), it indicates that the TPM should restore the state saved by the last TPM2_Shutdown().

TPM 2.0 Key Handles:

  • 0x80XXXXXX - Transient Objects that will not stay loaded between boots.

  • 0x81XXXXXX - Persistent Objects that should stay loaded if you reboot. the machine.

TPM 2.0 Keys:

  • A key hierarchy is created in TPM 2.0 by deriving a primary key using the TPM2_CreatePrimary() command.

    • A primary key has a "type" (e.g., must use one of the algorithms supported by the TPM.

    • The unique parameter in the inPublic struct passed to TPM2_CreatePrimary() provides a mechanism for the caller to generate (derive) different primary keys for the same algorithm within the same TPM hierarchy.

    • The outsideInfo parameter passed to TPM2_CreatePrimary() is a label for the primary key's creationData.

    • "TPM2.0 in Context" (Proudler, Chen, and Dalton) quote:

"Other input fields in TPM2_CreatePrimary are there to enable production of a 'creation' credential that is returned by the TPM2 with the SRK. The creation credential describes the circumstances in which the SRK was created: the current values of the selected PCRs ("creationPCR"), the name of the parent key (the reserved handle of the SPS), plus an arbitrary label ("outsideInfo") describing the SRK. Just like the SRK itself, this credential can be recreated at any time by repeating the TPM2_CreatePrimary command with the same parameters, as long as the SPS hasn't changed."

  • A key hierarchy is populated (e.g., Kmyth creates storage keys and sealed data objects) by using the TPM2_Create() command. Non-primary key and data objects have the following objectAttributes:

  • fixedTPM: SET prevents the key from being duplicated

  • stClear: SET clears object if platform properly switched off

  • fixedParent: SET only allows duplication with the parent (parent must also be duplicable).

  • sensitiveDataOrigin: SET indicates privKey generated by TPM

  • userWithAuth: CLEAR forces policy authorization for USER role

  • adminWithPolicy: SET forces policy authorization for ADMIN role

  • noDA: CLEAR enables dictionary attack protections

  • encryptedDuplication: SET forces encryption of sensitive portion of an object when duplicated.

  • restricted: SET means that key will refuse to operate on external data that mimics TPM-generated data. Storage keys (keys that are parents of other keys) must be restricted.

  • decrypt: SET means key can be used for decryption

  • sign: SET means key can be used for signatures


Security Guidance

Random-Sources

The most reliable and available source of random on a commercial machine is the kernel entropy accumulator. On modern UNIX/Linux machine this takes the form of /dev/random and /dev/urandom. These random sources have the advantage of being able to collect entropy from a variety of sources only available to the kernel. If correctly configured, they can carry entropy across a reboot cycle.

We use OpenSSL's RAND_bytes to generate our wrapping key. It seeds from /dev/urandom.

The user should be aware of the slow start issue present in kernel entropy accumulators. When a random number generator (RNG) is first configured, it has very little information available which cannot be guessed. Various mitigations for this problem are available, among them, writing a fresh random seed from some known good source to the entropy accumulator by writing to /dev/random. As the RNG continues to run, and more system input is fed in (interrupt timings, packet data, keyboard activity,...), anyone who is not in a position to see all of the input will eventually lose track of the internal state of the RNG.

Local Storage of Sensitive Material

For some applications, sensitive material must be available through the operating system's file IO interface; for example, one may need operational key accesible to processes that expect to read key material from a file. One option for limiting the exposure of sensitive material is to store it in a file in the ramfs RAM file system. We do not recommend the tmpfs RAM file system, because tmpfs may use swap space.

kmyth's People

Contributors

arp102 avatar b-carr avatar bit-belcher avatar bit-bender avatar costinteo avatar jarednecaise avatar jwzeta avatar peterhamilton avatar pircdef avatar scriptis-png avatar shellcollector avatar traditionalism avatar wmillstone avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kmyth's Issues

Unseal failing

Attempting to unseal a ski file gives an error:

$ ./kmyth-unseal -i out.ski -o out
kmyth-0.0.0 INFO - src/util/tpm2_config_tools.c(tpm2_init_connection:82) initialized connection to TPM 2.0 emulator
kmyth-0.0.0 ERROR - src/util/tpm2_kmyth_io.c(kmyth_getSkiBlock:929) unexpected delimiter ... exiting
kmyth-0.0.0 ERROR - src/util/tpm2_kmyth_io.c(tpm2_kmyth_read_ski_file:510) get PCR selection list error ... exiting
kmyth-0.0.0 ERROR - src/util/tpm2_kmyth_seal.c(tpm2_kmyth_unseal:402) error reading .ski file out.ski ... exiting
kmyth-0.0.0 ERROR - src/unseal/main.c(main:136) kmyth-unseal failed ... exiting

Add Install for libsgxseal

The kmyth sgx Makefile needs an install option that will install the shared objects and header alongside the tpm2 install. It also needs an uninstall to remove only the sgx portions.

Consistent Authorization String Handling

The kmyth applications accept as command line parameters an authorization password (used to create a hash used as an authorization value in a TPM policy) and a password for the TPM owner (storage) hierarchy. They are currently initialized differently. The authString variable is initialized to a NULL pointer and the ownerAuthPasswd variable is initialized to an empty string. This issue proposes to standardize on the approach where we initialize to the NULL pointer and then use a check for NULL and set to a default value, where required.

Add unit tests for kmyth basic TPM 2.0 interface utilities

Unit tests must be written and integrated into the kmyth unit testing framework for the miscellaneous set of kmyth utilities that facilitate interfacing with the TPM 2.0 for initialization and startup through maintaining the session and querying the TPM. More specifically, tests need to be added for the functionality implemented in tpm2/src/tpm/tpm2_interface.c.

Add unit tests for kmyth cipher utilities

Unit tests must be written and integrated into the kmyth unit testing framework for the kmyth cipher-related utility functionality implemented in tpm2/src/cipher/cipher.c.

Unused sk_handle parameter in create_sk() function

The function create_sk() in src/tpm/storage_key_tools.c, takes a storage key handle (sk_handle) as a parameter, but then does not use this parameter anywhere within the function. This interface, therefore, should be simplified and cleaned up to remove this unnecessary parameter.

Add unit tests for kmyth unseal application

Unit tests must be written and integrated into the kmyth unit testing framework for the top-level (main()) implementation of the TPM 2.0 based kmyth-unseal application in tpm2/src/main/unseal.c.

Update enclave_retrieve_key() API

The current API for calling the 'retrieve-key' functionality from within the enclave needs modification to support its use beyond the current demo. The following initial issues have been identified:

  • The 'key ID' parameter passed to the server is currently generated within the function. This needs to be exposed to the API to permit the caller of the enclave_retrieve_key() to specify this value
  • The returned key object is not exposed to the caller. The API needs to provide a reference to this value to the caller so that it has access to it.
  • The port value is specified as a string, should pass this as an integer rather than doing the string conversion as part of the function.

Investigate Merging Makefiles for SGX demo and test

The duplicate enclave build commands in sgx/demo/Makefile and sgx/test/Makefile are annoying to keep up to date.
This issue recommends potentially merging them to avoid the issues with maintaining duplicated build specifications.

Add formatting for SGX-sealed files.

At the moment we have no way to recognize that a file has been SGX-sealed like we do with the .ski formatting for TPM-sealed files. We should add an additional file type (maybe .nkl) along with a header/footer to identify and help parse these SGX-sealed files.

Add unit tests for kmyth PCR utilities

Unit tests must be written and integrated into the kmyth unit testing framework for the kmyth PCR utility functionality implemented in tpm2/src/tpm/pcrs.c.

Add unit tests for kmyth TPM object tools

Unit tests must be written and integrated into the kmyth unit testing framework for the kmyth TPM object tool functionality implemented in tpm2/src/tpm/object_tools.c.

Restructure build using recursive makefiles

As a step to make the code and build process more modular and portable, it will probably help to revamp the current single, top-level makefile approach by instead applying a hierarchical (recursive) makefile schema.

Create Kmyth Parameter Struct

The auth_string, pcrs_string, owner_auth_password, and cipher_string are passed in and out of several calls. These should be consolidated into a single struct to be passed in and out of tpm2_kmyth_seal and tpm2_kmyth_unseal

Bug: Parsing error for PCRs

The following was successfully executed even though it contains characters that should not be parseable:

$ kmyth-seal -i test.txt -p "0, 1panda, 2" -o test.ski

The following errored out correctly:

$ kmyth-seal -i test.txt -p "0, 1, 2, panda" -o test.ski

kmyth-0.0.0 ERROR - src/util/tpm2_pcrManagement.c(init_pcr_selection:113) error parsing PCR value ... exiting
kmyth-0.0.0 ERROR - src/util/tpm2_kmyth_seal.c(tpm2_kmyth_seal:112) error parsing PCR string: 0, 1, 2, panda ... exiting
kmyth-0.0.0 ERROR - src/util/tpm2_kmyth_seal.c(tpm2_kmyth_seal_file:446) Failed to kmyth-seal data ... exiting
kmyth-0.0.0 ERROR - src/main/seal.c(main:238) kmyth-seal error ... exiting

tpm2_get_impl_type() is specific to IBM's Software TPM

When using the Microsoft TPM simulator, kmyth applications classify it as a hardware TPM. As the current check examines the vendor string and tests whether or not it is "IBM", this is not surprising. The check, however, should probably also include the Microsoft simulator (and any others, if possible).

Add unit tests for kmyth TPM storage key tools

Unit tests must be written and integrated into the kmyth unit testing framework for the kmyth utility functions that manage and interact with TPM keys (i.e., storage root key and storage keys). More specifically, add tests for the functionality implemented in tpm2/src/tpm/storage_key_tools.c.

Clean up error handling and memory management

There are quite a few places in the code where memory isn't freed on failure, or where failure conditions aren't properly handled. We need to go through the entire codebase ensuring all errors are handling appropriately and all memory is freed appropriately.

Make get_srk_handle() more readable/modular

The function get_srk_handle() currently gets a list of all objects in TPM persistent storage. It then has a for loop that calls check_if_srk() on each of those objects. As soon as it comes across an object in that list that passes all of the criteria tested in check_if_srk() (i.e., check_if_srk() sets the isSRK boolean to true), it sets srk_handle to that handle value and breaks out of the for loop. Since srk_handle will be non-zero in this case, get_srk_handle() will just exit normally at this point with the srk_handle parameter available to the calling function. If the for loop exits after check_if_srk() has failed on all loaded objects, srk_handle will have never been changed from its zero initialization. In this case, derive_srk() will be called to re-derive the SRK from its seed and load it into persistent TPM storage. In this case derive_srk() provides the handle referencing the SRK in TPM storage to get_srk_handle() so that it can provide it to its calling function.

While the logic in get_srk_handle() seems fine, this issue attempts to make the function more readable and the code a little more modular. After discussion about this, a decision to simplify get_srk_handle() by abstracting it into the following two function calls, seemed the best way to achieve this:

  • get_existing_srk_handle() gets the list of objects in TPM persistent storage and checks them all against the SRK criteria. Upon return from this function, the srk_handle parameter passed to it is either zero (none of the loaded objects is the SRK) or contains the handle used to reference the SRK.
  • put_srk_into_tpm_persistent_storage() is a renamed derive_srk() function.

The new get_srk_handle() would call get_existing_srk_handle(). It would then check the srk_handle parameter resulting from this call and call put_srk_into_tpm_persistent_storage() if srk_handle is still zero (i.e., wasn't found by get_existing_srk_handle()).

Insufficient Buffer Error when Re-deriving SRK

When running kmyth-seal, the following error message is being observed:

kmyth-0.0.0 ERROR - src/util/tpm2_kmyth_object.c(tpm2_kmyth_create_object:353) Tss2_Sys_CreatePrimary(): rc = 0x00090006, mu:A buffer isn't large enough ... exiting

Enabling more detailed logging in TSS reveals the underlying marshaling error:

debug:marshal:src/tss2-mu/tpm2b-types.c:302:Tss2_MU_TPM2B_DIGEST_Marshal() buffer_size: 4096 with offset: 30 are insufficient for object of size 32769

Create-sgx-demo

Kmyth does not have a make associated with it's sgx source code, but it does provide a build in its test code. Instead of writing code that's partially a demo and partially unit tests, we should separate these into two distinct paths. The demo code should demonstrate how to use the enclave and build it alongside existing enclave code, and the test can focus on testing the local build.

Investigate ECDH session key generation in a single step

The compute_ecdh_shared_secret() function in sgx/common/src/ecdh_utils.c uses OpenSSL's ECDH_compute_key() call to produce a 'shared secret' result. The last parameter seems to allow the specification of a KDF. This might, therefore, support direct use of this result as a "session key", instead of a two-step (compute ECDH shared secret and then use shared secret to compute session key) approach.

Rename default branch

We will be re-naming our default branch from master to main. GitHub has published guidance on this topic.

New tools have been promised to make this more seamless, but, in our case, we should be in pretty good shape to go ahead and switch over. For instance, as of July 17, 2020, links to deleted branched will now automatically redirect to the default branch. The biggest challenge looks to be the current need to manually re-target open pull requests to the new default branch. For this reason, we may schedule the change for either a time in the near future when this is minimized (e.g., no or few open pull requests) or when the promised automated tooling becomes available to deal with this.

Update getkey to support both KMIP and 'simple' TLS server examples

The original version of kmyth-getkey demonstrated key retrieval from a generic TLS server. When a version of kmyth-getkey that incorporated libkmip library functionality to demonstrate a Kmyth client that retrieves keys from a KMIP server was developed, it replaced the original kmyth-getkey version.

As we would like to retain the functionality of both versions, this issue more specifically proposes modification of kmyth-getkey to support both (either of) "get_key_from_kmip_server()" and "get_key_from_tls_server()" options. Further, selection of which option to use should be via a required command line parameter.

'Retrieve Key' Protocol Improvement

Kmyth includes functionality for retrieving a key from a remote server (e.g., a KMIP server) into the enclave. Although, for the connection to the the key server, TLS is appropriate, in order to avoid potential licensing issues with our open source code, we did not implement a TLS client within the enclave. Instead, we implemented a TLS proxy, in untrusted code, which might reside, say, in environment that provides some level of enhanced protection. To demonstrate that the data between the enclave and the proxy can be secured, we initially implemented a trivial protocol based on an ECDH key agreement scheme.

While this was always intended as demonstration, and never as production code, we plan to replace the existing protocol with a slightly less-trivial example to demonstrate that a more complex protocol can terminate inside the enclave:

  1. The client sends a "client hello" message containing the client's identify and the client's ephemeral public key, signed by the client's long-term signing key.

  2. The server sends a "server hello" message containing the server's identity, the server's ephemeral public key, and the client's ephemeral public key, signed by the server's long-term signing key.

  3. Client and server derive the ECDH ephemeral key as a shared secret and run this through a key derivation function (KDF) using the two 'Hello' messages and the two public ephemerals as "additional info" to produce a 512 bit result.

  4. The client sends a "request" message containing the currently implemented request, along with the servers ephemeral public key. This message is encrypted with the first 256 bits of the key derived in (3) and the ciphertext is signed by the client's long-term signing key.

  5. The server sends the currently implemented "response" message, encrypted with the next 256 bits of the key derived in (3). The ciphertext is signed by the server's long-term signing key.

Review function naming

In pull request #55, we refactored the naming and organization of source and header files. As a follow-on, we should probably review, and refactor if/where appropriate, function names to be more consistent with these changes. As an example, we have a lot of function names that include tpm2 and/or kmyth in their naming. In some cases, this may be helpful or add clarity (e.g., to distinguish them from similarly named functionality in the TSS). In some cases, however, I think some cleanup may help with the readability of the code.

Seg Fault when tabrmd is not running

Attempting to run kmyth-seal without starting tabrmd results in a seg fault.

$ ./bin/kmyth-seal -i test.txt -o test.ski

** (process:3110): CRITICAL **: 09:37:15.882: failed to allocate dbus proxy object: Error calling StartServiceByName for com.intel.tss2.Tabrmd: Timeout was reached
kmyth-0.0.0 ERROR - src/util/tpm2_config_tools.c(tpm2_init_tcti_abrmd:145) Tss2_Tcti_Tabrmd_Init(): rc = 0x000A0008, tcti:Fails to connect to next lower layer
kmyth-0.0.0 ERROR - src/util/tpm2_config_tools.c(tpm2_init_tcti_abrmd:148) failed to initialize resource manager TCTI context ... exiting
kmyth-0.0.0 ERROR - src/util/tpm2_config_tools.c(tpm2_init_connection:37) unable to initialize TCTI context ... exiting
kmyth-0.0.0 ERROR - src/util/tpm2_kmyth_seal.c(tpm2_kmyth_seal:44) unable to init conn to TPM2 res mgr, check that it's running
kmyth-0.0.0 ERROR - src/util/tpm2_info_tools.c(tpm2_get_properties:44) Tss2_Get_Capability(): rc = 0x00080005, sys:A pointer is NULL that isn't allowed to be NULL.
kmyth-0.0.0 ERROR - src/util/tpm2_info_tools.c(tpm2_get_properties:46) unable to get capability = 1, property = 33554432, count = 273 ... exiting
Segmentation fault (core dumped)

read_bytes_from_file() memory cleanup on error

The last few error return cases in read_bytes_from_file() can return after memory has been allocated for for the output data buffer. It would be cleaner to not require the caller to free memory allocated by this function after an unsuccessful return.

Add unit tests for kmyth TLS utilities

Currently, for the kmyth functionality implemented in tpm2/src/util/tls_util.c, the only unit tests that have been written are some simple checks for invalid inputs to tls_set_context(). Additional unit tests, therefore, must be written and integrated into the kmyth unit testing framework for the TLS utility functions found in tpm2/src/util/tls_util.c.

Design and implement kmyth-reseal workflow

As part of the Feature/add policy or for authorization pull request (PR #166), a kmyth-reseal application was added. While the intent was to simplify the workflow for resealing an existing kmyth-sealed result (.ski file) requiring either the original or a new TPM policy digest criteria (logical OR of the two), the kmyth-reseal application does not yet do this.

The version currently implemented is a redundant implementation of kmyth-seal with the -g option invoked, which simply prints out the policy digest that results from the authorization criteria specified using the current machine configuration. While this is not the complete functionality of the envisioned kmyth-reseal application, we decided not to address this as part of PR #166 and instead with a future revision.

The kmyth-reseal utility should instead:

  1. kmyth-unseal a previously sealed .ski file result. The filename for this input should be specified as a required command line option.

  2. kmyth-seal the data unsealed in the first step. The filename for the output result should be specified as a required command line option. The authorization policy applied should be a "policy-OR" criteria satisfying either of the following two conditions:

    • The criteria based on the command line options specified (e.g., PCRs, etc) and the current system state.
    • The criteria based on the command line options and system state that results in the policy digest specified as a required command line option (Note: the -g option for the kmyth-seal application can be used to obtain this required input policy digest parameter)

Update README/INSTALL

With the new build structure in place the README and INSTALL files need to be updated to keep pace. In particular

  • you no longer have to separately install the logger
  • indent is EPEL for CentOS8, so we have to figure out what to do with that

There may be other inconsistencies, those are just the two I noticed.

Detect TPM "Policy-OR" criteria from .ski file (remove "policy OR" command line option for kmyth-unseal)

The Feature/add policy or for authorization pull request (PR #166) added the capability to TPM seal data that can be TPM unsealed if the policy digest matches one of two possible criteria (policy-OR). When unsealing, however, the user must currently specify the -p (policy OR) flag. As the existence of a policy OR criteria should be easily detectable when parsing/reading the input .ski file, however, the user should not have to specify this as a command line option. Instead, kmyth-unseal should just apply whatever authorization criteria is specified in the .ski file, including a policy OR criteria.

Add unit tests for kmyth seal application

Unit tests must be written and integrated into the kmyth unit testing framework for the top-level (main()) implementation of the TPM 2.0 based kmyth-seal application in tpm2/src/main/seal.c.

Fix logic in check_if_srk()

This function currently initializes the isSRK boolean parameter to true and then changes it to false if any of the SRK checks fail. Although early termination of this function should produce an error, it will also leave this variable in the state indicating that the SRK checks passed. It would be safer to avoid exiting the function with this parameter set to an improperly true result.

Seal failing on empty input file

Trying to seal an empty input file results in:

touch test.in
./bin/kmyth-seal -i test.in -o test.ski -v

kmyth-0.0.0 DEBUG - src/util/tpm2_config_tools.c(tpm2_init_sapi:162) ABI version is 1.2.1.108
kmyth-0.0.0 DEBUG - src/util/tpm2_config_tools.c(tpm2_init_sapi:195) initialized SAPI context
.
.
.
kmyth-0.0.0 DEBUG - src/util/aes_gcm.c(aes_gcm_encrypt:23) AES/GCM encryption starting
kmyth-0.0.0 ERROR - src/util/aes_gcm.c(aes_gcm_encrypt:35) no input data ... exiting
kmyth-0.0.0 ERROR - src/util/tpm2_kmyth_seal.c(kmyth_encrypt_data:717) error encrypting data ... exiting
kmyth-0.0.0 ERROR - src/util/tpm2_kmyth_seal.c(kmyth_wrap_input:675) unable to encrypt (wrap) data ... exiting
kmyth-0.0.0 ERROR - src/util/tpm2_kmyth_seal.c(tpm2_kmyth_seal:246) kmyth_wrap_input() call failed ... exiting
double free or corruption (out)
Aborted (core dumped)

Add unit tests for kmyth getkey application

Unit tests must be written and integrated into the kmyth unit testing framework for the top-level (main()) implementation of the TPM 2.0 based kmyth-getkey application in tpm2/src/main/getkey.c.

Make logger prefix optional for logging to screen

While it contains useful information, the prefix that precedes each log entry can be distracting when monitoring normal activity via stddest (stdout / stderr). If it were more configurable, the user would have the option to choose between the current full information view or a streamlined (less cluttered) log entry view.

The initial idea is to always include the prefix when entries are logged to file. When logged to screen, however, if the logging severity level is LOG_INFO or higher, however, logging to screen would omit the prefix. If the logging severity level is lower (e.g., LOG_DEBUG), however, the prefix would be included. The user would then, for normal operation, be presented simplified log entries, but would be able to obtain the full log entries (prefix included) by selecting the verbose logging option.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.