github.com/muhammedhassanm/blockchain@v0.0.0-20200120143007-697261defd4d/sawtooth-core-master/consensus/poet/cli/sawtooth_poet_cli/enclave.py (about)

     1  # Copyright 2017 Intel Corporation
     2  #
     3  # Licensed under the Apache License, Version 2.0 (the "License");
     4  # you may not use this file except in compliance with the License.
     5  # You may obtain a copy of the License at
     6  #
     7  #     http://www.apache.org/licenses/LICENSE-2.0
     8  #
     9  # Unless required by applicable law or agreed to in writing, software
    10  # distributed under the License is distributed on an "AS IS" BASIS,
    11  # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  # See the License for the specific language governing permissions and
    13  # limitations under the License.
    14  # ------------------------------------------------------------------------------
    15  
    16  from sawtooth_poet_cli import config
    17  from sawtooth_poet_cli.poet_enclave_module_wrapper import \
    18      PoetEnclaveModuleWrapper
    19  
    20  
    21  def add_enclave_parser(subparsers):
    22      """Add argument parser arguments for the `poet enclave` sub-command.
    23      """
    24      description = 'Generates enclave setup information'
    25  
    26      parser = subparsers.add_parser(
    27          'enclave',
    28          help=description,
    29          description=description + '.')
    30  
    31      parser.add_argument(
    32          '--enclave-module',
    33          default='simulator',
    34          choices=['simulator', 'sgx'],
    35          type=str,
    36          help='identify the enclave module to query')
    37      parser.add_argument(
    38          'characteristic',
    39          choices=['measurement', 'basename'],
    40          type=str,
    41          help='enclave characteristic to retrieve')
    42  
    43  
    44  def do_enclave(args):
    45      """Executes the `poet enclave` sub-command.
    46  
    47      This command reads the appropriate characteristic from the enclave.  The
    48      available characteristics are:
    49      measurement - the enclave measurement (also know as mr_enclave)
    50      basename - the enclave basename
    51  
    52      The resulting characteristic value is printed to stdout
    53      """
    54      with PoetEnclaveModuleWrapper(
    55              enclave_module=args.enclave_module,
    56              config_dir=config.get_config_dir(),
    57              data_dir=config.get_data_dir()) as poet_enclave_module:
    58          if args.characteristic == 'measurement':
    59              print(poet_enclave_module.get_enclave_measurement())
    60          elif args.characteristic == 'basename':
    61              print(poet_enclave_module.get_enclave_basename())
    62          else:
    63              AssertionError(
    64                  'Unknown enclave characteristic type: {}'.format(args.type))