|
2 | 2 | FABRIC_CA="$GOPATH/src/github.com/hyperledger/fabric-ca" |
3 | 3 | SCRIPTDIR="$FABRIC_CA/scripts/fvt" |
4 | 4 | TESTDATA="$FABRIC_CA/testdata" |
5 | | -FABRIC_CA_EXEC="$FABRIC_CA/bin/fabric-ca" |
6 | | -FABRIC_CA_HOME="$HOME/fabric-ca" |
| 5 | +export CA_CFG_PATH="/tmp/revoke_test" |
7 | 6 | RC=0 |
8 | | -URI="localhost:8888" |
9 | | -DB="$TESTDATA/fabric_ca.db" |
10 | | -USERS=("admin" "admin2" "notadmin") |
11 | | -PSWDS=("adminpw" "adminpw2" "pass") |
| 7 | +# FIXME should not require user:pass |
| 8 | +URI="http://user:pass@localhost:8888" |
| 9 | +DB="fabric_ca" |
| 10 | +USERS=("admin" "admin2" "notadmin" "testUser" "testUser2" "testUser3" ) |
| 11 | +PSWDS=("adminpw" "adminpw2" "pass" "user1" "user2" "user3" ) |
| 12 | +#USERS=("admin" "admin2" "notadmin") |
| 13 | +#PSWDS=("adminpw" "adminpw2" "pass") |
12 | 14 | HTTP_PORT="3755" |
13 | | -export FABRIC_CA_HOME="/tmp/${USERS[1]}" |
14 | 15 |
|
15 | 16 | . $SCRIPTDIR/fabric-ca_utils |
16 | 17 |
|
17 | | - |
18 | | -# Expected codes |
19 | | - # user cert |
20 | | -test1Result="1 good" |
21 | | -test2Result="1 revoked" |
22 | | -test3Result="1 revoked" |
| 18 | +genAffYaml() { |
| 19 | + local Planet=(0 1) |
| 20 | + local Landmass=(0) |
| 21 | + local Country=(0 1) |
| 22 | + local Province=(0 1 2) |
| 23 | + local Locale=(0) |
| 24 | + local City=(0 1) |
| 25 | + local Hood=(0 1 2 3 4 5 6) |
| 26 | + echo "affiliations:" |
| 27 | + indent="${indent} " |
| 28 | + for P in ${Planet[@]}; do |
| 29 | + echo "${indent}Planet$P:" |
| 30 | + indent="${indent} " |
| 31 | + for L in ${Landmass[@]}; do |
| 32 | + echo "${indent}Landmass$L:" |
| 33 | + indent="${indent} " |
| 34 | + for C in ${Country[@]}; do |
| 35 | + echo "${indent}Country$C:" |
| 36 | + indent="${indent} " |
| 37 | + for R in ${Province[@]}; do |
| 38 | + echo "${indent}Province$R:" |
| 39 | + indent="${indent} " |
| 40 | + for O in ${Locale[@]}; do |
| 41 | + echo "${indent}Locale$O:" |
| 42 | + indent="${indent} " |
| 43 | + for I in ${City[@]}; do |
| 44 | + echo "${indent}City$I:" |
| 45 | + indent="${indent} " |
| 46 | + for H in ${Hood[@]}; do |
| 47 | + echo "${indent}- Hood$H" |
| 48 | + done |
| 49 | + indent="${indent# }" |
| 50 | + done |
| 51 | + indent="${indent# }" |
| 52 | + done |
| 53 | + indent="${indent# }" |
| 54 | + done |
| 55 | + indent="${indent# }" |
| 56 | + done |
| 57 | + indent="${indent# }" |
| 58 | + done |
| 59 | + indent="${indent# }" |
| 60 | + done |
| 61 | + indent="${indent} " |
| 62 | +} |
23 | 63 |
|
24 | 64 | function testStatus() { |
25 | | - local user="$1" |
26 | | - user_status=$(sqlite3 $DB "SELECT * FROM users WHERE (id=\"$user\");") |
27 | | - cert_status=$(sqlite3 $DB "SELECT * FROM certificates WHERE (id=\"$user\");") |
28 | | - user_status_code=$(echo $user_status | awk -F'|' '{print $6}') |
29 | | - cert_status_code=$(echo $cert_status | awk -F'|' '{print $5}') |
30 | | - echo "$user_status_code $cert_status_code" |
| 65 | + local user="$1" |
| 66 | + local driver="$2" |
| 67 | + : ${driver:="sqlite3"} |
| 68 | + case $driver in |
| 69 | + sqlite3) |
| 70 | + user_status=$(sqlite3 $CA_CFG_PATH/$DB "SELECT * FROM users WHERE (id=\"$user\");") |
| 71 | + cert_status=$(sqlite3 $CA_CFG_PATH/$DB "SELECT * FROM certificates WHERE (id=\"$user\");") |
| 72 | + user_status_code=$(echo $user_status | awk -F'|' '{print $6}') |
| 73 | + cert_status_code=$(echo $cert_status | awk -F'|' '{print $5}') |
| 74 | + ;; |
| 75 | + mysql) |
| 76 | + user_status_code=$(mysql --host=localhost --user=root --password=mysql -e "SELECT * FROM users WHERE (id=\"$user\");" $DB| awk -F'\t' -v u=$user '$1~u {print $6}') |
| 77 | + cert_status_code=$(mysql --host=localhost --user=root --password=mysql -e "SELECT * FROM certificates WHERE (id=\"$user\");" $DB| awk -F'\t' -v u=$user '$1~u {print $5}') |
| 78 | + ;; |
| 79 | + postgres) |
| 80 | + user_status_code=$(/usr/bin/psql -U postgres -h localhost -c "SELECT id,state FROM users WHERE id='$user';" --dbname=fabric_ca | awk -v u=$user -F'|' '$1~u {gsub(/ /,"");print $2}') |
| 81 | + cert_status_code=$(/usr/bin/psql -U postgres -h localhost -c "SELECT id,encode(status,'escape') FROM certificates WHERE id='$user';" --dbname=fabric_ca | awk -v u=$user -F'|' '$1~u {gsub(/ /,"");print $2}') |
| 82 | + ;; |
| 83 | + esac |
| 84 | + echo "$user_status_code $cert_status_code" |
31 | 85 | } |
32 | 86 |
|
| 87 | +# Expected codes |
| 88 | + # user cert |
| 89 | +enrolledGood="1 good" |
| 90 | +enrolledRevoked="1 revoked" |
| 91 | +revokedRevoked="-1 revoked" |
| 92 | +TEST_RESULTS=("$revokedRevoked" "$revokedRevoked" "$enrolledRevoked" "$enrolledRevoked" "$enrolledGood" "$enrolledGood" ) |
| 93 | + |
33 | 94 | cd $TESTDATA |
34 | 95 | python -m SimpleHTTPServer $HTTP_PORT & |
35 | 96 | HTTP_PID=$! |
36 | 97 | pollServer python localhost "$HTTP_PORT" || ErrorExit "Failed to start HTTP server" |
37 | 98 | echo $HTTP_PID |
38 | | -trap "kill $HTTP_PID; CleanUp" INT |
39 | | - |
40 | | - |
41 | | -# Kill any running servers |
42 | | -$SCRIPTDIR/fabric-ca_setup.sh -R -x $FABRIC_CA_HOME |
43 | | - |
44 | | -# Setup CA server |
45 | | -$SCRIPTDIR/fabric-ca_setup.sh -I -S -X |
46 | | - |
47 | | -# Enroll |
48 | | -i=-1 |
49 | | -while test $((i++)) -lt 2; do |
50 | | - FABRIC_CA_HOME="/tmp/${USERS[i]}" |
51 | | - $SCRIPTDIR/enroll.sh -u "${USERS[i]}" -p "${PSWDS[i]}" -x "/tmp/${USERS[i]}" |
| 99 | +trap "kill $HTTP_PID; CleanUp; exit 1" INT |
| 100 | + |
| 101 | + |
| 102 | +for driver in mysql postgres sqlite3; do |
| 103 | + echo "" |
| 104 | + echo "" |
| 105 | + echo "" |
| 106 | + echo "" |
| 107 | + echo "=====================> TESTING $driver" |
| 108 | + # Kill any running servers |
| 109 | + $SCRIPTDIR/fabric-ca_setup.sh -R -d $driver |
| 110 | + |
| 111 | + # Setup CA server |
| 112 | + $SCRIPTDIR/fabric-ca_setup.sh -D -I -d $driver |
| 113 | + genAffYaml >> $CA_CFG_PATH/runFabricCaFvt.yaml |
| 114 | + $SCRIPTDIR/fabric-ca_setup.sh -o 60 -D -S -X -d $driver -x $CA_CFG_PATH |
| 115 | + if test "$?" -ne 0; then |
| 116 | + kill $HTTP_PID |
| 117 | + wait $HTTP_PID |
| 118 | + ErrorExit "Failed to setup server" RC |
| 119 | + fi |
| 120 | + sleep 5 |
| 121 | + # Enroll admin, admin2, notadmin, testUser |
| 122 | + i=-1 |
| 123 | + while test $((i++)) -lt 5; do |
| 124 | + enroll "${USERS[i]}" "${PSWDS[i]}" "$CA_CFG_PATH/${USERS[i]}" |
| 125 | + done |
| 126 | + |
| 127 | + # notadmin cannot revoke |
| 128 | + export FABRIC_CA_CLIENT_HOME="/tmp/revoke_test/${USERS[2]}" |
| 129 | + $FABRIC_CA_CLIENTEXEC revoke -u $URI --eid ${USERS[1]} |
| 130 | + test "$?" -eq 0 && ErrorMsg "Non-revoker successfully revoked cert" |
| 131 | + |
| 132 | + # Check the DB contents |
| 133 | + while test $((i++)) -lt 3; do |
| 134 | + test "$(testStatus ${USERS[i]} $driver)" = "$enrolledGood" || |
| 135 | + ErrorMsg "Incorrect user/certificate status for ${USERS[i]}" RC |
| 136 | + done |
| 137 | + |
| 138 | + ### Ensure case-insensitivity by using both upper/lower case |
| 139 | + ### in two separate instances |
| 140 | + # Grab the serial number of notadmin cert |
| 141 | + SN_UC="$(openssl x509 -noout -serial -in $CA_CFG_PATH/${USERS[2]}/msp/signcerts/cert.pem | awk -F'=' '{print toupper($2)}')" |
| 142 | + # and the auth keyid of notadmin cert - translate upper to lower case |
| 143 | + AKI_UC=$(openssl x509 -noout -text -in $CA_CFG_PATH/${USERS[2]}/msp/signcerts/cert.pem |awk '/keyid/ {gsub(/ *keyid:|:/,"",$1);print toupper($0)}') |
| 144 | + |
| 145 | + # Grab the serial number of testUser cert |
| 146 | + SN_LC="$(openssl x509 -noout -serial -in $CA_CFG_PATH/${USERS[3]}/msp/signcerts/cert.pem | awk -F'=' '{print tolower($2)}')" |
| 147 | + # and the auth keyid of testUser cert - translate upper to lower case |
| 148 | + AKI_LC=$(openssl x509 -noout -text -in $CA_CFG_PATH/${USERS[3]}/msp/signcerts/cert.pem |awk '/keyid/ {gsub(/ *keyid:|:/,"",$1);print tolower($0)}') |
| 149 | + |
| 150 | + # Revoke the certs |
| 151 | + echo "=========================> REVOKING by --eid" |
| 152 | + export FABRIC_CA_CLIENT_HOME="/tmp/revoke_test/${USERS[0]}" |
| 153 | + #### Blanket revoke all of admin2 certs |
| 154 | + $FABRIC_CA_CLIENTEXEC revoke -u $URI --eid ${USERS[1]} |
| 155 | + |
| 156 | + #### Revoke notadmin's cert by serial number and authority keyid |
| 157 | + #### using upper-case hexidecimal |
| 158 | + echo "=========================> REVOKING by -s -a (UPPERCASE)" |
| 159 | + $FABRIC_CA_CLIENTEXEC revoke -s $SN_UC -a $AKI_UC -u $URI |
| 160 | + |
| 161 | + #### Ensure that revoking an already revoked cert doesn't blow up |
| 162 | + echo "=========================> Issuing duplicate revoke by -s -a" |
| 163 | + $FABRIC_CA_CLIENTEXEC revoke -s $SN_UC -a $AKI_UC -u $URI |
| 164 | + |
| 165 | + #### Revoke using lower-case hexadeciaml |
| 166 | + # FIXME - should allow combination of SN + AKI + EID |
| 167 | + #$FABRIC_CA_CLIENTEXEC revoke -s $SN_LC -a $AKI_LC -u $URI --eid ${USERS[3]} |
| 168 | + echo "=========================> REVOKING by -s -a (LOWERCASE)" |
| 169 | + $FABRIC_CA_CLIENTEXEC revoke -s $SN_LC -a $AKI_LC -u $URI |
| 170 | + |
| 171 | + echo "=========================> REVOKING by --eid" |
| 172 | + export FABRIC_CA_CLIENT_HOME="/tmp/revoke_test/${USERS[0]}" |
| 173 | + #### Revoke across affiliations not allowed |
| 174 | + $FABRIC_CA_CLIENTEXEC revoke -u $URI --eid ${USERS[5]} |
| 175 | + |
| 176 | + #### Revoke my own cert |
| 177 | + echo "=========================> REVOKING self" |
| 178 | + $FABRIC_CA_CLIENTEXEC revoke --eid ${USERS[0]} |
| 179 | + |
| 180 | + # Verify the DB update |
| 181 | + for ((i=${#USERS[@]}; i<=0; i--)); do |
| 182 | + test "$(testStatus ${USERS[i-1]} $driver)" = "${TEST_RESULTS[i-1]}" || |
| 183 | + ErrorMsg "Incorrect user/certificate status for ${USERS[i-1]}" RC |
| 184 | + done |
| 185 | + |
| 186 | + # Veriy that the cert is no longer usable |
| 187 | + export FABRIC_CA_CLIENT_HOME="/tmp/revoke_test/${USERS[0]}" |
| 188 | + register ${USERS[0]} 'user100' |
| 189 | + test "$?" -eq 0 && ErrorMsg "${USERS[0]} authenticated with revoked certificate" RC |
| 190 | + export FABRIC_CA_CLIENT_HOME="/tmp/revoke_test/${USERS[1]}" |
| 191 | + register ${USERS[1]} 'user101' |
| 192 | + test "$?" -eq 0 && ErrorMsg "${USERS[1]} authenticated with revoked certificate" RC |
| 193 | + |
| 194 | + # Verify the DB update |
| 195 | + for ((i=${#USERS[@]}; i<=0; i--)); do |
| 196 | + test "$(testStatus ${USERS[i-1]} $driver)" = "${TEST_RESULTS[i-1]}" || |
| 197 | + ErrorMsg "Incorrect user/certificate status for ${USERS[i-1]}" RC |
| 198 | + done |
52 | 199 | done |
53 | | - |
54 | | -# notadmin cannot revoke |
55 | | -FABRIC_CA_HOME="/tmp/${USERS[2]}" |
56 | | -$FABRIC_CA_EXEC client revoke $URI ${USERS[2]} |
57 | | -test "$?" -eq 0 && ErrorMsg "Non-revoker successfully revoked cert" |
58 | | - |
59 | | -# Check the DB contents |
60 | | -test "$(testStatus ${USERS[0]})" = "$test1Result" || |
61 | | - ErrorMsg "Incorrect user/certificate status for ${USERS[0]}" RC |
62 | | -test "$(testStatus ${USERS[1]})" = "$test1Result" || |
63 | | - ErrorMsg "Incorrect user/certificate status for ${USERS[1]}" RC |
64 | | - |
65 | | -# Grab the serial number of admin cert (convert to decimal) |
66 | | -SN=$(echo "ibase=16;$(openssl x509 -noout -serial -in /tmp/${USERS[0]}/cert.pem | awk -F'=' '{print $2}')" | bc) |
67 | | -# and the auth keyid of admin cert - translate upper to lower case |
68 | | -AKI=$(openssl x509 -noout -text -in /tmp/${USERS[0]}/cert.pem |awk '/keyid/ {gsub(/ *keyid:|:/,"",$1);print tolower($0)}') |
69 | | - |
70 | | -# Revoke the certs |
71 | | -FABRIC_CA_HOME="/tmp/${USERS[0]}" |
72 | | -#### Blanket all of admin2 certs |
73 | | -$FABRIC_CA_EXEC client revoke $URI ${USERS[1]} |
74 | | -#### Revoke admin's cert by serial number and authority keyid |
75 | | -$FABRIC_CA_EXEC client revoke -serial $SN -aki $AKI $URI ${USERS[0]} |
76 | | - |
77 | | -# Verify the DB update |
78 | | -test "$(testStatus ${USERS[0]})" = "$test2Result" || |
79 | | - ErrorMsg "Incorrect user/certificate status for ${USERS[0]}" RC |
80 | | -test "$(testStatus ${USERS[1]})" = "$test2Result" || |
81 | | - ErrorMsg "Incorrect user/certificate status for ${USERS[1]}" RC |
82 | | - |
83 | | -# Veriy that the cert is no longer usable |
84 | | -FABRIC_CA_HOME="/tmp/${USERS[0]}" |
85 | | -$SCRIPTDIR/register.sh -u 'user100' |
86 | | -FABRIC_CA_HOME="/tmp/${USERS[0]}" |
87 | | -test "$?" -eq 0 && ErrorMsg "${USERS[0]} authenticated with revoked certificate" RC |
88 | | -FABRIC_CA_HOME="/tmp/${USERS[1]}" |
89 | | -$SCRIPTDIR/register.sh -u 'user101' |
90 | | -test "$?" -eq 0 && ErrorMsg "${USERS[1]} authenticated with revoked certificate" RC |
91 | | - |
92 | | -# Verify the DB update |
93 | | -test "$(testStatus ${USERS[0]})" = "$test3Result" || |
94 | | - ErrorMsg "Incorrect user/certificate status for ${USERS[0]}" RC |
95 | | -test "$(testStatus ${USERS[1]})" = "$test3Result" || |
96 | | - ErrorMsg "Incorrect user/certificate status for ${USERS[1]}" RC |
97 | | - |
98 | 200 | CleanUp $RC |
99 | 201 | kill $HTTP_PID |
100 | 202 | wait $HTTP_PID |
|
0 commit comments