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