-
Notifications
You must be signed in to change notification settings - Fork 708
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ FAB-6452 ] fabric-ca CSR to external CA
Test the creation of CSR's in conjuction with remote signers. Test each supported request object both from file and using command-line options. Change-Id: Id9bf23193d7269368fb22d039bcad64bb3cf7bae Signed-off-by: Allen Bailey <[email protected]>
- Loading branch information
Showing
5 changed files
with
112 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
#!/bin/bash | ||
|
||
: ${TESTCASE:=gencsr} | ||
FABRIC_CA="$GOPATH/src/github.com/hyperledger/fabric-ca" | ||
SCRIPTDIR="$FABRIC_CA/scripts/fvt" | ||
CA_CFG_PATH="/tmp/$TESTCASE" | ||
ADMINUSER="admin" | ||
USERDIR="$CA_CFG_PATH/$ADMINUSER" | ||
CONFIGFILE="$USERDIR/fabric-ca-client-config.yaml" | ||
ADMINCERT="$USERDIR/admincert.pem" | ||
CSR=$CA_CFG_PATH/$ADMINUSER/msp/signcerts/$ADMINUSER.csr | ||
. $SCRIPTDIR/fabric-ca_utils | ||
RC=0 | ||
export CA_CFG_PATH | ||
rm -rf /tmp/${TESTCASE} | ||
rm -rf /tmp/CAs/${TESTCASE} | ||
|
||
function signReq() { | ||
# sign CSR | ||
HOME=$CA_CFG_PATH/$ADMINUSER reqout=$CSR \ | ||
/etc/hyperledger/fabric-ca/pki -f signreq -a $TESTCASE -p $ADMINUSER <<EOF | ||
y | ||
y | ||
EOF | ||
} | ||
|
||
function verifyResult() { | ||
artifact="$1" | ||
expected_subject="$2" | ||
case $artifact in | ||
cert) actual_subject="$(openssl x509 -in $ADMINCERT -noout -subject -nameopt rfc2253 |sed 's/subject= //')" | ||
;; | ||
csr) actual_subject="$(openssl req -in $CSR -noout -subject -nameopt rfc2253 |sed 's/subject=//')" | ||
;; | ||
esac | ||
echo expected_subject: $expected_subject | ||
test "$expected_subject" = "$actual_subject" || ErrorMsg "expected \n\"$expected_subject\"\n found \"$actual_subject\"" | ||
} | ||
|
||
# Create a new external PKI CA | ||
/etc/hyperledger/fabric-ca/pki -f newca -a $TESTCASE | ||
|
||
# supply CN at the command line | ||
expected="CN=$ADMINUSER,OU=Fabric,O=Hyperledger,ST=North Carolina,C=US" | ||
fabric-ca-client gencsr --csr.cn "$ADMINUSER" -H $CA_CFG_PATH/$ADMINUSER | ||
openssl req -noout -in /tmp/gencsr/admin/msp/signcerts/admin.csr -subject | sed 's/subject=//' | ||
openssl req -noout -in $CSR -subject | sed 's/subject=//' | ||
verifyResult csr "$expected" | ||
signReq | ||
verifyResult cert "$expected" | ||
|
||
# supply CN from a file | ||
sed -i "s/cn:.*/cn: $ADMINUSER/" $USERDIR/fabric-ca-client-config.yaml | grep cn: | ||
fabric-ca-client gencsr -H $CA_CFG_PATH/$ADMINUSER | ||
openssl req -noout -in /tmp/gencsr/admin/msp/signcerts/admin.csr -subject | sed 's/subject=//' | ||
openssl req -noout -in $CSR -subject | sed 's/subject=//' | ||
verifyResult csr "$expected" | ||
signReq | ||
verifyResult cert "$expected" | ||
|
||
# CN from command line overrides file | ||
CSR=$CA_CFG_PATH/$ADMINUSER/msp/signcerts/new$ADMINUSER.csr | ||
expected="CN=new$ADMINUSER,OU=Fabric,O=Hyperledger,ST=North Carolina,C=US" | ||
fabric-ca-client gencsr --csr.cn "new$ADMINUSER" -H $CA_CFG_PATH/$ADMINUSER | ||
openssl req -noout -in /tmp/gencsr/admin/msp/signcerts/admin.csr -subject | sed 's/subject=//' | ||
openssl req -noout -in $CSR -subject | sed 's/subject=//' | ||
verifyResult csr "$expected" | ||
signReq | ||
verifyResult cert "$expected" | ||
|
||
## Supply names from file | ||
sed -i "s/C:.*/C: FR/ | ||
s/ST:.*/ST: Cantal/ | ||
s/ST:.*/ST: Cantal/ | ||
s/L:.*/L: Salers/ | ||
s/O:.*/O: Gourmet/ | ||
s/serialnumber:.*/serialnumber: ABCDEFGHIJKLMNOPQRSTUVWXYZ/" $USERDIR/fabric-ca-client-config.yaml | ||
CSR=$CA_CFG_PATH/$ADMINUSER/msp/signcerts/$ADMINUSER.csr | ||
expected="serialNumber=ABCDEFGHIJKLMNOPQRSTUVWXYZ,CN=admin,OU=Fabric,O=Gourmet,L=Salers,ST=Cantal,C=FR" | ||
fabric-ca-client gencsr -H $CA_CFG_PATH/$ADMINUSER | ||
openssl req -noout -in /tmp/gencsr/admin/msp/signcerts/admin.csr -subject | sed 's/subject=//' | ||
openssl req -noout -in $CSR -subject | sed 's/subject=//' | ||
verifyResult csr "$expected" | ||
signReq | ||
verifyResult cert "$expected" | ||
cat $USERDIR/fabric-ca-client-config.yaml | ||
# Names from command line overrides file | ||
CSR=$CA_CFG_PATH/$ADMINUSER/msp/signcerts/$ADMINUSER.csr | ||
expected='serialNumber=0123456789,CN=admin,OU=Vieux,O=Moulin,L=Charleville-M\C3\A9zi\C3\A8rs,ST=Ardennes,C=FR' | ||
fabric-ca-client gencsr --csr.names C=FR,ST=Ardennes,L=Charleville-Mézièrs,O=Moulin,OU=Vieux \ | ||
--csr.hosts 1.1.1.1,::1,example.com,[email protected] \ | ||
--csr.serialnumber "0123456789" \ | ||
--csr.cn admin \ | ||
-H $CA_CFG_PATH/$ADMINUSER | ||
openssl req -noout -in /tmp/gencsr/admin/msp/signcerts/admin.csr -subject | sed 's/subject=//' | ||
openssl req -noout -in $CSR -subject | sed 's/subject=//' | ||
verifyResult csr "$expected" | ||
signReq | ||
verifyResult cert "$expected" | ||
|
||
CleanUp $RC | ||
exit $RC |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters