Fabricに統合されたca
5635 ワード
テストディレクトリへ
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli
docker-compose-cli.yaml org 1にcaコンテナを追加 ca0:
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca0
- FABRIC_CA_SERVER_TLS_ENABLED=false
ports:
- "7054:7054"
command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/${PRIVATE_KEY} -b admin:adminpw -d'
volumes:
- ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
container_name: ca0
ca.certfile CA
ca.keyfile
-b CA Client CA Server
network_の変更setup.shスクリプトはCAコンテナ起動のパラメータに持ち込む folder="crypto-config/peerOrganizations/org1.example.com/ca"
privName=""
for file_a in ${folder}/*
do
temp_file=`basename $file_a`
if [ ${temp_file##*.} != "pem" ];then
privName=$temp_file
fi
done
echo $privName
CHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE up -d 2>&1
CHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT PRIVATE_KEY=$privName docker-compose -f $COMPOSE_FILE up -d 2>&1
fabricネットワークの起動
./network_setup.sh up
Fabric CA Clientのダウンロードとインストール
git clone https://github.com/hyperledger/fabric-ca $GOPATH/src/github.com/hyperledger/fabric-ca cd $GOPATH/src/github.com/hyperledger/fabric-ca make all cp -f bin/* $GOPATH/bin/
資格認定管理者の登録
export FABRIC_CA_CLIENT_HOME=$HOME/ca && fabric-ca-client enroll -u http://admin:adminpw@localhost:7054$HOME/caディレクトリの下にfabric-ca-client-configが作成されます.yamlファイルとmspフォルダ
新規ユーザーの登録
fabric-ca-client register --id.name devin --id.type user --id.affiliation org1.department1 --id.attrs 'hf.Revoker=true,foo=bar' 2017/10/19 16:44:57 [INFO] User provided config file:/root/ca/fabric-ca-client-config.yaml 2017/10/19 16:44:57 [INFO] Configuration file location:/root/ca/fabric-ca-client-config.yaml Password: vpjiGEcqJUHN
パスワードvpjiGEcqJUHNでユーザーdevinの秘密鍵と証明書を生成
fabric-ca-client enroll -u http://devin:vpjiGEcqJUHN@localhost:7054 -M $FABRIC_CA_CLIENT_HOME/devinmsp
新しいユーザー秘密鍵と証明書のコピー
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/peerOrganizations/org1.example.com/users mkdir devin cp -rf ~/ca/devinmsp devin/msp
mkdir devin/msp/admincerts cp devin/msp/signcerts/cert.pem devin/msp/admincerts/
ユーザーを検証するためのテストチェーンコードの作成
cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/mkdir test1 && cd test1/vim test1.go package main
import (
"bytes"
"crypto/x509"
"encoding/pem"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
type SimpleChaincode struct {
}
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
function, args := stub.GetFunctionAndParameters()
fmt.Println("invoke is running " + function)
if function == "cert" {
return t.testCertificate(stub, args)
}
return shim.Error("Received unknown function invocation")
}
func (t *SimpleChaincode) testCertificate(stub shim.ChaincodeStubInterface, args []string) pb.Response {
creatorByte, _ := stub.GetCreator()
certStart := bytes.IndexAny(creatorByte, "-----")
if certStart == -1 {
fmt.Errorf("No certificate found")
}
certText := creatorByte[certStart:]
bl, _ := pem.Decode(certText)
if bl == nil {
fmt.Errorf("Could not decode the PEM structure")
}
fmt.Println(string(certText))
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
fmt.Errorf("ParseCertificate failed")
}
fmt.Println(cert)
uname := cert.Subject.CommonName
fmt.Println("Name" + uname)
return shim.Success([]byte("Called testCertificate " + uname))
}
func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
fmt.Printf("Error starting SimpleChaincode: %s", err)
}
}
cliに入ってチェーンコードをインストールして実行します
docker exec -it cli bash
peer chaincode install -n test1 -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/test1 ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n test1 -v 1.0 -c '{"Args":[]}' peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate [email protected]
新しいユーザーの検証
相変わらずcliでCORE_を実行PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/devin/msp peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate devin
リファレンスドキュメント
Fabric CA環境の統合http://www.cnblogs.com/studyzy/p/7482451.html
ca0:
image: hyperledger/fabric-ca
environment:
- FABRIC_CA_HOME=/etc/hyperledger/fabric-ca-server
- FABRIC_CA_SERVER_CA_NAME=ca0
- FABRIC_CA_SERVER_TLS_ENABLED=false
ports:
- "7054:7054"
command: sh -c 'fabric-ca-server start --ca.certfile /etc/hyperledger/fabric-ca-server-config/ca.org1.example.com-cert.pem --ca.keyfile /etc/hyperledger/fabric-ca-server-config/${PRIVATE_KEY} -b admin:adminpw -d'
volumes:
- ./crypto-config/peerOrganizations/org1.example.com/ca/:/etc/hyperledger/fabric-ca-server-config
container_name: ca0
ca.certfile CA
ca.keyfile
-b CA Client CA Server
network_の変更setup.shスクリプトはCAコンテナ起動のパラメータに持ち込む folder="crypto-config/peerOrganizations/org1.example.com/ca"
privName=""
for file_a in ${folder}/*
do
temp_file=`basename $file_a`
if [ ${temp_file##*.} != "pem" ];then
privName=$temp_file
fi
done
echo $privName
CHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE up -d 2>&1
CHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT PRIVATE_KEY=$privName docker-compose -f $COMPOSE_FILE up -d 2>&1
fabricネットワークの起動
./network_setup.sh up
Fabric CA Clientのダウンロードとインストール
git clone https://github.com/hyperledger/fabric-ca $GOPATH/src/github.com/hyperledger/fabric-ca cd $GOPATH/src/github.com/hyperledger/fabric-ca make all cp -f bin/* $GOPATH/bin/
資格認定管理者の登録
export FABRIC_CA_CLIENT_HOME=$HOME/ca && fabric-ca-client enroll -u http://admin:adminpw@localhost:7054$HOME/caディレクトリの下にfabric-ca-client-configが作成されます.yamlファイルとmspフォルダ
新規ユーザーの登録
fabric-ca-client register --id.name devin --id.type user --id.affiliation org1.department1 --id.attrs 'hf.Revoker=true,foo=bar' 2017/10/19 16:44:57 [INFO] User provided config file:/root/ca/fabric-ca-client-config.yaml 2017/10/19 16:44:57 [INFO] Configuration file location:/root/ca/fabric-ca-client-config.yaml Password: vpjiGEcqJUHN
パスワードvpjiGEcqJUHNでユーザーdevinの秘密鍵と証明書を生成
fabric-ca-client enroll -u http://devin:vpjiGEcqJUHN@localhost:7054 -M $FABRIC_CA_CLIENT_HOME/devinmsp
新しいユーザー秘密鍵と証明書のコピー
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/peerOrganizations/org1.example.com/users mkdir devin cp -rf ~/ca/devinmsp devin/msp
mkdir devin/msp/admincerts cp devin/msp/signcerts/cert.pem devin/msp/admincerts/
ユーザーを検証するためのテストチェーンコードの作成
cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/mkdir test1 && cd test1/vim test1.go package main
import (
"bytes"
"crypto/x509"
"encoding/pem"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
type SimpleChaincode struct {
}
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
function, args := stub.GetFunctionAndParameters()
fmt.Println("invoke is running " + function)
if function == "cert" {
return t.testCertificate(stub, args)
}
return shim.Error("Received unknown function invocation")
}
func (t *SimpleChaincode) testCertificate(stub shim.ChaincodeStubInterface, args []string) pb.Response {
creatorByte, _ := stub.GetCreator()
certStart := bytes.IndexAny(creatorByte, "-----")
if certStart == -1 {
fmt.Errorf("No certificate found")
}
certText := creatorByte[certStart:]
bl, _ := pem.Decode(certText)
if bl == nil {
fmt.Errorf("Could not decode the PEM structure")
}
fmt.Println(string(certText))
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
fmt.Errorf("ParseCertificate failed")
}
fmt.Println(cert)
uname := cert.Subject.CommonName
fmt.Println("Name" + uname)
return shim.Success([]byte("Called testCertificate " + uname))
}
func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
fmt.Printf("Error starting SimpleChaincode: %s", err)
}
}
cliに入ってチェーンコードをインストールして実行します
docker exec -it cli bash
peer chaincode install -n test1 -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/test1 ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n test1 -v 1.0 -c '{"Args":[]}' peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate [email protected]
新しいユーザーの検証
相変わらずcliでCORE_を実行PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/devin/msp peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate devin
リファレンスドキュメント
Fabric CA環境の統合http://www.cnblogs.com/studyzy/p/7482451.html
folder="crypto-config/peerOrganizations/org1.example.com/ca"
privName=""
for file_a in ${folder}/*
do
temp_file=`basename $file_a`
if [ ${temp_file##*.} != "pem" ];then
privName=$temp_file
fi
done
echo $privName
CHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT docker-compose -f $COMPOSE_FILE up -d 2>&1
CHANNEL_NAME=$CH_NAME TIMEOUT=$CLI_TIMEOUT PRIVATE_KEY=$privName docker-compose -f $COMPOSE_FILE up -d 2>&1
./network_setup.sh up
Fabric CA Clientのダウンロードとインストール
git clone https://github.com/hyperledger/fabric-ca $GOPATH/src/github.com/hyperledger/fabric-ca cd $GOPATH/src/github.com/hyperledger/fabric-ca make all cp -f bin/* $GOPATH/bin/
資格認定管理者の登録
export FABRIC_CA_CLIENT_HOME=$HOME/ca && fabric-ca-client enroll -u http://admin:adminpw@localhost:7054$HOME/caディレクトリの下にfabric-ca-client-configが作成されます.yamlファイルとmspフォルダ
新規ユーザーの登録
fabric-ca-client register --id.name devin --id.type user --id.affiliation org1.department1 --id.attrs 'hf.Revoker=true,foo=bar' 2017/10/19 16:44:57 [INFO] User provided config file:/root/ca/fabric-ca-client-config.yaml 2017/10/19 16:44:57 [INFO] Configuration file location:/root/ca/fabric-ca-client-config.yaml Password: vpjiGEcqJUHN
パスワードvpjiGEcqJUHNでユーザーdevinの秘密鍵と証明書を生成
fabric-ca-client enroll -u http://devin:vpjiGEcqJUHN@localhost:7054 -M $FABRIC_CA_CLIENT_HOME/devinmsp
新しいユーザー秘密鍵と証明書のコピー
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/peerOrganizations/org1.example.com/users mkdir devin cp -rf ~/ca/devinmsp devin/msp
mkdir devin/msp/admincerts cp devin/msp/signcerts/cert.pem devin/msp/admincerts/
ユーザーを検証するためのテストチェーンコードの作成
cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/mkdir test1 && cd test1/vim test1.go package main
import (
"bytes"
"crypto/x509"
"encoding/pem"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
type SimpleChaincode struct {
}
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
function, args := stub.GetFunctionAndParameters()
fmt.Println("invoke is running " + function)
if function == "cert" {
return t.testCertificate(stub, args)
}
return shim.Error("Received unknown function invocation")
}
func (t *SimpleChaincode) testCertificate(stub shim.ChaincodeStubInterface, args []string) pb.Response {
creatorByte, _ := stub.GetCreator()
certStart := bytes.IndexAny(creatorByte, "-----")
if certStart == -1 {
fmt.Errorf("No certificate found")
}
certText := creatorByte[certStart:]
bl, _ := pem.Decode(certText)
if bl == nil {
fmt.Errorf("Could not decode the PEM structure")
}
fmt.Println(string(certText))
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
fmt.Errorf("ParseCertificate failed")
}
fmt.Println(cert)
uname := cert.Subject.CommonName
fmt.Println("Name" + uname)
return shim.Success([]byte("Called testCertificate " + uname))
}
func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
fmt.Printf("Error starting SimpleChaincode: %s", err)
}
}
cliに入ってチェーンコードをインストールして実行します
docker exec -it cli bash
peer chaincode install -n test1 -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/test1 ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n test1 -v 1.0 -c '{"Args":[]}' peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate [email protected]
新しいユーザーの検証
相変わらずcliでCORE_を実行PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/devin/msp peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate devin
リファレンスドキュメント
Fabric CA環境の統合http://www.cnblogs.com/studyzy/p/7482451.html
export FABRIC_CA_CLIENT_HOME=$HOME/ca && fabric-ca-client enroll -u http://admin:adminpw@localhost:7054$HOME/caディレクトリの下にfabric-ca-client-configが作成されます.yamlファイルとmspフォルダ
新規ユーザーの登録
fabric-ca-client register --id.name devin --id.type user --id.affiliation org1.department1 --id.attrs 'hf.Revoker=true,foo=bar' 2017/10/19 16:44:57 [INFO] User provided config file:/root/ca/fabric-ca-client-config.yaml 2017/10/19 16:44:57 [INFO] Configuration file location:/root/ca/fabric-ca-client-config.yaml Password: vpjiGEcqJUHN
パスワードvpjiGEcqJUHNでユーザーdevinの秘密鍵と証明書を生成
fabric-ca-client enroll -u http://devin:vpjiGEcqJUHN@localhost:7054 -M $FABRIC_CA_CLIENT_HOME/devinmsp
新しいユーザー秘密鍵と証明書のコピー
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/peerOrganizations/org1.example.com/users mkdir devin cp -rf ~/ca/devinmsp devin/msp
mkdir devin/msp/admincerts cp devin/msp/signcerts/cert.pem devin/msp/admincerts/
ユーザーを検証するためのテストチェーンコードの作成
cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/mkdir test1 && cd test1/vim test1.go package main
import (
"bytes"
"crypto/x509"
"encoding/pem"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
type SimpleChaincode struct {
}
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
function, args := stub.GetFunctionAndParameters()
fmt.Println("invoke is running " + function)
if function == "cert" {
return t.testCertificate(stub, args)
}
return shim.Error("Received unknown function invocation")
}
func (t *SimpleChaincode) testCertificate(stub shim.ChaincodeStubInterface, args []string) pb.Response {
creatorByte, _ := stub.GetCreator()
certStart := bytes.IndexAny(creatorByte, "-----")
if certStart == -1 {
fmt.Errorf("No certificate found")
}
certText := creatorByte[certStart:]
bl, _ := pem.Decode(certText)
if bl == nil {
fmt.Errorf("Could not decode the PEM structure")
}
fmt.Println(string(certText))
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
fmt.Errorf("ParseCertificate failed")
}
fmt.Println(cert)
uname := cert.Subject.CommonName
fmt.Println("Name" + uname)
return shim.Success([]byte("Called testCertificate " + uname))
}
func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
fmt.Printf("Error starting SimpleChaincode: %s", err)
}
}
cliに入ってチェーンコードをインストールして実行します
docker exec -it cli bash
peer chaincode install -n test1 -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/test1 ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n test1 -v 1.0 -c '{"Args":[]}' peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate [email protected]
新しいユーザーの検証
相変わらずcliでCORE_を実行PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/devin/msp peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate devin
リファレンスドキュメント
Fabric CA環境の統合http://www.cnblogs.com/studyzy/p/7482451.html
fabric-ca-client enroll -u http://devin:vpjiGEcqJUHN@localhost:7054 -M $FABRIC_CA_CLIENT_HOME/devinmsp
新しいユーザー秘密鍵と証明書のコピー
cd $GOPATH/src/github.com/hyperledger/fabric/examples/e2e_cli/crypto-config/peerOrganizations/org1.example.com/users mkdir devin cp -rf ~/ca/devinmsp devin/msp
mkdir devin/msp/admincerts cp devin/msp/signcerts/cert.pem devin/msp/admincerts/
ユーザーを検証するためのテストチェーンコードの作成
cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/mkdir test1 && cd test1/vim test1.go package main
import (
"bytes"
"crypto/x509"
"encoding/pem"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
type SimpleChaincode struct {
}
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
function, args := stub.GetFunctionAndParameters()
fmt.Println("invoke is running " + function)
if function == "cert" {
return t.testCertificate(stub, args)
}
return shim.Error("Received unknown function invocation")
}
func (t *SimpleChaincode) testCertificate(stub shim.ChaincodeStubInterface, args []string) pb.Response {
creatorByte, _ := stub.GetCreator()
certStart := bytes.IndexAny(creatorByte, "-----")
if certStart == -1 {
fmt.Errorf("No certificate found")
}
certText := creatorByte[certStart:]
bl, _ := pem.Decode(certText)
if bl == nil {
fmt.Errorf("Could not decode the PEM structure")
}
fmt.Println(string(certText))
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
fmt.Errorf("ParseCertificate failed")
}
fmt.Println(cert)
uname := cert.Subject.CommonName
fmt.Println("Name" + uname)
return shim.Success([]byte("Called testCertificate " + uname))
}
func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
fmt.Printf("Error starting SimpleChaincode: %s", err)
}
}
cliに入ってチェーンコードをインストールして実行します
docker exec -it cli bash
peer chaincode install -n test1 -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/test1 ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n test1 -v 1.0 -c '{"Args":[]}' peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate [email protected]
新しいユーザーの検証
相変わらずcliでCORE_を実行PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/devin/msp peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate devin
リファレンスドキュメント
Fabric CA環境の統合http://www.cnblogs.com/studyzy/p/7482451.html
cd $GOPATH/src/github.com/hyperledger/fabric/examples/chaincode/go/mkdir test1 && cd test1/vim test1.go
package main
import (
"bytes"
"crypto/x509"
"encoding/pem"
"fmt"
"github.com/hyperledger/fabric/core/chaincode/shim"
pb "github.com/hyperledger/fabric/protos/peer"
)
type SimpleChaincode struct {
}
func (t *SimpleChaincode) Init(stub shim.ChaincodeStubInterface) pb.Response {
return shim.Success(nil)
}
func (t *SimpleChaincode) Invoke(stub shim.ChaincodeStubInterface) pb.Response {
function, args := stub.GetFunctionAndParameters()
fmt.Println("invoke is running " + function)
if function == "cert" {
return t.testCertificate(stub, args)
}
return shim.Error("Received unknown function invocation")
}
func (t *SimpleChaincode) testCertificate(stub shim.ChaincodeStubInterface, args []string) pb.Response {
creatorByte, _ := stub.GetCreator()
certStart := bytes.IndexAny(creatorByte, "-----")
if certStart == -1 {
fmt.Errorf("No certificate found")
}
certText := creatorByte[certStart:]
bl, _ := pem.Decode(certText)
if bl == nil {
fmt.Errorf("Could not decode the PEM structure")
}
fmt.Println(string(certText))
cert, err := x509.ParseCertificate(bl.Bytes)
if err != nil {
fmt.Errorf("ParseCertificate failed")
}
fmt.Println(cert)
uname := cert.Subject.CommonName
fmt.Println("Name" + uname)
return shim.Success([]byte("Called testCertificate " + uname))
}
func main() {
err := shim.Start(new(SimpleChaincode))
if err != nil {
fmt.Printf("Error starting SimpleChaincode: %s", err)
}
}
cliに入ってチェーンコードをインストールして実行します
docker exec -it cli bash
peer chaincode install -n test1 -v 1.0 -p github.com/hyperledger/fabric/examples/chaincode/go/test1 ORDERER_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem peer chaincode instantiate -o orderer.example.com:7050 --tls true --cafile $ORDERER_CA -C mychannel -n test1 -v 1.0 -c '{"Args":[]}' peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate [email protected]
新しいユーザーの検証
相変わらずcliでCORE_を実行PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/devin/msp peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate devin
リファレンスドキュメント
Fabric CA環境の統合http://www.cnblogs.com/studyzy/p/7482451.html
相変わらずcliでCORE_を実行PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/devin/msp peer chaincode query -C mychannel -n test1 -c '{"Args":["cert"]}'
Query Result: Called testCertificate devin