@@ -136,30 +136,32 @@ func (chaincodeSupport *ChaincodeSupport) launchStarted(chaincode string) bool {
136
136
}
137
137
138
138
// NewChaincodeSupport creates a new ChaincodeSupport instance
139
- func NewChaincodeSupport (ccEndpoint string , userrunsCC bool , ccstartuptimeout time.Duration , ca accesscontrol.CA ) pb.ChaincodeSupportServer {
139
+ func NewChaincodeSupport (
140
+ ccEndpoint string ,
141
+ userrunsCC bool ,
142
+ ccstartuptimeout time.Duration ,
143
+ caCert []byte ,
144
+ certGenerator CertGenerator ,
145
+ ) * ChaincodeSupport {
140
146
ccprovider .SetChaincodesPath (config .GetPath ("peer.fileSystemPath" ) + string (filepath .Separator ) + "chaincodes" )
141
147
pnid := viper .GetString ("peer.networkId" )
142
148
pid := viper .GetString ("peer.id" )
143
149
144
150
theChaincodeSupport = & ChaincodeSupport {
145
- ca : ca ,
151
+ caCert : caCert ,
152
+ certGenerator : certGenerator ,
146
153
runningChaincodes : & runningChaincodes {
147
154
chaincodeMap : make (map [string ]* chaincodeRTEnv ),
148
155
launchStarted : make (map [string ]bool ),
149
156
}, peerNetworkID : pnid , peerID : pid ,
150
157
}
151
158
152
- theChaincodeSupport .auth = accesscontrol .NewAuthenticator (theChaincodeSupport , ca )
153
159
theChaincodeSupport .peerAddress = ccEndpoint
154
160
chaincodeLogger .Infof ("Chaincode support using peerAddress: %s\n " , theChaincodeSupport .peerAddress )
155
161
156
162
theChaincodeSupport .userRunsCC = userrunsCC
157
163
theChaincodeSupport .ccStartupTimeout = ccstartuptimeout
158
-
159
164
theChaincodeSupport .peerTLS = viper .GetBool ("peer.tls.enabled" )
160
- if ! theChaincodeSupport .peerTLS {
161
- theChaincodeSupport .auth .DisableAccessCheck ()
162
- }
163
165
164
166
kadef := 0
165
167
if ka := viper .GetString ("chaincode.keepalive" ); ka == "" {
@@ -196,7 +198,7 @@ func NewChaincodeSupport(ccEndpoint string, userrunsCC bool, ccstartuptimeout ti
196
198
theChaincodeSupport .shimLogLevel = getLogLevelFromViper ("shim" )
197
199
theChaincodeSupport .logFormat = viper .GetString ("chaincode.logging.format" )
198
200
199
- return theChaincodeSupport . auth
201
+ return theChaincodeSupport
200
202
}
201
203
202
204
// getLogLevelFromViper gets the chaincode container log levels from viper
@@ -213,10 +215,17 @@ func getLogLevelFromViper(module string) string {
213
215
return levelString
214
216
}
215
217
218
+ // CertGenerator generates client certificates for chaincode.
219
+ type CertGenerator interface {
220
+ // Generate returns a certificate and private key and associates
221
+ // the hash of the certificate with the given chaincode name
222
+ Generate (ccName string ) (* accesscontrol.CertAndPrivKeyPair , error )
223
+ }
224
+
216
225
// ChaincodeSupport responsible for providing interfacing with chaincodes from the Peer.
217
226
type ChaincodeSupport struct {
218
- ca accesscontrol. CA
219
- auth accesscontrol. Authenticator
227
+ caCert [] byte
228
+ certGenerator CertGenerator
220
229
runningChaincodes * runningChaincodes
221
230
peerAddress string
222
231
ccStartupTimeout time.Duration
@@ -358,7 +367,7 @@ func (chaincodeSupport *ChaincodeSupport) getTLSFiles(keyPair *accesscontrol.Cer
358
367
return map [string ][]byte {
359
368
TLSClientKeyPath : []byte (keyPair .Key ),
360
369
TLSClientCertPath : []byte (keyPair .Cert ),
361
- TLSClientRootCertPath : chaincodeSupport .ca . CertBytes () ,
370
+ TLSClientRootCertPath : chaincodeSupport .caCert ,
362
371
}
363
372
}
364
373
@@ -379,7 +388,7 @@ func (chaincodeSupport *ChaincodeSupport) getLaunchConfigs(cccid *ccprovider.CCC
379
388
// ----------------------------------------------------------------------------
380
389
var certKeyPair * accesscontrol.CertAndPrivKeyPair
381
390
if chaincodeSupport .peerTLS {
382
- certKeyPair , err = chaincodeSupport .auth .Generate (cccid .GetCanonicalName ())
391
+ certKeyPair , err = chaincodeSupport .certGenerator .Generate (cccid .GetCanonicalName ())
383
392
if err != nil {
384
393
return nil , nil , nil , errors .WithMessage (err , fmt .Sprintf ("failed generating TLS cert for %s" , cccid .GetCanonicalName ()))
385
394
}
0 commit comments