github.com/silveraid/fabric-ca@v1.1.0-preview.0.20180127000700-71974f53ab08/scripts/fvt/ldap_test.sh (about)

     1  #!/bin/bash
     2  #
     3  # Copyright IBM Corp. All Rights Reserved.
     4  #
     5  # SPDX-License-Identifier: Apache-2.0
     6  #
     7  
     8  FABRIC_CA="$GOPATH/src/github.com/hyperledger/fabric-ca"
     9  SCRIPTDIR="$FABRIC_CA/scripts/fvt"
    10  . $SCRIPTDIR/fabric-ca_utils
    11  RC=0
    12  export CA_CFG_PATH="/tmp/ldap"
    13  export UDIR="/tmp/users"
    14  
    15  rm -rf $UDIR
    16  mkdir -p $UDIR
    17  
    18  users1=( admin admin2 revoker revoker2 nonrevoker nonrevoker2 notadmin expiryUser testUser testUser2 )
    19  users2=( testUser3 )
    20  
    21  $SCRIPTDIR/fabric-ca_setup.sh -R
    22  $SCRIPTDIR/fabric-ca_setup.sh -I -a -D -X -S -n1
    23  
    24  checkUserCert() {
    25     # Make sure the "dn" attribute is in the user's certificate
    26     USER=$1
    27     CERTFILE=$UDIR/$USER/msp/signcerts/cert.pem
    28     ATTRS=$(openssl x509 -noout -text -in $CERTFILE | grep '{"attrs":{'| grep '"hf.Revoker"' | grep '"uid"')
    29     test "$ATTRS" == "" && ErrorMsg "Failed to find hf.Revoker and uid attributes in certificate for user $USER"
    30  }
    31  
    32  for u in ${users1[*]}; do
    33     export CA_CFG_PATH=$UDIR
    34     enroll $u ${u}pw uid,hf.Revoker
    35     test $? -ne 0 && ErrorMsg "Failed to enroll $u"
    36     checkUserCert $u
    37  done
    38  
    39  # Sleep for more than the idle connection timeout limit of 1 second
    40  sleep 3
    41  
    42  for u in ${users2[*]}; do
    43     export CA_CFG_PATH=$UDIR
    44     enroll $u ${u}pw uid,hf.Revoker
    45     test $? -ne 0 && ErrorMsg "Failed to enroll $u"
    46     checkUserCert $u
    47  done
    48  
    49  # User 'revoker' revokes user the ecert of user 'testUser'
    50  echo "User 'revoker' is revoking the ecert of user 'testUser' ..."
    51  certFile=$UDIR/testUser/msp/signcerts/cert.pem
    52  AKI=$(openssl x509 -noout -text -in $certFile |awk '/keyid/ {gsub(/ *keyid:|:/,"",$1);print toupper($0)}')
    53  SN=$(openssl x509 -noout -serial -in $certFile | awk -F'=' '{print toupper($2)}')
    54  URI=$PROTO${CA_HOST_ADDRESS}:$PROXY_PORT
    55  export FABRIC_CA_CLIENT_HOME=$UDIR/revoker
    56  $FABRIC_CA_CLIENTEXEC revoke -u $URI -a $AKI -s $SN $TLSOPT
    57  test "$?" -eq 0 || ErrorMsg "User 'revoker' failed to revoke user 'testUser'"
    58  
    59  CleanUp $RC
    60  exit $RC