github.com/zcqzcg/fabric-ca@v2.0.0-alpha.0.20200416163940-d878ee6db75a+incompatible/docs/source/users-guide.rst (about)

     1  Fabric CA User's Guide
     2  ======================
     3  
     4  The Hyperledger Fabric CA is a Certificate Authority (CA)
     5  for Hyperledger Fabric.
     6  
     7  It provides features such as:
     8  
     9    * registration of identities, or connects to LDAP as the user
    10      registry
    11    * issuance of Enrollment Certificates (ECerts)
    12    * certificate renewal and revocation
    13  
    14  Hyperledger Fabric CA consists of both a server and a client component as
    15  described later in this document.
    16  
    17  For developers interested in contributing to Hyperledger Fabric CA, see the
    18  `Fabric CA repository <https://github.com/hyperledger/fabric-ca>`__ for more
    19  information.
    20  
    21  
    22  .. _Back to Top:
    23  
    24  Table of Contents
    25  -----------------
    26  
    27  1. `Overview`_
    28  
    29  2. `Getting Started`_
    30  
    31     1. `Prerequisites`_
    32     2. `Install`_
    33     3. `Explore the Fabric CA CLI`_
    34  
    35  3. `Configuration Settings`_
    36  
    37     1. `A word on file paths`_
    38  
    39  4. `Fabric CA Server`_
    40  
    41     1. `Initializing the server`_
    42     2. `Starting the server`_
    43     3. `Configuring the database`_
    44     4. `Configuring LDAP`_
    45     5. `Setting up a cluster`_
    46     6. `Setting up multiple CAs`_
    47     7. `Enrolling an intermediate CA`_
    48     8. `Upgrading the server`_
    49     9. `Operations Service`_
    50  
    51  5. `Fabric CA Client`_
    52  
    53     1. `Enrolling the bootstrap identity`_
    54     2. `Registering a new identity`_
    55     3. `Enrolling a peer identity`_
    56     4. `Getting Identity Mixer credential`_
    57     5. `Getting Idemix CRI (Certificate Revocation Information)`_
    58     6. `Reenrolling an identity`_
    59     7. `Revoking a certificate or identity`_
    60     8. `Generating a CRL (Certificate Revocation List)`_
    61     9. `Attribute-Based Access Control`_
    62     10. `Dynamic Server Configuration Update`_
    63     11. `Enabling TLS`_
    64     12. `Contact specific CA instance`_
    65  
    66  6. `Configuring an HSM`_
    67  
    68     1. `Example`_
    69  
    70  7. `File Formats`_
    71  
    72     1. `Fabric CA server's configuration file format`_
    73     2. `Fabric CA client's configuration file format`_
    74  
    75  8. `Troubleshooting`_
    76  
    77  Overview
    78  --------
    79  
    80  The diagram below illustrates how the Hyperledger Fabric CA server fits into the
    81  overall Hyperledger Fabric architecture.
    82  
    83  .. image:: ./images/fabric-ca.png
    84  
    85  There are two ways of interacting with a Hyperledger Fabric CA server:
    86  via the Hyperledger Fabric CA client or through one of the Fabric SDKs.
    87  All communication to the Hyperledger Fabric CA server is via REST APIs.
    88  See `fabric-ca/swagger/swagger-fabric-ca.json` for the swagger documentation
    89  for these REST APIs.
    90  You may view this documentation via the http://editor2.swagger.io online editor.
    91  
    92  The Hyperledger Fabric CA client or SDK may connect to a server in a cluster
    93  of Hyperledger Fabric CA servers.   This is illustrated in the top right section
    94  of the diagram. The client routes to an HA Proxy endpoint which load balances
    95  traffic to one of the fabric-ca-server cluster members.
    96  
    97  All Hyperledger Fabric CA servers in a cluster share the same database for
    98  keeping track of identities and certificates.  If LDAP is configured, the identity
    99  information is kept in LDAP rather than the database.
   100  
   101  A server may contain multiple CAs.  Each CA is either a root CA or an
   102  intermediate CA.  Each intermediate CA has a parent CA which is either a
   103  root CA or another intermediate CA.
   104  
   105  Getting Started
   106  ---------------
   107  
   108  Prerequisites
   109  ~~~~~~~~~~~~~~~
   110  
   111  -  Go 1.10+ installation
   112  -  ``GOPATH`` environment variable is set correctly
   113  - libtool and libtdhl-dev packages are installed
   114  
   115  The following installs the libtool dependencies on Ubuntu:
   116  
   117  .. code:: bash
   118  
   119     sudo apt install libtool libltdl-dev
   120  
   121  The following installs the libtool dependencies on MacOSX:
   122  
   123  .. code:: bash
   124  
   125     brew install libtool
   126  
   127  .. note:: libtldl-dev is not necessary on MacOSX if you instal
   128            libtool via Homebrew
   129  
   130  For more information on libtool, see https://www.gnu.org/software/libtool.
   131  
   132  For more information on libltdl-dev, see https://www.gnu.org/software/libtool/manual/html_node/Using-libltdl.html.
   133  
   134  Install
   135  ~~~~~~~
   136  
   137  The following installs both the `fabric-ca-server` and `fabric-ca-client` binaries
   138  in $GOPATH/bin.
   139  
   140  .. code:: bash
   141  
   142      go get -u github.com/hyperledger/fabric-ca/cmd/...
   143  
   144  Note: If you have already cloned the fabric-ca repository, make sure you are on the
   145  master branch before running the 'go get' command above. Otherwise, you might see the
   146  following error:
   147  
   148  ::
   149  
   150      <gopath>/src/github.com/hyperledger/fabric-ca; git pull --ff-only
   151      There is no tracking information for the current branch.
   152      Please specify which branch you want to merge with.
   153      See git-pull(1) for details.
   154  
   155          git pull <remote> <branch>
   156  
   157      If you wish to set tracking information for this branch you can do so with:
   158  
   159          git branch --set-upstream-to=<remote>/<branch> tlsdoc
   160  
   161      package github.com/hyperledger/fabric-ca/cmd/fabric-ca-client: exit status 1
   162  
   163  Start Server Natively
   164  ~~~~~~~~~~~~~~~~~~~~~
   165  
   166  The following starts the `fabric-ca-server` with default settings.
   167  
   168  .. code:: bash
   169  
   170      fabric-ca-server start -b admin:adminpw
   171  
   172  The `-b` option provides the enrollment ID and secret for a bootstrap
   173  administrator; this is required if LDAP is not enabled with the "ldap.enabled"
   174  setting.
   175  
   176  A default configuration file named `fabric-ca-server-config.yaml`
   177  is created in the local directory which can be customized.
   178  
   179  Start Server via Docker
   180  ~~~~~~~~~~~~~~~~~~~~~~~
   181  
   182  Docker Hub
   183  ^^^^^^^^^^^^
   184  
   185  Go to: https://hub.docker.com/r/hyperledger/fabric-ca/tags/
   186  
   187  Find the tag that matches the architecture and version of fabric-ca
   188  that you want to pull.
   189  
   190  Navigate to `$GOPATH/src/github.com/hyperledger/fabric-ca/docker/server`
   191  and open up docker-compose.yml in an editor.
   192  
   193  Change the `image` line to reflect the tag you found previously. The file
   194  may look like this for an x86 architecture for version beta.
   195  
   196  .. code:: yaml
   197  
   198      fabric-ca-server:
   199        image: hyperledger/fabric-ca:x86_64-1.0.0-beta
   200        container_name: fabric-ca-server
   201        ports:
   202          - "7054:7054"
   203        environment:
   204          - FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
   205        volumes:
   206          - "./fabric-ca-server:/etc/hyperledger/fabric-ca-server"
   207        command: sh -c 'fabric-ca-server start -b admin:adminpw'
   208  
   209  Open up a terminal in the same directory as the docker-compose.yml file
   210  and execute the following:
   211  
   212  .. code:: bash
   213  
   214      # docker-compose up -d
   215  
   216  This will pull down the specified fabric-ca image in the Compose file
   217  if it does not already exist, and start an instance of the fabric-ca
   218  server.
   219  
   220  Building Your Own Docker image
   221  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   222  
   223  You can build and start the server via Docker Compose as shown below.
   224  
   225  .. code:: bash
   226  
   227      cd $GOPATH/src/github.com/hyperledger/fabric-ca
   228      make docker
   229      cd docker/server
   230      docker-compose up -d
   231  
   232  The hyperledger/fabric-ca Docker image contains both the fabric-ca-server and
   233  the fabric-ca-client.
   234  
   235  .. code:: bash
   236  
   237      # cd $GOPATH/src/github.com/hyperledger/fabric-ca
   238      # FABRIC_CA_DYNAMIC_LINK=true make docker
   239      # cd docker/server
   240      # docker-compose up -d
   241  
   242  Explore the Fabric CA CLI
   243  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
   244  
   245  This section simply provides the usage messages for the Fabric CA server and client
   246  for convenience.  Additional usage information is provided in following sections.
   247  
   248  The following links shows the :doc:`Server Command Line <servercli>` and
   249  :doc:`Client Command Line <clientcli>`.
   250  
   251  .. note:: Note that command line options that are string slices (lists) can be
   252            specified either by specifying the option with comma-separated list
   253            elements or by specifying the option multiple times, each with a
   254            string value that make up the list. For example, to specify
   255            ``host1`` and ``host2`` for the ``csr.hosts`` option, you can either
   256            pass ``--csr.hosts 'host1,host2'`` or
   257            ``--csr.hosts host1 --csr.hosts host2``. When using the former format,
   258            please make sure there are no space before or after any commas.
   259  
   260  `Back to Top`_
   261  
   262  Configuration Settings
   263  ~~~~~~~~~~~~~~~~~~~~~~
   264  
   265  The Fabric CA provides 3 ways to configure settings on the Fabric CA server
   266  and client. The precedence order is:
   267  
   268    1. CLI flags
   269    2. Environment variables
   270    3. Configuration file
   271  
   272  In the remainder of this document, we refer to making changes to
   273  configuration files. However, configuration file changes can be
   274  overridden through environment variables or CLI flags.
   275  
   276  For example, if we have the following in the client configuration file:
   277  
   278  .. code:: yaml
   279  
   280      tls:
   281        # Enable TLS (default: false)
   282        enabled: false
   283  
   284        # TLS for the client's listenting port (default: false)
   285        certfiles:
   286        client:
   287          certfile: cert.pem
   288          keyfile:
   289  
   290  The following environment variable may be used to override the ``cert.pem``
   291  setting in the configuration file:
   292  
   293  .. code:: bash
   294  
   295    export FABRIC_CA_CLIENT_TLS_CLIENT_CERTFILE=cert2.pem
   296  
   297  If we wanted to override both the environment variable and configuration
   298  file, we can use a command line flag.
   299  
   300  .. code:: bash
   301  
   302    fabric-ca-client enroll --tls.client.certfile cert3.pem
   303  
   304  The same approach applies to fabric-ca-server, except instead of using
   305  ``FABIRC_CA_CLIENT`` as the prefix to environment variables,
   306  ``FABRIC_CA_SERVER`` is used.
   307  
   308  .. _server:
   309  
   310  A word on file paths
   311  ^^^^^^^^^^^^^^^^^^^^^
   312  All the properties in the Fabric CA server and client configuration file
   313  that specify file names support both relative and absolute paths.
   314  Relative paths are relative to the config directory, where the
   315  configuration file is located. For example, if the config directory is
   316  ``~/config`` and the tls section is as shown below, the Fabric CA server
   317  or client will look for the ``root.pem`` file in the ``~/config``
   318  directory, ``cert.pem`` file in the ``~/config/certs`` directory and the
   319  ``key.pem`` file in the ``/abs/path`` directory
   320  
   321  .. code:: yaml
   322  
   323      tls:
   324        enabled: true
   325        certfiles:
   326          - root.pem
   327        client:
   328          certfile: certs/cert.pem
   329          keyfile: /abs/path/key.pem
   330  
   331  `Back to Top`_
   332  
   333  
   334  
   335  Fabric CA Server
   336  ----------------
   337  
   338  This section describes the Fabric CA server.
   339  
   340  You may initialize the Fabric CA server before starting it. This provides an
   341  opportunity for you to generate a default configuration file that can be
   342  reviewed and customized before starting the server.
   343  
   344  The Fabric CA server's home directory is determined as follows:
   345    - if the --home command line option is set, use its value
   346    - otherwise, if the ``FABRIC_CA_SERVER_HOME`` environment variable is set, use
   347      its value
   348    - otherwise, if ``FABRIC_CA_HOME`` environment variable is set, use
   349      its value
   350    - otherwise, if the ``CA_CFG_PATH`` environment variable is set, use
   351      its value
   352    - otherwise, use current working directory
   353  
   354  For the remainder of this server section, we assume that you have set
   355  the ``FABRIC_CA_HOME`` environment variable to
   356  ``$HOME/fabric-ca/server``.
   357  
   358  The instructions below assume that the server configuration file exists
   359  in the server's home directory.
   360  
   361  .. _initialize:
   362  
   363  Initializing the server
   364  ~~~~~~~~~~~~~~~~~~~~~~~
   365  
   366  Initialize the Fabric CA server as follows:
   367  
   368  .. code:: bash
   369  
   370      fabric-ca-server init -b admin:adminpw
   371  
   372  The ``-b`` (bootstrap identity) option is required for initialization when
   373  LDAP is disabled. At least one bootstrap identity is required to start the
   374  Fabric CA server; this identity is the server administrator.
   375  
   376  The server configuration file contains a Certificate Signing Request (CSR)
   377  section that can be configured. The following is a sample CSR.
   378  
   379  .. _csr-fields:
   380  
   381  .. code:: yaml
   382  
   383     cn: fabric-ca-server
   384     names:
   385        - C: US
   386          ST: "North Carolina"
   387          L:
   388          O: Hyperledger
   389          OU: Fabric
   390     hosts:
   391       - host1.example.com
   392       - localhost
   393     ca:
   394        expiry: 131400h
   395        pathlength: 1
   396  
   397  All of the fields above pertain to the X.509 signing key and certificate which
   398  is generated by the ``fabric-ca-server init``.  This corresponds to the
   399  ``ca.certfile`` and ``ca.keyfile`` files in the server's configuration file.
   400  The fields are as follows:
   401  
   402    -  **cn** is the Common Name
   403    -  **O** is the organization name
   404    -  **OU** is the organizational unit
   405    -  **L** is the location or city
   406    -  **ST** is the state
   407    -  **C** is the country
   408  
   409  If custom values for the CSR are required, you may customize the configuration
   410  file, delete the files specified by the ``ca.certfile`` and ``ca.keyfile``
   411  configuration items, and then run the ``fabric-ca-server init -b admin:adminpw``
   412  command again.
   413  
   414  The ``fabric-ca-server init`` command generates a self-signed CA certificate
   415  unless the ``-u <parent-fabric-ca-server-URL>`` option is specified.
   416  If the ``-u`` is specified, the server's CA certificate is signed by the
   417  parent Fabric CA server.
   418  In order to authenticate to the parent Fabric CA server, the URL must
   419  be of the form ``<scheme>://<enrollmentID>:<secret>@<host>:<port>``, where
   420  <enrollmentID> and <secret> correspond to an identity with an 'hf.IntermediateCA'
   421  attribute whose value equals 'true'.
   422  The ``fabric-ca-server init`` command also generates a default configuration
   423  file named **fabric-ca-server-config.yaml** in the server's home directory.
   424  
   425  If you want the Fabric CA server to use a CA signing certificate and key file which you provide,
   426  you must place your files in the location referenced by ``ca.certfile`` and ``ca.keyfile`` respectively.
   427  Both files must be PEM-encoded and must not be encrypted.
   428  More specifically, the contents of the CA certificate file must begin with ``-----BEGIN CERTIFICATE-----``
   429  and the contents of the key file must begin with ``-----BEGIN PRIVATE KEY-----`` and not
   430  ``-----BEGIN ENCRYPTED PRIVATE KEY-----``.
   431  
   432  Algorithms and key sizes
   433  
   434  The CSR can be customized to generate X.509 certificates and keys that
   435  support Elliptic Curve (ECDSA). The following setting is an
   436  example of the implementation of Elliptic Curve Digital Signature
   437  Algorithm (ECDSA) with curve ``prime256v1`` and signature algorithm
   438  ``ecdsa-with-SHA256``:
   439  
   440  .. code:: yaml
   441  
   442      key:
   443         algo: ecdsa
   444         size: 256
   445  
   446  The choice of algorithm and key size are based on security needs.
   447  
   448  Elliptic Curve (ECDSA) offers the following key size options:
   449  
   450  +--------+--------------+-----------------------+
   451  | size   | ASN1 OID     | Signature Algorithm   |
   452  +========+==============+=======================+
   453  | 256    | prime256v1   | ecdsa-with-SHA256     |
   454  +--------+--------------+-----------------------+
   455  | 384    | secp384r1    | ecdsa-with-SHA384     |
   456  +--------+--------------+-----------------------+
   457  | 521    | secp521r1    | ecdsa-with-SHA512     |
   458  +--------+--------------+-----------------------+
   459  
   460  Starting the server
   461  ~~~~~~~~~~~~~~~~~~~
   462  
   463  Start the Fabric CA server as follows:
   464  
   465  .. code:: bash
   466  
   467      fabric-ca-server start -b <admin>:<adminpw>
   468  
   469  If the server has not been previously initialized, it will initialize
   470  itself as it starts for the first time.  During this initialization, the
   471  server will generate the ca-cert.pem and ca-key.pem files if they don't
   472  yet exist and will also create a default configuration file if it does
   473  not exist.  See the `Initialize the Fabric CA server <#initialize>`__ section.
   474  
   475  Unless the Fabric CA server is configured to use LDAP, it must be
   476  configured with at least one pre-registered bootstrap identity to enable you
   477  to register and enroll other identities. The ``-b`` option specifies the
   478  name and password for a bootstrap identity.
   479  
   480  To cause the Fabric CA server to listen on ``https`` rather than
   481  ``http``, set ``tls.enabled`` to ``true``.
   482  
   483  SECURITY WARNING: The Fabric CA server should always be started with TLS
   484  enabled (``tls.enabled`` set to true). Failure to do so leaves the
   485  server vulnerable to an attacker with access to network traffic.
   486  
   487  To limit the number of times that the same secret (or password) can be
   488  used for enrollment, set the ``registry.maxenrollments`` in the configuration
   489  file to the appropriate value. If you set the value to 1, the Fabric CA
   490  server allows passwords to only be used once for a particular enrollment
   491  ID. If you set the value to -1, the Fabric CA server places no limit on
   492  the number of times that a secret can be reused for enrollment. The
   493  default value is -1. Setting the value to 0, the Fabric CA server will
   494  disable enrollment for all identities and registration of identities will
   495  not be allowed.
   496  
   497  The Fabric CA server should now be listening on port 7054.
   498  
   499  You may skip to the `Fabric CA Client <#fabric-ca-client>`__ section if
   500  you do not want to configure the Fabric CA server to run in a cluster or
   501  to use LDAP.
   502  
   503  Configuring the database
   504  ~~~~~~~~~~~~~~~~~~~~~~~~
   505  
   506  This section describes how to configure the Fabric CA server to connect
   507  to PostgreSQL or MySQL databases. The default database is SQLite and the
   508  default database file is ``fabric-ca-server.db`` in the Fabric CA
   509  server's home directory.
   510  
   511  If you don't care about running the Fabric CA server in a cluster, you
   512  may skip this section; otherwise, you must configure either PostgreSQL or
   513  MySQL as described below. Fabric CA supports the following database
   514  versions in a cluster setup:
   515  
   516  - PostgreSQL: 9.5.5 or later
   517  - MySQL: 5.7 or later
   518  
   519  PostgreSQL
   520  ^^^^^^^^^^
   521  
   522  The following sample may be added to the server's configuration file in
   523  order to connect to a PostgreSQL database. Be sure to customize the
   524  various values appropriately. There are limitations on what characters are allowed
   525  in the database name. Please refer to the following Postgres documentation
   526  for more information: https://www.postgresql.org/docs/current/static/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
   527  
   528  .. code:: yaml
   529  
   530      db:
   531        type: postgres
   532        datasource: host=localhost port=5432 user=Username password=Password dbname=fabric_ca sslmode=verify-full
   533  
   534  Specifying *sslmode* configures the type of SSL authentication. Valid
   535  values for sslmode are:
   536  
   537  |
   538  
   539  +----------------+----------------+
   540  | Mode           | Description    |
   541  +================+================+
   542  | disable        | No SSL         |
   543  +----------------+----------------+
   544  | require        | Always SSL     |
   545  |                | (skip          |
   546  |                | verification)  |
   547  +----------------+----------------+
   548  | verify-ca      | Always SSL     |
   549  |                | (verify that   |
   550  |                | the            |
   551  |                | certificate    |
   552  |                | presented by   |
   553  |                | the server was |
   554  |                | signed by a    |
   555  |                | trusted CA)    |
   556  +----------------+----------------+
   557  | verify-full    | Same as        |
   558  |                | verify-ca AND  |
   559  |                | verify that    |
   560  |                | the            |
   561  |                | certificate    |
   562  |                | presented by   |
   563  |                | the server was |
   564  |                | signed by a    |
   565  |                | trusted CA and |
   566  |                | the server     |
   567  |                | hostname       |
   568  |                | matches the    |
   569  |                | one in the     |
   570  |                | certificate    |
   571  +----------------+----------------+
   572  
   573  |
   574  
   575  If you would like to use TLS, then the ``db.tls`` section in the Fabric CA server
   576  configuration file must be specified. If SSL client authentication is enabled
   577  on the PostgreSQL server, then the client certificate and key file must also be
   578  specified in the ``db.tls.client`` section. The following is an example
   579  of the ``db.tls`` section:
   580  
   581  .. code:: yaml
   582  
   583      db:
   584        ...
   585        tls:
   586            enabled: true
   587            certfiles:
   588              - db-server-cert.pem
   589            client:
   590                  certfile: db-client-cert.pem
   591                  keyfile: db-client-key.pem
   592  
   593  | **certfiles** - A list of PEM-encoded trusted root certificate files.
   594  | **certfile** and **keyfile** - PEM-encoded certificate and key files that are used by the Fabric CA server to communicate securely with the PostgreSQL server
   595  
   596  PostgreSQL SSL Configuration
   597  """""""""""""""""""""""""""""
   598  
   599  **Basic instructions for configuring SSL on the PostgreSQL server:**
   600  
   601  1. In postgresql.conf, uncomment SSL and set to "on" (SSL=on)
   602  
   603  2. Place certificate and key files in the PostgreSQL data directory.
   604  
   605  Instructions for generating self-signed certificates for:
   606  https://www.postgresql.org/docs/9.5/static/ssl-tcp.html
   607  
   608  Note: Self-signed certificates are for testing purposes and should not
   609  be used in a production environment
   610  
   611  **PostgreSQL Server - Require Client Certificates**
   612  
   613  1. Place certificates of the certificate authorities (CAs) you trust in the file root.crt in the PostgreSQL data directory
   614  
   615  2. In postgresql.conf, set "ssl\_ca\_file" to point to the root cert of the client (CA cert)
   616  
   617  3. Set the clientcert parameter to 1 on the appropriate hostssl line(s) in pg\_hba.conf.
   618  
   619  For more details on configuring SSL on the PostgreSQL server, please refer
   620  to the following PostgreSQL documentation:
   621  https://www.postgresql.org/docs/9.4/static/libpq-ssl.html
   622  
   623  MySQL
   624  ^^^^^^^
   625  
   626  The following sample may be added to the Fabric CA server configuration file in
   627  order to connect to a MySQL database. Be sure to customize the various
   628  values appropriately. There are limitations on what characters are allowed
   629  in the database name. Please refer to the following MySQL documentation
   630  for more information: https://dev.mysql.com/doc/refman/5.7/en/identifiers.html
   631  
   632  On MySQL 5.7.X, certain modes affect whether the server permits '0000-00-00' as a valid date.
   633  It might be necessary to relax the modes that MySQL server uses. We want to allow
   634  the server to be able to accept zero date values.
   635  
   636  In my.cnf, find the configuration option *sql_mode* and remove *NO_ZERO_DATE* if present.
   637  Restart MySQL server after making this change.
   638  
   639  Please refer to the following MySQL documentation on different modes available
   640  and select the appropriate settings for the specific version of MySQL that is
   641  being used.
   642  
   643  https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html
   644  
   645  .. code:: yaml
   646  
   647      db:
   648        type: mysql
   649        datasource: root:rootpw@tcp(localhost:3306)/fabric_ca?parseTime=true&tls=custom
   650  
   651  If connecting over TLS to the MySQL server, the ``db.tls.client``
   652  section is also required as described in the **PostgreSQL** section above.
   653  
   654  MySQL SSL Configuration
   655  """"""""""""""""""""""""
   656  
   657  **Basic instructions for configuring SSL on MySQL server:**
   658  
   659  1. Open or create my.cnf file for the server. Add or uncomment the
   660     lines below in the [mysqld] section. These should point to the key and
   661     certificates for the server, and the root CA cert.
   662  
   663     Instructions on creating server and client-side certficates:
   664     http://dev.mysql.com/doc/refman/5.7/en/creating-ssl-files-using-openssl.html
   665  
   666     [mysqld] ssl-ca=ca-cert.pem ssl-cert=server-cert.pem ssl-key=server-key.pem
   667  
   668     Can run the following query to confirm SSL has been enabled.
   669  
   670     mysql> SHOW GLOBAL VARIABLES LIKE 'have\_%ssl';
   671  
   672     Should see:
   673  
   674     +----------------+----------------+
   675     | Variable_name  | Value          |
   676     +================+================+
   677     | have_openssl   | YES            |
   678     +----------------+----------------+
   679     | have_ssl       | YES            |
   680     +----------------+----------------+
   681  
   682  2. After the server-side SSL configuration is finished, the next step is
   683     to create a user who has a privilege to access the MySQL server over
   684     SSL. For that, log in to the MySQL server, and type:
   685  
   686     mysql> GRANT ALL PRIVILEGES ON *.* TO 'ssluser'@'%' IDENTIFIED BY
   687     'password' REQUIRE SSL; mysql> FLUSH PRIVILEGES;
   688  
   689     If you want to give a specific IP address from which the user will
   690     access the server change the '%' to the specific IP address.
   691  
   692  **MySQL Server - Require Client Certificates**
   693  
   694  Options for secure connections are similar to those used on the server side.
   695  
   696  -  ssl-ca identifies the Certificate Authority (CA) certificate. This
   697     option, if used, must specify the same certificate used by the server.
   698  -  ssl-cert identifies MySQL server's certificate.
   699  -  ssl-key identifies MySQL server's private key.
   700  
   701  Suppose that you want to connect using an account that has no special
   702  encryption requirements or was created using a GRANT statement that
   703  includes the REQUIRE SSL option. As a recommended set of
   704  secure-connection options, start the MySQL server with at least
   705  --ssl-cert and --ssl-key options. Then set the ``db.tls.certfiles`` property
   706  in the server configuration file and start the Fabric CA server.
   707  
   708  To require that a client certificate also be specified, create the
   709  account using the REQUIRE X509 option. Then the client must also specify
   710  proper client key and certificate files; otherwise, the MySQL server
   711  will reject the connection. To specify client key and certificate files
   712  for the Fabric CA server, set the ``db.tls.client.certfile``,
   713  and ``db.tls.client.keyfile`` configuration properties.
   714  
   715  Configuring LDAP
   716  ~~~~~~~~~~~~~~~~
   717  
   718  The Fabric CA server can be configured to read from an LDAP server.
   719  
   720  In particular, the Fabric CA server may connect to an LDAP server to do
   721  the following:
   722  
   723  -  authenticate an identity prior to enrollment
   724  -  retrieve an identity's attribute values which are used for authorization.
   725  
   726  Modify the LDAP section of the Fabric CA server's configuration file to configure the
   727  server to connect to an LDAP server.
   728  
   729  .. code:: yaml
   730  
   731      ldap:
   732         # Enables or disables the LDAP client (default: false)
   733         enabled: false
   734         # The URL of the LDAP server
   735         url: <scheme>://<adminDN>:<adminPassword>@<host>:<port>/<base>
   736         userfilter: <filter>
   737         attribute:
   738            # 'names' is an array of strings that identify the specific attributes
   739            # which are requested from the LDAP server.
   740            names: <LDAPAttrs>
   741            # The 'converters' section is used to convert LDAP attribute values
   742            # to fabric CA attribute values.
   743            #
   744            # For example, the following converts an LDAP 'uid' attribute
   745            # whose value begins with 'revoker' to a fabric CA attribute
   746            # named "hf.Revoker" with a value of "true" (because the expression
   747            # evaluates to true).
   748            #    converters:
   749            #       - name: hf.Revoker
   750            #         value: attr("uid") =~ "revoker*"
   751            #
   752            # As another example, assume a user has an LDAP attribute named
   753            # 'member' which has multiple values of "dn1", "dn2", and "dn3".
   754            # Further assume the following configuration.
   755            #    converters:
   756            #       - name: myAttr
   757            #         value: map(attr("member"),"groups")
   758            #    maps:
   759            #       groups:
   760            #          - name: dn1
   761            #            value: client
   762            #          - name: dn2
   763            #            value: peer
   764            # The value of the user's 'myAttr' attribute is then computed to be
   765            # "client,peer,dn3".  This is because the value of 'attr("member")' is
   766            # "dn1,dn2,dn3", and the call to 'map' with a 2nd argument of
   767            # "group" replaces "dn1" with "client" and "dn2" with "peer".
   768            converters:
   769              - name: <fcaAttrName>
   770                value: <fcaExpr>
   771            maps:
   772              <mapName>:
   773                  - name: <from>
   774                    value: <to>
   775  
   776  Where:
   777  
   778    * ``scheme`` is one of *ldap* or *ldaps*;
   779    * ``adminDN`` is the distinquished name of the admin user;
   780    * ``pass`` is the password of the admin user;
   781    * ``host`` is the hostname or IP address of the LDAP server;
   782    * ``port`` is the optional port number, where default 389 for *ldap*
   783      and 636 for *ldaps*;
   784    * ``base`` is the optional root of the LDAP tree to use for searches;
   785    * ``filter`` is a filter to use when searching to convert a login
   786      user name to a distinguished name. For example, a value of
   787      ``(uid=%s)`` searches for LDAP entries with the value of a ``uid``
   788      attribute whose value is the login user name. Similarly,
   789      ``(email=%s)`` may be used to login with an email address.
   790    * ``LDAPAttrs`` is an array of LDAP attribute names to request from the
   791      LDAP server on a user's behalf;
   792    * the attribute.converters section is used to convert LDAP attributes to fabric
   793      CA attributes, where
   794      * ``fcaAttrName`` is the name of a fabric CA attribute;
   795      * ``fcaExpr`` is an expression whose evaluated value is assigned to the fabric CA attribute.
   796      For example, suppose that <LDAPAttrs> is ["uid"], <fcaAttrName> is 'hf.Revoker',
   797      and <fcaExpr> is 'attr("uid") =~ "revoker*"'.  This means that an attribute
   798      named "uid" is requested from the LDAP server on a user's behalf.  The user is
   799      then given a value of 'true' for the 'hf.Revoker' attribute if the value of
   800      the user's 'uid' LDAP attribute begins with 'revoker'; otherwise, the user
   801      is given a value of 'false' for the 'hf.Revoker' attribute.
   802    * the attribute.maps section is used to map LDAP response values.  The typical
   803      use case is to map a distinguished name associated with an LDAP group to an
   804      identity type.
   805  
   806  The LDAP expression language uses the govaluate package as described at
   807  https://github.com/Knetic/govaluate/blob/master/MANUAL.md.  This defines
   808  operators such as "=~" and literals such as "revoker*", which is a regular
   809  expression.  The LDAP-specific variables and functions which extend the
   810  base govaluate language are as follows:
   811  
   812    * ``DN`` is a variable equal to the user's distinguished name.
   813    * ``affiliation`` is a variable equal to the user's affiliation.
   814    * ``attr`` is a function which takes 1 or 2 arguments.  The 1st argument
   815      is an LDAP attribute name.  The 2nd argument is a separator string which is
   816      used to join multiple values into a single string; the default separator
   817      string is ",". The ``attr`` function always returns a value of type
   818      'string'.
   819    * ``map`` is a function which takes 2 arguments.  The 1st argument
   820      is any string.  The second argument is the name of a map which is used to
   821      perform string substitution on the string from the 1st argument.
   822    * ``if`` is a function which takes a 3 arguments where the first argument
   823      must resolve to a boolean value.  If it evaluates to true, the second
   824      argument is returned; otherwise, the third argument is returned.
   825  
   826  For example, the following expression evaluates to true if the user has
   827  a distinguished name ending in "O=org1,C=US", or if the user has an affiliation
   828  beginning with "org1.dept2." and also has the "admin" attribute of "true".
   829  
   830    **DN =~ "*O=org1,C=US" || (affiliation =~ "org1.dept2.*" && attr('admin') = 'true')**
   831  
   832  NOTE: Since the ``attr`` function always returns a value of type 'string',
   833  numeric operators may not be used to construct expressions.
   834  For example, the following is NOT a valid expression:
   835  
   836  .. code:: yaml
   837  
   838       value: attr("gidNumber) >= 10000 && attr("gidNumber) < 10006
   839  
   840  Alternatively, a regular expression enclosed in quotes as shown below may be used
   841  to return an equivalent result:
   842  
   843  .. code:: yaml
   844  
   845       value: attr("gidNumber") =~ "1000[0-5]$" || attr("mail") == "root@example.com"
   846  
   847  The following is a sample configuration section for the default setting
   848  for the OpenLDAP server whose Docker image is at
   849  ``https://github.com/osixia/docker-openldap``.
   850  
   851  .. code:: yaml
   852  
   853      ldap:
   854         enabled: true
   855         url: ldap://cn=admin,dc=example,dc=org:admin@localhost:10389/dc=example,dc=org
   856         userfilter: (uid=%s)
   857  
   858  See ``FABRIC_CA/scripts/run-ldap-tests`` for a script which starts an
   859  OpenLDAP Docker image, configures it, runs the LDAP tests in
   860  ``FABRIC_CA/cli/server/ldap/ldap_test.go``, and stops the OpenLDAP
   861  server.
   862  
   863  When LDAP is configured, enrollment works as follows:
   864  
   865  
   866  -  The Fabric CA client or client SDK sends an enrollment request with a
   867     basic authorization header.
   868  -  The Fabric CA server receives the enrollment request, decodes the
   869     identity name and password in the authorization header, looks up the DN (Distinguished
   870     Name) associated with the identity name using the "userfilter" from the
   871     configuration file, and then attempts an LDAP bind with the identity's
   872     password. If the LDAP bind is successful, the enrollment processing is
   873     authorized and can proceed.
   874  
   875  Setting up a cluster
   876  ~~~~~~~~~~~~~~~~~~~~
   877  
   878  You may use any IP sprayer to load balance to a cluster of Fabric CA
   879  servers. This section provides an example of how to set up Haproxy to
   880  route to a Fabric CA server cluster. Be sure to change hostname and port
   881  to reflect the settings of your Fabric CA servers.
   882  
   883  haproxy.conf
   884  
   885  .. code::
   886  
   887      global
   888            maxconn 4096
   889            daemon
   890  
   891      defaults
   892            mode http
   893            maxconn 2000
   894            timeout connect 5000
   895            timeout client 50000
   896            timeout server 50000
   897  
   898      listen http-in
   899            bind *:7054
   900            balance roundrobin
   901            server server1 hostname1:port
   902            server server2 hostname2:port
   903            server server3 hostname3:port
   904  
   905  
   906  Note: If using TLS, need to use ``mode tcp``.
   907  
   908  Setting up multiple CAs
   909  ~~~~~~~~~~~~~~~~~~~~~~~
   910  
   911  The fabric-ca server by default consists of a single default CA. However, additional CAs
   912  can be added to a single server by using `cafiles` or `cacount` configuration options.
   913  Each additional CA will have its own home directory.
   914  
   915  cacount:
   916  ^^^^^^^^
   917  
   918  The `cacount` provides a quick way to start X number of default additional
   919  CAs. The home directory will be relative to the server directory. With this option,
   920  the directory structure will be as follows:
   921  
   922  .. code:: yaml
   923  
   924      --<Server Home>
   925        |--ca
   926          |--ca1
   927          |--ca2
   928  
   929  Each additional CA will get a default configuration file generated in it's home
   930  directory, within the configuration file it will contain a unique CA name.
   931  
   932  For example, the following command will start 2 default CA instances:
   933  
   934  .. code:: bash
   935  
   936     fabric-ca-server start -b admin:adminpw --cacount 2
   937  
   938  cafiles:
   939  ^^^^^^^^
   940  
   941  If absolute paths are not provided when using the cafiles configuration option,
   942  the CA home directory will be relative to the server directory.
   943  
   944  To use this option, CA configuration files must have already been generated and
   945  configured for each CA that is to be started. Each configuration file must have
   946  a unique CA name and Common Name (CN), otherwise the server will fail to start as these
   947  names must be unique. The CA configuration files will override any default
   948  CA configuration, and any missing options in the CA configuration files will be
   949  replaced by the values from the default CA.
   950  
   951  The precedence order will be as follows:
   952  
   953    1. CA Configuration file
   954    2. Default CA CLI flags
   955    3. Default CA Environment variables
   956    4. Default CA Configuration file
   957  
   958  A CA configuration file must contain at least the following:
   959  
   960  .. code:: yaml
   961  
   962      ca:
   963      # Name of this CA
   964      name: <CANAME>
   965  
   966      csr:
   967        cn: <COMMONNAME>
   968  
   969  You may configure your directory structure as follows:
   970  
   971  .. code:: yaml
   972  
   973      --<Server Home>
   974        |--ca
   975          |--ca1
   976            |-- fabric-ca-config.yaml
   977          |--ca2
   978            |-- fabric-ca-config.yaml
   979  
   980  For example, the following command will start two customized CA instances:
   981  
   982  .. code:: bash
   983  
   984      fabric-ca-server start -b admin:adminpw --cafiles ca/ca1/fabric-ca-config.yaml
   985      --cafiles ca/ca2/fabric-ca-config.yaml
   986  
   987  
   988  Enrolling an intermediate CA
   989  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   990  
   991  In order to create a CA signing certificate for an intermediate CA, the intermediate
   992  CA must enroll with a parent CA in the same way that a fabric-ca-client enrolls with a CA.
   993  This is done by using the -u option to specify the URL of the parent CA and the enrollment ID
   994  and secret as shown below.  The identity associated with this enrollment ID must have an
   995  attribute with a name of "hf.IntermediateCA" and a value of "true".  The CN (or Common Name)
   996  of the issued certificate will be set to the enrollment ID. An error will occur if an intermediate
   997  CA tries to explicitly specify a CN value.
   998  
   999  .. code:: bash
  1000  
  1001      fabric-ca-server start -b admin:adminpw -u http://<enrollmentID>:<secret>@<parentserver>:<parentport>
  1002  
  1003  For other intermediate CA flags see `Fabric CA server's configuration file format`_ section.
  1004  
  1005  
  1006  Upgrading the server
  1007  ~~~~~~~~~~~~~~~~~~~~
  1008  
  1009  The Fabric CA server must be upgraded before upgrading the Fabric CA client.
  1010  Prior to upgrade, it is suggested that the current database be backed up:
  1011  
  1012  - If using sqlite3, backup the current database file (which is named fabric-ca-server.db by default).
  1013  - For other database types, use the appropriate backup/replication mechanism.
  1014  
  1015  To upgrade a single instance of Fabric CA server:
  1016  
  1017  1. Stop the fabric-ca-server process.
  1018  2. Ensure the current database is backed up.
  1019  3. Replace previous fabric-ca-server binary with the upgraded version.
  1020  4. Launch the fabric-ca-server process.
  1021  5. Verify the fabric-ca-server process is available with the following
  1022     command where <host> is the hostname on which the server was started::
  1023  
  1024        fabric-ca-client getcainfo -u http://<host>:7054
  1025  
  1026  Upgrading a cluster:
  1027  ^^^^^^^^^^^^^^^^^^^^
  1028  To upgrade a cluster of fabric-ca-server instances using either a MySQL or Postgres database, perform the following procedure. We assume that you are using haproxy to load balance to two fabric-ca-server cluster members on host1 and host2, respectively, both listening on port 7054. After this procedure, you will be load balancing to upgraded fabric-ca-server cluster members on host3 and host4 respectively, both listening on port 7054.
  1029  
  1030  In order to monitor the changes using haproxy stats, enable statistics collection. Add the following lines to the global section of the haproxy configuration file:
  1031  
  1032  ::
  1033  
  1034      stats socket /var/run/haproxy.sock mode 666 level operator
  1035      stats timeout 2m
  1036  
  1037  Restart haproxy to pick up the changes::
  1038  
  1039      # haproxy -f <configfile> -st $(pgrep haproxy)
  1040  
  1041  To display summary information from the haproxy "show stat" command, the following function may prove useful for parsing the copious amount of CSV data returned:
  1042  
  1043  .. code:: bash
  1044  
  1045      haProxyShowStats() {
  1046         echo "show stat" | nc -U /var/run/haproxy.sock |sed '1s/^# *//'|
  1047            awk -F',' -v fmt="%4s %12s %10s %6s %6s %4s %4s\n" '
  1048               { if (NR==1) for (i=1;i<=NF;i++) f[tolower($i)]=i }
  1049               { printf fmt, $f["sid"],$f["pxname"],$f["svname"],$f["status"],
  1050                             $f["weight"],$f["act"],$f["bck"] }'
  1051      }
  1052  
  1053  
  1054  1) Initially your haproxy configuration file is similar to the following::
  1055  
  1056        server server1 host1:7054 check
  1057        server server2 host2:7054 check
  1058  
  1059     Change this configuration to the following::
  1060  
  1061        server server1 host1:7054 check backup
  1062        server server2 host2:7054 check backup
  1063        server server3 host3:7054 check
  1064        server server4 host4:7054 check
  1065  
  1066  2) Restart the HA proxy with the new configuration as follows::
  1067  
  1068        haproxy -f <configfile> -st $(pgrep haproxy)
  1069  
  1070     ``"haProxyShowStats"`` will now reflect the modified configuration,
  1071     with two active, older-version backup servers and two (yet to be started) upgraded servers::
  1072  
  1073        sid   pxname      svname  status  weig  act  bck
  1074          1   fabric-cas  server3   DOWN     1    1    0
  1075          2   fabric-cas  server4   DOWN     1    1    0
  1076          3   fabric-cas  server1     UP     1    0    1
  1077          4   fabric-cas  server2     UP     1    0    1
  1078  
  1079  3) Install upgraded binaries of fabric-ca-server on host3 and host4. The new
  1080     upgraded servers on host3 and host4 should be configured to use the same
  1081     database as their older counterparts on host1 and host2. After starting
  1082     the upgraded servers, the database will be automatically migrated. The
  1083     haproxy will forward all new traffic to the upgraded servers, since they
  1084     are not configured as backup servers. Verify using the ``"fabric-ca-client getcainfo"``
  1085     command that your cluster is still functioning appropriately before proceeding.
  1086     Also, ``"haProxyShowStats"`` should now reflect that all servers are active,
  1087     similar to the following::
  1088  
  1089        sid   pxname      svname  status  weig  act  bck
  1090          1   fabric-cas  server3    UP     1    1    0
  1091          2   fabric-cas  server4    UP     1    1    0
  1092          3   fabric-cas  server1    UP     1    0    1
  1093          4   fabric-cas  server2    UP     1    0    1
  1094  
  1095  4) Stop the old servers on host1 and host2. Verify using the
  1096     ``"fabric-ca-client getcainfo"`` command that your new cluster is still
  1097     functioning appropriately before proceeding. Then remove the older
  1098     server backup configuration from the haproxy configuration file,
  1099     so that it looks similar to the following::
  1100  
  1101        server server3 host3:7054 check
  1102        server server4 host4:7054 check
  1103  
  1104  5) Restart the HA proxy with the new configuration as follows::
  1105  
  1106        haproxy -f <configfile> -st $(pgrep haproxy)
  1107  
  1108     ``"haProxyShowStats"`` will now reflect the modified configuration,
  1109     with two active servers which have been upgraded to the new version::
  1110  
  1111        sid   pxname      svname  status  weig  act  bck
  1112          1   fabric-cas  server3   UP       1    1    0
  1113          2   fabric-cas  server4   UP       1    1    0
  1114  
  1115  
  1116  `Back to Top`_
  1117  
  1118  
  1119  Operations Service
  1120  ~~~~~~~~~~~~~~~~~~~~
  1121  
  1122  The CA Server hosts an HTTP server that offers a RESTful “operations” API. This API
  1123  is intended to be used by operators, not administrators or “users” of the network.
  1124  
  1125  The API exposes the following capabilities:
  1126  
  1127      Prometheus target for operational metrics (when configured)
  1128  
  1129  Configuring the Operations Service
  1130  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1131  
  1132  The operations service requires two basic pieces of configuration:
  1133  
  1134      The **address** and **port** to listen on.
  1135      The **TLS certificates** and **keys** to use for authentication and encryption. Note, **these
  1136      certificates should be generated by a separate and dedicated CA**. Do not use a CA that
  1137      has generated certificates for any organizations in any channels.
  1138  
  1139  The CA server can be configurated in the ``operations`` section of server's configuration file:
  1140  
  1141  .. code:: yaml
  1142  
  1143    operations:
  1144      # host and port for the operations server
  1145      listenAddress: 127.0.0.1:9443
  1146  
  1147      # TLS configuration for the operations endpoint
  1148      tls:
  1149        # TLS enabled
  1150        enabled: true
  1151  
  1152        # path to PEM encoded server certificate for the operations server
  1153        cert:
  1154          file: tls/server.crt
  1155  
  1156        # path to PEM encoded server key for the operations server
  1157        key:
  1158          file: tls/server.key
  1159  
  1160        # require client certificate authentication to access all resources
  1161        clientAuthRequired: false
  1162  
  1163        # paths to PEM encoded ca certificates to trust for client authentication
  1164        clientRootCAs:
  1165          files: []
  1166  
  1167  The ``listenAddress`` key defines the host and port that the operation server
  1168  will listen on. If the server should listen on all addresses, the host portion
  1169  can be omitted.
  1170  
  1171  The ``tls`` section is used to indicate whether or not TLS is enabled for the
  1172  operations service, the location of the service's certificate and private key,
  1173  and the locations of certificate authority root certificates that should be
  1174  trusted for client authentication. When ``clientAuthRequired`` is ``true``,
  1175  clients will be required to provide a certificate for authentication.
  1176  
  1177  Operations Security
  1178  ^^^^^^^^^^^^^^^^^^^^^^
  1179  
  1180  As the operations service is focused on operations and intentionally unrelated
  1181  to the Fabric network, it does not use the Membership Services Provider for
  1182  access control. Instead, the operations service relies entirely on mutual TLS with
  1183  client certificate authentication.
  1184  
  1185  It is highly recommended to enable mutual TLS by setting the value of ``clientAuthRequired``
  1186  to ``true`` in production environments. With this configuration, clients are
  1187  required to provide a valid certificate for authentication. If the client does
  1188  not provide a certificate or the service cannot verify the client’s certificate,
  1189  the request is rejected. Note that if ``clientAuthRequired`` is set to ``false``,
  1190  clients do not need to provide a certificate; if they do, however, and the service
  1191  cannot verify the certificate, then the request will be rejected.
  1192  
  1193  When TLS is disabled, authorization is bypassed and any client that can
  1194  connect to the operations endpoint will be able to use the API.
  1195  
  1196  Metrics
  1197  ^^^^^^^^^
  1198  
  1199  The Fabric CA exposes metrics that can provide insight into the behavior of the system.
  1200  Operators and administrators can use this information to better understand how the system
  1201  is performing over time.
  1202  
  1203  Configuring Metrics
  1204  ^^^^^^^^^^^^^^^^^^^^
  1205  
  1206  Fabric CA provides two ways to expose metrics: a **pull** model based on Prometheus
  1207  and a **push** model based on StatsD.
  1208  
  1209  Prometheus
  1210  ^^^^^^^^^^^
  1211  
  1212  A typical Prometheus deployment scrapes metrics by requesting them from an HTTP
  1213  endpoint exposed by instrumented targets. As Prometheus is responsible for
  1214  requesting the metrics, it is considered a pull system.
  1215  
  1216  When configured, a Fabric CA Server will present a ``/metrics`` resource
  1217  on the operations service. To enable Prometheus, set the provider value in the
  1218  server's configuration file to ``prometheus``.
  1219  
  1220  .. code:: yaml
  1221  
  1222    metrics:
  1223      provider: prometheus
  1224  
  1225  StatsD
  1226  ^^^^^^^
  1227  
  1228  StatsD is a simple statistics aggregation daemon. Metrics are sent to a
  1229  ``statsd`` daemon where they are collected, aggregated, and pushed to a backend
  1230  for visualization and alerting. As this model requires instrumented processes
  1231  to send metrics data to StatsD, this is considered a push system.
  1232  
  1233  The CA Server can be configured to send metrics to StatsD by setting the metrics
  1234  provider to ``statsd`` in the ``metrics`` section in servers' configuration filel. The ``statsd``
  1235  subsection must also be configured with the address of the StatsD daemon, the
  1236  network type to use (``tcp`` or ``udp``), and how often to send the metrics. An
  1237  optional ``prefix`` may be specified to help differentiate the source of the
  1238  metrics --- for example, differentiating metrics coming from separate servers ---
  1239  that would be prepended to all generated metrics.
  1240  
  1241  .. code:: yaml
  1242  
  1243    metrics:
  1244      provider: statsd
  1245      statsd:
  1246        network: udp
  1247        address: 127.0.0.1:8125
  1248        writeInterval: 10s
  1249        prefix: server-0
  1250  
  1251  For a look at the different metrics that are generated, check out
  1252  :doc:`metrics_reference`.
  1253  
  1254  `Back to Top`_
  1255  
  1256  .. _client:
  1257  
  1258  Fabric CA Client
  1259  ----------------
  1260  
  1261  This section describes how to use the fabric-ca-client command.
  1262  
  1263  The Fabric CA client's home directory is determined as follows:
  1264    - if the --home command line option is set, use its value
  1265    - otherwise, if the ``FABRIC_CA_CLIENT_HOME`` environment variable is set, use
  1266      its value
  1267    - otherwise, if the ``FABRIC_CA_HOME`` environment variable is set,
  1268      use its value
  1269    - otherwise, if the ``CA_CFG_PATH`` environment variable is set, use
  1270      its value
  1271    - otherwise, use ``$HOME/.fabric-ca-client``
  1272  
  1273  The instructions below assume that the client configuration file exists
  1274  in the client's home directory.
  1275  
  1276  Enrolling the bootstrap identity
  1277  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1278  
  1279  First, if needed, customize the CSR (Certificate Signing Request) section
  1280  in the client configuration file. Note that ``csr.cn`` field must be set
  1281  to the ID of the bootstrap identity. Default CSR values are shown below:
  1282  
  1283  .. code:: yaml
  1284  
  1285      csr:
  1286        cn: <<enrollment ID>>
  1287        key:
  1288          algo: ecdsa
  1289          size: 256
  1290        names:
  1291          - C: US
  1292            ST: North Carolina
  1293            L:
  1294            O: Hyperledger Fabric
  1295            OU: Fabric CA
  1296        hosts:
  1297         - <<hostname of the fabric-ca-client>>
  1298        ca:
  1299          pathlen:
  1300          pathlenzero:
  1301          expiry:
  1302  
  1303  See `CSR fields <#csr-fields>`__ for description of the fields.
  1304  
  1305  Then run ``fabric-ca-client enroll`` command to enroll the identity. For example,
  1306  following command enrolls an identity whose ID is **admin** and password is **adminpw**
  1307  by calling Fabric CA server that is running locally at 7054 port.
  1308  
  1309  .. code:: bash
  1310  
  1311      export FABRIC_CA_CLIENT_HOME=$HOME/fabric-ca/clients/admin
  1312      fabric-ca-client enroll -u http://admin:adminpw@localhost:7054
  1313  
  1314  The enroll command stores an enrollment certificate (ECert), corresponding private key and CA
  1315  certificate chain PEM files in the subdirectories of the Fabric CA client's ``msp`` directory.
  1316  You will see messages indicating where the PEM files are stored.
  1317  
  1318  Registering a new identity
  1319  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1320  
  1321  The identity performing the register request must be currently enrolled, and
  1322  must also have the proper authority to register the type of the identity that is being
  1323  registered.
  1324  
  1325  In particular, three authorization checks are made by the Fabric CA server
  1326  during registration as follows:
  1327  
  1328  1. The registrar (i.e. the invoker) must have the "hf.Registrar.Roles" attribute with a
  1329     comma-separated list of values where one of the values equals the type of
  1330     identity being registered; for example, if the registrar has the
  1331     "hf.Registrar.Roles" attribute with a value of "peer", the registrar
  1332     can register identities of type peer, but not client, admin, or orderer.
  1333  
  1334  2. The affiliation of the registrar must be equal to or a prefix of
  1335     the affiliation of the identity being registered.  For example, an registrar
  1336     with an affiliation of "a.b" may register an identity with an affiliation
  1337     of "a.b.c" but may not register an identity with an affiliation of "a.c".
  1338     If root affiliation is required for an identity, then the affiliation request
  1339     should be a dot (".") and the registrar must also have root affiliation.
  1340     If no affiliation is specified in the registration request, the identity being
  1341     registered will be given the affiliation of the registrar.
  1342  
  1343  3. The registrar can register an identity with attributes if all of the following conditions
  1344     are satisfied:
  1345  
  1346     - Registrar can register Fabric CA reserved attributes that have the prefix 'hf.'
  1347       only if the registrar possesses the attribute and it is part of the value of the
  1348       hf.Registrar.Attributes' attribute. Furthermore, if the attribute is of type list
  1349       then the value of attribute being registered must be equal to or a subset of the
  1350       value that the registrar has. If the attribute is of type boolean, the registrar
  1351       can register the attribute only if the registrar's value for the attribute is 'true'.
  1352     - Registering custom attributes (i.e. any attribute whose name does not begin with 'hf.')
  1353       requires that the registrar has the 'hf.Registar.Attributes' attribute with the value of
  1354       the attribute or pattern being registered. The only supported pattern is a string with
  1355       a "*" at the end. For example, "a.b.*" is a pattern which matches all attribute names
  1356       beginning with "a.b.". For example, if the registrar has hf.Registrar.Attributes=orgAdmin,
  1357       then the only attribute which the registrar can add or remove from an identity is the
  1358       'orgAdmin' attribute.
  1359     - If the requested attribute name is 'hf.Registrar.Attributes', an additional
  1360       check is performed to see if the requested values for this attribute are equal
  1361       to or a subset of the registrar's values for 'hf.Registrar.Attributes'. For this
  1362       to be true, each requested value must match a value in the registrar's value for
  1363       'hf.Registrar.Attributes' attribute. For example, if the registrar's value for
  1364       'hf.Registrar.Attributes' is 'a.b.*, x.y.z' and the requested attribute
  1365       value is 'a.b.c, x.y.z', it is valid because 'a.b.c' matches 'a.b.*' and 'x.y.z'
  1366       matches the registrar's 'x.y.z' value.
  1367  
  1368  Examples:
  1369     Valid Scenarios:
  1370        1. If the registrar has the attribute 'hf.Registrar.Attributes = a.b.*, x.y.z' and
  1371           is registering attribute 'a.b.c', it is valid 'a.b.c' matches 'a.b.*'.
  1372        2. If the registrar has the attribute 'hf.Registrar.Attributes = a.b.*, x.y.z' and
  1373           is registering attribute 'x.y.z', it is valid because 'x.y.z' matches the registrar's
  1374           'x.y.z' value.
  1375        3. If the registrar has the attribute 'hf.Registrar.Attributes = a.b.*, x.y.z' and
  1376           the requested attribute value is 'a.b.c, x.y.z', it is valid because 'a.b.c' matches
  1377           'a.b.*' and 'x.y.z' matches the registrar's 'x.y.z' value.
  1378        4. If the registrar has the attribute 'hf.Registrar.Roles = peer,client,admin,orderer' and
  1379           the requested attribute value is 'peer', 'peer,client,admin,orderer', or 'client,admin'
  1380           it is valid because the requested value is equal to or a subset of the registrar's value.
  1381  
  1382     Invalid Scenarios:
  1383        1. If the registrar has the attribute 'hf.Registrar.Attributes = a.b.*, x.y.z' and
  1384           is registering attribute 'hf.Registar.Attributes = a.b.c, x.y.*', it is invalid
  1385           because requested attribute 'x.y.*' is not a pattern owned by the registrar. The value
  1386           'x.y.*' is a superset of 'x.y.z'.
  1387        2. If the registrar has the attribute 'hf.Registrar.Attributes = a.b.*, x.y.z' and
  1388           is registering attribute 'hf.Registar.Attributes = a.b.c, x.y.z, attr1', it is invalid
  1389           because the registrar's 'hf.Registrar.Attributes' attribute values do not contain 'attr1'.
  1390        3. If the registrar has the attribute 'hf.Registrar.Attributes = a.b.*, x.y.z' and
  1391           is registering attribute 'a.b', it is invalid because the value 'a.b' is not contained in
  1392           'a.b.*'.
  1393        4. If the registrar has the attribute 'hf.Registrar.Attributes = a.b.*, x.y.z' and
  1394           is registering attribute 'x.y', it is invalid because 'x.y' is not contained by 'x.y.z'.
  1395        5. If the registrar has the attribute 'hf.Registrar.Roles = peer' and
  1396           the requested attribute value is 'peer,client', it is invalid because
  1397           the registrar does not have the client role in its value of hf.Registrar.Roles
  1398           attribute.
  1399        6. If the registrar has the attribute 'hf.Revoker = false' and the requested attribute
  1400           value is 'true', it is invalid because the hf.Revoker attribute is a boolean attribute
  1401           and the registrar's value for the attribute is not 'true'.
  1402  
  1403  The table below lists all the attributes that can be registered for an identity.
  1404  The names of attributes are case sensitive.
  1405  
  1406  +-----------------------------+------------+------------------------------------------------------------------------------------------------------------+
  1407  | Name                        | Type       | Description                                                                                                |
  1408  +=============================+============+============================================================================================================+
  1409  | hf.Registrar.Roles          | List       | List of roles that the registrar is allowed to manage                                                      |
  1410  +-----------------------------+------------+------------------------------------------------------------------------------------------------------------+
  1411  | hf.Registrar.DelegateRoles  | List       | List of roles that the registrar is allowed to give to a registree for its 'hf.Registrar.Roles' attribute  |
  1412  +-----------------------------+------------+------------------------------------------------------------------------------------------------------------+
  1413  | hf.Registrar.Attributes     | List       | List of attributes that registrar is allowed to register                                                   |
  1414  +-----------------------------+------------+------------------------------------------------------------------------------------------------------------+
  1415  | hf.GenCRL                   | Boolean    | Identity is able to generate CRL if attribute value is true                                                |
  1416  +-----------------------------+------------+------------------------------------------------------------------------------------------------------------+
  1417  | hf.Revoker                  | Boolean    | Identity is able to revoke an identity and/or certificates if attribute value is true                      |
  1418  +-----------------------------+------------+------------------------------------------------------------------------------------------------------------+
  1419  | hf.AffiliationMgr           | Boolean    | Identity is able to manage affiliations if attribute value is true                                         |
  1420  +-----------------------------+------------+------------------------------------------------------------------------------------------------------------+
  1421  | hf.IntermediateCA           | Boolean    | Identity is able to enroll as an intermediate CA if attribute value is true                                |
  1422  +-----------------------------+------------+------------------------------------------------------------------------------------------------------------+
  1423  
  1424  Note: When registering an identity, you specify an array of attribute names and values. If the array
  1425  specifies multiple array elements with the same name, only the last element is currently used. In other words,
  1426  multi-valued attributes are not currently supported.
  1427  
  1428  The following command uses the **admin** identity's credentials to register a new
  1429  identity with an enrollment id of "admin2", an affiliation of
  1430  "org1.department1", an attribute named "hf.Revoker" with a value of "true", and
  1431  an attribute named "admin" with a value of "true".  The ":ecert" suffix means that
  1432  by default the "admin" attribute and its value will be inserted into the identity's
  1433  enrollment certificate, which can then be used to make access control decisions.
  1434  
  1435  .. code:: bash
  1436  
  1437      export FABRIC_CA_CLIENT_HOME=$HOME/fabric-ca/clients/admin
  1438      fabric-ca-client register --id.name admin2 --id.affiliation org1.department1 --id.attrs 'hf.Revoker=true,admin=true:ecert'
  1439  
  1440  The password, also known as the enrollment secret, is printed.
  1441  This password is required to enroll the identity.
  1442  This allows an administrator to register an identity and give the
  1443  enrollment ID and the secret to someone else to enroll the identity.
  1444  
  1445  Multiple attributes can be specified as part of the --id.attrs flag, each
  1446  attribute must be comma separated. For an attribute value that contains a comma,
  1447  the attribute must be encapsulated in double quotes. See example below.
  1448  
  1449  .. code:: bash
  1450  
  1451      fabric-ca-client register -d --id.name admin2 --id.affiliation org1.department1 --id.attrs '"hf.Registrar.Roles=peer,client",hf.Revoker=true'
  1452  
  1453  or
  1454  
  1455  .. code:: bash
  1456  
  1457      fabric-ca-client register -d --id.name admin2 --id.affiliation org1.department1 --id.attrs '"hf.Registrar.Roles=peer,client"' --id.attrs hf.Revoker=true
  1458  
  1459  You may set default values for any of the fields used in the register command
  1460  by editing the client's configuration file.  For example, suppose the configuration
  1461  file contains the following:
  1462  
  1463  .. code:: yaml
  1464  
  1465      id:
  1466        name:
  1467        type: client
  1468        affiliation: org1.department1
  1469        maxenrollments: -1
  1470        attributes:
  1471          - name: hf.Revoker
  1472            value: true
  1473          - name: anotherAttrName
  1474            value: anotherAttrValue
  1475  
  1476  The following command would then register a new identity with an enrollment id of
  1477  "admin3" which it takes from the command line, and the remainder is taken from the
  1478  configuration file including the identity type: "client", affiliation: "org1.department1",
  1479  and two attributes: "hf.Revoker" and "anotherAttrName".
  1480  
  1481  .. code:: bash
  1482  
  1483      export FABRIC_CA_CLIENT_HOME=$HOME/fabric-ca/clients/admin
  1484      fabric-ca-client register --id.name admin3
  1485  
  1486  To register an identity with multiple attributes requires specifying all attribute names and values
  1487  in the configuration file as shown above.
  1488  
  1489  Setting `maxenrollments` to 0 or leaving it out from the configuration will result in the identity
  1490  being registered to use the CA's max enrollment value. Furthermore, the max enrollment value for
  1491  an identity being registered cannot exceed the CA's max enrollment value. For example, if the CA's
  1492  max enrollment value is 5. Any new identity must have a value less than or equal to 5, and also
  1493  can't set it to -1 (infinite enrollments).
  1494  
  1495  Next, let's register a peer identity which will be used to enroll the peer in the following section.
  1496  The following command registers the **peer1** identity.  Note that we choose to specify our own
  1497  password (or secret) rather than letting the server generate one for us.
  1498  
  1499  .. code:: bash
  1500  
  1501      export FABRIC_CA_CLIENT_HOME=$HOME/fabric-ca/clients/admin
  1502      fabric-ca-client register --id.name peer1 --id.type peer --id.affiliation org1.department1 --id.secret peer1pw
  1503  
  1504  Note that affiliations are case sensitive except for the non-leaf affiliations that are specified in
  1505  the server configuration file, which are always stored in lower case. For example, if the affiliations
  1506  section of the server configuration file looks like this:
  1507  
  1508  .. code:: bash
  1509  
  1510      affiliations:
  1511        BU1:
  1512          Department1:
  1513            - Team1
  1514        BU2:
  1515          - Department2
  1516          - Department3
  1517  
  1518  `BU1`, `Department1`, `BU2` are stored in lower case. This is because Fabric CA uses Viper to read configuration.
  1519  Viper treats map keys as case insensitive and always returns lowercase value. To register an identity with
  1520  `Team1` affiliation, `bu1.department1.Team1` would need to be specified to the
  1521  `--id.affiliation` flag as shown below:
  1522  
  1523  .. code:: bash
  1524  
  1525      export FABRIC_CA_CLIENT_HOME=$HOME/fabric-ca/clients/admin
  1526      fabric-ca-client register --id.name client1 --id.type client --id.affiliation bu1.department1.Team1
  1527  
  1528  Enrolling a peer identity
  1529  ~~~~~~~~~~~~~~~~~~~~~~~~~
  1530  
  1531  Now that you have successfully registered a peer identity, you may now
  1532  enroll the peer given the enrollment ID and secret (i.e. the *password*
  1533  from the previous section).  This is similar to enrolling the bootstrap identity
  1534  except that we also demonstrate how to use the "-M" option to populate the
  1535  Hyperledger Fabric MSP (Membership Service Provider) directory structure.
  1536  
  1537  The following command enrolls peer1.
  1538  Be sure to replace the value of the "-M" option with the path to your
  1539  peer's MSP directory which is the
  1540  'mspConfigPath' setting in the peer's core.yaml file.
  1541  You may also set the FABRIC_CA_CLIENT_HOME to the home directory of your peer.
  1542  
  1543  .. code:: bash
  1544  
  1545      export FABRIC_CA_CLIENT_HOME=$HOME/fabric-ca/clients/peer1
  1546      fabric-ca-client enroll -u http://peer1:peer1pw@localhost:7054 -M $FABRIC_CA_CLIENT_HOME/msp
  1547  
  1548  Enrolling an orderer is the same, except the path to the MSP directory is
  1549  the 'LocalMSPDir' setting in your orderer's orderer.yaml file.
  1550  
  1551  All enrollment certificates issued by the fabric-ca-server have organizational
  1552  units (or "OUs" for short) as follows:
  1553  
  1554  1. The root of the OU hierarchy equals the identity type
  1555  2. An OU is added for each component of the identity's affiliation
  1556  
  1557  For example, if an identity is of type `peer` and its affiliation is
  1558  `department1.team1`, the identity's OU hierarchy (from leaf to root) is
  1559  `OU=team1, OU=department1, OU=peer`.
  1560  
  1561  Getting Identity Mixer credential
  1562  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1563  Identity Mixer (Idemix) is a cryptographic protocol suite for privacy-preserving authentication and transfer of certified attributes.
  1564  Idemix allows clients to authenticate with verifiers without the involvement of the issuer (CA) and selectively disclose only those attributes
  1565  that are required by the verifier and can do so without being linkable across their transactions.
  1566  
  1567  Fabric CA server can issue Idemix credentials in addition to X509 certificates. An Idemix credential can be requested by sending the request to
  1568  the ``/api/v1/idemix/credential`` API endpoint. For more information on this and other Fabric CA server API endpoints, please refer to
  1569  `swagger-fabric-ca.json <https://github.com/hyperledger/fabric-ca/blob/master/swagger/swagger-fabric-ca.json>`_.
  1570  
  1571  The Idemix credential issuance is a two step process. First, send a request with an empty body to the ``/api/v1/idemix/credential``
  1572  API endpoint to get a nonce and CA's Idemix public key. Second, create a credential request using the nonce and CA's Idemix public key and
  1573  send another request with the credential request in the body to  the ``/api/v1/idemix/credential`` API endpoint to get an Idemix credential,
  1574  Credential Revocation Information (CRI), and attribute names and values. Currently, only three attributes are supported:
  1575  
  1576  - **OU** - organization unit of the identity. The value of this attribute is set to identity's affiliation. For example, if identity's affiliation is `dept1.unit1`, then OU attribute is set to `dept1.unit1`
  1577  - **IsAdmin** - if the identity is an admin or not. The value of this attribute is set to the value of `isAdmin` registration attribute.
  1578  - **EnrollmentID** - enrollment ID of the identity
  1579  
  1580  You can refer to the `handleIdemixEnroll` function in https://github.com/hyperledger/fabric-ca/blob/master/lib/client.go for reference implementation
  1581  of the two step process for getting Idemix credential.
  1582  
  1583  The ``/api/v1/idemix/credential`` API endpoint accepts both basic and token authorization headers. The basic authorization header should
  1584  contain User's registration ID and password. If the identity already has X509 enrollment certificate, it can also be used to create a token authorization header.
  1585  
  1586  Note that Hyperledger Fabric will support clients to sign transactions with both X509 and Idemix credentials, but will only support X509 credentials
  1587  for peer and orderer identities. As before, applications can use a Fabric SDK to send requests to the Fabric CA server. SDKs hide the complexity
  1588  associated with creating authorization header and request payload, and with processing the response.
  1589  
  1590  Getting Idemix CRI (Certificate Revocation Information)
  1591  -------------------------------------------------------
  1592  An Idemix CRI (Credential Revocation Information) is similar in purpose to an X509 CRL (Certificate Revocation List):
  1593  to revoke what was previously issued.  However, there are some differences.
  1594  
  1595  In X509, the issuer revokes an end user's certificate and its ID is included in the CRL.
  1596  The verifier checks to see if the user's certificate is in the CRL and if so, returns an authorization failure.
  1597  The end user is not involved in this revocation process, other than receiving an authorization error from a verifier.
  1598  
  1599  In Idemix, the end user is involved.  The issuer revokes an end user's credential similar to X509 and evidence of this
  1600  revocation is recorded in the CRI.  The CRI is given to the end user (aka "prover").  The end user then generates a
  1601  proof that their credential has not been revoked according to the CRI.  The end user gives this proof to the verifier
  1602  who verifies the proof according to the CRI.
  1603  For verification to succeed, the version of the CRI (known as the "epoch") used by the end user and verifier must be same.
  1604  The latest CRI can be requested by sending a request to ``/api/v1/idemix/cri`` API endpoint.
  1605  
  1606  The version of the CRI is incremented when an enroll request is received by the fabric-ca-server and there are no revocation
  1607  handles remaining in the revocation handle pool. In this case, the fabric-ca-server must generate a new pool of revocation
  1608  handles which increments the epoch of the CRI. The number of revocation handles in the revocation handle pool is configurable
  1609  via the ``idemix.rhpoolsize`` server configuration property.
  1610  
  1611  Reenrolling an identity
  1612  ~~~~~~~~~~~~~~~~~~~~~~~
  1613  
  1614  Suppose your enrollment certificate is about to expire or has been compromised.
  1615  You can issue the reenroll command to renew your enrollment certificate as follows.
  1616  
  1617  .. code:: bash
  1618  
  1619      export FABRIC_CA_CLIENT_HOME=$HOME/fabric-ca/clients/peer1
  1620      fabric-ca-client reenroll
  1621  
  1622  Revoking a certificate or identity
  1623  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1624  An identity or a certificate can be revoked. Revoking an identity will revoke all
  1625  the certificates owned by the identity and will also prevent the identity from getting
  1626  any new certificates. Revoking a certificate will invalidate a single certificate.
  1627  
  1628  In order to revoke a certificate or an identity, the calling identity must have
  1629  the ``hf.Revoker`` and ``hf.Registrar.Roles`` attribute. The revoking identity
  1630  can only revoke a certificate or an identity that has an affiliation that is
  1631  equal to or prefixed by the revoking identity's affiliation. Furthermore, the
  1632  revoker can only revoke identities with types that are listed in the revoker's
  1633  ``hf.Registrar.Roles`` attribute.
  1634  
  1635  For example, a revoker with affiliation **orgs.org1** and 'hf.Registrar.Roles=peer,client'
  1636  attribute can revoke either a **peer** or **client** type identity affiliated with
  1637  **orgs.org1** or **orgs.org1.department1** but can't revoke an identity affiliated with
  1638  **orgs.org2** or of any other type.
  1639  
  1640  The following command disables an identity and revokes all of the certificates
  1641  associated with the identity. All future requests received by the Fabric CA server
  1642  from this identity will be rejected.
  1643  
  1644  .. code:: bash
  1645  
  1646      fabric-ca-client revoke -e <enrollment_id> -r <reason>
  1647  
  1648  The following are the supported reasons that can be specified using ``-r`` flag:
  1649  
  1650    1. unspecified
  1651    2. keycompromise
  1652    3. cacompromise
  1653    4. affiliationchange
  1654    5. superseded
  1655    6. cessationofoperation
  1656    7. certificatehold
  1657    8. removefromcrl
  1658    9. privilegewithdrawn
  1659    10. aacompromise
  1660  
  1661  For example, the bootstrap admin who is associated with root of the affiliation tree
  1662  can revoke **peer1**'s identity as follows:
  1663  
  1664  .. code:: bash
  1665  
  1666      export FABRIC_CA_CLIENT_HOME=$HOME/fabric-ca/clients/admin
  1667      fabric-ca-client revoke -e peer1
  1668  
  1669  An enrollment certificate that belongs to an identity can be revoked by
  1670  specifying its AKI (Authority Key Identifier) and serial number as follows:
  1671  
  1672  .. code:: bash
  1673  
  1674      fabric-ca-client revoke -a xxx -s yyy -r <reason>
  1675  
  1676  For example, you can get the AKI and the serial number of a certificate using the openssl command
  1677  and pass them to the ``revoke`` command to revoke the said certificate as follows:
  1678  
  1679  .. code:: bash
  1680  
  1681     serial=$(openssl x509 -in userecert.pem -serial -noout | cut -d "=" -f 2)
  1682     aki=$(openssl x509 -in userecert.pem -text | awk '/keyid/ {gsub(/ *keyid:|:/,"",$1);print tolower($0)}')
  1683     fabric-ca-client revoke -s $serial -a $aki -r affiliationchange
  1684  
  1685  The `--gencrl` flag can be used to generate a CRL (Certificate Revocation List) that contains all the revoked
  1686  certificates. For example, following command will revoke the identity **peer1**, generates a CRL and stores
  1687  it in the **<msp folder>/crls/crl.pem** file.
  1688  
  1689  .. code:: bash
  1690  
  1691      fabric-ca-client revoke -e peer1 --gencrl
  1692  
  1693  A CRL can also be generated using the `gencrl` command. Refer to the `Generating a CRL (Certificate Revocation List)`_
  1694  section for more information on the `gencrl` command.
  1695  
  1696  Generating a CRL (Certificate Revocation List)
  1697  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1698  After a certificate is revoked in the Fabric CA server, the appropriate MSPs in Hyperledger Fabric must also be updated.
  1699  This includes both local MSPs of the peers as well as MSPs in the appropriate channel configuration blocks.
  1700  To do this, PEM encoded CRL (certificate revocation list) file must be placed in the `crls`
  1701  folder of the MSP. The ``fabric-ca-client gencrl`` command can be used to generate a CRL. Any identity
  1702  with ``hf.GenCRL`` attribute can create a CRL that contains serial numbers of all certificates that were revoked
  1703  during a certain period. The created CRL is stored in the `<msp folder>/crls/crl.pem` file.
  1704  
  1705  The following command will create a CRL containing all the revoked certficates (expired and unexpired) and
  1706  store the CRL in the `~/msp/crls/crl.pem` file.
  1707  
  1708  .. code:: bash
  1709  
  1710      export FABRIC_CA_CLIENT_HOME=~/clientconfig
  1711      fabric-ca-client gencrl -M ~/msp
  1712  
  1713  The next command will create a CRL containing all certificates (expired and unexpired) that were revoked after
  1714  2017-09-13T16:39:57-08:00 (specified by the `--revokedafter` flag) and before 2017-09-21T16:39:57-08:00
  1715  (specified by the `--revokedbefore` flag) and store the CRL in the `~/msp/crls/crl.pem` file.
  1716  
  1717  .. code:: bash
  1718  
  1719      export FABRIC_CA_CLIENT_HOME=~/clientconfig
  1720      fabric-ca-client gencrl --caname "" --revokedafter 2017-09-13T16:39:57-08:00 --revokedbefore 2017-09-21T16:39:57-08:00 -M ~/msp
  1721  
  1722  
  1723  The `--caname` flag specifies the name of the CA to which this request is sent. In this example, the gencrl request is
  1724  sent to the default CA.
  1725  
  1726  The `--revokedafter` and `--revokedbefore` flags specify the lower and upper boundaries of a time period.
  1727  The generated CRL will contain certificates that were revoked in this time period. The values must be UTC
  1728  timestamps specified in RFC3339 format. The `--revokedafter` timestamp cannot be greater than the
  1729  `--revokedbefore` timestamp.
  1730  
  1731  By default, 'Next Update' date of the CRL is set to next day. The `crl.expiry` CA configuration property
  1732  can be used to specify a custom value.
  1733  
  1734  The gencrl command will also accept `--expireafter` and `--expirebefore` flags that can be used to generate a CRL
  1735  with revoked certificates that expire during the period specified by these flags. For example, the following command
  1736  will generate a CRL that contains certificates that were revoked after 2017-09-13T16:39:57-08:00 and
  1737  before 2017-09-21T16:39:57-08:00, and that expire after 2017-09-13T16:39:57-08:00 and before 2018-09-13T16:39:57-08:00
  1738  
  1739  .. code:: bash
  1740  
  1741      export FABRIC_CA_CLIENT_HOME=~/clientconfig
  1742      fabric-ca-client gencrl --caname "" --expireafter 2017-09-13T16:39:57-08:00 --expirebefore 2018-09-13T16:39:57-08:00  --revokedafter 2017-09-13T16:39:57-08:00 --revokedbefore 2017-09-21T16:39:57-08:00 -M ~/msp
  1743  
  1744  Enabling TLS
  1745  ~~~~~~~~~~~~
  1746  
  1747  This section describes in more detail how to configure TLS for a Fabric CA client.
  1748  
  1749  The following sections may be configured in the ``fabric-ca-client-config.yaml``.
  1750  
  1751  .. code:: yaml
  1752  
  1753      tls:
  1754        # Enable TLS (default: false)
  1755        enabled: true
  1756        certfiles:
  1757          - root.pem
  1758        client:
  1759          certfile: tls_client-cert.pem
  1760          keyfile: tls_client-key.pem
  1761  
  1762  The **certfiles** option is the set of root certificates trusted by the
  1763  client. This will typically just be the root Fabric CA server's
  1764  certificate found in the server's home directory in the **ca-cert.pem**
  1765  file.
  1766  
  1767  The **client** option is required only if mutual TLS is configured on
  1768  the server.
  1769  
  1770  Attribute-Based Access Control
  1771  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1772  
  1773  Access control decisions can be made by chaincode (and by the Hyperledger Fabric runtime)
  1774  based upon an identity's attributes.  This is called
  1775  **Attribute-Based Access Control**, or **ABAC** for short.
  1776  
  1777  In order to make this possible, an identity's enrollment certificate (ECert)
  1778  may contain one or more attribute name and value.  The chaincode then
  1779  extracts an attribute's value to make an access control decision.
  1780  
  1781  For example, suppose that you are developing application *app1* and want a
  1782  particular chaincode operation to be accessible only by app1 administrators.
  1783  Your chaincode could verify that the caller's certificate (which was issued by
  1784  a CA trusted for the channel) contains an attribute named *app1Admin* with a
  1785  value of *true*.  Of course the name of the attribute can be anything and the
  1786  value need not be a boolean value.
  1787  
  1788  So how do you get an enrollment certificate with an attribute?
  1789  There are two methods:
  1790  
  1791  1.   When you register an identity, you can specify that an enrollment certificate
  1792       issued for the identity should by default contain an attribute.  This behavior
  1793       can be overridden at enrollment time, but this is useful for establishing
  1794       default behavior and, assuming registration occurs outside of your application,
  1795       does not require any application change.
  1796  
  1797       The following shows how to register *user1* with two attributes:
  1798       *app1Admin* and *email*.
  1799       The ":ecert" suffix causes the *appAdmin* attribute to be inserted into user1's
  1800       enrollment certificate by default, when the user does not explicitly request
  1801       attributes at enrollment time.  The *email* attribute is not added
  1802       to the enrollment certificate by default.
  1803  
  1804  .. code:: bash
  1805  
  1806       fabric-ca-client register --id.name user1 --id.secret user1pw --id.type client --id.affiliation org1 --id.attrs 'app1Admin=true:ecert,email=user1@gmail.com'
  1807  
  1808  2. When you enroll an identity, you may explicitly request that one or more attributes
  1809     be added to the certificate.
  1810     For each attribute requested, you may specify whether the attribute is
  1811     optional or not.  If it is not requested optionally and the identity does
  1812     not possess the attribute, an error will occur.
  1813  
  1814     The following shows how to enroll *user1* with the *email* attribute,
  1815     without the *app1Admin* attribute, and optionally with the *phone*
  1816     attribute (if the user possesses the *phone* attribute).
  1817  
  1818  .. code:: bash
  1819  
  1820     fabric-ca-client enroll -u http://user1:user1pw@localhost:7054 --enrollment.attrs "email,phone:opt"
  1821  
  1822  The table below shows the three attributes which are automatically registered for every identity.
  1823  
  1824  ===================================   =====================================
  1825       Attribute Name                               Attribute Value
  1826  ===================================   =====================================
  1827    hf.EnrollmentID                        The enrollment ID of the identity
  1828    hf.Type                                The type of the identity
  1829    hf.Affiliation                         The affiliation of the identity
  1830  ===================================   =====================================
  1831  
  1832  To add any of the above attributes **by default** to a certificate, you must
  1833  explicitly register the attribute with the ":ecert" specification.
  1834  For example, the following registers identity 'user1' so that
  1835  the 'hf.Affiliation' attribute will be added to an enrollment certificate if
  1836  no specific attributes are requested at enrollment time.  Note that the
  1837  value of the affiliation (which is 'org1') must be the same in both the
  1838  '--id.affiliation' and the '--id.attrs' flags.
  1839  
  1840  .. code:: bash
  1841  
  1842      fabric-ca-client register --id.name user1 --id.secret user1pw --id.type client --id.affiliation org1 --id.attrs 'hf.Affiliation=org1:ecert'
  1843  
  1844  For information on the chaincode library API for Attribute-Based Access Control,
  1845  see `https://github.com/hyperledger/fabric-chaincode-go/blob/master/pkg/cid/README.md <https://github.com/hyperledger/fabric-chaincode-go/blob/master/pkg/cid/README.md>`_
  1846  
  1847  Dynamic Server Configuration Update
  1848  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1849  
  1850  This section describes how to use fabric-ca-client to dynamically update portions
  1851  of the fabric-ca-server's configuration without restarting the server.
  1852  
  1853  All commands in this section require that you first be enrolled by executing the
  1854  `fabric-ca-client enroll` command.
  1855  
  1856  Dynamically updating identities
  1857  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1858  
  1859  This section describes how to use fabric-ca-client to dynamically update identities.
  1860  
  1861  An authorization failure will occur if the client identity does not satisfy all of the following:
  1862  
  1863   - The client identity must possess the "hf.Registrar.Roles" attribute with a comma-separated list of
  1864     values where one of the values equals the type of identity being updated; for example, if the client's
  1865     identity has the "hf.Registrar.Roles" attribute with a value of "client", the client can update
  1866     identities of type 'client', but not 'peer'.
  1867  
  1868   - The affiliation of the client's identity must be equal to or a prefix of the affiliation of the identity
  1869     being updated.  For example, a client with an affiliation of "a.b" may update an identity with an affiliation
  1870     of "a.b.c" but may not update an identity with an affiliation of "a.c". If root affiliation is required for an
  1871     identity, then the update request should specify a dot (".") for the affiliation and the client must also have
  1872     root affiliation.
  1873  
  1874  The following shows how to add, modify, and remove an affiliation.
  1875  
  1876  Getting Identity Information
  1877  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  1878  
  1879  A caller may retrieve information on a identity from the fabric-ca server as long as the caller meets
  1880  the authorization requirements highlighted in the section above. The following command shows how to get an
  1881  identity.
  1882  
  1883  .. code:: bash
  1884  
  1885      fabric-ca-client identity list --id user1
  1886  
  1887  A caller may also request to retrieve information on all identities that it is authorized to see by
  1888  issuing the following command.
  1889  
  1890  .. code:: bash
  1891  
  1892      fabric-ca-client identity list
  1893  
  1894  Adding an identity
  1895  """""""""""""""""""
  1896  
  1897  The following adds a new identity for 'user1'. Adding a new identity performs the same action as registering an
  1898  identity via the 'fabric-ca-client register' command. There are two available methods for adding a new identity.
  1899  The first method is via the `--json` flag where you describe the identity in a JSON string.
  1900  
  1901  .. code:: bash
  1902  
  1903      fabric-ca-client identity add user1 --json '{"secret": "user1pw", "type": "client", "affiliation": "org1", "max_enrollments": 1, "attrs": [{"name": "hf.Revoker", "value": "true"}]}'
  1904  
  1905  The following adds a user with root affiliation. Note that an affiliation name of "." means the root affiliation.
  1906  
  1907  .. code:: bash
  1908  
  1909      fabric-ca-client identity add user1 --json '{"secret": "user1pw", "type": "client", "affiliation": ".", "max_enrollments": 1, "attrs": [{"name": "hf.Revoker", "value": "true"}]}'
  1910  
  1911  The second method for adding an identity is to use direct flags. See the example below for adding 'user1'.
  1912  
  1913  .. code:: bash
  1914  
  1915      fabric-ca-client identity add user1 --secret user1pw --type client --affiliation . --maxenrollments 1 --attrs hf.Revoker=true
  1916  
  1917  The table below lists all the fields of an identity and whether they are required or optional, and any default values they might have.
  1918  
  1919  +----------------+------------+------------------------+
  1920  | Fields         | Required   | Default Value          |
  1921  +================+============+========================+
  1922  | ID             | Yes        |                        |
  1923  +----------------+------------+------------------------+
  1924  | Secret         | No         |                        |
  1925  +----------------+------------+------------------------+
  1926  | Affiliation    | No         | Caller's Affiliation   |
  1927  +----------------+------------+------------------------+
  1928  | Type           | No         | client                 |
  1929  +----------------+------------+------------------------+
  1930  | Maxenrollments | No         | 0                      |
  1931  +----------------+------------+------------------------+
  1932  | Attributes     | No         |                        |
  1933  +----------------+------------+------------------------+
  1934  
  1935  
  1936  Modifying an identity
  1937  """"""""""""""""""""""
  1938  
  1939  There are two available methods for modifying an existing identity. The first method is via the `--json` flag where you describe
  1940  the modifications in to an identity in a JSON string. Multiple modifications can be made in a single request. Any element of an identity that
  1941  is not modified will retain its original value.
  1942  
  1943  NOTE: A maxenrollments value of "-2" specifies that the CA's max enrollment setting is to be used.
  1944  
  1945  The command below make multiple modification to an identity using the --json flag.
  1946  
  1947  .. code:: bash
  1948  
  1949      fabric-ca-client identity modify user1 --json '{"secret": "newPassword", "affiliation": ".", "attrs": [{"name": "hf.Regisrar.Roles", "value": "peer,client"},{"name": "hf.Revoker", "value": "true"}]}'
  1950  
  1951  The commands below make modifications using direct flags. The following updates the enrollment secret (or password) for identity 'user1' to 'newsecret'.
  1952  
  1953  .. code:: bash
  1954  
  1955      fabric-ca-client identity modify user1 --secret newsecret
  1956  
  1957  The following updates the affiliation of identity 'user1' to 'org2'.
  1958  
  1959  .. code:: bash
  1960  
  1961      fabric-ca-client identity modify user1 --affiliation org2
  1962  
  1963  The following updates the type of identity 'user1' to 'peer'.
  1964  
  1965  .. code:: bash
  1966  
  1967      fabric-ca-client identity modify user1 --type peer
  1968  
  1969  
  1970  The following updates the maxenrollments of identity 'user1' to 5.
  1971  
  1972  .. code:: bash
  1973  
  1974      fabric-ca-client identity modify user1 --maxenrollments 5
  1975  
  1976  By specifying a maxenrollments value of '-2', the following causes identity 'user1' to use
  1977  the CA's max enrollment setting.
  1978  
  1979  .. code:: bash
  1980  
  1981      fabric-ca-client identity modify user1 --maxenrollments -2
  1982  
  1983  The following sets the value of the 'hf.Revoker' attribute for identity 'user1' to 'false'.
  1984  If the identity has other attributes, they are not changed.  If the identity did not previously
  1985  possess the 'hf.Revoker' attribute, the attribute is added to the identity. An attribute may
  1986  also be removed by specifying no value for the attribute.
  1987  
  1988  .. code:: bash
  1989  
  1990      fabric-ca-client identity modify user1 --attrs hf.Revoker=false
  1991  
  1992  The following removes the 'hf.Revoker' attribute for user 'user1'.
  1993  
  1994  .. code:: bash
  1995  
  1996      fabric-ca-client identity modify user1 --attrs hf.Revoker=
  1997  
  1998  The following demonstrates that multiple options may be used in a single `fabric-ca-client identity modify`
  1999  command. In this case, both the secret and the type are updated for user 'user1'.
  2000  
  2001  .. code:: bash
  2002  
  2003      fabric-ca-client identity modify user1 --secret newpass --type peer
  2004  
  2005  Removing an identity
  2006  """""""""""""""""""""
  2007  
  2008  The following removes identity 'user1' and also revokes any certificates associated with the 'user1' identity.
  2009  
  2010  .. code:: bash
  2011  
  2012      fabric-ca-client identity remove user1
  2013  
  2014  Note: Removal of identities is disabled in the fabric-ca-server by default, but may be enabled
  2015  by starting the fabric-ca-server with the `--cfg.identities.allowremove` option.
  2016  
  2017  Dynamically updating affiliations
  2018  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2019  
  2020  This section describes how to use fabric-ca-client to dynamically update affiliations. The
  2021  following shows how to add, modify, remove, and list an affiliation.
  2022  
  2023  Adding an affiliation
  2024  """""""""""""""""""""""
  2025  
  2026  An authorization failure will occur if the client identity does not satisfy all of the following:
  2027  
  2028    - The client identity must possess the attribute 'hf.AffiliationMgr' with a value of 'true'.
  2029    - The affiliation of the client identity must be hierarchically above the affiliation being updated.
  2030      For example, if the client's affiliation is "a.b", the client may add affiliation "a.b.c" but not
  2031      "a" or "a.b".
  2032  
  2033  The following adds a new affiliation named ‘org1.dept1’.
  2034  
  2035  .. code:: bash
  2036  
  2037      fabric-ca-client affiliation add org1.dept1
  2038  
  2039  Modifying an affiliation
  2040  """""""""""""""""""""""""
  2041  
  2042  An authorization failure will occur if the client identity does not satisfy all of the following:
  2043  
  2044    - The client identity must possess the attribute 'hf.AffiliationMgr' with a value of 'true'.
  2045    - The affiliation of the client identity must be hierarchically above the affiliation being updated.
  2046      For example, if the client's affiliation is "a.b", the client may add affiliation "a.b.c" but not
  2047      "a" or "a.b".
  2048    - If the '--force' option is true and there are identities which must be modified, the client
  2049      identity must also be authorized to modify the identity.
  2050  
  2051  The following renames the 'org2' affiliation to 'org3'.  It also renames any sub affiliations
  2052  (e.g. 'org2.department1' is renamed to 'org3.department1').
  2053  
  2054  .. code:: bash
  2055  
  2056      fabric-ca-client affiliation modify org2 --name org3
  2057  
  2058  If there are identities that are affected by the renaming of an affiliation, it will result in
  2059  an error unless the '--force' option is used. Using the '--force' option will update the affiliation
  2060  of identities that are affected to use the new affiliation name.
  2061  
  2062  .. code:: bash
  2063  
  2064      fabric-ca-client affiliation modify org1 --name org2 --force
  2065  
  2066  Removing an affiliation
  2067  """""""""""""""""""""""""
  2068  
  2069  An authorization failure will occur if the client identity does not satisfy all of the following:
  2070  
  2071    - The client identity must possess the attribute 'hf.AffiliationMgr' with a value of 'true'.
  2072    - The affiliation of the client identity must be hierarchically above the affiliation being updated.
  2073      For example, if the client's affiliation is "a.b", the client may remove affiliation "a.b.c" but not
  2074      "a" or "a.b".
  2075    - If the '--force' option is true and there are identities which must be modified, the client
  2076      identity must also be authorized to modify the identity.
  2077  
  2078  The following removes affiliation 'org2' and also any sub affiliations.
  2079  For example, if 'org2.dept1' is an affiliation below 'org2', it is also removed.
  2080  
  2081  .. code:: bash
  2082  
  2083      fabric-ca-client affiliation remove org2
  2084  
  2085  If there are identities that are affected by the removing of an affiliation, it will result
  2086  in an error unless the '--force' option is used. Using the '--force' option will also remove
  2087  all identities that are associated with that affiliation, and the certificates associated with
  2088  any of these identities.
  2089  
  2090  Note: Removal of affiliations is disabled in the fabric-ca-server by default, but may be enabled
  2091  by starting the fabric-ca-server with the `--cfg.affiliations.allowremove` option.
  2092  
  2093  Listing affiliation information
  2094  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2095  
  2096  An authorization failure will occur if the client identity does not satisfy all of the following:
  2097  
  2098    - The client identity must possess the attribute 'hf.AffiliationMgr' with a value of 'true'.
  2099    - Affiliation of the client identity must be equal to or be hierarchically above the
  2100      affiliation being updated. For example, if the client's affiliation is "a.b",
  2101      the client may get affiliation information on "a.b" or "a.b.c" but not "a" or "a.c".
  2102  
  2103  The following command shows how to get a specific affiliation.
  2104  
  2105  .. code:: bash
  2106  
  2107      fabric-ca-client affiliation list --affiliation org2.dept1
  2108  
  2109  A caller may also request to retrieve information on all affiliations that it is authorized to see by
  2110  issuing the following command.
  2111  
  2112  .. code:: bash
  2113  
  2114      fabric-ca-client affiliation list
  2115  
  2116  Manage Certificates
  2117  ~~~~~~~~~~~~~~~~~~~~
  2118  
  2119  This section describes how to use fabric-ca-client to manage certificates.
  2120  
  2121  Listing certificate information
  2122  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  2123  
  2124  The certificates that are visible to a caller include:
  2125  
  2126    - Those certificates which belong to the caller
  2127    - If the caller possesses the ``hf.Registrar.Roles`` attribute or the ``hf.Revoker`` attribute with a value of ``true``,
  2128      all certificates which belong to identities in and below the caller's affiliation. For example, if the client's
  2129      affiliation is ``a.b``, the client may get certificates for identities who's affiliation
  2130      is ``a.b`` or ``a.b.c`` but not ``a`` or ``a.c``.
  2131  
  2132  If executing a list command that requests certificates of more than one identity, only certificates of identities
  2133  with an affiliation that is equal to or hierarchically below the caller's affiliation will be listed.
  2134  
  2135  The certificates which will be listed may be filtered based on ID, AKI, serial number, expiration time, revocation time, notrevoked, and notexpired flags.
  2136  
  2137  * ``id``: List certificates for this enrollment ID
  2138  * ``serial``: List certificates that have this serial number
  2139  * ``aki``: List certificates that have this AKI
  2140  * ``expiration``: List certificates that have expiration dates that fall within this expiration time
  2141  * ``revocation``: List certificates that were revoked within this revocation time
  2142  * ``notrevoked``: List certificates that have not yet been revoked
  2143  * ``notexpired``: List certificates that have not yet expired
  2144  
  2145  You can use flags ``notexpired`` and ``notrevoked`` as filters to exclude revoked certificates and/or expired certificates from the result set.
  2146  For example, if you only care about certificates that have expired but have not been revoked you can use the ``expiration`` and ``notrevoked`` flags to
  2147  get back such results. An example of this case is provided below.
  2148  
  2149  Time should be specified based on RFC3339. For instance, to list certificates that have expirations between
  2150  March 1, 2018 at 1:00 PM and June 15, 2018 at 2:00 AM, the input time string would look like 2018-03-01T13:00:00z
  2151  and 2018-06-15T02:00:00z. If time is not a concern, and only the dates matter, then the time part can be left
  2152  off and then the strings become 2018-03-01 and 2018-06-15.
  2153  
  2154  The string ``now`` may be used to denote the current time and the empty string to denote any time. For example, ``now::`` denotes
  2155  a time range from now to any time in the future, and ``::now`` denotes a time range from any time in the past until now.
  2156  
  2157  The following command shows how to list certificates using various filters.
  2158  
  2159  List all certificates:
  2160  
  2161  .. code:: bash
  2162  
  2163   fabric-ca-client certificate list
  2164  
  2165  List all certificates by id:
  2166  
  2167  .. code:: bash
  2168  
  2169   fabric-ca-client certificate list --id admin
  2170  
  2171  List certificate by serial and aki:
  2172  
  2173  .. code:: bash
  2174  
  2175   fabric-ca-client certificate list --serial 1234 --aki 1234
  2176  
  2177  List certificate by id and serial/aki:
  2178  
  2179  .. code:: bash
  2180  
  2181   fabric-ca-client certificate list --id admin --serial 1234 --aki 1234
  2182  
  2183  List certificates that are neither revoker nor expired by id:
  2184  
  2185  .. code:: bash
  2186  
  2187   fabric-ca-client certificate list --id admin --notrevoked --notexpired
  2188  
  2189  List all certificates that have not been revoked for an id (admin):
  2190  
  2191  .. code:: bash
  2192  
  2193   fabric-ca-client certificate list --id admin --notrevoked
  2194  
  2195  List all certificates have not expired for an id (admin):
  2196  
  2197  The "--notexpired" flag is equivalent to "--expiration now::", which means certificates
  2198  will expire some time in the future.
  2199  
  2200  .. code:: bash
  2201  
  2202   fabric-ca-client certificate list --id admin --notexpired
  2203  
  2204  List all certificates that were revoked between a time range for an id (admin):
  2205  
  2206  .. code:: bash
  2207  
  2208   fabric-ca-client certificate list --id admin --revocation 2018-01-01T01:30:00z::2018-01-30T05:00:00z
  2209  
  2210  List all certificates that were revoked between a time range but have not expired for an id (admin):
  2211  
  2212  .. code:: bash
  2213  
  2214   fabric-ca-client certificate list --id admin --revocation 2018-01-01::2018-01-30 --notexpired
  2215  
  2216  List all revoked certificates using duration (revoked between 30 days and 15 days ago) for an id (admin):
  2217  
  2218  .. code:: bash
  2219  
  2220   fabric-ca-client certificate list --id admin --revocation -30d::-15d
  2221  
  2222  List all revoked certificates before a time
  2223  
  2224  .. code:: bash
  2225  
  2226   fabric-ca-client certificate list --revocation ::2018-01-30
  2227  
  2228  List all revoked certificates after a time
  2229  
  2230  .. code:: bash
  2231  
  2232   fabric-ca-client certificate list --revocation 2018-01-30::
  2233  
  2234  List all revoked certificates before now and after a certain date
  2235  
  2236  .. code:: bash
  2237  
  2238   fabric-ca-client certificate list --id admin --revocation 2018-01-30::now
  2239  
  2240  List all certificate that expired between a time range but have not been revoked for an id (admin):
  2241  
  2242  .. code:: bash
  2243  
  2244   fabric-ca-client certificate list --id admin --expiration 2018-01-01::2018-01-30 --notrevoked
  2245  
  2246  List all expired certificates using duration (expired between 30 days and 15 days ago) for an id (admin):
  2247  
  2248  .. code:: bash
  2249  
  2250   fabric-ca-client certificate list --expiration -30d::-15d
  2251  
  2252  List all certificates that have expired or will expire before a certain time
  2253  
  2254  .. code:: bash
  2255  
  2256   fabric-ca-client certificate list --expiration ::2058-01-30
  2257  
  2258  List all certificates that have expired or will expire after a certain time
  2259  
  2260  .. code:: bash
  2261  
  2262   fabric-ca-client certificate list --expiration 2018-01-30::
  2263  
  2264  List all expired certificates before now and after a certain date
  2265  
  2266  .. code:: bash
  2267  
  2268   fabric-ca-client certificate list --expiration 2018-01-30::now
  2269  
  2270  List certificates expiring in the next 10 days:
  2271  
  2272  .. code:: bash
  2273  
  2274   fabric-ca-client certificate list --id admin --expiration ::+10d --notrevoked
  2275  
  2276  The list certificate command can also be used to store certificates on the file
  2277  system. This is a convenient way to populate the admins folder in an MSP, The "-store" flag
  2278  points to the location on the file system to store the certificates.
  2279  
  2280  Configure an identity to be an admin, by storing certificates for an identity
  2281  in the MSP:
  2282  
  2283  .. code:: bash
  2284  
  2285   export FABRIC_CA_CLIENT_HOME=/tmp/clientHome
  2286   fabric-ca-client certificate list --id admin --store msp/admincerts
  2287  
  2288  Contact specific CA instance
  2289  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2290  
  2291  When a server is running multiple CA instances, requests can be directed to a
  2292  specific CA. By default, if no CA name is specified in the client request the
  2293  request will be directed to the default CA on the fabric-ca server. A CA name
  2294  can be specified on the command line of a client command using the ``caname``
  2295  filter as follows:
  2296  
  2297  .. code:: bash
  2298  
  2299      fabric-ca-client enroll -u http://admin:adminpw@localhost:7054 --caname <caname>
  2300  
  2301  `Back to Top`_
  2302  
  2303  Configuring an HSM
  2304  ------------------
  2305  By default, the Fabric CA server and client store private keys in a PEM-encoded file,
  2306  but they can also be configured to store private keys in an HSM (Hardware Security Module)
  2307  via PKCS11 APIs. This behavior is configured in the BCCSP (BlockChain Crypto Service Provider)
  2308  section of the server’s or client’s configuration file. Currently, Fabric only
  2309  supports the PKCS11 standard to communicate with an HSM.
  2310  
  2311  Example
  2312  ~~~~~~~
  2313  
  2314  The following example demonstrates how to configure the Fabric CA server or
  2315  client to use a software version of PKCS11 called SoftHSM (see https://github.com/opendnssec/SoftHSMv2).
  2316  
  2317  After installing SoftHSM, make sure to set your SOFTHSM2_CONF environment variable to
  2318  point to the location where the SoftHSM2 configuration file is stored. The config file looks like
  2319  
  2320  .. code::
  2321  
  2322    directories.tokendir = /tmp/
  2323    objectstore.backend = file
  2324    log.level = INFO
  2325  
  2326  You can find example configuration file named SoftHSM2.conf under testdata directory.
  2327  
  2328  Create a token, label it “ForFabric”, set the pin to ‘98765432’
  2329  (refer to SoftHSM documentation).
  2330  
  2331  You can use both the config file and environment variables to configure BCCSP.
  2332  For example, set the bccsp section of Fabric CA server configuration file as follows.
  2333  Note that the default field’s value is PKCS11.
  2334  
  2335  .. code:: yaml
  2336  
  2337    #############################################################################
  2338    # BCCSP (BlockChain Crypto Service Provider) section is used to select which
  2339    # crypto library implementation to use
  2340    #############################################################################
  2341    bccsp:
  2342      default: PKCS11
  2343      pkcs11:
  2344        Library: /usr/local/Cellar/softhsm/2.1.0/lib/softhsm/libsofthsm2.so
  2345        Pin: 98765432
  2346        Label: ForFabric
  2347        hash: SHA2
  2348        security: 256
  2349        filekeystore:
  2350          # The directory used for the software file-based keystore
  2351          keystore: msp/keystore
  2352  
  2353  And you can override relevant fields via environment variables as follows:
  2354  
  2355  .. code:: bash
  2356  
  2357    FABRIC_CA_SERVER_BCCSP_DEFAULT=PKCS11
  2358    FABRIC_CA_SERVER_BCCSP_PKCS11_LIBRARY=/usr/local/Cellar/softhsm/2.1.0/lib/softhsm/libsofthsm2.so
  2359    FABRIC_CA_SERVER_BCCSP_PKCS11_PIN=98765432
  2360    FABRIC_CA_SERVER_BCCSP_PKCS11_LABEL=ForFabric
  2361  
  2362  
  2363  The prebuilt Hyperledger Fabric Docker images are not enabled to use PKCS11. If
  2364  you are deploying the Fabric CA using Docker, you need to build your own image
  2365  and enable PKCS11 using the following command:
  2366  
  2367  .. code:: bash
  2368  
  2369    make docker GO_TAGS=pkcs11
  2370  
  2371  You also need to ensure that the PKCS11 library is available to be used by the
  2372  CA by installing it or mounting it inside the container. If you are deploying
  2373  your Fabric CA using Docker Compose, you can update your Compose files to mount
  2374  the SoftHSM library and configuration file inside the container using volumes.
  2375  As an example, you would add the following environment and volumes variables to
  2376  your Docker Compose file:
  2377  
  2378  .. code::
  2379  
  2380    environment:
  2381       - SOFTHSM2_CONF=/etc/hyperledger/fabric/config.file
  2382    volumes:
  2383       - /home/softhsm/config.file:/etc/hyperledger/fabric/config.file
  2384       - /usr/local/Cellar/softhsm/2.1.0/lib/softhsm/libsofthsm2.so:/etc/hyperledger/fabric/libsofthsm2.so
  2385  
  2386  
  2387  `Back to Top`_
  2388  
  2389  File Formats
  2390  ------------
  2391  
  2392  Fabric CA server's configuration file format
  2393  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2394  
  2395  A default configuration file is created in the server's home directory
  2396  (see `Fabric CA Server <#server>`__ section for more info). The following
  2397  link shows a sample :doc:`Server configuration file <serverconfig>`.
  2398  
  2399  Fabric CA client's configuration file format
  2400  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2401  
  2402  A default configuration file is created in the client's home directory
  2403  (see `Fabric CA Client <#client>`__ section for more info). The following
  2404  link shows a sample :doc:`Client configuration file <clientconfig>`.
  2405  
  2406  `Back to Top`_
  2407  
  2408  Troubleshooting
  2409  ---------------
  2410  
  2411  1. If you see a ``Killed: 9`` error on OSX when trying to execute
  2412     ``fabric-ca-client`` or ``fabric-ca-server``, there is a long thread
  2413     describing this problem at https://github.com/golang/go/issues/19734.
  2414     The short answer is that to work around this issue, you can run the
  2415     following command::
  2416  
  2417      # sudo ln -s /usr/bin/true /usr/local/bin/dsymutil
  2418  
  2419  2. The error ``[ERROR] No certificates found for provided serial and aki`` will occur
  2420     if the following sequence of events occurs:
  2421  
  2422     a. You issue a `fabric-ca-client enroll` command, creating an enrollment certificate (i.e. an ECert).
  2423        This stores a copy of the ECert in the fabric-ca-server's database.
  2424     b. The fabric-ca-server's database is deleted and recreated, thus losing the ECert from step 'a'.
  2425        For example, this may happen if you stop and restart a Docker container hosting the fabric-ca-server,
  2426        but your fabric-ca-server is using the default sqlite database and the database file is not stored
  2427        on a volume and is therefore not persistent.
  2428     c. You issue a `fabric-ca-client register` command or any other command which tries to use the ECert from
  2429        step 'a'.  In this case, since the database no longer contains the ECert, the
  2430        ``[ERROR] No certificates found for provided serial and aki`` will occur.
  2431  
  2432     To resolve this error, you must enroll again by repeating step 'a'.  This will issue a new ECert
  2433     which will be stored in the current database.
  2434  
  2435  3. When sending multiple parallel requests to a Fabric CA Server cluster that uses shared sqlite3 databases,
  2436     the server occasionally returns a 'database locked' error. This is most probably because the database
  2437     transaction timed out while waiting for database lock (held by another cluster member) to be released.
  2438     This is an invalid configuration because sqlite is an embedded database, which means the Fabric CA server
  2439     cluster must share the same file via a shared file system, which introduces a SPoF (single point of failure),
  2440     which contradicts the purpose of cluster topology. The best practice is to use either Postgres or MySQL
  2441     databases in a cluster topology.
  2442  
  2443  4. Suppose an error similar to
  2444     ``Failed to deserialize creator identity, err The supplied identity is not valid, Verify() returned x509: certificate signed by unknown authority``
  2445     is returned by a peer or orderer when using an enrollment certificate issued by the Fabric CA Server.  This indicates that
  2446     the signing CA certificate used by the Fabric CA Server to issue certificates does not match a certificate in the `cacerts` or `intermediatecerts`
  2447     folder of the MSP used to make authorization checks.
  2448  
  2449     The MSP which is used to make authorization checks depends on which operation you were performing when the error occurred.
  2450     For example, if you were trying to install chaincode on a peer, the local MSP on the file system of the peer is used;
  2451     otherwise, if you were performing some channel specific operation such as instantiating chaincode on a specific channel,
  2452     the MSP in the genesis block or the most recent configuration block of the channel is used.
  2453  
  2454     To confirm that this is the problem, compare the AKI (Authority Key Identifier) of the enrollment certificate
  2455     to the SKI (Subject Key Identifier) of the certificate(s) in the `cacerts` and `intermediatecerts` folder of appropriate MSP.
  2456     The command `openssl x509 -in <PEM-file> -noout -text | grep -A1 "Authority Key Identifier"` will display the AKI and
  2457     `openssl x509 -in <PEM-file> -noout -text | grep -A1 "Subject Key Identifier"` will display the SKI.
  2458     If they are not equal, you have confirmed that this is the cause of the error.
  2459  
  2460     This can happen for multiple reasons including:
  2461  
  2462     a. You used `cryptogen` to generate your key material but did not start `fabric-ca-server` with the signing key and certificate generated
  2463        by `cryptogen`.
  2464  
  2465        To resolve (assuming `FABRIC_CA_SERVER_HOME` is set to the home directory of your `fabric-ca-server`):
  2466  
  2467        1. Stop `fabric-ca-server`.
  2468        2. Copy `crypto-config/peerOrganizations/<orgName>/ca/*pem` to `$FABRIC_CA_SERVER_HOME/ca-cert.pem`.
  2469        3. Copy `crypto-config/peerOrganizations/<orgName>/ca/*_sk` to `$FABRIC_CA_SERVER_HOME/msp/keystore/`.
  2470        4. Start `fabric-ca-server`.
  2471        5. Delete any previously issued enrollment certificates and get new certificates by enrolling again.
  2472  
  2473     b. You deleted and recreated the CA signing key and certificate used by the Fabric CA Server after generating the genesis block.
  2474        This can happen if the Fabric CA Server is running in a Docker container, the container was restarted, and its home directory
  2475        is not on a volume mount.  In this case, the Fabric CA Server will create a new CA signing key and certificate.
  2476  
  2477        Assuming that you can not recover the original CA signing key, the only way to recover from this scenario is to update the
  2478        certificate in the `cacerts` (or `intermediatecerts`) of the appropriate MSPs to the new CA certificate.
  2479  
  2480  .. Licensed under Creative Commons Attribution 4.0 International License
  2481     https://creativecommons.org/licenses/by/4.0/