@@ -21,17 +21,13 @@ import (
21
21
"io"
22
22
"path/filepath"
23
23
"strconv"
24
+ "strings"
24
25
"sync"
25
26
"time"
26
27
27
28
"github.com/golang/protobuf/proto"
28
- logging "github.com/op/go-logging"
29
- "github.com/spf13/viper"
30
- "golang.org/x/net/context"
31
-
32
- "strings"
33
-
34
29
"github.com/hyperledger/fabric/common/flogging"
30
+ "github.com/hyperledger/fabric/core/chaincode/accesscontrol"
35
31
"github.com/hyperledger/fabric/core/chaincode/platforms"
36
32
"github.com/hyperledger/fabric/core/chaincode/shim"
37
33
"github.com/hyperledger/fabric/core/common/ccprovider"
@@ -41,6 +37,9 @@ import (
41
37
"github.com/hyperledger/fabric/core/container/ccintf"
42
38
"github.com/hyperledger/fabric/core/ledger"
43
39
pb "github.com/hyperledger/fabric/protos/peer"
40
+ logging "github.com/op/go-logging"
41
+ "github.com/spf13/viper"
42
+ "golang.org/x/net/context"
44
43
)
45
44
46
45
type key string
@@ -49,7 +48,7 @@ const (
49
48
// DevModeUserRunsChaincode property allows user to run chaincode in development environment
50
49
DevModeUserRunsChaincode string = "dev"
51
50
chaincodeStartupTimeoutDefault int = 5000
52
- peerAddressDefault string = "0.0.0.0:7051 "
51
+ peerAddressDefault string = "0.0.0.0:7052 "
53
52
54
53
//TXSimulatorKey is used to attach ledger simulation context
55
54
TXSimulatorKey key = "txsimulatorkey"
@@ -132,38 +131,39 @@ func (chaincodeSupport *ChaincodeSupport) launchStarted(chaincode string) bool {
132
131
}
133
132
134
133
// NewChaincodeSupport creates a new ChaincodeSupport instance
135
- func NewChaincodeSupport (getCCEndpoint func () (* pb.PeerEndpoint , error ), userrunsCC bool , ccstartuptimeout time.Duration ) * ChaincodeSupport {
134
+ func NewChaincodeSupport (getCCEndpoint func () (* pb.PeerEndpoint , error ), userrunsCC bool , ccstartuptimeout time.Duration , ca accesscontrol. CA ) pb. ChaincodeSupportServer {
136
135
ccprovider .SetChaincodesPath (config .GetPath ("peer.fileSystemPath" ) + string (filepath .Separator ) + "chaincodes" )
137
-
138
136
pnid := viper .GetString ("peer.networkId" )
139
137
pid := viper .GetString ("peer.id" )
140
138
141
- theChaincodeSupport = & ChaincodeSupport {runningChaincodes : & runningChaincodes {chaincodeMap : make (map [string ]* chaincodeRTEnv ), launchStarted : make (map [string ]bool )}, peerNetworkID : pnid , peerID : pid }
139
+ theChaincodeSupport = & ChaincodeSupport {
140
+ runningChaincodes : & runningChaincodes {
141
+ chaincodeMap : make (map [string ]* chaincodeRTEnv ),
142
+ launchStarted : make (map [string ]bool ),
143
+ }, peerNetworkID : pnid , peerID : pid ,
144
+ }
142
145
143
- //initialize global chain
146
+ theChaincodeSupport . auth = accesscontrol . NewAuthenticator ( theChaincodeSupport , ca )
144
147
145
148
ccEndpoint , err := getCCEndpoint ()
146
149
if err != nil {
147
- chaincodeLogger .Errorf ("Error getting chaincode endpoint, using chaincode.peerAddress: %s" , err )
148
- theChaincodeSupport .peerAddress = viper . GetString ( "chaincode.peerAddress" )
150
+ chaincodeLogger .Errorf ("Error getting chaincode endpoint because %v , using %s" , err , peerAddressDefault )
151
+ theChaincodeSupport .peerAddress = peerAddressDefault
149
152
} else {
150
153
theChaincodeSupport .peerAddress = ccEndpoint .Address
151
154
}
152
155
chaincodeLogger .Infof ("Chaincode support using peerAddress: %s\n " , theChaincodeSupport .peerAddress )
153
- //peerAddress = viper.GetString("peer.address")
154
- if theChaincodeSupport .peerAddress == "" {
155
- theChaincodeSupport .peerAddress = peerAddressDefault
156
- }
157
156
158
157
theChaincodeSupport .userRunsCC = userrunsCC
159
-
160
158
theChaincodeSupport .ccStartupTimeout = ccstartuptimeout
161
159
162
160
theChaincodeSupport .peerTLS = viper .GetBool ("peer.tls.enabled" )
163
161
if theChaincodeSupport .peerTLS {
164
162
theChaincodeSupport .peerTLSCertFile = config .GetPath ("peer.tls.cert.file" )
165
163
theChaincodeSupport .peerTLSKeyFile = config .GetPath ("peer.tls.key.file" )
166
164
theChaincodeSupport .peerTLSSvrHostOrd = viper .GetString ("peer.tls.serverhostoverride" )
165
+ } else {
166
+ theChaincodeSupport .auth .DisableAccessCheck ()
167
167
}
168
168
169
169
kadef := 0
@@ -201,7 +201,7 @@ func NewChaincodeSupport(getCCEndpoint func() (*pb.PeerEndpoint, error), userrun
201
201
theChaincodeSupport .shimLogLevel = getLogLevelFromViper ("shim" )
202
202
theChaincodeSupport .logFormat = viper .GetString ("chaincode.logging.format" )
203
203
204
- return theChaincodeSupport
204
+ return theChaincodeSupport . auth
205
205
}
206
206
207
207
// getLogLevelFromViper gets the chaincode container log levels from viper
@@ -226,6 +226,7 @@ func getLogLevelFromViper(module string) string {
226
226
227
227
// ChaincodeSupport responsible for providing interfacing with chaincodes from the Peer.
228
228
type ChaincodeSupport struct {
229
+ auth accesscontrol.Authenticator
229
230
runningChaincodes * runningChaincodes
230
231
peerAddress string
231
232
ccStartupTimeout time.Duration
@@ -360,6 +361,13 @@ func (chaincodeSupport *ChaincodeSupport) sendReady(context context.Context, ccc
360
361
return err
361
362
}
362
363
364
+ func (chaincodeSupport * ChaincodeSupport ) appendTLScerts (args []string , keyPair * accesscontrol.CertAndPrivKeyPair ) []string {
365
+ if keyPair == nil {
366
+ return args
367
+ }
368
+ return append (args , []string {"--key" , keyPair .Key , "--cert" , keyPair .Cert }... )
369
+ }
370
+
363
371
//get args and env given chaincodeID
364
372
func (chaincodeSupport * ChaincodeSupport ) getArgsAndEnv (cccid * ccprovider.CCContext , cLang pb.ChaincodeSpec_Type ) (args []string , envs []string , err error ) {
365
373
canName := cccid .GetCanonicalName ()
@@ -375,7 +383,12 @@ func (chaincodeSupport *ChaincodeSupport) getArgsAndEnv(cccid *ccprovider.CCCont
375
383
// the image may be stale and the admin will need to remove the current containers
376
384
// before restarting the peer.
377
385
// ----------------------------------------------------------------------------
386
+ var certKeyPair * accesscontrol.CertAndPrivKeyPair
378
387
if chaincodeSupport .peerTLS {
388
+ certKeyPair , err = chaincodeSupport .auth .Generate (cccid .GetCanonicalName ())
389
+ if err != nil {
390
+ return nil , nil , fmt .Errorf ("failed generating TLS cert for %s: %v" , cccid .GetCanonicalName (), err )
391
+ }
379
392
envs = append (envs , "CORE_PEER_TLS_ENABLED=true" )
380
393
if chaincodeSupport .peerTLSSvrHostOrd != "" {
381
394
envs = append (envs , "CORE_PEER_TLS_SERVERHOSTOVERRIDE=" + chaincodeSupport .peerTLSSvrHostOrd )
@@ -398,6 +411,7 @@ func (chaincodeSupport *ChaincodeSupport) getArgsAndEnv(cccid *ccprovider.CCCont
398
411
switch cLang {
399
412
case pb .ChaincodeSpec_GOLANG , pb .ChaincodeSpec_CAR :
400
413
args = []string {"chaincode" , fmt .Sprintf ("-peer.address=%s" , chaincodeSupport .peerAddress )}
414
+ args = theChaincodeSupport .appendTLScerts (args , certKeyPair )
401
415
case pb .ChaincodeSpec_JAVA :
402
416
args = []string {"java" , "-jar" , "chaincode.jar" , "--peerAddress" , chaincodeSupport .peerAddress }
403
417
default :
0 commit comments